diff options
| -rw-r--r-- | MLKInterpreter.m | 58 | ||||
| -rw-r--r-- | MLKLLVMCompiler.h | 2 | ||||
| -rw-r--r-- | MLKLLVMCompiler.mm | 9 | ||||
| -rw-r--r-- | MLKRoot.m | 11 | ||||
| -rw-r--r-- | globals.h | 6 | ||||
| -rw-r--r-- | globals.m | 3 | 
6 files changed, 58 insertions, 31 deletions
| 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); diff --git a/MLKLLVMCompiler.h b/MLKLLVMCompiler.h index cf2823b..8a10c86 100644 --- a/MLKLLVMCompiler.h +++ b/MLKLLVMCompiler.h @@ -32,6 +32,8 @@ using namespace llvm;  #endif  @interface MLKLLVMCompiler : NSObject ++(void) load; +  +(void) initialize;  +(id) compile:(id)object diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index aa0ab79..4b63a89 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -76,6 +76,15 @@ static Constant  @implementation MLKLLVMCompiler ++(void) load +{ +  if (!MLKDefaultCompiler) +    { +      MLKDefaultCompiler = self; +      MLKLoadCompilesP = YES; +    } +} +  +(void) initialize  {    module = new llvm::Module ("MLKLLVMModule"); @@ -32,6 +32,7 @@  #import "MLKSingleFloat.h"  #import "MLKDoubleFloat.h"  #import "NSObject-MLKPrinting.h" +#import "globals.h"  #import "runtime-compatibility.h"  #import "util.h" @@ -708,17 +709,19 @@ as provided by method %@ of object %@",                           with:nil]]);  } -#ifdef USE_LLVM  +(NSArray *) compile:(NSArray *)args  { +  if (!MLKDefaultCompiler) +    [NSException raise:@"MLKNotImplementedException" +                 format:@"It seems as though there is no compiler here."]; +    //NSLog (@"Compiling lambda form."); -  id thing = [MLKLLVMCompiler compile:denullify([args objectAtIndex:0]) -                              inContext:[MLKLexicalContext globalContext]]; +  id thing = [MLKDefaultCompiler compile:denullify([args objectAtIndex:0]) +                                 inContext:[MLKLexicalContext globalContext]];    //NSLog (@"Compilation done.");    //NSLog (@"Compiled: %@", thing);    RETURN_VALUE (thing);  } -#endif  +(NSArray *) fset:(NSArray *)args  { @@ -16,4 +16,10 @@   * along with this program.  If not, see <http://www.gnu.org/licenses/>.   */ +#import <Foundation/NSObject.h> + +  extern id MLKEndOfArgumentsMarker; + +extern id MLKDefaultCompiler; +extern BOOL MLKLoadCompilesP; @@ -23,6 +23,9 @@  id MLKEndOfArgumentsMarker; +id MLKDefaultCompiler = nil; +BOOL MLKLoadCompilesP = NO; +  @interface MLKGlobalManager : NSObject  +(void) load; | 
