Merge pull request #377 from asarhaddon/fix-runtests-pre-eval
[jackhill/mal.git] / miniMAL / step8_macros.json
index c56cd7e..b0b894d 100644 (file)
@@ -1,11 +1,11 @@
 ["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"]],
+["load", ["`", "miniMAL-core.json"]],
+["load", ["`", "types.json"]],
+["load", ["`", "reader.json"]],
+["load", ["`", "printer.json"]],
+["load", ["`", "env.json"]],
+["load", ["`", "core.json"]],
 
 ["def", "READ", ["fn", ["strng"], ["read-str", "strng"]]],
 
     ["let", ["ast", ["macroexpand", "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"]],
+        ["if", ["empty?", "ast"],
+          "ast",
+          ["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", ["=", ["`", "defmacro!"], "a0"],
+              ["let", ["func", ["EVAL", ["nth", "ast", 2], "env"]],
+                ["do",
+                  ["set", "func", ["`", "macro?"], true],
+                  ["env-set", "env", ["nth", "ast", 1], "func"]]],
+            ["if", ["=", ["`", "macroexpand"], "a0"],
+              ["macroexpand", ["nth", "ast", 1], "env"],
+            ["if", ["=", ["`", "do"], "a0"],
               ["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", ["=", ["`", "defmacro!"], "a0"],
-            ["let", ["func", ["EVAL", ["nth", "ast", 2], "env"]],
-              ["do",
-                ["set", "func", ["`", "macro?"], true],
-                ["env-set", "env", ["nth", "ast", 1], "func"]]],
-          ["if", ["=", ["`", "macroexpand"], "a0"],
-            ["macroexpand", ["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"]]]]]]]]]]]]]]]]]],
+                ["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]]],
   ["try",
     ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]],
     ["catch", "exc",
-      ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]],
+      ["str", ["`", "Error: "],
+        ["if", ["isa", "exc", "Error"],
+          [".", "exc", ["`", "toString"]],
+          ["pr-str", "exc", true]]]]]]],
 
 ["`", "core.mal: defined using miniMAL"],
 ["map", ["fn", ["k"], ["env-set", "repl-env",
 ["env-set", "repl-env", ["symbol", ["`", "eval"]],
                         ["fn", ["ast"], ["EVAL", "ast", "repl-env"]]],
 ["env-set", "repl-env", ["symbol", ["`", "*ARGV*"]],
-                        ["slice", "*ARGV*", 1]],
+                        ["slice", "ARGS", 1]],
 
 ["`", "core.mal: defined using mal itself"],
 ["rep", ["`", "(def! not (fn* (a) (if a false true)))"]],
 ["rep", ["`", "(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))"]],
 ["rep", ["`", "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"]],
 
-["if", ["not", ["empty?", "*ARGV*"]],
-  ["rep", ["str", ["`", "(load-file \""], ["get", "*ARGV*", 0], ["`", "\")"]]],
+["if", ["not", ["empty?", "ARGS"]],
+  ["rep", ["str", ["`", "(load-file \""], ["get", "ARGS", 0], ["`", "\")"]]],
   ["repl", ["`", "user> "], "rep"]],
 
 null