From 189d02b12aa33fc18eaff9558675d9fa9d6ba668 Mon Sep 17 00:00:00 2001
From: Matthias Andreas Benkard <matthias@benkard.de>
Date: Fri, 27 Jun 2008 14:42:33 +0200
Subject: MLKInterpreter: Fix APPLY and %LAMBDA.

---
 MLKInterpretedClosure.h |  8 ++++----
 MLKInterpretedClosure.m | 21 ++++++++++++++++-----
 MLKInterpreter.m        | 14 +++++++++-----
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/MLKInterpretedClosure.h b/MLKInterpretedClosure.h
index 5d1ac25..942a9b8 100644
--- a/MLKInterpretedClosure.h
+++ b/MLKInterpretedClosure.h
@@ -33,10 +33,10 @@
   MLKLexicalEnvironment *environment;
 }
 
--(id) initWithBodyForm:(id)form
-        lambdaListName:(MLKSymbol *)symbol
-               context:(MLKLexicalContext *)lexctx
-           environment:(MLKLexicalEnvironment *)lexenv;
+-(id) initWithBodyForms:(id)forms
+         lambdaListName:(MLKSymbol *)symbol
+                context:(MLKLexicalContext *)lexctx
+            environment:(MLKLexicalEnvironment *)lexenv;
 
 -(NSArray *) applyToArray:(NSArray *)arguments;
 
diff --git a/MLKInterpretedClosure.m b/MLKInterpretedClosure.m
index 48f1805..edf7e17 100644
--- a/MLKInterpretedClosure.m
+++ b/MLKInterpretedClosure.m
@@ -19,20 +19,31 @@
 #import "MLKCons.h"
 #import "MLKInterpretedClosure.h"
 #import "MLKInterpreter.h"
+#import "MLKPackage.h"
 #import "runtime-compatibility.h"
 
 #import <Foundation/NSDictionary.h>
 #import <Foundation/NSSet.h>
 
 
+static MLKSymbol *PROGN;
+
+
 @implementation MLKInterpretedClosure
--(id) initWithBodyForm:(id)form
-        lambdaListName:(MLKSymbol *)symbol
-               context:(MLKLexicalContext *)lexctx
-           environment:(MLKLexicalEnvironment *)lexenv
++(void) initialize
+{
+  MLKPackage *cl;
+  cl = [MLKPackage findPackage:@"COMMON-LISP"];
+  PROGN = [cl intern:@"PROGN"];
+}
+
+-(id) initWithBodyForms:(id)forms
+         lambdaListName:(MLKSymbol *)symbol
+                context:(MLKLexicalContext *)lexctx
+            environment:(MLKLexicalEnvironment *)lexenv
 {
   self = [super init];
-  ASSIGN (bodyForm, form);
+  ASSIGN (bodyForm, [MLKCons cons:PROGN with:forms]);
   ASSIGN (context, lexctx);
   ASSIGN (environment, lexenv);
   ASSIGN (lambdaListName, symbol);
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index 01a915f..7fc14d7 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -127,9 +127,13 @@ static MLKSymbol *_LAMBDA;
                                     inLexicalContext:context
                                     withEnvironment:lexenv];
 
-              return [[[program cdr] car] applyToArray:(rest
-                                                        ? (id)[rest array]
-                                                        : (id)[NSArray array])];
+              id <MLKFuncallable> function = [self eval:[[program cdr] car]
+                                                   inLexicalContext:context
+                                                   withEnvironment:lexenv];
+
+              return [function applyToArray:(rest
+                                             ? (id)[rest array]
+                                             : (id)[NSArray array])];
             }
           else if (car == _DEFMACRO)
             {
@@ -163,11 +167,11 @@ static MLKSymbol *_LAMBDA;
               // would be a lambda list in a real LAMBDA form must be a
               // symbol here.
               id lambdaList = [[program cdr] car];
-              id body = [[[program cdr] cdr] cdr];
+              id body = [[program cdr] cdr];
               MLKInterpretedClosure *closure;
 
               closure = AUTORELEASE ([[MLKInterpretedClosure alloc]
-                                       initWithBodyForm:body
+                                       initWithBodyForms:body
                                        lambdaListName:lambdaList
                                        context:context
                                        environment:lexenv]);
-- 
cgit v1.2.3