aboutsummaryrefslogtreecommitdiff
path: root/miniMAL/step2_eval.json
blob: d4fd56d39b821e76cf57cbecdde5d97db8b2e577 (plain)
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
["do",

["load-file", ["`", "miniMAL-core.json"]],
["load-file", ["`", "types.json"]],
["load-file", ["`", "reader.json"]],
["load-file", ["`", "printer.json"]],

["def", "READ", ["fn", ["strng"],
  ["read-str", "strng"]]],

["def", "eval-ast", ["fn", ["ast", "env"],
  ["if", ["symbol?", "ast"],
    ["let", ["sym", ["get", "ast", ["`", "val"]]],
      ["if", ["contains?", "env", "sym"],
        ["get", "env", "sym"],
        ["throw", ["str", ["`", "'"], "sym", ["`", "' not found"]]]]],
  ["if", ["list?", "ast"],
    ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"],
  "ast"]]]],

["def", "EVAL", ["fn", ["ast", "env"],
  ["if", ["not", ["list?", "ast"]],
    ["eval-ast", "ast", "env"],
    ["let", ["el", ["eval-ast", "ast", "env"],
             "f", ["first", "el"],
             "args", ["rest", "el"]],
      ["apply", "f", "args"]]]]],

["def", "PRINT", ["fn", ["exp"],
  ["pr-str", "exp", true]]],


["def", "repl-env",
  ["hash-map",
    ["`", "+"], "+",
    ["`", "-"], "-",
    ["`", "*"], "*",
    ["`", "/"], ["fn", ["a", "b"], ["parseInt", ["/", "a", "b"]]]]],

["def", "rep", ["fn", ["strng"],
  ["try",
    ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]],
    ["catch", "exc",
      ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]],

["repl", ["`", "user> "], "rep"],

null

]