aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miniMAL/env.json4
-rw-r--r--miniMAL/miniMAL-core.json10
-rw-r--r--miniMAL/step4_if_fn_do.json81
-rw-r--r--miniMAL/types.json8
4 files changed, 98 insertions, 5 deletions
diff --git a/miniMAL/env.json b/miniMAL/env.json
index 30ab952..0dfa67b 100644
--- a/miniMAL/env.json
+++ b/miniMAL/env.json
@@ -7,7 +7,7 @@
["get", ["first", "b"], ["`", "val"]]],
["assoc!", "env", ["get", ["nth", "b", 1], ["`", "val"]], "e"],
["env-bind", ["assoc!", "env", ["get", ["first", "b"], ["`", "val"]],
- ["get", ["first", "e"], ["`", "val"]]],
+ ["first", "e"]],
["rest", "b"],
["rest", "e"]]]]]],
@@ -15,7 +15,7 @@
["let", ["env", ["hash-map", ["`", "__outer__"], ["first", "args"]]],
["if", ["<=", ["count", "args"], 1],
"env",
- ["bind-env", "env", ["get", "args", 1], ["get", "args", 2]]]]]],
+ ["env-bind", "env", ["get", "args", 1], ["get", "args", 2]]]]]],
["def", "env-find", ["fn", ["env", "key"],
["let", ["k", ["get", "key", ["`", "val"]]],
diff --git a/miniMAL/miniMAL-core.json b/miniMAL/miniMAL-core.json
index a4acfec..d870604 100644
--- a/miniMAL/miniMAL-core.json
+++ b/miniMAL/miniMAL-core.json
@@ -77,6 +77,16 @@
["def", "apply", ["fn", ["a", "b"], [".", "a", ["`", "apply"], "a", "b"]]],
+["def", "or", ["~", ["fn", ["&", "xs"],
+ ["if", ["empty?", "xs"],
+ null,
+ ["if", ["=", 1, ["count", "xs"]],
+ ["first", "xs"],
+ ["list", ["`", "let"], ["list", ["`", "or_FIXME"], ["first", "xs"]],
+ ["list", ["`", "if"], ["`", "or_FIXME"],
+ ["`", "or_FIXME"],
+ ["concat", ["`", ["or"]], ["rest", "xs"]]]]]]]]],
+
["def", "typeof", ["fn", ["a"], ["js", ["str", ["`", "typeof "], ["pr-str", "a"]]]]],
["def", "repl", ["fn",["prompt", "rep"],
diff --git a/miniMAL/step4_if_fn_do.json b/miniMAL/step4_if_fn_do.json
new file mode 100644
index 0000000..93c0929
--- /dev/null
+++ b/miniMAL/step4_if_fn_do.json
@@ -0,0 +1,81 @@
+["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"]]],
+ ["if", ["=", ["`", "do"], "a0"],
+ ["let", ["el", ["eval-ast", ["rest", "ast"], "env"]],
+ ["nth", "el", ["-", ["count", "el"], 1]]],
+ ["if", ["=", ["`", "if"], "a0"],
+ ["let", ["cond", ["EVAL", ["nth", "ast", 1], "env"]],
+ ["if", ["or", ["=", "cond", null], ["=", "cond", false]],
+ ["if", [">", ["count", "ast"], 3],
+ ["EVAL", ["nth", "ast", 3], "env"],
+ null],
+ ["EVAL", ["nth", "ast", 2], "env"]]],
+ ["if", ["=", ["`", "fn*"], "a0"],
+ ["fn", ["&", "args"],
+ ["let", ["e", ["env-new", "env", ["nth", "ast", 1], "args"]],
+ ["EVAL", ["nth", "ast", 2], "e"]]],
+ ["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"]],
+
+["def", "rep", ["fn", ["strng"],
+ ["try",
+ ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]],
+ ["catch", "exc",
+ ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]],
+
+["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"],
+
+["rep", ["`", "(def! not (fn* (a) (if a false true)))"]],
+
+["repl", ["`", "user> "], "rep"],
+
+null
+
+]
diff --git a/miniMAL/types.json b/miniMAL/types.json
index 2f4d264..37cc50e 100644
--- a/miniMAL/types.json
+++ b/miniMAL/types.json
@@ -5,9 +5,11 @@
["`", "val"], "name"]]],
["def", "symbol?", ["fn", ["obj"],
- ["if", ["=", ["`", "Symbol"], ["get", "obj", ["`", "type"]]],
- true,
- false]]],
+ ["if", ["=", "obj", null],
+ false,
+ ["if", ["=", ["`", "Symbol"], ["get", "obj", ["`", "type"]]],
+ true,
+ false]]]],
null
]