Very first draft of import expression

This commit is contained in:
Scott Richmond 2022-04-08 19:13:57 -04:00
parent 5df9c71bcc
commit 3749d2ea50

View File

@ -19,7 +19,7 @@
(recur word (::parent ctx)) (recur word (::parent ctx))
(throw (ex-info (str "Unbound name: " word) {})))))) (throw (ex-info (str "Unbound name: " word) {}))))))
(declare interpret-ast match) (declare interpret-ast match interpret)
(defn- match-tuple [pattern value ctx-atom] (defn- match-tuple [pattern value ctx-atom]
(cond (cond
@ -245,6 +245,21 @@
(swap! ctx update-ctx {name ns}) (swap! ctx update-ctx {name ns})
ns))))) ns)))))
(defn- interpret-import [ast ctx]
(let [path (:path ast)
name (:name ast)]
(if (contains? @ctx name)
(throw (ex-info (str "Name " name " is alrady bound") {}))
(let [result ;; TODO: add any error handling at all
(-> path
(slurp)
(scanner/scan)
(parser/parse)
(interpret))]
(swap! ctx update-ctx {name result})
result
))))
(defn interpret-ast [ast ctx] (defn interpret-ast [ast ctx]
(case (::ast/type ast) (case (::ast/type ast)
@ -270,6 +285,8 @@
::ast/ns (interpret-ns ast ctx) ::ast/ns (interpret-ns ast ctx)
::ast/import (interpret-import ast ctx)
::ast/block ::ast/block
(let [exprs (:exprs ast) (let [exprs (:exprs ast)
inner (pop exprs) inner (pop exprs)