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