Interpret ns

This commit is contained in:
Scott Richmond 2022-04-07 18:51:48 -04:00
parent 9eecce77bc
commit be2d291fd3

View File

@ -232,6 +232,19 @@
(let [[k v] kv] (let [[k v] kv]
[k (f v)])))) [k (f v)]))))
(defn- interpret-ns [ast ctx]
(let [members (:members ast)
name (:name ast)]
(if (contains? @ctx name)
(throw (ex-info (str "ns name " name "is already bound") {}))
(let [ns (into
{::data/struct true ::data/type ::data/ns ::data/name name}
(map-values #(interpret-ast % ctx))
members)]
(do
(swap! ctx update-ctx {name ns})
ns)))))
(defn interpret-ast [ast ctx] (defn interpret-ast [ast ctx]
(case (::ast/type ast) (case (::ast/type ast)
@ -255,6 +268,8 @@
::ast/placeholder ::data/placeholder ::ast/placeholder ::data/placeholder
::ast/ns (interpret-ns ast ctx)
::ast/block ::ast/block
(let [exprs (:exprs ast) (let [exprs (:exprs ast)
inner (pop exprs) inner (pop exprs)
@ -313,6 +328,12 @@
else -> :oops else -> :oops
} }
ns bar {
foo
}
bar :foo
") ")
(println "") (println "")