First off: Wow! I think a system that is able to easily incorporate c++
into a free cl will open up a wide range of possibilities. Your work
will be greatly appreciated. Myself, I'd like to itegrate sbcl with a 3d
scenegraph system like Ogre or CrystalSpace at some point and this
should make it a relative snap since they are inevitably written in c++.
I'm just a cl beginner myself, but it seems like a CLOS wrapper around
each class and some generated generic methods could be made to handle
overloaded methods. On the other hand, the more direct alien interface
might remain exposed for performance reasons.
John Morrison wrote:
> Hi All;
> I have some CL code that parses the output of the latest GCCXML to
> produce sb-alien bindings so one can call the C++ from SBCl. For what
> it's worth, I would like to make the code available under some
> non-commercial-hostile license to assuage my guilt for using SBCL and
> CMUCL for many years. The code is fairly grotesque as of the moment
> ("if I had a dog that looked like that, I'd shave its butt and make it
> walks backwards"), but it works on my admittedly small test suite
> (well, instance variables have yet to be done, as there are some
> issues regarding location of base class instance variables within the
> memory of the derived class instance). It is also, right now,
> specific to GCC (GCCXML is reputed to be able to "imitate" other
> compilers, but I haven't tried it).
> As my Common Lisp kung fu in general is woefully inadequate, and my
> SB-ALIEN kung fu is even worse, I come seeking Enlightenment regarding
> the most aesthetically-pleasing shape the generated code should take.
> E.g., right now one allocates and initializes a C++ instance
> separately by first calling "make-alien" and then calling the
> constructor (ugly, bug-prone).
> (Q1) Should I stick with my separate functions for each class method,
> or should I attempt to emit a CLOS class for each C++ class, call
> "make-alien" and then the right constructor in an initialize-instance
> method, and define CLOS methods for each C++ method? Should I try and
> provide keyword args for the various constructor arguments?
> (Q2) How should I best handle naming issues when it comes to C++
> function overloading? E.g., If there are several constructors with
> various arguments, is there some CL/SBCL/ALIEN type-checking magic
> that will enable SBCL to call the "right" C++ constructor, or do I
> stick with my ugly hack of appending the mangled,
> guaranteed-to-be-unique character string? (E.g., new-class1-C1Ev for
> class1's constructor of no args other than "self")
> Any other advice?
> --- C++ starts here ---
> class class1
> void class1method(void);
> void class1method2(int);
> int class1slot1int;
> --- Auto-generated alien bindings start here ---
> (defmacro d-a-r (cppname lispname &rest r)
> `(define-alien-routine (,cppname ,lispname) ,@r))
> (array char 32)) ; Note slot definitions are missing
> (d-a-r "_ZN6class113class1method2Ei"
> (self (* class1)) (arg3052 sb-alien:int)) ; method
> (d-a-r "_ZN6class112class1methodEv"
> class1-class1method sb-alien:void
> (self (* class1)) ) ; method _ZN6class112class1methodEv
> (d-a-r "_ZN6class1D1Ev"
> delete-class1 sb-alien:void
> (self (* class1))) ; delete-class1
> (d-a-r "_ZN6class1C1Ev"
> sb-alien:void (self (* class1)) )
> --- Common Lisp usage code starts here ---
> (defvar c1 (make-alien class1))
> (with-alien () (new-class1-C1Ev c1))
> (with-alien () (class1-class1method2 c1 456))
> (with-alien ()
> (delete-class1 c1)