summaryrefslogtreecommitdiff
path: root/MLKInterpreter.m
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-27 19:05:08 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-27 19:05:08 +0200
commit5458d9ab8b91c0eacc012ad188fc0b63846adf3f (patch)
treecd3f68da945134cb9a6e89c0add87a691af66b33 /MLKInterpreter.m
parent2e2b608c4f04f9a5591f354029c257453b6c31cf (diff)
Add FUNCTION.
Diffstat (limited to 'MLKInterpreter.m')
-rw-r--r--MLKInterpreter.m28
1 files changed, 28 insertions, 0 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index 46b8676..8237f7b 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -54,6 +54,7 @@ static MLKSymbol *LAMBDA;
static MLKSymbol *LET;
static MLKSymbol *APPLY;
static MLKSymbol *FUNCALL;
+static MLKSymbol *FUNCTION;
static MLKSymbol *EVAL;
static MLKSymbol *QUOTE;
static MLKSymbol *SETQ;
@@ -85,6 +86,8 @@ static MLKSymbol *_LAMBDA;
LET = [cl intern:@"LET"];
APPLY = [cl intern:@"APPLY"];
EVAL = [cl intern:@"EVAL"];
+ FUNCALL = [cl intern:@"FUNCALL"];
+ FUNCTION = [cl intern:@"FUNCTION"];
QUOTE = [cl intern:@"QUOTE"];
SETQ = [cl intern:@"SETQ"];
SETF = [cl intern:@"SETF"];
@@ -317,6 +320,31 @@ static MLKSymbol *_LAMBDA;
withEnvironment:[MLKLexicalEnvironment
globalEnvironment]];
}
+ else if (car == FUNCTION)
+ {
+ id functionName = [[program cdr] car];
+
+ if ([functionName isKindOfClass:[MLKCons class]]
+ && ([functionName car] == LAMBDA
+ || [functionName car] == _LAMBDA))
+ {
+ return [self eval:functionName
+ inLexicalContext:context
+ withEnvironment:lexenv
+ expandOnly:expandOnly];
+ }
+ else if (expandOnly)
+ {
+ RETURN_VALUE (program);
+ }
+ else
+ {
+ // FIXME: Function names need not be symbols.
+ id <MLKFuncallable> function =
+ [lexenv functionForSymbol:functionName];
+ RETURN_VALUE (function);
+ }
+ }
else if (car == IF)
{
id condition = [[program cdr] car];