-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.c
59 lines (46 loc) · 1.49 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "runtime.h"
extern void builtinLoadSo(struct Cora *co);
int main(int argc, char *argv[]) {
uintptr_t dummy;
struct Cora* co = coraNew();
coraInit(co, &dummy);
Obj imported = intern("*imported*");
co->args[1] = makeCString("init.so");
co->args[2] = makeCString("cora/init");
co->nargs = 3;
trampoline(co, 0, builtinLoadSo);
primSet(co, imported, cons(makeCString("cora/init"), Nil));
primSet(co, imported, cons(makeCString("cora/lib/toc/internal"), symbolGet(imported)));
co->args[1] = makeCString("toc.so");
co->args[2] = makeCString("");
co->nargs = 3;
trampoline(co, 0, builtinLoadSo);
primSet(co, imported, cons(makeCString("cora/lib/toc"), symbolGet(imported)));
struct SexpReader r = {co: co};
int errCode = 0;
for (int i=0; ; i++) {
printf("%d #> ", i);
Obj exp = sexpRead(&r, stdin, &errCode);
if (errCode != 0) {
break;
}
/* printf("before macro expand =="); */
/* sexpWrite(stdout, exp); */
/* printf("\n"); */
co->args[0] = globalRef(intern("macroexpand"));
co->args[1] = exp;
co->nargs = 2;
trampoline(co, 0, coraDispatch);
exp = co->args[1];
/* printf("after macro expand =="); */
/* sexpWrite(stdout, exp); */
/* printf(" --- %d %d\n", co->base, co->pos); */
/* printf("\n"); */
co->args[0] = globalRef(intern("cora/lib/toc.eval0"));
co->args[1] = exp;
co->nargs = 2;
trampoline(co, 0, coraDispatch);
sexpWrite(stdout, co->args[1]);
printf("\n");
}
}