-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisp.c
40 lines (31 loc) · 888 Bytes
/
lisp.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
#include "builtins.c"
void repl(lenv *e) {
puts("Lisp version 0.2.0");
puts("Enter exit for closing repl\n");
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (1) {
char *input = readline("lisp> ");
add_history(input);
ast *tree = parse(input);
if (tree->type != AST_ERROR) {
lval *x = lval_eval(e, lval_read(tree));
lval_println(x);
lval_del(x);
} else {
lval *err = lval_err(tree->context, tree->val);
lval_println(err);
}
free_ast(tree);
free(input);
}
#pragma clang diagnostic pop
}
int main(int argc, char **argv) {
lenv *global_env = lenv_new();
lenv_add_builtins(global_env);
load_input_files(argc, argv, global_env);
if (argc == 1)
repl(global_env);
return 0;
}