loader: drop write-only compiled-form cache and its unused helpers
compiled?/get-compiled-forms/clear-compiled-cache were never called, and load-ns only ever wrote to :compiled-cache with no reader. All dead once the self-host path landed. Removed the helpers, the cache writes, and the :compiled-cache env field.
This commit is contained in:
parent
497970029d
commit
984af02532
2 changed files with 26 additions and 60 deletions
|
|
@ -45,67 +45,34 @@
|
||||||
(eval-form ctx @{} form)))
|
(eval-form ctx @{} form)))
|
||||||
|
|
||||||
(defn load-ns
|
(defn load-ns
|
||||||
"Load a Clojure namespace from a .clj file.
|
"Load a Clojure namespace from a .clj file. Per-form routing (compile-or-
|
||||||
When ctx has :compile? enabled, forms are compiled to Janet source,
|
interpret, stateful forms interpret) is shared with eval-one via eval-toplevel.
|
||||||
evaluated via Janet's evaluator, and cached.
|
|
||||||
|
|
||||||
(load-ns ctx filepath) → namespace symbol string"
|
(load-ns ctx filepath) → namespace symbol string"
|
||||||
[ctx filepath]
|
[ctx filepath]
|
||||||
(let [env (ctx :env)
|
(def source (slurp filepath))
|
||||||
compile? (get env :compile?)
|
(var ns-name nil)
|
||||||
cache (get env :compiled-cache)]
|
(var remaining source)
|
||||||
|
(var forms @[])
|
||||||
(def source (slurp filepath))
|
|
||||||
(var ns-name nil)
|
|
||||||
(var remaining source)
|
|
||||||
(var forms @[])
|
|
||||||
|
|
||||||
# Parse all forms
|
|
||||||
(while (> (length (string/trim remaining)) 0)
|
|
||||||
(def [form rest] (parse-next remaining))
|
|
||||||
(set remaining rest)
|
|
||||||
(when (not (nil? form))
|
|
||||||
(array/push forms form)
|
|
||||||
# Extract ns name from the first ns form
|
|
||||||
(when (and (nil? ns-name)
|
|
||||||
(array? form)
|
|
||||||
(> (length form) 0)
|
|
||||||
(and (struct? (first form))
|
|
||||||
(= :symbol ((first form) :jolt/type))
|
|
||||||
(= "ns" ((first form) :name))))
|
|
||||||
(let [name-form (in form 1)]
|
|
||||||
(set ns-name (if (struct? name-form) (name-form :name) (string name-form)))))))
|
|
||||||
|
|
||||||
(when (nil? ns-name)
|
|
||||||
(error (string "No ns form found in " filepath)))
|
|
||||||
|
|
||||||
# Per-form routing (compile-or-interpret, stateful forms interpret) is shared
|
|
||||||
# with eval-one via eval-toplevel. When compiling, also record the forms so a
|
|
||||||
# namespace can be inspected / re-emitted.
|
|
||||||
(when compile?
|
|
||||||
(var cached (get cache ns-name))
|
|
||||||
(when (nil? cached)
|
|
||||||
(set cached @[])
|
|
||||||
(put cache ns-name cached))
|
|
||||||
(each form forms (array/push cached form)))
|
|
||||||
(each form forms (eval-toplevel ctx form))
|
|
||||||
ns-name))
|
|
||||||
|
|
||||||
(defn compiled?
|
# Parse all forms
|
||||||
"Check if a namespace has been compiled and cached."
|
(while (> (length (string/trim remaining)) 0)
|
||||||
[ctx ns-name]
|
(def [form rest] (parse-next remaining))
|
||||||
(let [cache (get (ctx :env) :compiled-cache)]
|
(set remaining rest)
|
||||||
(not (nil? (get cache ns-name)))))
|
(when (not (nil? form))
|
||||||
|
(array/push forms form)
|
||||||
|
# Extract ns name from the first ns form
|
||||||
|
(when (and (nil? ns-name)
|
||||||
|
(array? form)
|
||||||
|
(> (length form) 0)
|
||||||
|
(and (struct? (first form))
|
||||||
|
(= :symbol ((first form) :jolt/type))
|
||||||
|
(= "ns" ((first form) :name))))
|
||||||
|
(let [name-form (in form 1)]
|
||||||
|
(set ns-name (if (struct? name-form) (name-form :name) (string name-form)))))))
|
||||||
|
|
||||||
(defn get-compiled-forms
|
(when (nil? ns-name)
|
||||||
"Get the compiled Janet source forms for a namespace."
|
(error (string "No ns form found in " filepath)))
|
||||||
[ctx ns-name]
|
|
||||||
(get (ctx :env) :compiled-cache ns-name))
|
|
||||||
|
|
||||||
(defn clear-compiled-cache
|
(each form forms (eval-toplevel ctx form))
|
||||||
"Clear the compiled form cache for a namespace or all namespaces."
|
ns-name)
|
||||||
[ctx &opt ns-name]
|
|
||||||
(let [cache (get (ctx :env) :compiled-cache)]
|
|
||||||
(if ns-name
|
|
||||||
(put cache ns-name nil)
|
|
||||||
(loop [[k] :pairs cache] (put cache k nil)))))
|
|
||||||
|
|
|
||||||
|
|
@ -373,7 +373,6 @@
|
||||||
# to a .clj/.cljc file. jolt-core holds the portable Clojure layer
|
# to a .clj/.cljc file. jolt-core holds the portable Clojure layer
|
||||||
# (analyzer/IR/core); deps.edn resolution appends dep src dirs.
|
# (analyzer/IR/core); deps.edn resolution appends dep src dirs.
|
||||||
:source-paths @["jolt-core" "src/jolt"]
|
:source-paths @["jolt-core" "src/jolt"]
|
||||||
:compiled-cache @{}
|
|
||||||
:type-registry @{}
|
:type-registry @{}
|
||||||
:data-readers (let [dr @{}]
|
:data-readers (let [dr @{}]
|
||||||
(put dr (keyword "#inst") (fn [s] s))
|
(put dr (keyword "#inst") (fn [s] s))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue