Commit | Line | Data |
---|---|---|
7ebf5219 JM |
1 | ["do", |
2 | ||
b32495e9 JM |
3 | ["load", ["`", "miniMAL-core.json"]], |
4 | ["load", ["`", "types.json"]], | |
5 | ["load", ["`", "reader.json"]], | |
6 | ["load", ["`", "printer.json"]], | |
7 | ["load", ["`", "env.json"]], | |
8 | ["load", ["`", "core.json"]], | |
7ebf5219 | 9 | |
c5d30235 | 10 | ["def", "READ", ["fn", ["strng"], ["read-str", "strng"]]], |
7ebf5219 JM |
11 | |
12 | ["def", "eval-ast", ["fn", ["ast", "env"], | |
13 | ["if", ["symbol?", "ast"], | |
14 | ["env-get", "env", "ast"], | |
15 | ["if", ["list?", "ast"], | |
16 | ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"], | |
32045546 JM |
17 | ["if", ["vector?", "ast"], |
18 | ["vectorl", ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"]], | |
19 | ["if", ["map?", "ast"], | |
20 | ["let", ["new-hm", ["hash-map"]], | |
21 | ["do", | |
22 | ["map", ["fn", ["k"], ["set", "new-hm", | |
23 | ["EVAL", "k", "env"], | |
24 | ["EVAL", ["get", "ast", "k"], "env"]]], | |
25 | ["keys", "ast"]], | |
26 | "new-hm"]], | |
27 | "ast"]]]]]], | |
7ebf5219 JM |
28 | |
29 | ["def", "LET", ["fn", ["env", "args"], | |
30 | ["if", [">", ["count", "args"], 0], | |
31 | ["do", | |
32 | ["env-set", "env", ["nth", "args", 0], | |
33 | ["EVAL", ["nth", "args", 1], "env"]], | |
34 | ["LET", "env", ["rest", ["rest", "args"]]]]]]], | |
35 | ||
36 | ["def", "EVAL", ["fn", ["ast", "env"], | |
37 | ["if", ["not", ["list?", "ast"]], | |
f618f6a1 | 38 | ["eval-ast", "ast", "env"], |
33783b04 DM |
39 | ["if", ["empty?", "ast"], |
40 | "ast", | |
41 | ["let", ["a0", ["get", ["first", "ast"], ["`", "val"]]], | |
42 | ["if", ["=", ["`", "def!"], "a0"], | |
43 | ["env-set", "env", ["nth", "ast", 1], | |
44 | ["EVAL", ["nth", "ast", 2], "env"]], | |
45 | ["if", ["=", ["`", "let*"], "a0"], | |
46 | ["let", ["let-env", ["env-new", "env"]], | |
47 | ["do", | |
48 | ["LET", "let-env", ["nth", "ast", 1]], | |
49 | ["EVAL", ["nth", "ast", 2], "let-env"]]], | |
50 | ["if", ["=", ["`", "do"], "a0"], | |
51 | ["let", ["el", ["eval-ast", ["rest", "ast"], "env"]], | |
52 | ["nth", "el", ["-", ["count", "el"], 1]]], | |
53 | ["if", ["=", ["`", "if"], "a0"], | |
54 | ["let", ["cond", ["EVAL", ["nth", "ast", 1], "env"]], | |
55 | ["if", ["or", ["=", "cond", null], ["=", "cond", false]], | |
56 | ["if", [">", ["count", "ast"], 3], | |
57 | ["EVAL", ["nth", "ast", 3], "env"], | |
58 | null], | |
59 | ["EVAL", ["nth", "ast", 2], "env"]]], | |
60 | ["if", ["=", ["`", "fn*"], "a0"], | |
61 | ["fn", ["&", "args"], | |
62 | ["let", ["e", ["env-new", "env", ["nth", "ast", 1], "args"]], | |
63 | ["EVAL", ["nth", "ast", 2], "e"]]], | |
64 | ["let", ["el", ["eval-ast", "ast", "env"], | |
65 | "f", ["first", "el"], | |
66 | "args", ["rest", "el"]], | |
67 | ["apply", "f", "args"]]]]]]]]]]]], | |
7ebf5219 JM |
68 | |
69 | ["def", "PRINT", ["fn", ["exp"], | |
70 | ["pr-str", "exp", true]]], | |
71 | ||
72 | ||
73 | ["def", "repl-env", ["env-new"]], | |
74 | ||
75 | ["def", "rep", ["fn", ["strng"], | |
76 | ["try", | |
77 | ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]], | |
78 | ["catch", "exc", | |
dd7a4f55 JM |
79 | ["str", ["`", "Error: "], |
80 | ["if", ["isa", "exc", "Error"], | |
81 | [".", "exc", ["`", "toString"]], | |
82 | ["pr-str", "exc", true]]]]]]], | |
7ebf5219 | 83 | |
c5d30235 JM |
84 | ["`", "core.mal: defined using miniMAL"], |
85 | ["map", ["fn", ["k"], ["env-set", "repl-env", | |
86 | ["symbol", "k"], | |
87 | ["get", "core-ns", "k"]]], | |
88 | ["keys", "core-ns"]], | |
7ebf5219 | 89 | |
c5d30235 | 90 | ["`", "core.mal: defined using mal itself"], |
7ebf5219 JM |
91 | ["rep", ["`", "(def! not (fn* (a) (if a false true)))"]], |
92 | ||
93 | ["repl", ["`", "user> "], "rep"], | |
94 | ||
95 | null | |
96 | ||
97 | ] |