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)))
|
||||
|
||||
(defn load-ns
|
||||
"Load a Clojure namespace from a .clj file.
|
||||
When ctx has :compile? enabled, forms are compiled to Janet source,
|
||||
evaluated via Janet's evaluator, and cached.
|
||||
|
||||
"Load a Clojure namespace from a .clj file. Per-form routing (compile-or-
|
||||
interpret, stateful forms interpret) is shared with eval-one via eval-toplevel.
|
||||
|
||||
(load-ns ctx filepath) → namespace symbol string"
|
||||
[ctx filepath]
|
||||
(let [env (ctx :env)
|
||||
compile? (get env :compile?)
|
||||
cache (get env :compiled-cache)]
|
||||
|
||||
(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))
|
||||
(def source (slurp filepath))
|
||||
(var ns-name nil)
|
||||
(var remaining source)
|
||||
(var forms @[])
|
||||
|
||||
(defn compiled?
|
||||
"Check if a namespace has been compiled and cached."
|
||||
[ctx ns-name]
|
||||
(let [cache (get (ctx :env) :compiled-cache)]
|
||||
(not (nil? (get cache ns-name)))))
|
||||
# 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)))))))
|
||||
|
||||
(defn get-compiled-forms
|
||||
"Get the compiled Janet source forms for a namespace."
|
||||
[ctx ns-name]
|
||||
(get (ctx :env) :compiled-cache ns-name))
|
||||
(when (nil? ns-name)
|
||||
(error (string "No ns form found in " filepath)))
|
||||
|
||||
(defn clear-compiled-cache
|
||||
"Clear the compiled form cache for a namespace or all namespaces."
|
||||
[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)))))
|
||||
(each form forms (eval-toplevel ctx form))
|
||||
ns-name)
|
||||
|
|
|
|||
|
|
@ -373,7 +373,6 @@
|
|||
# to a .clj/.cljc file. jolt-core holds the portable Clojure layer
|
||||
# (analyzer/IR/core); deps.edn resolution appends dep src dirs.
|
||||
:source-paths @["jolt-core" "src/jolt"]
|
||||
:compiled-cache @{}
|
||||
:type-registry @{}
|
||||
:data-readers (let [dr @{}]
|
||||
(put dr (keyword "#inst") (fn [s] s))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue