2005-05-01 11:48:36 +00:00
|
|
|
#include "Lambda.h"
|
|
|
|
#include "Nil.h"
|
|
|
|
#include "Symbol.h"
|
|
|
|
#include "string.h"
|
2005-05-08 10:37:57 +00:00
|
|
|
#include "Cons.h"
|
2005-05-01 11:48:36 +00:00
|
|
|
#include "defs.h"
|
2005-05-08 10:37:57 +00:00
|
|
|
#include "Error.h"
|
|
|
|
#include "Machine.h"
|
2005-05-01 11:48:36 +00:00
|
|
|
|
|
|
|
@implementation Lambda
|
2011-02-14 13:39:43 +00:00
|
|
|
+ (id) newWithCode: (CompiledCode *) c environment: (Frame *) e
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return [[self alloc] initWithCode: c environment: e];
|
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
- (id) initWithCode: (CompiledCode *) c environment: (Frame *) e
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
code = c;
|
|
|
|
env = e;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
- (void) invokeOnMachine: (Machine *) m
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2005-05-06 23:25:06 +00:00
|
|
|
[super invokeOnMachine: m];
|
2005-05-08 10:37:57 +00:00
|
|
|
if (length([m stack]) < [code minimumArguments]) {
|
|
|
|
[m value: [Error type: "call"
|
|
|
|
message: sprintf("expected at least %i arguments, received %i",
|
|
|
|
[code minimumArguments], length([m stack]))
|
|
|
|
by: m]];
|
|
|
|
return;
|
|
|
|
}
|
2005-05-01 11:48:36 +00:00
|
|
|
[m loadCode: code];
|
|
|
|
[m environment: env];
|
2005-05-08 06:38:01 +00:00
|
|
|
[m procedure: self];
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
2005-05-02 02:33:44 +00:00
|
|
|
|
|
|
|
- (void) markReachable
|
|
|
|
{
|
|
|
|
[env mark];
|
|
|
|
[code mark];
|
|
|
|
}
|
|
|
|
|
2005-05-01 11:48:36 +00:00
|
|
|
@end
|