diff options
author | Eduardo Julian | 2014-11-29 02:29:56 -0400 |
---|---|---|
committer | Eduardo Julian | 2014-11-29 02:29:56 -0400 |
commit | 74f1d02a2f16da9e2ce2fb747dad07979a9db26a (patch) | |
tree | d710b3178c804a4fe5d4f8cad0903fc787e60710 /src/lang/compiler.clj | |
parent | 71b63cbbb858b85dd4850c4aa174cf7ec509b11c (diff) |
+ Added simple let expressions. (No destructuring of tuples/records yet)
+ Added records and simple operations on them (get, set & remove).
Diffstat (limited to 'src/lang/compiler.clj')
-rw-r--r-- | src/lang/compiler.clj | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index 74e0ba46e..6e37213a8 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -65,6 +65,14 @@ ?elems)] (return (vec =elems)))) +(defcompiler compile-record + [::&parser/record ?kvs] + (exec [=kvs (map-m (fn [[?label ?value]] + (exec [=value (apply-m compile-form (wrap ?value))] + (return [?label =value]))) + ?kvs)] + (return (into {} =kvs)))) + (defcompiler compile-tagged [::&parser/tagged ?tag ?data] (exec [=data (apply-m compile-form (wrap ?data))] @@ -92,6 +100,11 @@ =expr (apply-m compile-form (wrap* fn-env ?expr))] (return [?tag =bindings =expr]))) +(defcompiler compile-let-binding + [::&parser/let-binding [::&parser/ident ?name] ?expr] + (exec [=expr (apply-m compile-form (wrap ?expr))] + (return [(symbol ?name) =expr]))) + (defcompiler compile-case [::&parser/case ?variant ?branches] (exec [=variant (apply-m compile-form (wrap ?variant)) @@ -107,6 +120,21 @@ ]] (return =case))) +(defcompiler compile-let + [::&parser/let ?bindings ?expr] + (exec [=expr (apply-m compile-form (wrap ?expr)) + =bindings (map-m #(apply-m compile-let-binding (wrap %)) + ?bindings) + :let [;; _ (prn '=bindings =bindings) + =let (reduce (fn [inner [?name ?expr]] + `(let [~?name ~?expr] + ~inner)) + =expr + =bindings) + ;; _ (prn '=let =let) + ]] + (return =let))) + (defcompiler compile-def [::&parser/def ?form ?body] (match ?form @@ -145,9 +173,11 @@ compile-float compile-ident compile-tuple + compile-record compile-tagged compile-if compile-case + compile-let compile-def compile-defdata compile-fn-call])) |