Interpret ns

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

View File

@ -232,12 +232,25 @@
(let [[k v] kv]
[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]
(case (::ast/type ast)
::ast/atom (:value ast)
::ast/word (resolve-word(:word ast) ctx)
::ast/word (resolve-word (:word ast) ctx)
::ast/let (interpret-let ast ctx)
@ -255,6 +268,8 @@
::ast/placeholder ::data/placeholder
::ast/ns (interpret-ns ast ctx)
::ast/block
(let [exprs (:exprs ast)
inner (pop exprs)
@ -313,6 +328,12 @@
else -> :oops
}
ns bar {
foo
}
bar :foo
")
(println "")
@ -335,7 +356,7 @@
* refactor calling keywords
* refactor accessing structs vs. hashes
")
")