|
From: <cod...@go...> - 2008-12-08 20:35:35
|
Author: jam...@us...
Date: Mon Dec 8 12:12:08 2008
New Revision: 366
Modified:
branches/objc2/hoc/HOC/HOC/Super.hs
branches/objc2/hoc/HOC_cbits/Class.h
branches/objc2/hoc/HOC_cbits/Class.m
branches/objc2/hoc/HOC_cbits/Exceptions.m
branches/objc2/hoc/HOC_cbits/GetNewHaskellData.m
branches/objc2/hoc/HOC_cbits/Ivars.h
branches/objc2/hoc/HOC_cbits/Ivars.m
branches/objc2/hoc/HOC_cbits/Methods.h
branches/objc2/hoc/HOC_cbits/Methods.m
branches/objc2/hoc/HOC_cbits/NewClass.m
Log:
Big ugly patch implementing Objective C 2.0 runtime support. Seems to be
working, passes all tests, etc.
I intend to clean it up a bit still, especially in the vicinity of
NewClass.m
Modified: branches/objc2/hoc/HOC/HOC/Super.hs
==============================================================================
--- branches/objc2/hoc/HOC/HOC/Super.hs (original)
+++ branches/objc2/hoc/HOC/HOC/Super.hs Mon Dec 8 12:12:08 2008
@@ -1,5 +1,6 @@
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies,
- UndecidableInstances, FlexibleInstances #-}
+ UndecidableInstances, FlexibleInstances,
+ ForeignFunctionInterface #-}
module HOC.Super(
SuperClass, SuperTarget, Super(super), withExportedSuper
) where
@@ -54,8 +55,8 @@
=> Super (ID sub) (SuperTarget super) where
super obj = SuperTarget (fromID $ toID obj)
-getSuperClassForObject obj = do cls <- peekByteOff obj 0 :: IO (Ptr (Ptr
()))
- peekElemOff cls 1
+foreign import ccall "Class.h getSuperClassForObject"
+ getSuperClassForObject :: Ptr ObjCObject -> IO (Ptr ())
instance MessageTarget a => MessageTarget (SuperTarget a) where
isNil (SuperTarget x) = isNil x
Modified: branches/objc2/hoc/HOC_cbits/Class.h
==============================================================================
--- branches/objc2/hoc/HOC_cbits/Class.h (original)
+++ branches/objc2/hoc/HOC_cbits/Class.h Mon Dec 8 12:12:08 2008
@@ -1,3 +1,4 @@
#include <objc/objc.h>
id getClassByName(const char* name);
+Class getSuperClassForObject(id self);
\ No newline at end of file
Modified: branches/objc2/hoc/HOC_cbits/Class.m
==============================================================================
--- branches/objc2/hoc/HOC_cbits/Class.m (original)
+++ branches/objc2/hoc/HOC_cbits/Class.m Mon Dec 8 12:12:08 2008
@@ -13,3 +13,14 @@
return objc_getClass(name);
#endif
}
+
+Class getSuperClassForObject(id self)
+{
+#ifdef GNUSTEP
+ return self->class_pointer->super_class;
+#elif defined(__OBJC2__)
+ return class_getSuperclass(object_getClass(self));
+#else
+ return self->isa->super_class;
+#endif
+}
\ No newline at end of file
Modified: branches/objc2/hoc/HOC_cbits/Exceptions.m
==============================================================================
--- branches/objc2/hoc/HOC_cbits/Exceptions.m (original)
+++ branches/objc2/hoc/HOC_cbits/Exceptions.m Mon Dec 8 12:12:08 2008
@@ -26,12 +26,18 @@
#if GNUSTEP
super.self = self;
- super.class = self->class_pointer->super_class;
+ super.class = getSuperClassForObject(self);
(*objc_msg_lookup_super(&super, selDealloc))(self, selDealloc);
#else
super.receiver = self;
- super.class = self->isa->super_class;
+
+# ifdef __OBJC2__
+ super.super_class = getSuperClassForObject(self);
+# else
+ super.class = getSuperClassForObject(self);
+# endif
+
objc_msgSendSuper(&super, selDealloc);
#endif
}
Modified: branches/objc2/hoc/HOC_cbits/GetNewHaskellData.m
==============================================================================
--- branches/objc2/hoc/HOC_cbits/GetNewHaskellData.m (original)
+++ branches/objc2/hoc/HOC_cbits/GetNewHaskellData.m Mon Dec 8 12:12:08
2008
@@ -47,7 +47,13 @@
#endif
if(m)
+ {
+#ifdef __OBJC2__
+ imp = method_getImplementation(m);
+#else
imp = m->method_imp;
+#endif
+ }
if(imp)
return (*(getHaskellDataIMP)imp)(obj, selGetHaskellData);
Modified: branches/objc2/hoc/HOC_cbits/Ivars.h
==============================================================================
--- branches/objc2/hoc/HOC_cbits/Ivars.h (original)
+++ branches/objc2/hoc/HOC_cbits/Ivars.h Mon Dec 8 12:12:08 2008
@@ -28,8 +28,12 @@
uint8_t alignment
);
+#ifndef __OBJC2__
+
struct objc_ivar_list * buildIndexedIvarList(
struct hoc_ivar_list *list,
int start_offset,
int *instance_size /* out */
);
+
+#endif
\ No newline at end of file
Modified: branches/objc2/hoc/HOC_cbits/Ivars.m
==============================================================================
--- branches/objc2/hoc/HOC_cbits/Ivars.m (original)
+++ branches/objc2/hoc/HOC_cbits/Ivars.m Mon Dec 8 12:12:08 2008
@@ -33,8 +33,10 @@
list->ivar_list[i].ivar_alignment = alignment;
}
+#ifndef __OBJC2__
+
/* Used to be makeIvarList in NewClass.m */
-struct objc_ivar_list * makeIndexedIvarList(int n)
+static struct objc_ivar_list * makeIndexedIvarList(int n)
{
struct objc_ivar_list *list =
calloc(1, sizeof(struct objc_ivar_list)
@@ -44,7 +46,7 @@
}
/* Used to be setIvarInList in NewClass.m */
-void setIvarInIndexedList(
+static void setIvarInIndexedList(
struct objc_ivar_list *list,
int i,
char *name,
@@ -88,3 +90,4 @@
return outList;
}
+#endif // ifndef __OBJC2__
\ No newline at end of file
Modified: branches/objc2/hoc/HOC_cbits/Methods.h
==============================================================================
--- branches/objc2/hoc/HOC_cbits/Methods.h (original)
+++ branches/objc2/hoc/HOC_cbits/Methods.h Mon Dec 8 12:12:08 2008
@@ -50,4 +50,8 @@
haskellIMP imp
);
-struct objc_method_list * convertMethodList(struct hoc_method_list * list);
\ No newline at end of file
+#ifndef __OBJC2__
+
+struct objc_method_list * convertMethodList(struct hoc_method_list * list);
+
+#endif
\ No newline at end of file
Modified: branches/objc2/hoc/HOC_cbits/Methods.m
==============================================================================
--- branches/objc2/hoc/HOC_cbits/Methods.m (original)
+++ branches/objc2/hoc/HOC_cbits/Methods.m Mon Dec 8 12:12:08 2008
@@ -26,7 +26,7 @@
{
struct hoc_method_list *list =
calloc(1, sizeof(struct hoc_method_list)
- + (n-1) * sizeof(struct objc_method));
+ + (n-1) * sizeof(struct hoc_method));
list->method_count = n;
return list;
}
@@ -56,6 +56,8 @@
list->method_list[i].method_imp = imp;
}
+#ifndef __OBJC2__
+
/* Was previously makeMethodList */
static struct objc_method_list * makeObjcMethodList(int n)
{
@@ -97,4 +99,6 @@
}
return newList;
-}
\ No newline at end of file
+}
+
+#endif // ifndef __OBJC2__
\ No newline at end of file
Modified: branches/objc2/hoc/HOC_cbits/NewClass.m
==============================================================================
--- branches/objc2/hoc/HOC_cbits/NewClass.m (original)
+++ branches/objc2/hoc/HOC_cbits/NewClass.m Mon Dec 8 12:12:08 2008
@@ -20,6 +20,8 @@
else
return getClassByName((const char*) class->super_class);
+#elif defined(__OBJC2__)
+ return class_getSuperclass(class);
#else
return class->super_class;
#endif
@@ -33,16 +35,14 @@
{
struct objc_class * meta_class;
struct objc_class * new_class;
- struct objc_class * root_class;
- int instance_size;
assert(objc_lookUpClass(name) == nil);
- for(root_class = super_class;
- root_class->super_class != nil;
- root_class = getSuper(root_class))
- ;
-
+ /* Allocate the class and metaclass */
+#ifdef __OBJC2__
+ new_class = objc_allocateClassPair(super_class, name, 0);
+ meta_class = object_getClass(new_class);
+#else
new_class = calloc( 2, sizeof(struct objc_class) );
meta_class = &new_class[1];
@@ -52,14 +52,34 @@
new_class->name = name;
meta_class->name = name;
+#endif
- new_class->ivars = buildIndexedIvarList(
- ivars,
- super_class->instance_size,
- &instance_size);
-
- new_class->instance_size = super_class->instance_size + instance_size;
+ /* Add instance variables to the class */
+#ifdef __OBJC2__
+ {
+ int i;
+
+ for (i = 0; i < ivars->ivar_count; i++)
+ {
+ struct hoc_ivar *ivar = &ivars->ivar_list[i];
+ class_addIvar(new_class, ivar->ivar_name,
+ ivar->ivar_size, ivar->ivar_alignment, ivar->ivar_types);
+ }
+
+ }
+#else
+ {
+ int instance_size;
+ new_class->ivars = buildIndexedIvarList(
+ ivars,
+ super_class->instance_size,
+ &instance_size);
+
+ new_class->instance_size = super_class->instance_size +
instance_size;
+ }
+#endif
+ /* Add methods and class methods */
#ifdef GNUSTEP
new_class->super_class = (void*)(super_class->name);
meta_class->super_class = (void*)(super_class->isa->name);
@@ -84,20 +104,46 @@
class_add_method_list(new_class, convertMethodList(methods));
class_add_method_list(meta_class, convertMethodList(class_methods));
+#elif defined(__OBJC2__)
+ {
+ int i;
+ for (i = 0; i < methods->method_count; i++)
+ {
+ struct hoc_method * m = &methods->method_list[i];
+ class_addMethod(new_class, m->method_name, m->method_imp,
m->method_types);
+ }
+
+ for (i = 0; i < class_methods->method_count; i++)
+ {
+ struct hoc_method * m = &class_methods->method_list[i];
+ class_addMethod(meta_class, m->method_name, m->method_imp,
m->method_types);
+ }
+
+ objc_registerClassPair(new_class);
+ }
#else
- new_class->methodLists = calloc( 1, sizeof(struct objc_method_list *) );
- meta_class->methodLists = calloc( 1, sizeof(struct objc_method_list *) );
- new_class->methodLists[0] = (struct objc_method_list*) -1;
- meta_class->methodLists[0] = (struct objc_method_list*) -1;
-
- new_class->super_class = super_class;
- meta_class->super_class = super_class->isa;
- meta_class->isa = (void *)root_class->isa;
-
- objc_addClass( new_class );
-
- class_addMethods(new_class, convertMethodList(methods));
- class_addMethods(meta_class, convertMethodList(class_methods));
+ {
+ struct objc_class * root_class;
+ for(root_class = super_class;
+ root_class->super_class != nil;
+ root_class = getSuper(root_class))
+ ;
+
+ new_class->methodLists = calloc( 1, sizeof(struct objc_method_list *)
);
+ meta_class->methodLists = calloc( 1, sizeof(struct objc_method_list
*) );
+ new_class->methodLists[0] = (struct objc_method_list*) -1;
+ meta_class->methodLists[0] = (struct objc_method_list*) -1;
+
+ new_class->super_class = super_class;
+ meta_class->super_class = super_class->isa;
+ meta_class->isa = (void *)root_class->isa;
+
+ objc_addClass( new_class );
+
+ class_addMethods(new_class, convertMethodList(methods));
+ class_addMethods(meta_class, convertMethodList(class_methods));
+ }
#endif
+
}
|