diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-31 11:49:11 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-31 11:49:11 +0200 |
commit | 604cc04c18af75e65b52a6b22b98d0f687d047c7 (patch) | |
tree | 5b3e205c23c5d52e163ff571aa2f6cdc488fb36b | |
parent | ca17649dab6d0d1ed49a3e072827e8324629aa64 (diff) |
Add %LOOP.
-rw-r--r-- | MLKInterpreter.m | 32 |
1 files changed, 32 insertions, 0 deletions
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; |