-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.c
77 lines (63 loc) · 1.66 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <sys/types.h>
#include "vm.h"
#include "str.h"
#include "builtin.h"
static void
repl(struct VM *vm, int pos, FILE* stream) {
int ref = pos++;
for (int i=0; ; i++) {
if (stream == stdin) {
printf("%d #> ", i);
}
struct SexpReader r = {.pkgMapping = Nil};
int errCode = 0;
Obj exp = sexpRead(vm, pos, &r, stream, &errCode);
if (errCode != 0) {
break;
}
/* printf("before macro expand =="); */
/* sexpWrite(stdout, exp); */
vmSet(vm, ref, exp);
exp = macroExpand(vm, pos, ref);
/* printf("after macro expand =="); */
/* sexpWrite(stdout, exp); */
/* printf("\n"); */
vmSet(vm, ref, exp);
Obj res = eval(vm, pos, ref);
if (stream == stdin) {
sexpWrite(stdout, res);
printf("\n");
}
}
}
int main(int argc, char *argv[]) {
struct VM* vm = newVM();
int pos = 0;
// CORA PATH
strBuf tmp = getCoraPath();
strBuf tmp1 = strDup(toStr(tmp));
loadByteCode(vm, pos, toStr(strCat(tmp, cstr("cora/init.bc"))));
loadByteCode(vm, pos, toStr(strCat(tmp1, cstr("cora/compile.bc"))));
repl(vm, pos, stdin);
}
/* static void */
/* replBytecode(struct VM *vm, FILE* stream) { */
/* for (int i=0; ; i++) { */
/* printf("%d #> ", i); */
/* int err = 0; */
/* struct SexpReader r = {.pkgMapping = Nil}; */
/* int errCode; */
/* Obj exp = sexpRead(&r, stdin, &errCode); */
/* if (err != 0) { */
/* break; */
/* } */
/* char *exec = bytecodeToExec(exp); */
/* Obj res = run(&vm, exec); */
/* sexpWrite(stdout, res); */
/* printf("\n"); */
/* } */
/* } */