diff options
-rw-r--r-- | MLKDynamicContext.m | 3 | ||||
-rw-r--r-- | MLKInterpreter.m | 9 | ||||
-rw-r--r-- | MLKRoot.m | 48 |
3 files changed, 57 insertions, 3 deletions
diff --git a/MLKDynamicContext.m b/MLKDynamicContext.m index 083fc14..ed01263 100644 --- a/MLKDynamicContext.m +++ b/MLKDynamicContext.m @@ -265,6 +265,9 @@ static MLKDynamicContext *global_context; [vars setObject:NIL forKey:[[MLKPackage findPackage:@"TOILET-SYSTEM"] intern:@"*SYSTEM-INITIALISED-P*"]]; + [vars setObject:[MLKInteger integerWithInt:0] + forKey:[[MLKPackage findPackage:@"TOILET-SYSTEM"] + intern:@"*LOAD-LEVEL*"]]; global_context = [[self alloc] initWithParent:nil variables:vars diff --git a/MLKInterpreter.m b/MLKInterpreter.m index 159de2a..a2aa81e 100644 --- a/MLKInterpreter.m +++ b/MLKInterpreter.m @@ -1392,6 +1392,9 @@ static MLKSymbol *MULTIPLE_VALUE_CALL; +(BOOL) load:(MLKStream *)stream verbose:(BOOL)verbose print:(BOOL)print { id eofValue = [[NSObject alloc] init]; + int level = MLKIntWithInteger ([[MLKDynamicContext currentContext] + valueForSymbol:[sys intern:@"*LOAD-LEVEL*"]]); + int i; while (YES) { @@ -1427,7 +1430,10 @@ static MLKSymbol *MULTIPLE_VALUE_CALL; formdesc = MLKPrintToString(code); //fprintf (stderr, "; COMPILE-MINIMALLY: %s\n", [formdesc UTF8String]); - fprintf (stderr, "; LOAD: %s\n", [formdesc UTF8String]); + fprintf (stderr, "; "); + for (i = 0; i < level; i++) + fprintf (stderr, "| "); + fprintf (stderr, "LOAD: %s\n", [formdesc UTF8String]); expansion = denullify([[MLKInterpreter eval:code inLexicalContext:[MLKLexicalContext @@ -1462,7 +1468,6 @@ static MLKSymbol *MULTIPLE_VALUE_CALL; } } - //NSLog (@"; LOAD: END"); return YES; } @end @@ -150,18 +150,64 @@ static id truify (BOOL value) { // FIXME BOOL success; + int l, i; NSString *fileName = denullify ([args objectAtIndex:0]); NSInputStream *input = [NSInputStream inputStreamWithFileAtPath:fileName]; MLKStream *stream = LAUTORELEASE ([[MLKStream alloc] initWithInputStream:input]); + MLKDynamicContext *oldContext = [MLKDynamicContext currentContext]; + int level = MLKIntWithInteger ([oldContext + valueForSymbol:[sys intern:@"*LOAD-LEVEL*"]]); + MLKDynamicContext *ctx; + + l = [fileName length]; + fprintf (stderr, ";\n; "); + for (i = 0; i < 68 - 2*level; i++) + fprintf (stderr, "_"); + + fprintf (stderr, "\n; /"); + for (i = 0; i < 30 - l/2 - level; i++) + fprintf (stderr, "-"); + fprintf (stderr, " LOAD: %s ", [fileName UTF8String]); + for (i = 0; i < 30 - (l+1)/2 - level; i++) + fprintf (stderr, "-"); + fprintf (stderr, "\n; |\n"); //NSLog (@"%d", [input hasBytesAvailable]); [input open]; //NSLog (@"%d", [input hasBytesAvailable]); - success = [MLKInterpreter load:stream verbose:YES print:YES]; + ctx = [[MLKDynamicContext alloc] + initWithParent:oldContext + variables:nil + handlers:nil + restarts:nil + catchTags:nil + activeHandlerEnvironment:nil]; + [ctx addValue:MLKIntegerWithInt(level + 1) + forSymbol:[sys intern:@"*LOAD-LEVEL*"]]; + [ctx pushContext]; + NS_DURING + { + success = [MLKInterpreter load:stream verbose:YES print:YES]; + } + NS_HANDLER + { + [MLKDynamicContext popContext]; + LRELEASE (ctx); + [input close]; + } + NS_ENDHANDLER; + + [MLKDynamicContext popContext]; + LRELEASE (ctx); [input close]; + fprintf (stderr, "; \\"); + for (i = 0; i < 68 - 2*level; i++) + fprintf (stderr, "_"); + fprintf (stderr, "\n; \n"); + RETURN_VALUE (truify (success)); } |