summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <mulk@Minimulk.local>2008-08-24 17:57:15 +0200
committerMatthias Benkard <mulk@Minimulk.local>2008-08-24 17:57:15 +0200
commit926dce9dc2c7afa009cacab46fb6f1b704c80ca7 (patch)
treef07b5a21d37c3454a1e9efd372249e76d04b83fa
parent3fd292f83ef33f8052feb22eb133d37913d33c66 (diff)
Fix some bugs in the new interpreter.
-rw-r--r--MLKInterpreter.m75
1 files changed, 34 insertions, 41 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index 334b33c..1921c5a 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -136,27 +136,11 @@
}
else
{
- expansion = denullify([[MLKInterpreter
- eval:code
- inLexicalContext:[MLKLexicalContext
- globalContext]
- withEnvironment:[MLKLexicalEnvironment
- globalEnvironment]]
- objectAtIndex:0]);
-
- if ([code isKindOfClass:[MLKCons class]] && [code cdr])
- formdesc = [NSString stringWithFormat:@"(%@ %@ ...)",
- MLKPrintToString([expansion car]),
- MLKPrintToString([[expansion cdr] car])];
- else
- formdesc = MLKPrintToString(expansion);
-
- //fprintf (stderr, "; LOAD: %s\n", [formdesc UTF8String]);
+ expansion = code;
result = [MLKInterpreter
eval:expansion
inLexicalContext:[MLKLexicalContext globalContext]
withEnvironment:[MLKLexicalEnvironment globalEnvironment]];
- //NSLog (@"; LOAD: Top-level form evaluated.");
}
LRELEASE (pool);
@@ -187,18 +171,27 @@
-(NSArray *) interpretWithEnvironment:(MLKLexicalEnvironment *)env
{
+ NSArray *values;
+
#define TRACE_EVAL 0
#if TRACE_EVAL
BOOL trace = NO;
+
+ //if ([dynamicContext valueForSymbol:V_INITP])
+ // trace = YES;
+
+ //if (trace)
+ NSLog (@"; EVAL: %@", MLKPrintToString(_form));
+#endif // TRACE_EVAL
+
+ values = [self reallyInterpretWithEnvironment:env];
- if ([dynamicContext valueForSymbol:V_INITP])
- trace = YES;
-
- if (trace)
- NSLog (@"; EVAL: %@", MLKPrintToString(program));
+#if TRACE_EVAL
+ //if (trace)
+ NSLog (@"; EVAL END: %@", MLKPrintToString(_form));
#endif // TRACE_EVAL
- return [self reallyInterpretWithEnvironment:env];
+ return values;
}
@@ -221,23 +214,14 @@
@implementation MLKSymbolForm (MLKInterpretation)
-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
{
- if ([_context symbolNamesSymbolMacro:_form])
- {
- id macrofun, expansion;
-
- macrofun = [_context macroForSymbol:_form];
- expansion = [macrofun applyToArray:
- [NSArray arrayWithObjects:
- _form, _context, nil]];
-
- return [expansion interpretWithEnvironment:env];
- }
- else if ([_context variableIsLexical:_form])
+ if ([_context variableIsLexical:_form])
{
+// NSLog (@"Lexical?");
RETURN_VALUE ([env valueForSymbol:_form]);
}
else
{
+// NSLog (@"Special?");
RETURN_VALUE ([[MLKDynamicContext currentContext] valueForSymbol:_form]);
}
}
@@ -343,7 +327,7 @@
@implementation MLKIfForm (MLKInterpretation)
-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
{
- id cndval = [[_conditionForm interpretWithEnvironment:env] objectAtIndex:0];
+ id cndval = denullify([[_conditionForm interpretWithEnvironment:env] objectAtIndex:0]);
if (cndval)
return [_consequentForm interpretWithEnvironment:env];
else
@@ -367,7 +351,7 @@
@end
-@implementation MLKLambdaForm (MLKInterpretation)
+@implementation MLKSimpleLambdaForm (MLKInterpretation)
-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
{
id lambdaList = [_tail car];
@@ -435,7 +419,7 @@
id value = [[[_variableBindingForms objectAtIndex:i]
interpretWithEnvironment:env]
objectAtIndex:0];
- if ([_context variableIsLexical:variable])
+ if ([_bodyContext variableIsLexical:variable])
{
[newenv addValue:value forSymbol:variable];
}
@@ -467,6 +451,14 @@
@end
+@implementation MLKVariableBindingForm (MLKInterpretation)
+-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
+{
+ return [_valueForm interpretWithEnvironment:env];
+}
+@end
+
+
@implementation MLKSimpleLoopForm (MLKInterpretation)
-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
{
@@ -510,7 +502,7 @@
-(NSArray *) interpretBodyWithEnvironment:(MLKLexicalEnvironment *)env
{
int i;
- NSArray *values = nil;
+ NSArray *values = [NSArray array];
for (i = 0; i < [_bodyForms count]; i++)
{
@@ -573,7 +565,7 @@
@implementation MLKQuoteForm (MLKInterpretation)
-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
{
- return _quotedData;
+ RETURN_VALUE (_quotedData);
}
@end
@@ -641,7 +633,6 @@
-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
{
int i;
- NSArray *results = nil;
NSMutableArray *args = [NSMutableArray array];
for (i = 0; i < [_argumentForms count]; i++)
@@ -654,6 +645,8 @@
if (![_context symbolNamesFunction:_head])
{
+ NSArray *results = nil;
+
if (_head && [_head homePackage] == sys)
{
results = [MLKRoot dispatch:_head withArguments:args];