2005-05-01 11:48:36 +00:00
|
|
|
#include "Void.h"
|
|
|
|
#include "Nil.h"
|
|
|
|
#include "Number.h"
|
|
|
|
#include "builtins.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "Cons.h"
|
|
|
|
#include "Continuation.h"
|
2005-05-08 03:44:18 +00:00
|
|
|
#include "BaseContinuation.h"
|
2005-05-06 23:25:06 +00:00
|
|
|
#include "Boolean.h"
|
2005-05-01 11:48:36 +00:00
|
|
|
|
2005-05-06 23:25:06 +00:00
|
|
|
SchemeObject bi_display (SchemeObject args, Machine m)
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
print([[args car] printForm]);
|
|
|
|
return [Void voidConstant];
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemeObject bi_newline (SchemeObject args, Machine m)
|
|
|
|
{
|
|
|
|
print("\n");
|
|
|
|
return [Void voidConstant];
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemeObject bi_add (SchemeObject args, Machine m)
|
|
|
|
{
|
|
|
|
local integer sum = 0;
|
|
|
|
local SchemeObject cur;
|
|
|
|
|
|
|
|
for (cur = args; cur != [Nil nil]; cur = [cur cdr]) {
|
|
|
|
sum += [(Number) [cur car] intValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [Number newFromInt: sum];
|
|
|
|
}
|
|
|
|
|
2005-05-06 23:25:06 +00:00
|
|
|
SchemeObject bi_cons (SchemeObject args, Machine m)
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2005-05-06 23:25:06 +00:00
|
|
|
[args cdr: [[args cdr] car]];
|
|
|
|
return args;
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
2005-05-06 23:25:06 +00:00
|
|
|
|
|
|
|
SchemeObject bi_null (SchemeObject args, Machine m)
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2005-05-06 23:25:06 +00:00
|
|
|
return [args car] == [Nil nil]
|
|
|
|
?
|
|
|
|
[Boolean trueConstant] :
|
|
|
|
[Boolean falseConstant];
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemeObject bi_car (SchemeObject args, Machine m)
|
|
|
|
{
|
|
|
|
return [[args car] car];
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemeObject bi_cdr (SchemeObject args, Machine m)
|
|
|
|
{
|
|
|
|
return [[args car] cdr];
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemeObject bi_apply (SchemeObject args, Machine m)
|
|
|
|
{
|
|
|
|
[m stack: [[args cdr] car]];
|
|
|
|
[[args car] invokeOnMachine: m];
|
|
|
|
return NIL;
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 03:44:18 +00:00
|
|
|
SchemeObject bi_callcc (SchemeObject args, Machine m)
|
|
|
|
{
|
|
|
|
if ([m continuation]) {
|
|
|
|
[m stack: cons([m continuation], [Nil nil])];
|
|
|
|
} else {
|
|
|
|
[m stack: cons([BaseContinuation baseContinuation],
|
|
|
|
[Nil nil])];
|
|
|
|
}
|
|
|
|
[[args car] invokeOnMachine: m];
|
|
|
|
return NIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-06 23:25:06 +00:00
|
|
|
void builtin_addtomachine (Machine m)
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2005-05-06 23:25:06 +00:00
|
|
|
[m addGlobal: symbol("display")
|
|
|
|
value: [Primitive newFromFunc: bi_display]];
|
|
|
|
[m addGlobal: symbol("newline")
|
|
|
|
value: [Primitive newFromFunc: bi_newline]];
|
|
|
|
[m addGlobal: symbol("+")
|
|
|
|
value: [Primitive newFromFunc: bi_add]];
|
|
|
|
[m addGlobal: symbol("cons")
|
|
|
|
value: [Primitive newFromFunc: bi_cons]];
|
|
|
|
[m addGlobal: symbol("null?")
|
|
|
|
value: [Primitive newFromFunc: bi_null]];
|
|
|
|
[m addGlobal: symbol("car")
|
|
|
|
value: [Primitive newFromFunc: bi_car]];
|
|
|
|
[m addGlobal: symbol("cdr")
|
|
|
|
value: [Primitive newFromFunc: bi_cdr]];
|
|
|
|
[m addGlobal: symbol("apply")
|
|
|
|
value: [Primitive newFromFunc: bi_apply]];
|
2005-05-08 03:44:18 +00:00
|
|
|
[m addGlobal: symbol("call-with-current-continuation")
|
|
|
|
value: [Primitive newFromFunc: bi_callcc]];
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|