diff options
| author | Joel Martin <github@martintribe.org> | 2015-02-11 23:24:00 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-02-24 09:17:42 -0600 |
| commit | defc6335a611fcb78bc33fe6f3b074a2d88aa54c (patch) | |
| tree | ffb621d4ba2a50c993eb11fc32fb5b0437e9ba85 /miniMAL/step3_env.json | |
| parent | 5351b94a47422d9e66b0a96dc243445a04970379 (diff) | |
| download | mal-defc6335a611fcb78bc33fe6f3b074a2d88aa54c.tar.gz mal-defc6335a611fcb78bc33fe6f3b074a2d88aa54c.zip | |
miniMAL: step3
Diffstat (limited to 'miniMAL/step3_env.json')
| -rw-r--r-- | miniMAL/step3_env.json | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/miniMAL/step3_env.json b/miniMAL/step3_env.json new file mode 100644 index 0000000..9b45277 --- /dev/null +++ b/miniMAL/step3_env.json @@ -0,0 +1,64 @@ +["do", + +["load-file", ["`", "miniMAL-core.json"]], +["load-file", ["`", "types.json"]], +["load-file", ["`", "reader.json"]], +["load-file", ["`", "printer.json"]], +["load-file", ["`", "env.json"]], + +["def", "READ", ["fn", ["strng"], + ["read-str", "strng"]]], + +["def", "eval-ast", ["fn", ["ast", "env"], + ["if", ["symbol?", "ast"], + ["env-get", "env", "ast"], + ["if", ["list?", "ast"], + ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"], + "ast"]]]], + +["def", "LET", ["fn", ["env", "args"], + ["if", [">", ["count", "args"], 0], + ["do", + ["env-set", "env", ["nth", "args", 0], + ["EVAL", ["nth", "args", 1], "env"]], + ["LET", "env", ["rest", ["rest", "args"]]]]]]], + +["def", "EVAL", ["fn", ["ast", "env"], + ["if", ["not", ["list?", "ast"]], + ["eval-ast", "ast", "env"], + ["let", ["a0", ["get", ["first", "ast"], ["`", "val"]]], + ["if", ["=", ["`", "def!"], "a0"], + ["env-set", "env", ["nth", "ast", 1], + ["EVAL", ["nth", "ast", 2], "env"]], + ["if", ["=", ["`", "let*"], "a0"], + ["let", ["let-env", ["env-new", "env"]], + ["do", + ["LET", "let-env", ["nth", "ast", 1]], + ["EVAL", ["nth", "ast", 2], "let-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", ["env-new"]], +["env-set", "repl-env", ["symbol", ["`", "+"]], "+"], +["env-set", "repl-env", ["symbol", ["`", "-"]], "-"], +["env-set", "repl-env", ["symbol", ["`", "*"]], "*"], +["def", "div", ["fn", ["a", "b"], ["parseInt", ["/", "a", "b"]]]], +["env-set", "repl-env", ["symbol", ["`", "/"]], "div"], + +["def", "rep", ["fn", ["strng"], + ["try", + ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]], + ["catch", "exc", + ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]], + +["repl", ["`", "user> "], "rep"], + +null + +] |
