Commit | Line | Data |
---|---|---|
dc2c5b3d JM |
1 | ["do", |
2 | ||
3 | ["load-file", ["`", "miniMAL-core.json"]], | |
4 | ["load-file", ["`", "types.json"]], | |
5 | ["load-file", ["`", "reader.json"]], | |
6 | ["load-file", ["`", "printer.json"]], | |
7 | ["load-file", ["`", "env.json"]], | |
8 | ["load-file", ["`", "core.json"]], | |
9 | ||
10 | ["def", "READ", ["fn", ["strng"], ["read-str", "strng"]]], | |
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"]]]]]], | |
dc2c5b3d 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"], | |
f618f6a1 | 51 | ["do", |
33783b04 DM |
52 | ["eval-ast", ["slice", "ast", 1, ["-", ["count", "ast"], 1]], "env"], |
53 | ["EVAL", ["nth", "ast", ["-", ["count", "ast"], 1]], "env"]], | |
54 | ["if", ["=", ["`", "if"], "a0"], | |
55 | ["let", ["cond", ["EVAL", ["nth", "ast", 1], "env"]], | |
56 | ["if", ["or", ["=", "cond", null], ["=", "cond", false]], | |
57 | ["if", [">", ["count", "ast"], 3], | |
58 | ["EVAL", ["nth", "ast", 3], "env"], | |
59 | null], | |
60 | ["EVAL", ["nth", "ast", 2], "env"]]], | |
61 | ["if", ["=", ["`", "fn*"], "a0"], | |
62 | ["malfunc", | |
63 | ["fn", ["&", "args"], | |
64 | ["let", ["e", ["env-new", "env", ["nth", "ast", 1], "args"]], | |
65 | ["EVAL", ["nth", "ast", 2], "e"]]], | |
66 | ["nth", "ast", 2], "env", ["nth", "ast", 1]], | |
67 | ["let", ["el", ["eval-ast", "ast", "env"], | |
68 | "f", ["first", "el"], | |
69 | "args", ["rest", "el"]], | |
70 | ["if", ["malfunc?", "f"], | |
71 | ["EVAL", ["get", "f", ["`", "ast"]], | |
72 | ["env-new", ["get", "f", ["`", "env"]], | |
73 | ["get", "f", ["`", "params"]], | |
74 | "args"]], | |
75 | ["apply", "f", "args"]]]]]]]]]]]]], | |
dc2c5b3d JM |
76 | |
77 | ["def", "PRINT", ["fn", ["exp"], | |
78 | ["pr-str", "exp", true]]], | |
79 | ||
80 | ||
81 | ["def", "repl-env", ["env-new"]], | |
82 | ||
83 | ["def", "rep", ["fn", ["strng"], | |
84 | ["try", | |
85 | ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]], | |
86 | ["catch", "exc", | |
87 | ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]], | |
88 | ||
89 | ["`", "core.mal: defined using miniMAL"], | |
90 | ["map", ["fn", ["k"], ["env-set", "repl-env", | |
91 | ["symbol", "k"], | |
92 | ["get", "core-ns", "k"]]], | |
93 | ["keys", "core-ns"]], | |
94 | ||
95 | ["`", "core.mal: defined using mal itself"], | |
96 | ["rep", ["`", "(def! not (fn* (a) (if a false true)))"]], | |
97 | ||
98 | ["repl", ["`", "user> "], "rep"], | |
99 | ||
100 | null | |
101 | ||
102 | ] |