summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <mulk@minimulk.mst-plus>2008-08-28 18:46:26 +0200
committerMatthias Benkard <mulk@minimulk.mst-plus>2008-08-28 18:46:26 +0200
commit810f69d41261d94d99bd0bec78415065753cee5f (patch)
tree8f3d68123b6161c812ea093e0d19dc0b150a79f6
parentcad01f32f911f1129675063cf0f1f57049c40116 (diff)
Listener: Run the evaluator in its own thread.
-rw-r--r--MLKListenerController.h2
-rw-r--r--MLKListenerController.m29
2 files changed, 23 insertions, 8 deletions
diff --git a/MLKListenerController.h b/MLKListenerController.h
index ef54d19..ce206ac 100644
--- a/MLKListenerController.h
+++ b/MLKListenerController.h
@@ -36,5 +36,7 @@
- (void)writeChar:(unichar)ch;
- (void)writeString:(NSString *)string;
+- (void)evalObject:(id)object;
+
- (IBAction)submit:(id)sender;
@end
diff --git a/MLKListenerController.m b/MLKListenerController.m
index 3db8772..f472448 100644
--- a/MLKListenerController.m
+++ b/MLKListenerController.m
@@ -41,11 +41,10 @@
- (IBAction)submit:(id)sender
{
+ MLKPackage *package;
id object;
NSDictionary *attrs;
NSString *input = [inputField stringValue];
- MLKPackage *package;
- MLKDynamicContext *newctx;
[submitButton setEnabled:NO];
@@ -70,10 +69,10 @@
package = [[MLKDynamicContext currentContext]
valueForSymbol:[[MLKPackage findPackage:@"COMMON-LISP"]
intern:@"*PACKAGE*"]];
-
+
NSMutableAttributedString *text = [outputTextView textStorage];
[text beginEditing];
-
+
attrs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSColor blueColor], NSForegroundColorAttributeName, nil];
NSString *barePrompt = [NSString stringWithFormat:@"%@> ", [package name]];
@@ -81,15 +80,27 @@
LAUTORELEASE ([[NSAttributedString alloc] initWithString:barePrompt
attributes:attrs]);
[text appendAttributedString:prompt];
-
+
attrs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSColor blackColor], NSForegroundColorAttributeName, nil];
NSAttributedString *inputFeedback =
LAUTORELEASE ([[NSAttributedString alloc] initWithString:input attributes:attrs]);
[text appendAttributedString:inputFeedback];
-
+
[[text mutableString] appendString:@"\n"];
- [text endEditing];
+ [text endEditing];
+
+ [NSThread detachNewThreadSelector:@selector(evalObject:)
+ toTarget:self
+ withObject:object];
+}
+
+- (void)evalObject:(id)object
+{
+ MLKDynamicContext *newctx;
+ NSDictionary *attrs;
+ NSMutableAttributedString *text = [outputTextView textStorage];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[statusText setStringValue:@"Compiling and executing."];
NS_DURING
@@ -142,7 +153,7 @@
attrs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSColor redColor], NSForegroundColorAttributeName, nil];
NSAttributedString *response =
- LAUTORELEASE ([[NSAttributedString alloc] initWithString:MLKPrintToString(object)
+ LAUTORELEASE ([[NSAttributedString alloc] initWithString:bare_msg
attributes:attrs]);
[text appendAttributedString:response];
}
@@ -157,6 +168,8 @@
[text endEditing];
[submitButton setEnabled:YES];
+
+ [pool release];
}
- (void)writeChar:(unichar)ch