[fpc-devel] Creating a Cocoa Application

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Sun Jan 6 11:39:29 CET 2008


Hello,

I'm again, trying to do some slow progress on the task of writting a
cocoa application in pascal. We have objc runtime headers translated,
but there are no examples explaining how to use them. In the past I
posted to Apple mailling lists without sucess, so maybe someone could
help me "reverse engineer" a simple example and go from there.

Attached one can find a trivial objective-c application (main.m) and
it's corresponding assembler code (main.asm).

It should be noted that any code written in objective-c should be
possible to describe in a procedural way using calls to the
objective-c runtime library.

So, here is how the app starts:

#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[])
{
    // Any ideas what is this? It will first call NSAutoreleasePool
alloc method and then the init method??
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

    // The next 2 should be simple procedures AFAIK, no not much
problem with them.
    NSApplicationLoad();
	/* uses a default "OK" button and no alternate buttons */
    NSRunAlertPanel(@"This is the title", @"This is the message", nil,
nil, nil);

    // Call release method from object pool
    [pool release];

    return 0;
}

I read the corresponding assembler code, but it's *very* confusing.

The order in which CALL's are made is:

        // NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
	call	L_objc_getClass$stub
	call	L_objc_msgSend$stub
	call	L_objc_msgSend$stub

        // The 2 simple procedures afaik
	call	L_NSApplicationLoad$stub
	call	L_NSRunAlertPanel$stub

        // [pool release];
	call	L_objc_msgSend$stub

So, getting which procedures are called where isn't that hard, but I
couldn't understand what is filled on the parameters. Any ideas?

By the way, what does the instruction "leal" do?? I don't remember
anything similar from intel intructions tables:
	leal	L_OBJC_SELECTOR_REFERENCES_0-"L00000000001$pb"(%ebx), %eax

thanks,
-- 
Felipe Monteiro de Carvalho
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.m
Type: application/octet-stream
Size: 477 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20080106/2ae7831a/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.s
Type: application/octet-stream
Size: 4884 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20080106/2ae7831a/attachment-0001.obj>


More information about the fpc-devel mailing list