Chez Phase 2 (inc L): var def-time metadata (jolt-zikh)

Capture a def's reader metadata on the Chez var. The :def emit now lowers a def
with non-empty metadata to def-var-with-meta!, which stores the user meta
(^:private / ^Type tag / docstring -> {:doc}) in an eq side-table keyed by the
var-cell. jolt-meta of a var-cell merges that onto {:ns :name} derived from the
cell, so every var reports {:ns :name} like Clojure with the def-time meta
layered on. (^{:map} metadata on a def name stays uncompilable for the compiler
generally — analyzer rejects it, the Janet back end punts to its interpreter,
which Chez lacks — so it's out of subset, not a meta-capture gap.)

Added natives-meta.ss to the prelude-cache fingerprint. Prelude parity
1969 -> 1972, 0 new divergences; the three var-metadata allowlist entries
(^:private / ^Type tag / docstring) dropped. New focused gate
test/chez/_var_meta.janet.
This commit is contained in:
Yogthos 2026-06-18 17:13:46 -04:00
parent 32e2d8bd58
commit 737288bff5
6 changed files with 87 additions and 11 deletions

View file

@ -218,6 +218,15 @@
(or (struct? form) (table? form)) (emit-quoted-map form)
(errorf "emit-quoted: unsupported quoted form %p" form))))
# A def's :meta is a jolt map value (Janet struct/table or phm). Non-empty?
# (a plain def carries {} — keep it on the lean def-var! path).
(defn- jmeta-nonempty? [m]
(cond
(nil? m) false
(phm/phm? m) (> (length (phm/phm-to-struct m)) 0)
(or (struct? m) (table? m)) (> (length m) 0)
false))
(defn- emit-binding [b]
(def b (vv b))
(string "(" (munge (get b 0)) " " (emit (get b 1)) ")"))
@ -481,9 +490,16 @@
:fn (emit-fn node)
# (def name) with no init (declare): reserve the var cell (declare-var!
# doesn't clobber an existing root) so a forward reference resolves.
:def (if (get node :no-init)
# A def with non-empty reader metadata (^:private / ^Type tag / docstring ->
# {:doc}) lowers to def-var-with-meta! so (meta (var x)) sees it (jolt-zikh).
:def (cond
(get node :no-init)
(string "(declare-var! " (chez-str-lit (get node :ns)) " "
(chez-str-lit (get node :name)) ")")
(jmeta-nonempty? (get node :meta))
(string "(def-var-with-meta! " (chez-str-lit (get node :ns)) " "
(chez-str-lit (get node :name)) " " (emit (get node :init)) " "
(emit-quoted (get node :meta)) ")")
(string "(def-var! " (chez-str-lit (get node :ns)) " "
(chez-str-lit (get node :name)) " " (emit (get node :init)) ")"))
(errorf "emit: unhandled op %p" (get node :op)))))