Emit every non-macro clojure.core form through the live analyzer -> Chez emit pipeline as a def-var! prelude (prelude mode, tier dependency order), load it before a user expression, and you get an -e-capable jolt-chez: analysis on Janet, execution on Chez. driver/emit-core-prelude assembles it (each form behind a silent load guard so the Phase-2 multimethod forms don't break the rest); bin/jolt-chez is the -e CLI, caching the prelude on disk keyed by source hash. run-corpus-prelude.janet is the full parity gate this opens, the prelude-backed sibling of run-corpus-chez. First baseline: 1220/2497 evaluated cases pass, 0 new divergences (10 allowlisted: dynamic vars, class names, eval-order — deferred Phase 2). The rest is the punch-list: ~360 emit-fail (real host interop, out of the analyzer subset) and ~900 runtime crashes, mostly core fns calling host-coupled seed natives with no Chez shim yet (str/format/vec, transients). Follow-ups jolt-t6cr/kl2l/q3w8/9ls5. Two shims landed to get the prelude to load and run. atoms.ss: atom/deref/swap!/ reset! (+ the compare/vals kernel) — needed at load time for global-hierarchy = (atom (make-hierarchy)). predicates.ss: the type predicates + name/namespace/boolean the overlay assumes are seed natives, matching the seed's strict semantics. post-prelude.ss re-asserts char?/atom? after the prelude: the overlay implements those by reading :jolt/type, which is false for Chez-native chars/atoms, so its def-var! would clobber the correct native versions. Per-case Scheme files are PID-unique so a foreground -e never reads a half-written file while the gate runs.
49 lines
2 KiB
Text
49 lines
2 KiB
Text
# -e-capable jolt-chez (jolt-9ziu): the Option-2 back end as a runnable CLI.
|
|
#
|
|
# Analysis runs on Janet (the portable analyzer); EXECUTION runs on Chez with the
|
|
# full clojure.core assembled as a Scheme prelude (driver/emit-core-prelude). The
|
|
# prelude is assembled once and cached on disk keyed by a fingerprint of the core
|
|
# sources + the Chez RT/emitter, so repeated invocations (e.g. the run-corpus.janet
|
|
# gate, one subprocess per case) reuse it.
|
|
#
|
|
# Usage (the run-corpus.janet boundary): jolt-chez -e "EXPR"
|
|
# Run from the repo root (the prelude loads host/chez/rt.ss by relative path).
|
|
(import ../../src/jolt/api :as api)
|
|
(import ./driver :as d)
|
|
|
|
(defn- fingerprint []
|
|
# Hash the inputs that shape the prelude: the core tiers + the emitter + the
|
|
# Chez RT shims. Any change invalidates the cached prelude.
|
|
(def parts @[])
|
|
(each tf d/core-tier-files
|
|
(array/push parts (slurp (string "jolt-core/clojure/core/" tf ".clj"))))
|
|
(each f ["host/chez/emit.janet" "host/chez/driver.janet" "host/chez/rt.ss"
|
|
"host/chez/values.ss" "host/chez/collections.ss" "host/chez/seq.ss"
|
|
"host/chez/atoms.ss" "host/chez/predicates.ss" "host/chez/regex.ss"]
|
|
(array/push parts (slurp f)))
|
|
(string/slice (string (hash (string/join parts))) 0))
|
|
|
|
(defn- ensure-prelude [ctx]
|
|
(def dir (or (os/getenv "JOLT_IMAGE_CACHE_DIR") (os/getenv "TMPDIR") "/tmp"))
|
|
(def path (string dir "/jolt-chez-prelude-" (fingerprint) ".ss"))
|
|
(unless (os/stat path)
|
|
(def [scm _ _] (d/emit-core-prelude ctx))
|
|
(spit path scm))
|
|
path)
|
|
|
|
(defn main [& argv]
|
|
# argv: [script "-e" EXPR]
|
|
(def args (drop 1 argv))
|
|
(unless (and (= (length args) 2) (= (first args) "-e"))
|
|
(eprint "usage: jolt-chez -e EXPR")
|
|
(os/exit 2))
|
|
(def src (in args 1))
|
|
(def ctx (api/init-cached {:compile? true}))
|
|
(def prelude-path (ensure-prelude ctx))
|
|
(def [code out err] (d/eval-e-with-prelude ctx src prelude-path))
|
|
(when (= code :emit-err)
|
|
(eprint "jolt-chez: cannot compile: " out)
|
|
(os/exit 1))
|
|
(unless (= "" out) (print out))
|
|
(unless (= "" err) (eprint err))
|
|
(os/exit code))
|