summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKCompiledClosure.h7
-rw-r--r--MLKCompiledClosure.m26
-rw-r--r--MLKLLVMCompiler.mm13
3 files changed, 27 insertions, 19 deletions
diff --git a/MLKCompiledClosure.h b/MLKCompiledClosure.h
index 772f29c..5ddd1a9 100644
--- a/MLKCompiledClosure.h
+++ b/MLKCompiledClosure.h
@@ -26,9 +26,10 @@
@interface MLKCompiledClosure : NSObject <MLKFuncallable>
{
- int _dataLength;
- id (*_code)();
- id *_data;
+@public
+ int m_dataLength;
+ id (*m_code)();
+ id *m_data;
}
// Why intptr_t? Because it makes it easier to call this method from
diff --git a/MLKCompiledClosure.m b/MLKCompiledClosure.m
index fd643e3..b379dd3 100644
--- a/MLKCompiledClosure.m
+++ b/MLKCompiledClosure.m
@@ -40,18 +40,18 @@
{
int i;
- _dataLength = dataLength;
- _code = code;
+ m_dataLength = dataLength;
+ m_code = code;
#ifdef __OBJC_GC__
- _data = NSAllocateCollectable (dataLength * sizeof(id), NSScannedOption);
+ m_data = NSAllocateCollectable (dataLength * sizeof(id), NSScannedOption);
#else
- _data = malloc (dataLength * sizeof(id));
+ m_data = malloc (dataLength * sizeof(id));
#endif
- for (i = 0; i < _dataLength; i++)
+ for (i = 0; i < m_dataLength; i++)
{
- _data[i] = LRETAIN (data[i]);
+ m_data[i] = LRETAIN (data[i]);
}
return self;
@@ -76,7 +76,7 @@
int i;
arg_types[0] = &ffi_type_pointer;
- argv[0] = &_data;
+ argv[0] = &m_data;
for (i = 1; i < argc - 1; i++)
{
@@ -101,7 +101,7 @@
// NSLog (@"Argument %d: %p", i, *((void**)argv[i]));
// }
- ffi_call (&cif, FFI_FN (_code), &return_value, (void**)argv);
+ ffi_call (&cif, FFI_FN (m_code), &return_value, (void**)argv);
// return_value = ((id (*)(void *, ...))_code) (_data, argpointers[0], argpointers[1], MLKEndOfArgumentsMarker);
// FIXME: multiple values
@@ -120,12 +120,12 @@
-(id (*)()) code
{
- return _code;
+ return m_code;
}
-(void *) closureData
{
- return _data;
+ return m_data;
}
-(void) dealloc
@@ -135,10 +135,10 @@
[super dealloc];
// FIXME: Decrease refcount of _code.
- for (i = 0; i < _dataLength; i++)
+ for (i = 0; i < m_dataLength; i++)
{
- LRELEASE (_data[i]);
+ LRELEASE (m_data[i]);
}
- free (_data);
+ free (m_data);
}
@end
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 51ac0d3..5428927 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -56,7 +56,10 @@
#include <vector>
#include <stddef.h>
+#ifdef MACOSX
#include <objc/runtime.h>
+#include <objc/objc-api.h>
+#endif
using namespace llvm;
using namespace std;
@@ -561,9 +564,13 @@ static Constant
// the GEP offset in terms of bytes.
Value *closure = builder.CreateBitCast ([_compiler insertMethodCall:@"value" onObject:binding], VoidPointerTy);
- //offsetof (MLKCompiledClosure, _code);
- ptrdiff_t code_offset = ivar_getOffset (class_getInstanceVariable ([MLKCompiledClosure class], "_code"));
- ptrdiff_t data_offset = ivar_getOffset (class_getInstanceVariable ([MLKCompiledClosure class], "_data"));
+#if defined(OBJC_API_VERSION) && OBJC_API_VERSION >= 2
+ ptrdiff_t code_offset = ivar_getOffset (class_getInstanceVariable ([MLKCompiledClosure class], "m_code"));
+ ptrdiff_t data_offset = ivar_getOffset (class_getInstanceVariable ([MLKCompiledClosure class], "m_data"));
+#else
+ ptrdiff_t code_offset = offsetof (MLKCompiledClosure, m_code);
+ ptrdiff_t data_offset = offsetof (MLKCompiledClosure, m_data);
+#endif
Constant *code_offset_value = ConstantInt::get (Type::Int32Ty, code_offset, false);
Constant *data_offset_value = ConstantInt::get (Type::Int32Ty, data_offset, false);
Value *codeptr = builder.CreateGEP (closure, code_offset_value);