diff options
| author | Joel Martin <github@martintribe.org> | 2015-02-15 20:46:19 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-02-15 20:46:19 -0600 |
| commit | 1981bf5766d9bb75a652cc781b817cc3150d12ef (patch) | |
| tree | b6663351e6290a05b048de1878ccd5a42db54333 | |
| parent | 9d8f02993276fe9b77f7c21099d1b9f1602d195c (diff) | |
| download | mal-1981bf5766d9bb75a652cc781b817cc3150d12ef.tar.gz mal-1981bf5766d9bb75a652cc781b817cc3150d12ef.zip | |
miniMAL: step7
| -rw-r--r-- | miniMAL/core.json | 2 | ||||
| -rw-r--r-- | miniMAL/miniMAL-core.json | 26 | ||||
| -rw-r--r-- | miniMAL/reader.json | 19 | ||||
| -rw-r--r-- | miniMAL/step7_quote.json | 121 | ||||
| -rw-r--r-- | miniMAL/types.json | 4 |
5 files changed, 162 insertions, 10 deletions
diff --git a/miniMAL/core.json b/miniMAL/core.json index 8b66801..a1549db 100644 --- a/miniMAL/core.json +++ b/miniMAL/core.json @@ -36,6 +36,8 @@ ["`", "list"], "list", ["`", "list?"], "list?", + ["`", "cons"], "cons", + ["`", "concat"], "concat", ["`", "empty?"], "empty?", ["`", "count"], "_count"]], diff --git a/miniMAL/miniMAL-core.json b/miniMAL/miniMAL-core.json index d870604..b885d9b 100644 --- a/miniMAL/miniMAL-core.json +++ b/miniMAL/miniMAL-core.json @@ -77,15 +77,25 @@ ["def", "apply", ["fn", ["a", "b"], [".", "a", ["`", "apply"], "a", "b"]]], +["def", "and", ["~", ["fn", ["&", "xs"], + ["if", ["empty?", "xs"], + true, + ["if", ["=", 1, ["count", "xs"]], + ["first", "xs"], + ["list", ["`", "let"], ["list", ["`", "and_FIXME"], ["first", "xs"]], + ["list", ["`", "if"], ["`", "and_FIXME"], + ["concat", ["`", ["and"]], ["rest", "xs"]], + ["`", "and_FIXME"]]]]]]]], + ["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"]]]]]]]]], + ["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"]]]]], diff --git a/miniMAL/reader.json b/miniMAL/reader.json index 7058558..108d626 100644 --- a/miniMAL/reader.json +++ b/miniMAL/reader.json @@ -66,11 +66,28 @@ ["def", "read-form", ["fn", ["rdr"], ["let", ["token", ["rdr-peek", "rdr"]], + ["if", ["=", ["`", "'"], "token"], + ["do", + ["rdr-next", "rdr"], + ["list", ["symbol", ["`", "quote"]], ["read-form", "rdr"]]], + ["if", ["=", ["`", "`"], "token"], + ["do", + ["rdr-next", "rdr"], + ["list", ["symbol", ["`", "quasiquote"]], ["read-form", "rdr"]]], + ["if", ["=", ["`", "~"], "token"], + ["do", + ["rdr-next", "rdr"], + ["list", ["symbol", ["`", "unquote"]], ["read-form", "rdr"]]], + ["if", ["=", ["`", "~@"], "token"], + ["do", + ["rdr-next", "rdr"], + ["list", ["symbol", ["`", "splice-unquote"]], ["read-form", "rdr"]]], + ["if", ["=", ["`", ")"], "token"], ["throw", ["`", "unexpected ')'"]], ["if", ["=", ["`", "("], "token"], ["read-list", "rdr"], - ["read-atom", "rdr"]]]]]], + ["read-atom", "rdr"]]]]]]]]]], ["def", "read-str", ["fn", ["strn"], ["let", ["tokens", ["tokenize", "strn"], diff --git a/miniMAL/step7_quote.json b/miniMAL/step7_quote.json new file mode 100644 index 0000000..5cd0afa --- /dev/null +++ b/miniMAL/step7_quote.json @@ -0,0 +1,121 @@ +["do", + +["load-file", ["`", "miniMAL-core.json"]], +["load-file", ["`", "types.json"]], +["load-file", ["`", "reader.json"]], +["load-file", ["`", "printer.json"]], +["load-file", ["`", "env.json"]], +["load-file", ["`", "core.json"]], + +["def", "READ", ["fn", ["strng"], ["read-str", "strng"]]], + +["def", "pair?", ["fn", ["x"], + ["if", ["list?", "x"], + ["if", [">", ["count", "x"], 0], true, false], + false]]], + +["def", "quasiquote", ["fn", ["ast"], + ["if", ["not", ["pair?", "ast"]], + ["list", ["symbol", ["`", "quote"]], "ast"], + ["if", ["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]], + ["nth", "ast", 1], + ["if", ["and", ["pair?", ["nth", "ast", 0]], + ["=", ["`", "splice-unquote"], + ["get", ["nth", ["nth", "ast", 0], 0], ["`", "val"]]]], + ["list", ["symbol", ["`", "concat"]], + ["nth", ["nth", "ast", 0], 1], + ["quasiquote", ["rest", "ast"]]], + ["list", ["symbol", ["`", "cons"]], + ["quasiquote", ["nth", "ast", 0]], + ["quasiquote", ["rest", "ast"]]]]]]]], + +["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", ["=", ["`", "quote"], "a0"], + ["nth", "ast", 1], + ["if", ["=", ["`", "quasiquote"], "a0"], + ["EVAL", ["quasiquote", ["nth", "ast", 1]], "env"], + ["if", ["=", ["`", "do"], "a0"], + ["do", + ["eval-ast", ["slice", "ast", 1, ["-", ["count", "ast"], 1]], "env"], + ["EVAL", ["nth", "ast", ["-", ["count", "ast"], 1]], "env"]], + ["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"], + ["malfunc", + ["fn", ["&", "args"], + ["let", ["e", ["env-new", "env", ["nth", "ast", 1], "args"]], + ["EVAL", ["nth", "ast", 2], "e"]]], + ["nth", "ast", 2], "env", ["nth", "ast", 1]], + ["let", ["el", ["eval-ast", "ast", "env"], + "f", ["first", "el"], + "args", ["rest", "el"]], + ["if", ["malfunc?", "f"], + ["EVAL", ["get", "f", ["`", "ast"]], + ["env-new", ["get", "f", ["`", "env"]], + ["get", "f", ["`", "params"]], + "args"]], + ["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"]]]]]]], + +["`", "core.mal: defined using miniMAL"], +["map", ["fn", ["k"], ["env-set", "repl-env", + ["symbol", "k"], + ["get", "core-ns", "k"]]], + ["keys", "core-ns"]], +["env-set", "repl-env", ["symbol", ["`", "eval"]], + ["fn", ["ast"], ["EVAL", "ast", "repl-env"]]], +["env-set", "repl-env", ["symbol", ["`", "*ARGV*"]], + ["slice", "*ARGV*", 1]], + +["`", "core.mal: defined using mal itself"], +["rep", ["`", "(def! not (fn* (a) (if a false true)))"]], +["rep", ["`", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"]], + +["if", ["not", ["empty?", "*ARGV*"]], + ["rep", ["str", ["`", "(load-file \""], ["get", "*ARGV*", 0], ["`", "\")"]]], + ["repl", ["`", "user> "], "rep"]], + +null + +] diff --git a/miniMAL/types.json b/miniMAL/types.json index 2e85775..2af650d 100644 --- a/miniMAL/types.json +++ b/miniMAL/types.json @@ -14,7 +14,9 @@ ["if", ["list?", "b"], ["_cmp_seqs", "a", "b"], false], - ["=", "a", "b"]]]], + ["if", ["symbol?", "a"], + ["=", ["get", "a", ["`", "val"]], ["get", "b", ["`", "val"]]], + ["=", "a", "b"]]]]], ["def", "symbol", ["fn", ["name"], ["hash-map", ["`", "type"], ["`", "Symbol"], |
