diff options
Diffstat (limited to 'Objective-C')
-rw-r--r-- | Objective-C/libobjcl.h | 27 | ||||
-rw-r--r-- | Objective-C/libobjcl.m | 230 |
2 files changed, 0 insertions, 257 deletions
diff --git a/Objective-C/libobjcl.h b/Objective-C/libobjcl.h index 8b37609..fae8636 100644 --- a/Objective-C/libobjcl.h +++ b/Objective-C/libobjcl.h @@ -11,33 +11,6 @@ extern NSException *objcl_oom_exception; -typedef struct objcl_object -{ - char* type; - - union - { - id id_val; - Class class_val; - NSException *exc_val; - SEL sel_val; - char char_val; - short short_val; - int int_val; - long long_val; - long long long_long_val; - float float_val; - double double_val; - BOOL bool_val; - char *charptr_val; - void *ptr_val; - } data; -} *OBJCL_OBJ_DATA; - - -#define EXCEPTION_TYPESPEC "ERROR" - - void objcl_initialise_runtime (void); diff --git a/Objective-C/libobjcl.m b/Objective-C/libobjcl.m index 15855ed..11450f7 100644 --- a/Objective-C/libobjcl.m +++ b/Objective-C/libobjcl.m @@ -36,236 +36,6 @@ objcl_shutdown_runtime (void) } -#ifdef __NEXT_RUNTIME__ -size_t -objc_sizeof_type (const char *typespec) -{ - switch (typespec[0]) - { - case '@': return sizeof (id); - case '#': return sizeof (Class); - case ':': return sizeof (SEL); - case 'c': return sizeof (char); - case 'C': return sizeof (unsigned char); - case 's': return sizeof (short); - case 'S': return sizeof (unsigned short); - case 'i': return sizeof (int); - case 'I': return sizeof (unsigned int); - case 'l': return sizeof (long); - case 'L': return sizeof (unsigned long); - case 'q': return sizeof (long long); - case 'Q': return sizeof (unsigned long long); - case 'f': return sizeof (float); - case 'd': return sizeof (double); - case 'B': return sizeof (BOOL); - case '?': - case '^': return sizeof (void *); - case '*': return sizeof (char *); - default: - NSLog (@"Dammit. What the heck is `%s' supposed to mean?", - typespec); - return 0; /* FIXME: Should signal an error. */ - } -} -#endif - - -static void -_objcl_get_arg_pointer (void *buffer, OBJCL_OBJ_DATA argdata) -{ - void *source = NULL; - - switch (argdata->type[0]) - { - case '@': source = &argdata->data.id_val; break; - case '#': source = &argdata->data.id_val; break; - case ':': source = &argdata->data.sel_val; break; - case 'c': source = &argdata->data.char_val; break; - case 'C': source = &argdata->data.char_val; break; - case 's': source = &argdata->data.short_val; break; - case 'S': source = &argdata->data.short_val; break; - case 'i': source = &argdata->data.int_val; break; - case 'I': source = &argdata->data.int_val; break; - case 'l': source = &argdata->data.long_val; break; - case 'L': source = &argdata->data.long_val; break; - case 'q': source = &argdata->data.long_long_val; break; - case 'Q': source = &argdata->data.long_long_val; break; - case 'f': source = &argdata->data.float_val; break; - case 'd': source = &argdata->data.double_val; break; - case 'B': source = &argdata->data.bool_val; break; -/* _OBJCL_ARG_CASE(_C_PTR, ptr); */ - case '^': source = &argdata->data.ptr_val; break; - case '?': source = &argdata->data.ptr_val; break; - case '*': source = &argdata->data.charptr_val; break; -/* - case 'v': source = &argdata->data.oid_val; break; - case 'b': source = &argdata->data.bitfield_val; break; - _OBJCL_ARG_CASE(_C_ATOM, atom); - _OBJCL_ARG_CASE(_C_ARY_B, ); - _OBJCL_ARG_CASE(_C_UNION_B, ); - _OBJCL_ARG_CASE(_C_STRUCT_B, ); - _OBJCL_ARG_CASE(_C_VECTOR, ); - _OBJCL_ARG_CASE(_C_COMPLEX, ); -*/ -/* case '?': */ - default: - NSLog (@"Dammit. What the heck is `%s' supposed to mean?", - argdata->type); - return; /* FIXME: Should signal an error. */ - } - - memmove (buffer, source, objc_sizeof_type (argdata->type)); -} - - -static void -_objcl_invoke_method (id self_, - OBJCL_OBJ_DATA result, - NSMethodSignature *signature, - SEL selector, - int argc, - va_list arglist) -{ - int i; - NSInvocation *invocation; - void *result_ptr = NULL; - const char *type = [signature methodReturnType]; - - result->type = malloc (strlen (type) + 1); - strcpy (result->type, type); - - if (signature == NULL) - { - [[NSException exceptionWithName: @"MLKNoSignatureFoundException" - reason: @"No signature found" - userInfo: NULL] raise]; - } - - - switch (type[0]) - { - case '@': result_ptr = &(result->data.id_val); break; - case '#': result_ptr = &result->data.id_val; break; - case ':': result_ptr = &result->data.sel_val; break; - case 'c': result_ptr = &result->data.char_val; break; - case 'C': result_ptr = &result->data.char_val; break; - case 's': result_ptr = &result->data.short_val; break; - case 'S': result_ptr = &result->data.short_val; break; - case 'i': result_ptr = &result->data.int_val; break; - case 'I': result_ptr = &result->data.int_val; break; - case 'l': result_ptr = &result->data.long_val; break; - case 'L': result_ptr = &result->data.long_val; break; - case 'q': result_ptr = &result->data.long_long_val; break; - case 'Q': result_ptr = &result->data.long_long_val; break; - case 'f': result_ptr = &result->data.float_val; break; - case 'd': result_ptr = &result->data.double_val; break; - case 'B': result_ptr = &result->data.bool_val; break; - case '?': - case '^': result_ptr = &result->data.ptr_val; break; - case '*': result_ptr = &result->data.charptr_val; break; - /* - case _C_BFLD: result_ptr = &result->data._val; break; - case _C_VOID: result_ptr = &result->data._val; break; - case _C_UNDEF: result_ptr = &result->data._val; break; - case _C_ATOM: result_ptr = &result->data._val; break; - case _C_ARY_B: result_ptr = &result->data._val; break; - case _C_ARY_E: result_ptr = &result->data._val; break; - case _C_UNION_B: result_ptr = &result->data._val; break; - case _C_UNION_E: result_ptr = &result->data._val; break; - case _C_STRUCT_B: result_ptr = &result->data._val; break; - case _C_STRUCT_E: result_ptr = &result->data._val; break; - case _C_VECTOR: result_ptr = &result->data._val; break; - case _C_COMPLEX: result_ptr = &result->data._val; break; - */ - } - - invocation = [NSInvocation invocationWithMethodSignature: signature]; - [invocation setTarget: self_]; - [invocation setSelector: selector]; - - for (i = 0; i < argc; i++) - { - const char* type = [signature getArgumentTypeAtIndex: (i + 2)]; - void *buffer = malloc (objc_sizeof_type (type)); - OBJCL_OBJ_DATA arg = va_arg (arglist, OBJCL_OBJ_DATA); - _objcl_get_arg_pointer (buffer, arg); - - if (type[0] == '#') - NSLog (@"Argument %d: %@ (type %s)", i, buffer, type); - else - NSLog (@"Argument %d: type %s.", i, type); - - [invocation setArgument: buffer - atIndex: (i + 2)]; - - free (buffer); - } - - [invocation retainArguments]; - NSLog (@"Invoking %@ on %@.", invocation, self_); - [invocation invoke]; - NSLog (@"Fetching return value."); - [invocation getReturnValue: result_ptr]; - if (result->type[0] == '#') - NSLog (@"Returning: %@", result->data.id_val); - else - NSLog (@"Returning."); -} - - -OBJCL_OBJ_DATA -objcl_invoke_method (OBJCL_OBJ_DATA receiver, - SEL method_selector, - int argc, - ...) -{ - va_list arglist; - id self_ = NULL; - NSMethodSignature *signature; - OBJCL_OBJ_DATA result = malloc (sizeof (struct objcl_object)); - - NS_DURING - { - switch (receiver->type[0]) - { - case '#': - self_ = receiver->data.class_val; - break; - case '@': - self_ = receiver->data.id_val; - break; - case 'E': - self_ = receiver->data.exc_val; - break; - default: - return NULL; - } - - - signature = [self_ methodSignatureForSelector: method_selector]; - - va_start (arglist, argc); - _objcl_invoke_method (self_, - result, - signature, - method_selector, - argc, - arglist); - va_end (arglist); - } - NS_HANDLER - { - result->type = malloc (strlen (EXCEPTION_TYPESPEC) + 1); - strcpy (result->type, EXCEPTION_TYPESPEC); - result->data.exc_val = localException; - NS_VALUERETURN (result, void *); - } - NS_ENDHANDLER - - return result; -} - - #ifdef USE_LIBFFI id objcl_invoke_with_types (int argc, |