diff options
| author | Joel Martin <github@martintribe.org> | 2015-02-16 01:50:04 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-02-24 09:17:45 -0600 |
| commit | 8cfab77665957e8b26935e2b1690f65585273a09 (patch) | |
| tree | 618f09b70daef9e7f675df27d6daa7d9b75a1c84 | |
| parent | ad28cf3cb19d91399c52149d798f6c6efb780a51 (diff) | |
| download | mal-8cfab77665957e8b26935e2b1690f65585273a09.tar.gz mal-8cfab77665957e8b26935e2b1690f65585273a09.zip | |
miniMAL: self-hosting! Add atoms. Fix malfunc.
- refactor malfunc to use objects like others.
| -rw-r--r-- | miniMAL/core.json | 24 | ||||
| -rw-r--r-- | miniMAL/printer.json | 4 | ||||
| -rw-r--r-- | miniMAL/stepA_interop.json | 2 | ||||
| -rw-r--r-- | miniMAL/types.json | 44 |
4 files changed, 53 insertions, 21 deletions
diff --git a/miniMAL/core.json b/miniMAL/core.json index 9799b16..164a846 100644 --- a/miniMAL/core.json +++ b/miniMAL/core.json @@ -69,6 +69,16 @@ null], null]]], +["def", "reset!", ["fn", ["atm", "val"], + ["set", "atm", ["`", "val"], "val"]]], + +["def", "swap!", ["fn", ["atm", "f", "&", "args"], + ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"], + "fargs", ["cons", ["get", "atm", ["`", "val"]], "args"], + "val", ["apply", "fn", "fargs"]], + ["do", + ["set", "atm", ["`", "val"], "val"], + "val"]]]], ["def", "core-ns", ["hash-map", @@ -128,11 +138,17 @@ ["`", "first"], "_first", ["`", "rest"], ["fn", ["a"], ["rest", "a"]], ["`", "empty?"], "empty?", - ["`", "count"], "_count", - ["`", "apply"], "_apply", - ["`", "map"], "_map", + ["`", "count"], "_count", + ["`", "apply"], "_apply", + ["`", "map"], "_map", + ["`", "conj"], null, ["`", "with-meta"], "with_meta", - ["`", "meta"], "meta"]], + ["`", "meta"], "meta", + ["`", "atom"], "atom", + ["`", "atom?"], "atom?", + ["`", "deref"], ["fn", ["a"], ["get", "a", ["`", "val"]]], + ["`", "reset!"], "reset!", + ["`", "swap!"], "swap!"]], null] diff --git a/miniMAL/printer.json b/miniMAL/printer.json index 273d80a..2a6a51d 100644 --- a/miniMAL/printer.json +++ b/miniMAL/printer.json @@ -52,7 +52,9 @@ ["`", " "], ["pr-str", ["get", "exp", ["`", "ast"]]], ["`", ")"]], - ["str", ["`", "#<unknown: "], "exp", ["`", ">"]]]]]]]]]]]]]], + ["if", ["atom?", "exp"], + ["str", ["`", "(atom "], ["get", "exp", ["`", "val"]], ["`", ")"]], + ["str", ["`", "#<unknown: "], "exp", ["`", ">"]]]]]]]]]]]]]]], ["def", "pr-list", ["fn", ["lst", "print_readably", "sep"], [".", ["map", ["fn", ["s"], ["pr-str", "s", "print_readably"]], "lst"], diff --git a/miniMAL/stepA_interop.json b/miniMAL/stepA_interop.json index 44dc33b..2181d30 100644 --- a/miniMAL/stepA_interop.json +++ b/miniMAL/stepA_interop.json @@ -161,7 +161,7 @@ ["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], ["`", "\")"]]], + ["println", ["rep", ["str", ["`", "(load-file \""], ["get", "*ARGV*", 0], ["`", "\")"]]]], ["do", ["rep", ["`", "(println (str \"Mal [\" *host-language* \"]\"))"]], ["repl", ["`", "user> "], "rep"]]], diff --git a/miniMAL/types.json b/miniMAL/types.json index 26c5ffe..f67683e 100644 --- a/miniMAL/types.json +++ b/miniMAL/types.json @@ -36,7 +36,16 @@ null]], ["keys", "obj"]], "new-obj"]], - ["throw", "clone of unsupported type"]]]]]], + ["if", ["malfunc?", "obj"], + ["let", ["new-obj", ["malfunc", ["get", "obj", ["`", "fn"]], + ["get", "obj", ["`", "ast"]], + ["get", "obj", ["`", "env"]], + ["get", "obj", ["`", "params"]]]], + ["do", + ["set", "new-obj", ["`", "macro?"], ["get", "obj", ["`", "macro?"]]], + ["set", "new-obj", ["`", "__meta__"], ["get", "obj", ["`", "__meta__"]]], + "new-obj"]], + ["throw", "clone of unsupported type"]]]]]]], ["def", "clone", ["fn", ["obj"], ["let", ["new-obj", ["_clone", "obj"]], @@ -111,21 +120,26 @@ ["def", "map?", ["fn", ["a"], ["isa", "a", "HashMap"]]], - +["def", "MalFunc", ["fn", [], null]], ["def", "malfunc", ["fn", ["fn", "ast", "env", "params"], - ["hash-map", ["`", "type"], ["`", "MalFunc"], - ["`", "fn"], "fn", - ["`", "ast"], "ast", - ["`", "env"], "env", - ["`", "params"], "params", - ["`", "macro?"], false]]], - -["def", "malfunc?", ["fn", ["obj"], - ["if", ["=", "obj", null], - false, - ["if", ["=", ["`", "MalFunc"], ["get", "obj", ["`", "type"]]], - true, - false]]]], + ["assocs!", ["new", "MalFunc"], + ["list", ["`", "fn"], "fn", + ["`", "ast"], "ast", + ["`", "env"], "env", + ["`", "params"], "params", + ["`", "macro?"], false]]]], + +["def", "malfunc?", ["fn", ["a"], + ["isa", "a", "MalFunc"]]], + +["def", "Atom", ["fn", [], null]], +["def", "atom", ["fn", ["a"], + ["let", ["atm", ["new", "Atom"]], + ["do", + ["set", "atm", ["`", "val"], "a"], + "atm"]]]], +["def", "atom?", ["fn", ["a"], + ["isa", "a", "Atom"]]], null ] |
