[Prev][Next][Index][Thread]

Re: Objective C bridge



On Monday, March 12, 2001, at 05:15 PM, Dustin Voss wrote:

> In article <1227715686-170041908@tdv.com>, Rob Myers <robm@tdv.com>  
> wrote: 
>  
> > Here's some code to dynamically register classes and methods with the  
> > Apple Objctive-C runtime. 
>  
> This is extremely useful. I've asked the Objective C newsgroup for  
> information on the runtime API, but they never responded. They're in the  
> midst of some standards war over there. 

Still? I unsubscribed from c.l.o-c ages ago because of that. :-(

> Where did you get this from? The Omni site? 

It's original code. I pieced together what needed doing from Darwin open source code, PyObjc, the output of  a couple of test programs, and the listing I posted before. :-)

It should be possible to build the descriptors (the "@4@4:8" in the listing) using macros in much the same way as melange builds c-calls. I'm still not 100% clear on Objective-C method passing, objc method IMPs are defined as id (*IMP)(id this, SEL selector, ...) IIRC, so we could just walk the parameter list and pass it to the Dylan code in #rest if this is the case for all methods (which I don't think it is).

Instantiating a Dylan object when the Obj-c class is instantiated means registering a Dylan callback that makes the object as the Class's alloc (or init?) method. Given that we are in control of the size of the memory block allocated for each instance (Class->instance_size) we can just add sizeof(void*) to the end of each Dylan Bridge instance and store the Dylan object reference there. So after glue is generated, "this" should be a Dylan object to Dylan code and an Obj-c object to Obj-c code. 

- Rob.

--
Rob Myers - http://www.robmyers.org/dylan
Advanced Free Software Development Tools -
http://www.gwydiondylan.org/