ASM help needed... (on x86/windows/gcc)
I want to do a binding to ObjectiveC Basically I need to implement a function like retval_t objc_msg_send(id obj, SEL sel, ...); which would forward its call (same arguments, including the unidentified ... (va_list)) to an other function know by pointer which would be looked up from the 1st 2 parameters. the return value should be forwarded too!! I was thinking to something as below (a simple jump!), but I'm not sure: 1. it will work (maye the puch/pop will overwrite fct?! my ASM is ten years old...) 2. of the syntax pseudo code to be corrected (for x86/windows/gcc): return_t objc_msg_send(id obj, SEL sel, ...) { asm pushall; void (*)() fct = lookup(obj, sel); asm popall; asm longjmp fct; } Note to those knowing a bit of ObjC: No, this function is absolutely not implemented on GNUstep, although it could be found on NeXT and MacOSX, tss
Re: ASM help needed... (on x86/windows/gcc)
Simple, I'm building an ObjectiveC binding from .NET. Basically my .NET code generator transform all objectiveC method in a call to objc_msg_send() (from the .NET code, which could call C directly) the problem with _built_in_apply() is you need to know the size of the stack. and that's a real issue for method such as +stringWithFormat:... with takes a variable number of argument - Original Message - From: "Andrew Pinski" <[EMAIL PROTECTED]> To: "Mike Stump" <[EMAIL PROTECTED]> Cc: "Lloyd Dupont" <[EMAIL PROTECTED]>; Sent: Friday, May 20, 2005 9:53 AM Subject: Re: ASM help needed... (on x86/windows/gcc) On May 19, 2005, at 7:49 PM, Mike Stump wrote: On May 19, 2005, at 4:08 PM, Lloyd Dupont wrote: I want to do a binding to ObjectiveC For how you described the question, libffi would be the natural choice and obviates the need for asms or machine dependencies. Maybe Andrew might have some insight into something libobjc specific that might help... The real question is why do you need objc_msg_send? That function is only used for the NeXT runtime. You can use the __builtin_apply/__builtin_return to implement this but I will warn you that they are really don't work for a lot of stuff. You should be using higher level constructs like -[forward::] and stuff. Thanks, Andrew Pinski
Re: ASM help needed... (on x86/windows/gcc)
The problem with ffi and such (from the little I know of them) is that I might have to forward function with an unknown number of parameter (such as printf) whereas a little longjmp would solve all my problem, wouldn't it? - Original Message - From: "Mike Stump" <[EMAIL PROTECTED]> To: "Lloyd Dupont" <[EMAIL PROTECTED]> Cc: Sent: Friday, May 20, 2005 9:49 AM Subject: Re: ASM help needed... (on x86/windows/gcc) On May 19, 2005, at 4:08 PM, Lloyd Dupont wrote: I want to do a binding to ObjectiveC For how you described the question, libffi would be the natural choice and obviates the need for asms or machine dependencies. Maybe Andrew might have some insight into something libobjc specific that might help...
Re: ASM help needed... (on x86/windows/gcc)
After lots of test, (and some experimental ASM which I quickly discard for my too rusty ASM skills) I found this nice solution build from idea from the sources: (However an ASM version with a jump would have been much more reliable (regarding argument forwarding, particularly with variable argument list), simple and fast): --- DLL_EXPORT retval_t objcsharp_msg_send(id obj, const char* msg, ...) { void* args = __builtin_apply_args(); SEL sel = sel_get_uid(msg); Method_t m = class_get_instance_method (obj->class_pointer, sel); if(m != NULL) { __builtin_return( __builtin_apply( (void(*)()) m->method_imp, args, method_get_sizeof_arguments(m) )); } else { SEL frwd_sel = sel_get_any_uid("forwardInvocation:"); if(sel && __objc_responds_to (obj, frwd_sel)) { NSInvocation * i = [[NSInvocation alloc] initWithArgframe: args selector: sel]; [i autorelease]; [obj forwardInvocation:i]; } else { objc_error (obj, OBJC_ERR_UNIMPLEMENTED, "ObjectiveC Runtime error, unimplemented method: %s\n", msg); } return 0; } } --- for info here was the kind of ASM I was looking at: pseudo ASM (failing) -- retval_t objc_msgSend(id obj, SEL sel, ...) { asm(" pusha \r\n"); IMP imp = objc_msg_lookup(obj, sel); asm(" popa \r\n"); asm( "longjmp %0 \r\n" : "=p" (imp) ); } - ----- Original Message - From: "Andrew Pinski" <[EMAIL PROTECTED]> To: "Lloyd Dupont" <[EMAIL PROTECTED]> Cc: "Mike Stump" <[EMAIL PROTECTED]>; Sent: Friday, May 20, 2005 10:25 AM Subject: Re: ASM help needed... (on x86/windows/gcc) On May 19, 2005, at 8:10 PM, Lloyd Dupont wrote: Simple, I'm building an ObjectiveC binding from .NET. Basically my .NET code generator transform all objectiveC method in a call to objc_msg_send() (from the .NET code, which could call C directly) the problem with _built_in_apply() is you need to know the size of the stack. and that's a real issue for method such as +stringWithFormat:... with takes a variable number of argument I would suggest you look into how libobjc implements forward. Thanks, Andrew Pinski