diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-03 19:37:31 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-03 19:37:31 +0200 |
commit | 107dee15d5422f327ce55625a0a321b98693394e (patch) | |
tree | 5a77586c31fecdfc16c3fb16745dff6fdf34fc5a | |
parent | 7bb62035f03da386db26668b1aff93fac04d3a32 (diff) |
Interpreter: Improve error handling in the face of nonsensical expressions.
-rw-r--r-- | MLKInterpreter.m | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m index e03df1d..247bc8e 100644 --- a/MLKInterpreter.m +++ b/MLKInterpreter.m @@ -136,7 +136,7 @@ static MLKSymbol *_LAMBDA; { id car = [program car]; - if ([car isKindOfClass:[MLKSymbol class]]) + if ([car isKindOfClass:[MLKSymbol class]] || !car) { if (car == APPLY) { @@ -145,10 +145,13 @@ static MLKSymbol *_LAMBDA; withEnvironment:lexenv] objectAtIndex:0]); - id <MLKFuncallable> function = denullify([[self eval:[[program cdr] car] - inLexicalContext:context - withEnvironment:lexenv] - objectAtIndex:0]); + id function = denullify([[self eval:[[program cdr] car] + inLexicalContext:context + withEnvironment:lexenv] + objectAtIndex:0]); + + if ([function isKindOfClass:[MLKSymbol class]]) + function = [lexenv functionForSymbol:function]; return [function applyToArray:(rest ? (id)[rest array] @@ -530,12 +533,19 @@ static MLKSymbol *_LAMBDA; } } } - else if (![car isKindOfClass:[MLKCons class]] && [car car] == LAMBDA) + else if ([car isKindOfClass:[MLKCons class]] && [car car] == LAMBDA) { return [self eval:[MLKCons cons:FUNCALL with:program] inLexicalContext:context withEnvironment:lexenv]; } + else + { + [NSException raise:@"MLKInvalidExpressionException" + format:@"%@ is not a valid operator name.", + [car descriptionForLisp]]; + return nil; + } } } @@ -554,6 +564,7 @@ static MLKSymbol *_LAMBDA; preserveWhitespace:NO]; //NSLog (@"%@", code); + //NSLog (@"%@", [code descriptionForLisp]); //NSLog (@"%@", stream); //NSLog (@"..."); @@ -565,6 +576,7 @@ static MLKSymbol *_LAMBDA; eval:code inLexicalContext:[MLKLexicalContext globalContext] withEnvironment:[MLKLexicalEnvironment globalEnvironment]]; + //NSLog (@"; LOAD: Top-level form evaluated."); if (print) { |