From 604cc04c18af75e65b52a6b22b98d0f687d047c7 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 31 Jul 2008 11:49:11 +0200 Subject: Add %LOOP. --- MLKInterpreter.m | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/MLKInterpreter.m b/MLKInterpreter.m index 8237f7b..2fe49a5 100644 --- a/MLKInterpreter.m +++ b/MLKInterpreter.m @@ -66,6 +66,7 @@ static MLKSymbol *UNWIND_PROTECT; static MLKSymbol *VALUES; static MLKSymbol *_DEFMACRO; static MLKSymbol *_LAMBDA; +static MLKSymbol *_LOOP; @implementation MLKInterpreter @@ -84,6 +85,7 @@ static MLKSymbol *_LAMBDA; THROW = [cl intern:@"THROW"]; LAMBDA = [cl intern:@"LAMBDA"]; LET = [cl intern:@"LET"]; + _LOOP = [sys intern:@"%LOOP"]; APPLY = [cl intern:@"APPLY"]; EVAL = [cl intern:@"EVAL"]; FUNCALL = [cl intern:@"FUNCALL"]; @@ -558,6 +560,36 @@ static MLKSymbol *_LAMBDA; return result; } + else if (car == _LOOP) + { + id rest; + + if (expandOnly) + { + RETURN_VALUE ([MLKCons cons:_LOOP + with:[[[self eval:[MLKCons cons:PROGN + with:[program cdr]] + inLexicalContext:context + withEnvironment:lexenv + expandOnly:YES] + objectAtIndex:0] + cdr]]); + } + + while (YES) + { + rest = program; + while ((rest = [rest cdr])) + { + [self eval:[rest car] + inLexicalContext:context + withEnvironment:lexenv + expandOnly:expandOnly]; + } + } + + RETURN_VALUE (nil); // never reached + } else if (car == PROGN) { id result = nil; -- cgit v1.2.3