summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 11:21:51 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 11:21:51 +0200
commit274b31d8f18e1003c61d5add875c6fdc72419ba6 (patch)
tree60e0209d1934e4757db201e95c953a0f7e5c1ab3
parentf75ebaf84575244e278606dad84200f0127c0efc (diff)
Replace MLKCompiledProcedure with MLKCompiledClosure.
-rw-r--r--GNUmakefile2
-rw-r--r--MLKCompiledClosure.h (renamed from MLKCompiledProcedure.h)15
-rw-r--r--MLKCompiledClosure.m (renamed from MLKCompiledProcedure.m)70
3 files changed, 57 insertions, 30 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 6460914..bb43d64 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -49,7 +49,7 @@ endif
ToiletKit_OBJC_FILES = functions.m globals.m MLKArray.m \
MLKBackquoteReader.m MLKBinding.m MLKCharacter.m \
- MLKCommaReader.m MLKCompiledProcedure.m MLKCons.m \
+ MLKCommaReader.m MLKCompiledClosure.m MLKCons.m \
MLKDoubleFloat.m \
MLKDispatchingMacroCharacterReader.m \
MLKDynamicContext.m MLKEnvironment.m MLKFloat.m \
diff --git a/MLKCompiledProcedure.h b/MLKCompiledClosure.h
index 175c085..a4498d2 100644
--- a/MLKCompiledProcedure.h
+++ b/MLKCompiledClosure.h
@@ -24,12 +24,20 @@
#import <Foundation/NSString.h>
-@interface MLKCompiledProcedure : NSObject <MLKFuncallable>
+@interface MLKCompiledClosure : NSObject <MLKFuncallable>
{
- void *_code;
+ int _dataLength;
+ id (*_code)();
+ id *_data;
}
--(id) initWithCode:(void *)code;
+-(id) initWithCode:(void *)code
+ data:(id *)data
+ length:(int)dataLength;
+
++(id) closureWithCode:(void *)code
+ data:(id *)data
+ length:(int)dataLength;;
-(NSArray *) applyToArray:(NSArray *)arguments;
@@ -37,5 +45,4 @@
-(NSString *) descriptionForLisp;
-(void) dealloc;
--(void) finalize;
@end
diff --git a/MLKCompiledProcedure.m b/MLKCompiledClosure.m
index ee8664b..35c8aca 100644
--- a/MLKCompiledProcedure.m
+++ b/MLKCompiledClosure.m
@@ -16,45 +16,64 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#import "MLKCompiledProcedure.h"
+#import "MLKCompiledClosure.h"
+
+#import "functions.h"
#import "globals.h"
+#import "runtime-compatibility.h"
#import "util.h"
-#import <Foundation/NSArray.h>
-
-#ifdef HAVE_FFI_H
-#include <ffi.h>
-#elif HAVE_FFI_FFI_H
-#include <ffi/ffi.h>
-#endif
+#import <Foundation/NSDictionary.h>
+#import <Foundation/NSSet.h>
-#include <stdlib.h>
+#import <stdlib.h>
-@implementation MLKCompiledProcedure
+@implementation MLKCompiledClosure
-(id) initWithCode:(void *)code
+ data:(id *)data
+ length:(int)dataLength
{
- self = [super init];
+ int i;
+
+ _data = data;
+ _dataLength = dataLength;
_code = code;
+
+ for (i = 0; i < _dataLength; i++)
+ {
+ LRETAIN (_data[i]);
+ }
+
return self;
}
++(id) closureWithCode:(void *)code
+ data:(id *)data
+ length:(int)dataLength
+{
+ return LAUTORELEASE ([[self alloc] initWithCode:code data:data length:dataLength]);
+}
+
-(NSArray *) applyToArray:(NSArray *)arguments
{
- int argc = ([arguments count] + 1);
+ int argc = ([arguments count] + 2);
ffi_cif cif;
ffi_type *arg_types[argc];
ffi_status status;
- id *argv[argc];
+ void *argv[argc];
id argpointers[argc - 1];
id return_value;
int i;
- for (i = 0; i < argc - 1; i++)
+ arg_types[0] = &ffi_type_pointer;
+ argv[0] = &_data;
+
+ for (i = 1; i < argc - 1; i++)
{
arg_types[i] = &ffi_type_pointer;
- argpointers[i] = denullify([arguments objectAtIndex:i]);
- argv[i] = &argpointers[i];
+ argpointers[i-1] = denullify([arguments objectAtIndex:i]);
+ argv[i] = &argpointers[i-1];
}
arg_types[argc - 1] = &ffi_type_pointer;
@@ -75,24 +94,25 @@
-(NSString *) description
{
- return MLKPrintToString(self);
+ return MLKPrintToString (self);
}
-(NSString *) descriptionForLisp
{
- return [NSString stringWithFormat:@"<Compiled procedure @%p>", self];
+ return [NSString stringWithFormat:@"<Compiled closure @%p>", self];
}
-(void) dealloc
{
- // FIXME: Can we really just use free() here?
- free (_code);
+ int i;
+
[super dealloc];
-}
--(void) finalize
-{
- // FIXME: Can we really just use free() here?
- free (_code);
+ // FIXME: Decrease refcount of _code.
+ for (i = 0; i < _dataLength; i++)
+ {
+ LRELEASE (_data[i]);
+ }
+ free (_data);
}
@end