diff options
author | Matthias Benkard <mulk@minimulk.mst-plus> | 2008-08-28 18:28:25 +0200 |
---|---|---|
committer | Matthias Benkard <mulk@minimulk.mst-plus> | 2008-08-28 18:28:25 +0200 |
commit | cad01f32f911f1129675063cf0f1f57049c40116 (patch) | |
tree | d0a7f7e832d58187926c5fa3469df89cd33eb372 /MLKListenerController.m | |
parent | 5f0f8e7c29b6812c1f7a2696d345a5dc7b1a217a (diff) |
Listener: Execute code after reading it.
Diffstat (limited to 'MLKListenerController.m')
-rw-r--r-- | MLKListenerController.m | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/MLKListenerController.m b/MLKListenerController.m index 28e556b..3db8772 100644 --- a/MLKListenerController.m +++ b/MLKListenerController.m @@ -19,6 +19,9 @@ #import "MLKListenerController.h" #import "MLKDynamicContext.h" +#import "MLKLexicalContext.h" +#import "MLKLexicalEnvironment.h" +#import "MLKInterpreter.h" #import "MLKPackage.h" #import "MLKReader.h" #import "util.h" @@ -30,6 +33,12 @@ ensure_symbols(); } +- (void) initialiseInterpreter +{ + [inputField setStringValue:@"(load \"init.lisp\")"]; + [self submit:self]; +} + - (IBAction)submit:(id)sender { id object; @@ -85,6 +94,8 @@ [statusText setStringValue:@"Compiling and executing."]; NS_DURING { + int i; + NSArray *results; NSDictionary *vars = [NSDictionary dictionaryWithObjectsAndKeys: self, QUERY_IO, self, ERROR_OUTPUT, @@ -102,11 +113,38 @@ activeHandlerEnvironment:nil]; [newctx pushContext]; - // ... + results = [MLKInterpreter eval:object + inLexicalContext:[MLKLexicalContext globalContext] + withEnvironment:[MLKLexicalEnvironment globalEnvironment]]; + + for (i = 0; i < [results count]; i++) + { + id result = denullify ([results objectAtIndex:i]); + + [text beginEditing]; + attrs = [NSDictionary dictionaryWithObjectsAndKeys: + [NSColor purpleColor], NSForegroundColorAttributeName, nil]; + NSAttributedString *response = + LAUTORELEASE ([[NSAttributedString alloc] initWithString:MLKPrintToString(result) + attributes:attrs]); + [text appendAttributedString:response]; + [[text mutableString] appendString:@"\n"]; + } } NS_HANDLER { - // ... + NSString *bare_msg = [NSString stringWithFormat: + @"Caught an unhandled exception.\nName: %s\nReason: %s\n", + [[localException name] UTF8String], + [[localException reason] UTF8String]]; + + [text beginEditing]; + attrs = [NSDictionary dictionaryWithObjectsAndKeys: + [NSColor redColor], NSForegroundColorAttributeName, nil]; + NSAttributedString *response = + LAUTORELEASE ([[NSAttributedString alloc] initWithString:MLKPrintToString(object) + attributes:attrs]); + [text appendAttributedString:response]; } NS_ENDHANDLER; @@ -114,14 +152,6 @@ LDESTROY (newctx); [statusText setStringValue:@"Ready."]; - [text beginEditing]; - attrs = [NSDictionary dictionaryWithObjectsAndKeys: - [NSColor purpleColor], NSForegroundColorAttributeName, nil]; - NSAttributedString *response = - LAUTORELEASE ([[NSAttributedString alloc] initWithString:MLKPrintToString(object) - attributes:attrs]); - [text appendAttributedString:response]; - [[text mutableString] appendString:@"\n"]; [text endEditing]; |