aboutsummaryrefslogtreecommitdiff
path: root/src/lang/compiler.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/lang/compiler.clj')
-rw-r--r--src/lang/compiler.clj30
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]))