aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-02-11 22:31:39 -0600
committerJoel Martin <github@martintribe.org>2015-02-11 22:31:39 -0600
commit5351b94a47422d9e66b0a96dc243445a04970379 (patch)
tree78bbfd113b3ba012485453a877958d60ec1260f1
parentc1fe72ae2b94d37cbf027aa185c27307d9776c56 (diff)
downloadmal-5351b94a47422d9e66b0a96dc243445a04970379.tar.gz
mal-5351b94a47422d9e66b0a96dc243445a04970379.zip
miniMAL: step2
-rw-r--r--docs/TODO3
-rw-r--r--miniMAL/printer.json2
-rw-r--r--miniMAL/reader.json3
-rw-r--r--miniMAL/step1_read_print.json1
-rw-r--r--miniMAL/step2_eval.json50
-rw-r--r--miniMAL/types.json13
6 files changed, 69 insertions, 3 deletions
diff --git a/docs/TODO b/docs/TODO
index 0b3fb59..741d024 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -100,6 +100,9 @@ Mal:
- line numbers in errors
- step5_tco
+miniMAL:
+ - figure out why {} literals are "static"/persistent
+
Perl:
- fix metadata on native functions
- implement conj
diff --git a/miniMAL/printer.json b/miniMAL/printer.json
index 28d5d4d..99f4198 100644
--- a/miniMAL/printer.json
+++ b/miniMAL/printer.json
@@ -17,7 +17,7 @@
["`", "true"],
["if", ["=", false, "exp"],
["`", "false"],
- ["if", ["=", ["`", "Symbol"], ["get", "exp", ["`", "type"]]],
+ ["if", ["symbol?", "exp"],
["get", "exp", ["`", "val"]],
["str", ["`", "#<unknown: "], "exp", ["`", ">"]]]]]]]]]]],
diff --git a/miniMAL/reader.json b/miniMAL/reader.json
index 2cdcde4..4e25b59 100644
--- a/miniMAL/reader.json
+++ b/miniMAL/reader.json
@@ -40,8 +40,7 @@
true,
["if", ["=", ["`", "false"], "token"],
false,
- ["hash-map", ["`", "type"], ["`", "Symbol"],
- ["`", "val"], "token"]]]]]]]]],
+ ["symbol", "token"]]]]]]]]],
["def", "read-list-entries", ["fn", ["rdr"],
["let", ["tok", ["rdr-peek", "rdr"]],
diff --git a/miniMAL/step1_read_print.json b/miniMAL/step1_read_print.json
index 392cab6..dc1f269 100644
--- a/miniMAL/step1_read_print.json
+++ b/miniMAL/step1_read_print.json
@@ -1,6 +1,7 @@
["do",
["load-file", ["`", "miniMAL-core.json"]],
+["load-file", ["`", "types.json"]],
["load-file", ["`", "reader.json"]],
["load-file", ["`", "printer.json"]],
diff --git a/miniMAL/step2_eval.json b/miniMAL/step2_eval.json
new file mode 100644
index 0000000..d4fd56d
--- /dev/null
+++ b/miniMAL/step2_eval.json
@@ -0,0 +1,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
+
+]
diff --git a/miniMAL/types.json b/miniMAL/types.json
new file mode 100644
index 0000000..2f4d264
--- /dev/null
+++ b/miniMAL/types.json
@@ -0,0 +1,13 @@
+["do",
+
+["def", "symbol", ["fn", ["name"],
+ ["hash-map", ["`", "type"], ["`", "Symbol"],
+ ["`", "val"], "name"]]],
+
+["def", "symbol?", ["fn", ["obj"],
+ ["if", ["=", ["`", "Symbol"], ["get", "obj", ["`", "type"]]],
+ true,
+ false]]],
+
+null
+]