Interpret structs

This commit is contained in:
Scott Richmond 2022-04-03 14:48:23 -04:00
parent 7c4751dda8
commit 31d407c181

View File

@ -115,7 +115,12 @@
(throw (ex-info "Called keywords must be unary" {})) (throw (ex-info "Called keywords must be unary" {}))
(let [kw (interpret kw ctx) (let [kw (interpret kw ctx)
map (second (interpret tuple ctx))] map (second (interpret tuple ctx))]
(get map kw)))) (if (::ast/struct map)
(if (contains? map kw)
(kw map)
(throw (ex-info (str "Struct error: no member at " kw) {})))
(get map kw))
)))
(defn- call-fn [fn tuple ctx] (defn- call-fn [fn tuple ctx]
(let [passed (interpret tuple ctx)] (let [passed (interpret tuple ctx)]
@ -147,7 +152,10 @@
(defn- interpret-synthetic-term [prev-value curr ctx] (defn- interpret-synthetic-term [prev-value curr ctx]
(let [type (::ast/type curr)] (let [type (::ast/type curr)]
(if (= type ::ast/atom) (if (= type ::ast/atom)
(get prev-value (:value curr)) (if (::ast/struct prev-value)
(if (contains? prev-value (:value curr))
(get prev-value (:value curr))
(throw (ex-info (str "Struct error: no member " (:value curr)) {}))))
(call-fn prev-value curr ctx)))) (call-fn prev-value curr ctx))))
(defn- interpret-synthetic [ast ctx] (defn- interpret-synthetic [ast ctx]
@ -234,6 +242,10 @@
(let [members (:members ast)] (let [members (:members ast)]
(into {} (map-values #(interpret % ctx)) members)) (into {} (map-values #(interpret % ctx)) members))
::ast/struct
(let [members (:members ast)]
(into {::ast/struct true} (map-values #(interpret % ctx)) members))
(throw (ex-info "Unknown AST node type" {:node ast})))) (throw (ex-info "Unknown AST node type" {:node ast}))))
(do (do