-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidelisp_wasm.c
78 lines (71 loc) · 2.33 KB
/
idelisp_wasm.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
78
#include "core.c"
#include <emscripten/emscripten.h>
void EMSCRIPTEN_KEEPALIVE exec(char* source) {
Decimal = mpc_new("decimal");
Number = mpc_new("number");
String = mpc_new("string");
Symbol = mpc_new("symbol");
Keyword = mpc_new("keyword");
Comment = mpc_new("comment");
HashMap = mpc_new("hashmap");
Sexpr = mpc_new("sexpr");
Qexpr = mpc_new("qexpr");
Expr = mpc_new("expr");
IdeLISP = mpc_new("idelisp");
mpca_lang(MPCA_LANG_DEFAULT,
" \
decimal : /-?[0-9]+\\.[0-9]+/ ; \
number : /-?[0-9]+/ ; \
string : /\"(\\\\.|[^\"])*\"/ ; \
keyword : /:[a-zA-Z0-9_+^\\-*\\/\\\\=<>!&%\\?]+/ ; \
symbol : /[a-zA-Z0-9_+^\\-*\\/\\\\=<>!&%\\?]+/ ; \
comment : /;[^\\r\\n]*/ ; \
hashmap : '{' <expr>* '}' ; \
sexpr : '(' <expr>* ')' ; \
qexpr : \"'(\" <expr>* ')' ; \
expr : <decimal> | <number> | <string> | <keyword> | <symbol> \
| <sexpr> | <qexpr> | <comment> | <hashmap> ; \
idelisp : /^/ <expr>* /$/ ; \
",
Decimal,
Number,
String,
Keyword,
Symbol,
Comment,
HashMap,
Sexpr,
Qexpr,
Expr,
IdeLISP);
ideenv* env = ideenv_new();
env->depth = 0;
ideenv_add_builtins(env);
mpc_result_t result;
if (mpc_parse("input", source, IdeLISP, &result)) {
mpc_ast_t* root_node = result.output;
ideobj* v = ideobj_eval(
env,
ideobj_read(root_node)
);
ideobj_println(v);
ideobj_del(v);
} else {
mpc_err_print(result.error);
}
mpc_ast_delete(result.output);
mpc_cleanup(
11,
Decimal,
Number,
String,
Keyword,
Symbol,
Comment,
HashMap,
Sexpr,
Qexpr,
Expr,
IdeLISP
);
};