From: <cod...@go...> - 2009-08-17 22:41:49
|
Revision: 406 Author: wol...@gm... Date: Mon Aug 17 15:41:10 2009 Log: Make things compile under GNUstep (issue #17) http://code.google.com/p/hoc/source/detail?r=406 Modified: /trunk/hoc/HOC_cbits/Class.m /trunk/hoc/HOC_cbits/Ivars.h /trunk/hoc/HOC_cbits/Ivars.m /trunk/hoc/HOC_cbits/MemoryManagement.m /trunk/hoc/HOC_cbits/NewClass.m /trunk/hoc/HOC_cbits/RetainedHaskellPart.m ======================================= --- /trunk/hoc/HOC_cbits/Class.m Sun Dec 21 13:42:00 2008 +++ /trunk/hoc/HOC_cbits/Class.m Mon Aug 17 15:41:10 2009 @@ -34,16 +34,18 @@ Class root_class; for(root_class = super_class; - getSuperclassForClass(root_class) != nil; - root_class = getSuperclassForClass(root_class)) - ; + getSuperclassForClass(root_class) != nil; + root_class = getSuperclassForClass(root_class)) + ; return root_class; } Class getClassForObject(id object) { -#ifdef __OBJC2__ +#ifdef GNUSTEP + return object->class_pointer; +#elif defined(__OBJC2__) return object_getClass(object); #else return object->isa; ======================================= --- /trunk/hoc/HOC_cbits/Ivars.h Sun Dec 21 13:42:00 2008 +++ /trunk/hoc/HOC_cbits/Ivars.h Mon Aug 17 15:41:10 2009 @@ -1,6 +1,17 @@ #include <stdlib.h> #include <stdint.h> +#ifdef GNUSTEP +struct objc_ivar * +class_getInstanceVariable(Class cls, const char *name); + +struct objc_ivar * +object_getInstanceVariable(id obj, const char *name, void** out); + +struct objc_ivar * +object_setInstanceVariable(id obj, const char *name, void* val); +#endif + struct hoc_ivar { char *ivar_name; char *ivar_types; ======================================= --- /trunk/hoc/HOC_cbits/Ivars.m Sun Dec 21 13:42:00 2008 +++ /trunk/hoc/HOC_cbits/Ivars.m Mon Aug 17 15:41:10 2009 @@ -9,6 +9,49 @@ #include "Ivars.h" +#ifdef GNUSTEP +struct objc_ivar * +class_getInstanceVariable(Class cls, const char *name) +{ + struct objc_ivar *ivar = NULL; + + while(cls) + { + if(cls->ivars) + { + int i; + + for(i=0;i<cls->ivars->ivar_count;i++) + { + if(!strcmp(cls->ivars->ivar_list[i].ivar_name, name)) + return &cls->ivars->ivar_list[i]; + } + } + cls = cls->super_class; + } + return NULL; +} + +struct objc_ivar * +object_getInstanceVariable(id obj, const char *name, void** out) +{ + struct objc_ivar *ivar = class_getInstanceVariable(obj->class_pointer,name); + if(ivar) + *out = *(void**) ((char*)obj + ivar->ivar_offset); + return ivar; +} + +struct objc_ivar * +object_setInstanceVariable(id obj, const char *name, void* val) +{ + struct objc_ivar *ivar = class_getInstanceVariable(obj->class_pointer,name); + if(ivar) + *(void**) ((char*)obj + ivar->ivar_offset) = val; + return ivar; +} +#endif + + struct hoc_ivar_list * makeIvarList(int n) { struct hoc_ivar_list *list = ======================================= --- /trunk/hoc/HOC_cbits/MemoryManagement.m Thu Aug 13 08:45:30 2009 +++ /trunk/hoc/HOC_cbits/MemoryManagement.m Mon Aug 17 15:41:10 2009 @@ -48,6 +48,7 @@ #ifdef GNUSTEP #define objc_msgSend(self,sel) (*objc_msg_lookup(self,sel))(self,sel) +#define objc_msgSendSuper(super,sel) (*objc_msg_lookup_super(super,sel))(super->self,sel) #endif static SEL selRetain = 0; @@ -90,8 +91,13 @@ struct objc_super * super = calloc(1, sizeof(struct objc_super)); +#if GNUSTEP + super->self = obj; + super->class = cls; +#else super->receiver = obj; super->super_class = cls; +#endif objc_msgSendSuper(super, selRetain); } @@ -107,8 +113,13 @@ struct objc_super * super = calloc(1, sizeof(struct objc_super)); +#if GNUSTEP + super->self = obj; + super->class = cls; +#else super->receiver = obj; super->super_class = cls; +#endif objc_msgSendSuper(super, selRelease); } ======================================= --- /trunk/hoc/HOC_cbits/NewClass.m Sun Dec 21 13:42:00 2008 +++ /trunk/hoc/HOC_cbits/NewClass.m Mon Aug 17 15:41:10 2009 @@ -49,7 +49,7 @@ module->version = 8; module->size = sizeof(Module); - module->name = strdup(name); + module->name = strdup(new_class->name); module->symtab = symtab; symtab->cls_def_cnt = 1; symtab->defs[0] = new_class; ======================================= --- /trunk/hoc/HOC_cbits/RetainedHaskellPart.m Tue Oct 28 06:02:53 2003 +++ /trunk/hoc/HOC_cbits/RetainedHaskellPart.m Mon Aug 17 15:41:10 2009 @@ -6,49 +6,7 @@ #include <objc/objc-class.h> #endif #include "RetainedHaskellPart.h" - -#ifdef GNUSTEP -static struct objc_ivar * -object_findInstanceVar(id obj, const char *name) -{ - Class cls = obj->class_pointer; - struct objc_ivar *ivar = NULL; - - while(cls) - { - if(cls->ivars) - { - int i; - - for(i=0;i<cls->ivars->ivar_count;i++) - { - if(!strcmp(cls->ivars->ivar_list[i].ivar_name, name)) - return &cls->ivars->ivar_list[i]; - } - } - cls = cls->super_class; - } - return NULL; -} - -static struct objc_ivar * -object_getInstanceVariable(id obj, const char *name, void** out) -{ - struct objc_ivar *ivar = object_findInstanceVar(obj,name); - if(ivar) - *out = *(void**) ((char*)obj + ivar->ivar_offset); - return ivar; -} - -static struct objc_ivar * -object_setInstanceVariable(id obj, const char *name, void* val) -{ - struct objc_ivar *ivar = object_findInstanceVar(obj,name); - if(ivar) - *(void**) ((char*)obj + ivar->ivar_offset) = val; - return ivar; -} -#endif +#include "Ivars.h" void* getRetainedHaskellPart(id obj) { |