aboutsummaryrefslogtreecommitdiff
path: root/src/lang/interpreter.clj
diff options
context:
space:
mode:
authorEduardo Julian2014-11-29 02:29:56 -0400
committerEduardo Julian2014-11-29 02:29:56 -0400
commit74f1d02a2f16da9e2ce2fb747dad07979a9db26a (patch)
treed710b3178c804a4fe5d4f8cad0903fc787e60710 /src/lang/interpreter.clj
parent71b63cbbb858b85dd4850c4aa174cf7ec509b11c (diff)
+ Added simple let expressions. (No destructuring of tuples/records yet)
+ Added records and simple operations on them (get, set & remove).
Diffstat (limited to '')
-rw-r--r--src/lang/interpreter.clj29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/lang/interpreter.clj b/src/lang/interpreter.clj
index 73148831e..85be602da 100644
--- a/src/lang/interpreter.clj
+++ b/src/lang/interpreter.clj
@@ -18,6 +18,8 @@
(def <=' (fn [x] (fn [y] (<= x y))))
(def -' (fn [x] (fn [y] (- x y))))
+(def +' (fn [x] (fn [y] (+ x y))))
+(def *' (fn [x] (fn [y] (* x y))))
;; [Utils]
(def ^:private +state+
@@ -64,7 +66,7 @@
output#)
_#
(do ;; (println "Unknown syntax: " (pr-str ~'*token*))
- (fail* (str "Unknown syntax: " (pr-str ~'*token*)))))))))
+ (fail* (str "Unknown syntax: " (pr-str ~'*token*)))))))))
(defeval eval-ident
[::&parser/ident ?ident]
@@ -103,6 +105,23 @@
]
(return nil)))
+(defeval eval-get
+ [::&parser/get ?tag [::&parser/ident ?record]]
+ (exec [=record (resolve ?record)]
+ (return (get =record ?tag))))
+
+(defeval eval-set
+ [::&parser/set ?tag ?value [::&parser/ident ?record]]
+ (exec [state &util/get-state
+ =value (apply-m eval-form (wrap-in state ?value))
+ =record (resolve ?record)]
+ (return (assoc =record ?tag =value))))
+
+(defeval eval-remove
+ [::&parser/remove ?tag [::&parser/ident ?record]]
+ (exec [=record (resolve ?record)]
+ (return (dissoc =record ?tag))))
+
(defeval eval-fn-call
[::&parser/fn-call ?fn ?args]
(exec [state &util/get-state
@@ -120,6 +139,9 @@
eval-ident
eval-def
eval-defdata
+ eval-get
+ eval-set
+ eval-remove
eval-fn-call]))
(defn eval [text]
@@ -150,4 +172,9 @@
;; (fold * 1 (repeat exp base)))
;; Syntax for chars: #"a"
+
+
+ ;; (set@ {#z 30} bar) (set@ {#z 30 #w "YOLO"} bar)
+ ;; (remove@ [#x #y] bar)
+ ;; (get@ [#x #y] bar)
)