From ad05662ae05336aa5db20f9d34d5c1d5bba9d6c2 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 23 Aug 2008 16:34:08 +0200 Subject: Make compilers pluggable at runtime. --- MLKInterpreter.m | 58 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'MLKInterpreter.m') diff --git a/MLKInterpreter.m b/MLKInterpreter.m index 0cdf904..7fd59ad 100644 --- a/MLKInterpreter.m +++ b/MLKInterpreter.m @@ -35,6 +35,7 @@ #import "MLKRoot.h" #import "MLKSymbol.h" #import "NSObject-MLKPrinting.h" +#import "globals.h" #import "runtime-compatibility.h" #import "special-symbols.h" #import "util.h" @@ -1230,34 +1231,37 @@ fprintf (stderr, "| "); fprintf (stderr, "LOAD: %s\n", [formdesc UTF8String]); -#ifdef USE_LLVM - expansion = code; - result = [MLKLLVMCompiler eval:code]; -#else // !USE_LLVM - expansion = denullify([[MLKInterpreter - eval:code - inLexicalContext:[MLKLexicalContext - globalContext] - withEnvironment:[MLKLexicalEnvironment - globalEnvironment] - mode:not_compile_time_mode] - objectAtIndex:0]); - - if ([code isKindOfClass:[MLKCons class]] && [code cdr]) - formdesc = [NSString stringWithFormat:@"(%@ %@ ...)", - MLKPrintToString([expansion car]), - MLKPrintToString([[expansion cdr] car])]; + if (MLKLoadCompilesP) + { + expansion = code; + result = [MLKDefaultCompiler eval:code]; + } else - formdesc = MLKPrintToString(expansion); - - //fprintf (stderr, "; LOAD: %s\n", [formdesc UTF8String]); - result = [MLKInterpreter - eval:expansion - inLexicalContext:[MLKLexicalContext globalContext] - withEnvironment:[MLKLexicalEnvironment globalEnvironment] - expandOnly:NO]; - //NSLog (@"; LOAD: Top-level form evaluated."); -#endif //!USE_LLVM + { + expansion = denullify([[MLKInterpreter + eval:code + inLexicalContext:[MLKLexicalContext + globalContext] + withEnvironment:[MLKLexicalEnvironment + globalEnvironment] + mode:not_compile_time_mode] + 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]); + result = [MLKInterpreter + eval:expansion + inLexicalContext:[MLKLexicalContext globalContext] + withEnvironment:[MLKLexicalEnvironment globalEnvironment] + expandOnly:NO]; + //NSLog (@"; LOAD: Top-level form evaluated."); + } LRELEASE (pool); -- cgit v1.2.3