summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-02 18:04:14 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-02 18:04:14 +0200
commit697e27d004afaaa55792741cbab55b75f24156b9 (patch)
treee4e8dbe34fcbb913793d064d87eb6b8f87922249
parenta579f93456607eae5d6bdaef32befbfd80bf5d59 (diff)
Interpreter: Implement UNWIND-PROTECT.
-rw-r--r--MLKInterpreter.m30
-rw-r--r--MLKPackage.m1
2 files changed, 30 insertions, 1 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index 229661d..730aaa9 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -73,6 +73,7 @@ static MLKSymbol *SETF;
static MLKSymbol *SET;
static MLKSymbol *_FSET;
static MLKSymbol *PROGV;
+static MLKSymbol *UNWIND_PROTECT;
static MLKSymbol *VALUES;
static MLKSymbol *_DEFMACRO;
static MLKSymbol *_LAMBDA;
@@ -102,6 +103,7 @@ static MLKSymbol *_LAMBDA;
_FSET = [sys intern:@"%FSET"];
PROGV = [cl intern:@"PROGV"];
VALUES = [cl intern:@"VALUES"];
+ UNWIND_PROTECT = [cl intern:@"UNWIND-PROTECT"];
_DEFMACRO = [sys intern:@"%DEFMACRO"];
_LAMBDA = [sys intern:@"%LAMBDA"];
}
@@ -384,7 +386,7 @@ static MLKSymbol *_LAMBDA;
else if ([dynamicContext bindingForSymbol:symbol])
[dynamicContext setValue:value forSymbol:symbol];
else
- // Maybe print a warning.
+ // FIXME: Maybe print a warning.
[[MLKDynamicContext globalContext] addValue:value
forSymbol:symbol];
@@ -437,6 +439,32 @@ static MLKSymbol *_LAMBDA;
{
//FIXME: ...
}
+ else if (car == UNWIND_PROTECT)
+ {
+ NSArray *results;
+
+ NS_DURING
+ {
+ results = [self eval:[[program cdr] car]
+ inLexicalContext:context
+ withEnvironment:lexenv];
+ }
+ NS_HANDLER
+ {
+ [self eval:[MLKCons cons:PROGN with:[[program cdr] cdr]]
+ inLexicalContext:context
+ withEnvironment:lexenv];
+
+ [localException raise];
+ }
+ NS_ENDHANDLER;
+
+ [self eval:[MLKCons cons:PROGN with:[[program cdr] cdr]]
+ inLexicalContext:context
+ withEnvironment:lexenv];
+
+ return results;
+ }
else if (car == VALUES)
{
id results = [NSMutableArray array];
diff --git a/MLKPackage.m b/MLKPackage.m
index 0a9b0be..1fa668d 100644
--- a/MLKPackage.m
+++ b/MLKPackage.m
@@ -76,6 +76,7 @@ static NSMutableDictionary *packages = nil;
[cl export:[cl intern:@"EVAL"]];
[cl export:[cl intern:@"SPECIAL"]];
[cl export:[cl intern:@"SET"]];
+ [cl export:[cl intern:@"UNWIND-PROTECT"]];
[sys export:[sys intern:@"%DEFMACRO"]];
[sys export:[sys intern:@"%LAMBDA"]];