From 96870ab2cd94ba6e36585837b69048c544e6d6b6 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 17 Aug 2008 22:04:27 +0200 Subject: Promote special operators SET and %FSET to intrinsics. --- MLKRoot.m | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'MLKRoot.m') diff --git a/MLKRoot.m b/MLKRoot.m index b051dd3..0c59c23 100644 --- a/MLKRoot.m +++ b/MLKRoot.m @@ -99,6 +99,10 @@ static id truify (BOOL value) withString:@"_" options:NSLiteralSearch range:NSMakeRange(0, [methodName length])]; + [methodName replaceOccurrencesOfString:@"%" + withString:@"" + options:NSLiteralSearch + range:NSMakeRange(0, [methodName length])]; [methodName appendString:@":"]; selector = NSSelectorFromString (methodName); @@ -715,4 +719,31 @@ as provided by method %@ of object %@", RETURN_VALUE (thing); } #endif + ++(NSArray *) fset:(NSArray *)args +{ + id symbol = denullify ([args objectAtIndex:0]); + id value = denullify ([args objectAtIndex:1]); + + [[MLKLexicalContext globalContext] addFunction:symbol]; + [[MLKLexicalEnvironment globalEnvironment] addFunction:value + forSymbol:symbol]; + + RETURN_VALUE (value); +} + ++(NSArray *) set:(NSArray *)args +{ + id symbol = denullify ([args objectAtIndex:0]); + id value = denullify ([args objectAtIndex:1]); + MLKDynamicContext *dynamicContext = [MLKDynamicContext currentContext]; + + if ([dynamicContext bindingForSymbol:symbol]) + [dynamicContext setValue:value forSymbol:symbol]; + else + [[MLKDynamicContext globalContext] addValue:value + forSymbol:symbol]; + + RETURN_VALUE (value); +} @end -- cgit v1.2.3 From d86ccf58d5b462100d1f4ec5d016024543ec7f53 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 17 Aug 2008 22:43:25 +0200 Subject: Replace special operator %DEFMACRO with intrinsic function %MACROSET. --- MLKRoot.m | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'MLKRoot.m') diff --git a/MLKRoot.m b/MLKRoot.m index 0c59c23..b12cd17 100644 --- a/MLKRoot.m +++ b/MLKRoot.m @@ -746,4 +746,15 @@ as provided by method %@ of object %@", RETURN_VALUE (value); } + ++(NSArray *) macroset:(NSArray *)args +{ + id symbol = denullify ([args objectAtIndex:0]); + id value = denullify ([args objectAtIndex:1]); + + [[MLKLexicalContext globalContext] addMacro:value + forSymbol:symbol]; + + RETURN_VALUE (value); +} @end -- cgit v1.2.3 From bdfe4801295945b92f84b8c03cb2e0be485ae4f0 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 18 Aug 2008 01:19:06 +0200 Subject: Promote special operator APPLY to an intrinsic function. --- MLKRoot.m | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'MLKRoot.m') diff --git a/MLKRoot.m b/MLKRoot.m index b12cd17..0db7483 100644 --- a/MLKRoot.m +++ b/MLKRoot.m @@ -711,11 +711,11 @@ as provided by method %@ of object %@", #ifdef USE_LLVM +(NSArray *) compile:(NSArray *)args { - NSLog (@"Compiling lambda form."); + //NSLog (@"Compiling lambda form."); id thing = [MLKLLVMCompiler compile:denullify([args objectAtIndex:0]) inContext:[MLKLexicalContext globalContext]]; - NSLog (@"Compilation done."); - NSLog (@"Compiled: %@", thing); + //NSLog (@"Compilation done."); + //NSLog (@"Compiled: %@", thing); RETURN_VALUE (thing); } #endif @@ -757,4 +757,20 @@ as provided by method %@ of object %@", RETURN_VALUE (value); } + ++(NSArray *) apply:(NSArray *)args +{ + id function = denullify ([args objectAtIndex:0]); + id arglist = denullify ([args objectAtIndex:1]); + + if (!function || [function isKindOfClass:[MLKSymbol class]]) + { + function = [[MLKLexicalEnvironment globalEnvironment] + functionForSymbol:function]; + } + + return [function applyToArray:(arglist + ? (id)[arglist array] + : (id)[NSArray array])]; +} @end -- cgit v1.2.3