From 697e27d004afaaa55792741cbab55b75f24156b9 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Wed, 2 Jul 2008 18:04:14 +0200 Subject: Interpreter: Implement UNWIND-PROTECT. --- MLKInterpreter.m | 30 +++++++++++++++++++++++++++++- MLKPackage.m | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) 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"]]; -- cgit v1.2.3