summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKForm.h2
-rw-r--r--MLKForm.m6
-rw-r--r--MLKInterpretedClosure.h14
-rw-r--r--MLKInterpretedClosure.m38
-rw-r--r--MLKInterpreter.m8
5 files changed, 26 insertions, 42 deletions
diff --git a/MLKForm.h b/MLKForm.h
index a57faa3..ef62d97 100644
--- a/MLKForm.h
+++ b/MLKForm.h
@@ -200,6 +200,8 @@
{
MLKSymbol *_lambdaListName;
}
+
+-(MLKSymbol *) lambdaListName;
@end
diff --git a/MLKForm.m b/MLKForm.m
index 16ab207..024ac2d 100644
--- a/MLKForm.m
+++ b/MLKForm.m
@@ -215,6 +215,7 @@
[NSArray arrayWithObjects:
_form, context, nil]]
objectAtIndex:0]);
+ //NSLog (@"=> %@", MLKPrintToString (expansion));
return LRETAIN ([MLKForm formWithObject:expansion
inContext:context
@@ -483,6 +484,11 @@
inContext:newContext];
return self;
}
+
+-(MLKSymbol *) lambdaListName
+{
+ return _lambdaListName;
+}
@end
diff --git a/MLKInterpretedClosure.h b/MLKInterpretedClosure.h
index 4955c4c..9651c70 100644
--- a/MLKInterpretedClosure.h
+++ b/MLKInterpretedClosure.h
@@ -16,7 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#import "MLKForm.h"
#import "MLKFuncallable.h"
+#import "MLKInterpreter.h"
#import "MLKLexicalContext.h"
#import "MLKLexicalEnvironment.h"
@@ -26,16 +28,12 @@
@interface MLKInterpretedClosure : NSObject <MLKFuncallable>
{
- id bodyForm;
- MLKSymbol *lambdaListName;
- MLKLexicalContext *context;
- MLKLexicalEnvironment *environment;
+ MLKSimpleLambdaForm *_form;
+ MLKLexicalEnvironment *_environment;
}
--(id) initWithBodyForms:(id)forms
- lambdaListName:(MLKSymbol *)symbol
- context:(MLKLexicalContext *)lexctx
- environment:(MLKLexicalEnvironment *)lexenv;
+-(id) initWithForm:(MLKSimpleLambdaForm *)aForm
+ environment:(MLKLexicalEnvironment *)lexenv;
-(NSArray *) applyToArray:(NSArray *)arguments;
diff --git a/MLKInterpretedClosure.m b/MLKInterpretedClosure.m
index 6507956..8389bdb 100644
--- a/MLKInterpretedClosure.m
+++ b/MLKInterpretedClosure.m
@@ -38,16 +38,12 @@ static MLKSymbol *PROGN;
PROGN = [cl intern:@"PROGN"];
}
--(id) initWithBodyForms:(id)forms
- lambdaListName:(MLKSymbol *)symbol
- context:(MLKLexicalContext *)lexctx
- environment:(MLKLexicalEnvironment *)lexenv
+-(id) initWithForm:(MLKSimpleLambdaForm *)form
+ environment:(MLKLexicalEnvironment *)lexenv
{
self = [super init];
- LASSIGN (bodyForm, [MLKCons cons:PROGN with:forms]);
- LASSIGN (context, lexctx);
- LASSIGN (environment, lexenv);
- LASSIGN (lambdaListName, symbol);
+ LASSIGN (_environment, lexenv);
+ LASSIGN (_form, form);
return self;
}
@@ -56,24 +52,12 @@ static MLKSymbol *PROGN;
id arglist = [MLKCons listWithArray:arguments];
MLKLexicalEnvironment *new_environment =
- [MLKLexicalEnvironment environmentWithParent:environment
- variables:[NSDictionary dictionaryWithObject:nullify(arglist)
- forKey:lambdaListName]
+ [MLKLexicalEnvironment environmentWithParent:_environment
+ variables:[NSDictionary dictionaryWithObject:arglist
+ forKey:nullify([_form lambdaListName])]
functions:nil];
- MLKLexicalContext *new_context =
- [MLKLexicalContext contextWithParent:context
- variables:[NSSet setWithObject:lambdaListName]
- functions:nil
- goTags:nil
- macros:nil
- compilerMacros:nil
- symbolMacros:nil
- declarations:nil];
-
- return [MLKInterpreter eval:bodyForm
- inLexicalContext:new_context
- withEnvironment:new_environment];
+ return [_form interpretBodyWithEnvironment:new_environment];
}
-(NSString *) description
@@ -88,10 +72,8 @@ static MLKSymbol *PROGN;
-(void) dealloc
{
- LDESTROY (bodyForm);
- LDESTROY (lambdaListName);
- LDESTROY (context);
- LDESTROY (environment);
+ LDESTROY (_environment);
+ LDESTROY (_form);
[super dealloc];
}
@end
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index 1921c5a..9612ad4 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -354,13 +354,9 @@
@implementation MLKSimpleLambdaForm (MLKInterpretation)
-(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env
{
- id lambdaList = [_tail car];
- id body = [_tail cdr];
id closure = LAUTORELEASE ([[MLKInterpretedClosure alloc]
- initWithBodyForms:_body
- lambdaListName:lambdaList
- context:_context
- environment:env]);
+ initWithForm:self
+ environment:env]);
RETURN_VALUE (closure);
}
@end