summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-02 17:37:08 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-02 17:37:08 +0200
commitd889c23d138e8df1342bb50bc472e0315b821491 (patch)
treea3b01527e75109795d8b2d7c876f4df3384c446b
parent6b498f0726a38efc7802dad29a47633ad5aed6e7 (diff)
Interpreter: Implement SETQ.
-rw-r--r--MLKInterpreter.m37
1 files changed, 31 insertions, 6 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index 5dd6cc7..4ecd42d 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -351,12 +351,37 @@ static MLKSymbol *_LAMBDA;
}
else if (car == SETQ)
{
- //FIXME: ...
+ id symbol = [[program cdr] car];
+ id value = [[self eval:[[[program cdr] cdr] car]
+ inLexicalContext:context
+ withEnvironment:lexenv]
+ objectAtIndex:0];
+ id rest = [[[program cdr] cdr] cdr];
+
+ if (![program cdr])
+ return [NSArray arrayWithObject:[NSNull null]];
+
//FIXME: Don't forget handling symbol macros correctly.
+
+ if ([context variableIsLexical:symbol])
+ [lexenv setValue:value forSymbol:symbol];
+ else if ([dynamicContext bindingForSymbol:symbol])
+ [dynamicContext setValue:value forSymbol:symbol];
+ else
+ // Maybe print a warning.
+ [[MLKDynamicContext globalContext] addValue:value
+ forSymbol:symbol];
+
+
+ if (rest)
+ return [self eval:[MLKCons cons:SETQ with:rest]
+ inLexicalContext:context
+ withEnvironment:lexenv];
+ else
+ return [NSArray arrayWithObject:value];
}
else if (car == SET)
{
- MLKDynamicContext *ctx = [MLKDynamicContext currentContext];
id symbol = [[self eval:[[program cdr] car]
inLexicalContext:context
withEnvironment:lexenv]
@@ -366,11 +391,11 @@ static MLKSymbol *_LAMBDA;
withEnvironment:lexenv]
objectAtIndex:0];
- if ([ctx bindingForSymbol:symbol])
- [ctx setValue:value forSymbol:symbol];
+ if ([dynamicContext bindingForSymbol:symbol])
+ [dynamicContext setValue:value forSymbol:symbol];
else
- [[MLKDynamicContext globalContext]
- addValue:value forSymbol:symbol];
+ [[MLKDynamicContext globalContext] addValue:value
+ forSymbol:symbol];
return [NSArray arrayWithObject:symbol];
}