From: <cod...@go...> - 2008-12-06 03:04:12
|
Author: jam...@us... Date: Fri Dec 5 19:03:30 2008 New Revision: 359 Added: branches/objc2/hoc/HOC_cbits/Methods.h branches/objc2/hoc/HOC_cbits/Methods.m Modified: branches/objc2/hoc/HOC_cbits/Exceptions.m branches/objc2/hoc/HOC_cbits/NewClass.h branches/objc2/hoc/HOC_cbits/NewClass.m Log: Extracted existing method-related code to new files "Methods.m" and "Methods.h" in HOC_cbits. Modified: branches/objc2/hoc/HOC_cbits/Exceptions.m ============================================================================== --- branches/objc2/hoc/HOC_cbits/Exceptions.m (original) +++ branches/objc2/hoc/HOC_cbits/Exceptions.m Fri Dec 5 19:03:30 2008 @@ -2,6 +2,7 @@ #include "NewClass.h" #include "Class.h" #include "Ivars.h" +#include "Methods.h" #include "Selector.h" #include "Marshalling.h" #include "HsFFI.h" Added: branches/objc2/hoc/HOC_cbits/Methods.h ============================================================================== --- (empty file) +++ branches/objc2/hoc/HOC_cbits/Methods.h Fri Dec 5 19:03:30 2008 @@ -0,0 +1,29 @@ +#ifdef GNUSTEP +#include <objc/objc-api.h> +#else +#include <objc/objc-runtime.h> +#endif + +#include <ffi.h> + +#ifdef __OBJC__ +@class NSException; +#else +typedef void NSException; +#endif + +typedef NSException *(*haskellIMP)( + ffi_cif *cif, + void * ret, + void **args + ); + +struct objc_method_list * makeMethodList(int n); +void setMethodInList( + struct objc_method_list *list, + int i, + SEL sel, + char *types, /* never deallocate this */ + ffi_cif *cif, /* never deallocate this */ + haskellIMP imp + ); Added: branches/objc2/hoc/HOC_cbits/Methods.m ============================================================================== --- (empty file) +++ branches/objc2/hoc/HOC_cbits/Methods.m Fri Dec 5 19:03:30 2008 @@ -0,0 +1,50 @@ +#include <stdlib.h> +#include "Methods.h" +#include "Statistics.h" + +#ifdef __OBJC__ +#import <Foundation/NSException.h> +#endif + +static void objcIMP(ffi_cif *cif, void * ret, void **args, void *userData) +{ + recordHOCEvent(kHOCAboutToEnterHaskell, args); + NSException *e = (*(haskellIMP)userData)(cif, ret, args); + recordHOCEvent(kHOCLeftHaskell, args); + if(e != nil) + [e raise]; +} + +static ffi_closure *newIMP(ffi_cif *cif, haskellIMP imp) +{ + ffi_closure *closure = (ffi_closure*) calloc(1, sizeof(ffi_closure)); + ffi_prep_closure(closure, cif, &objcIMP, (void*) imp); + return closure; +} + +struct objc_method_list * makeMethodList(int n) +{ + struct objc_method_list *list = + calloc(1, sizeof(struct objc_method_list) + + (n-1) * sizeof(struct objc_method)); + list->method_count = n; + return list; +} + +void setMethodInList( + struct objc_method_list *list, + int i, + SEL sel, + char *types, + ffi_cif *cif, + haskellIMP imp + ) +{ +#ifdef GNUSTEP + list->method_list[i].method_name = (SEL) sel_get_name(sel); +#else + list->method_list[i].method_name = sel; +#endif + list->method_list[i].method_types = types; + list->method_list[i].method_imp = (IMP) newIMP(cif, imp); +} Modified: branches/objc2/hoc/HOC_cbits/NewClass.h ============================================================================== --- branches/objc2/hoc/HOC_cbits/NewClass.h (original) +++ branches/objc2/hoc/HOC_cbits/NewClass.h Fri Dec 5 19:03:30 2008 @@ -4,14 +4,6 @@ #include <objc/objc-runtime.h> #endif -#include <ffi.h> - -#ifdef __OBJC__ -@class NSException; -#else -typedef void NSException; -#endif - struct hoc_ivar_list; void newClass(struct objc_class * super_class, @@ -20,18 +12,3 @@ struct objc_method_list *methods, /* never deallocate this */ struct objc_method_list *class_methods); /* never deallocate this */ -typedef NSException *(*haskellIMP)( - ffi_cif *cif, - void * ret, - void **args - ); - -struct objc_method_list * makeMethodList(int n); -void setMethodInList( - struct objc_method_list *list, - int i, - SEL sel, - char *types, /* never deallocate this */ - ffi_cif *cif, /* never deallocate this */ - haskellIMP imp - ); Modified: branches/objc2/hoc/HOC_cbits/NewClass.m ============================================================================== --- branches/objc2/hoc/HOC_cbits/NewClass.m (original) +++ branches/objc2/hoc/HOC_cbits/NewClass.m Fri Dec 5 19:03:30 2008 @@ -4,7 +4,6 @@ #include "Class.h" #include "Ivars.h" #include "NewClass.h" -#include "Statistics.h" #ifdef GNUSTEP #define isa class_pointer @@ -101,46 +100,3 @@ #endif } - -static void objcIMP(ffi_cif *cif, void * ret, void **args, void *userData) -{ - recordHOCEvent(kHOCAboutToEnterHaskell, args); - NSException *e = (*(haskellIMP)userData)(cif, ret, args); - recordHOCEvent(kHOCLeftHaskell, args); - if(e != nil) - [e raise]; -} - -static ffi_closure *newIMP(ffi_cif *cif, haskellIMP imp) -{ - ffi_closure *closure = (ffi_closure*) calloc(1, sizeof(ffi_closure)); - ffi_prep_closure(closure, cif, &objcIMP, (void*) imp); - return closure; -} - -struct objc_method_list * makeMethodList(int n) -{ - struct objc_method_list *list = - calloc(1, sizeof(struct objc_method_list) - + (n-1) * sizeof(struct objc_method)); - list->method_count = n; - return list; -} - -void setMethodInList( - struct objc_method_list *list, - int i, - SEL sel, - char *types, - ffi_cif *cif, - haskellIMP imp - ) -{ -#ifdef GNUSTEP - list->method_list[i].method_name = (SEL) sel_get_name(sel); -#else - list->method_list[i].method_name = sel; -#endif - list->method_list[i].method_types = types; - list->method_list[i].method_imp = (IMP) newIMP(cif, imp); -} |