core: close the compile-path gaps that broke uberscripting Selmer + config
Loading these libs via require worked (load-ns-source interprets, macros
expand lazily) but the same code inlined by uberscript routes through
eval-toplevel and compiled, surfacing four gaps:
- a ^{:map} metadata def name reads as (def (with-meta name m) v); the
analyzer died extracting the name (config.core's defonce env). It now
throws uncompilable so the interpreter, which handles it, takes over.
- declare was a no-op, so a compiled forward reference to a declared
name that collides with a janet root binding bound to the host fn
(selmer.parser's (declare parse) compiled to janet's 1-arg parse).
declare now expands to no-init defs, the interpreter interns them,
and the analyzer routes no-init def to the interpreter.
- class? was missing (selmer.util's exception macro calls it at
expansion time). Always false, like ratio? — no Class objects here.
- require of an unlocatable namespace silently left an empty ns behind,
deferring the failure to an unresolved symbol far from the cause. It
now throws like Clojure's FileNotFoundException. Namespaces entered
in-session count as loaded (Clojure puts them in *loaded-libs*), and
the SCI bootstrap opts out via :lenient-require? since its
clj-targeted requires can't all exist on this host.
This commit is contained in:
parent
c2511fee7e
commit
703a59d40b
10 changed files with 127 additions and 34 deletions
|
|
@ -138,4 +138,31 @@
|
|||
(eval-string c "(defn g [] 2)")
|
||||
(assert (= 2 (ct-eval c "(calls-g)")) "compiled caller sees redefined global"))
|
||||
|
||||
# Map-literal metadata on a def'd name reads as (def (with-meta name m) v); the
|
||||
# analyzer must route it to the interpreter (uncompilable), not die extracting
|
||||
# the name. Regression: yogthos/config's (defonce ^{:doc "…"} env …) broke
|
||||
# every load-string/uberscript path while loading fine through require.
|
||||
(let [c (init-cached {:compile? true})]
|
||||
(assert (= 42 (do (eval-string c `(def ^{:doc "d"} md-def 42)`)
|
||||
(ct-eval c "md-def")))
|
||||
"compile-mode def with ^{:map} metadata")
|
||||
(assert (= "d" (ct-eval c "(:doc (meta (var md-def)))"))
|
||||
"map metadata lands on the var")
|
||||
(assert (= 7 (do (eval-string c `(defonce ^{:doc "o"} md-once 7)`)
|
||||
(ct-eval c "md-once")))
|
||||
"compile-mode defonce with ^{:map} metadata"))
|
||||
|
||||
# (declare name) must intern a var so a compiled forward reference binds to it —
|
||||
# not to a like-named Janet host builtin. Regression: selmer.parser's
|
||||
# (declare parse) + a (parse …) call compiled to janet's 1-arg `parse`.
|
||||
(let [c (init-cached {:compile? true})]
|
||||
(eval-string c "(declare parse)")
|
||||
(eval-string c "(defn callit [s] (parse s 1 2))")
|
||||
(eval-string c "(defn parse [s a b] [s a b])")
|
||||
(assert (deep= ["x" 1 2] (ct-eval c `(callit "x")`))
|
||||
"compiled forward ref through declare beats host fallback")
|
||||
(eval-string c "(def no-init-var)")
|
||||
(assert (= true (ct-eval c "(do (def no-init-var 5) (= 5 no-init-var))"))
|
||||
"(def name) with no init interns; later def binds"))
|
||||
|
||||
(print "\nAll Phase 6 tests passed!")
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@
|
|||
|
||||
(print "5: require form (standalone)...")
|
||||
(let [ctx (fresh-ctx)]
|
||||
# Populate other.lib first — require of an unlocatable ns now throws
|
||||
# (Clojure's FileNotFoundException), see namespaces-spec.
|
||||
(let [other-ns (ctx-find-ns ctx "other.lib")]
|
||||
(ns-intern other-ns "f" (fn [x] x)))
|
||||
(eval-form ctx @{} (parse-string "(require '[other.lib :as o])"))
|
||||
(let [ns (ctx-find-ns ctx "user")
|
||||
aliased (ns-alias-lookup ns "o")]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@
|
|||
(reader-features-set! ["jolt" "clj" "default"])
|
||||
|
||||
(def ctx (init-cached))
|
||||
# Best-effort loading: SCI's clj-targeted requires (borkdude.graal.locking,
|
||||
# clojure.tools.reader.*) don't exist on this host; a strict require would fail
|
||||
# whole ns forms and cascade. See maybe-require-ns.
|
||||
(put (ctx :env) :lenient-require? true)
|
||||
|
||||
(printf "Loading SCI stubs...\n")
|
||||
(defn load-stubs [ctx filepath]
|
||||
|
|
|
|||
|
|
@ -73,6 +73,9 @@
|
|||
["do nested" "1" "(do (do (do (do 1))))"]
|
||||
["do returns last" "3" "(do 1 2 3)"]
|
||||
["def + deref var" "true" "(var? (def one 1))"]
|
||||
["def no init interns var" "true" "(var? (def no-init))"]
|
||||
["def no init keeps existing root" "7" "(do (def kept 7) (def kept) kept)"]
|
||||
["declare interns var" "true" "(do (declare fwd-declared) (var? (var fwd-declared)))"]
|
||||
["def redefine" "100" "(do (def one 1) (def one 100) one)"]
|
||||
["def in fn mutates" "[:default :meow]" "(do (def a :default) (def set-a (fn* [v] (def a v))) (let* [before a] (set-a :meow) [before a]))"]
|
||||
["call literal fn" "1" "((fn* [] 1))"]
|
||||
|
|
|
|||
|
|
@ -34,7 +34,14 @@
|
|||
["require clojure.set" "#{1 2 3}" "(do (require '[clojure.set :as set]) (set/union #{1 2} #{3}))"]
|
||||
["require clojure.walk" "{:a 2}" "(do (require '[clojure.walk :as w]) (w/postwalk (fn [x] (if (number? x) (inc x) x)) {:a 1}))"]
|
||||
["walk keywordize-keys" "{:a 1}" "(do (require '[clojure.walk :as w]) (w/keywordize-keys {\"a\" 1}))"]
|
||||
["walk stringify-keys" "true" "(do (require '[clojure.walk :as w]) (= {\"a\" 1} (w/stringify-keys {:a 1})))"])
|
||||
["walk stringify-keys" "true" "(do (require '[clojure.walk :as w]) (= {\"a\" 1} (w/stringify-keys {:a 1})))"]
|
||||
# Clojure throws FileNotFoundException; silently succeeding masks typos and
|
||||
# missing roots until the first unresolved-symbol error far from the cause.
|
||||
["require missing lib throws" :throws "(require '[no.such.lib])"]
|
||||
["use missing lib throws" :throws "(use 'no.such.lib)"]
|
||||
# …but an ns created in-session is in *loaded-libs* (the ns macro puts it
|
||||
# there), so require/use of it must NOT hit the loader.
|
||||
["require of in-session ns ok" "1" "(do (ns made.here) (def x 1) (require '[made.here]) made.here/x)"])
|
||||
|
||||
(defspec "namespaces / alias, ns-unalias, ns-publics"
|
||||
["alias + use" "\"1,2\"" "(do (require (quote clojure.string)) (alias (quote st) (quote clojure.string)) (st/join \",\" [1 2]))"]
|
||||
|
|
|
|||
|
|
@ -73,6 +73,11 @@
|
|||
["simple-ident?" "true" "(simple-ident? :a)"]
|
||||
["ratio?" "false" "(ratio? 3)"]
|
||||
["decimal?" "false" "(decimal? 3)"]
|
||||
# No first-class Class objects on this host (class names are symbols handled
|
||||
# in instance?/new positions), so class? is always false — like Clojure's
|
||||
# class? of a symbol. Selmer's `exception` macro calls it at expansion time.
|
||||
["class? of value" "false" "(class? \"s\")"]
|
||||
["class? of symbol" "false" "(class? 'java.lang.String)"]
|
||||
["rational? int" "true" "(rational? 3)"]
|
||||
["rational? float" "false" "(rational? 3.5)"]
|
||||
["nat-int? zero" "true" "(nat-int? 0)"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue