Chez Phase 2: clojure.set + clojure.math + pprint (jolt-j5vg, jolt-22vo)
Close the remaining Phase-2 stdlib parity gaps. clojure.set: pure Clojure over core, so just added to the prelude stdlib tier (driver.janet stdlib-ns-files + jolt-chez fingerprint), same as clojure.edn. clojure.math: not a .clj on the seed (native math/ bindings via jolt-h79), so Chez gets its own host/chez/math.ss def-var!ing each fn over Chez native flonum math. The analyzer already knows the ns (api.janet install-clojure-math!), so refs lower to var-deref. Also adds the missing 'long' coercion to converters.ss (int's sibling; several math cases wrap in long). clojure.pprint: dropped the 2-arity's (binding [*out* writer] ...). *out* isn't a bindable var in jolt — printing routes through the host (dyn :out) seam, so the binding never redirected anything; it only made the defn uncompilable, which the seed tolerated via interpreter fallback. Chez has no fallback, so the whole pprint defn died. Dropping it is behavior-preserving (writer was always ignored) and lets pprint compile cleanly. Both corpus cases pass. Corpus parity 2259 -> 2280, crashes 191 -> 170, 0 new divergences. Floor raised. New unit test test/chez/_stdlib.janet (27/27). Full Janet gate green (147 files).
This commit is contained in:
parent
6df60229b0
commit
109bfcd09d
8 changed files with 175 additions and 7 deletions
80
test/chez/_stdlib.janet
Normal file
80
test/chez/_stdlib.janet
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# jolt-j5vg / jolt-22vo / clojure.pprint — Phase-2 stdlib parity closeout.
|
||||
#
|
||||
# clojure.set — pure Clojure (src/jolt/clojure/set.clj) added to the Chez
|
||||
# prelude tier (driver.janet stdlib-ns-files).
|
||||
# clojure.math — native flonum-math shims (host/chez/math.ss) def-var!'d into
|
||||
# the clojure.math ns; the analyzer already knows the ns exists
|
||||
# (api.janet install-clojure-math!), so refs lower to var-deref.
|
||||
# clojure.pprint — minimal shim on the prelude; pprint's 2-arity no longer uses
|
||||
# (binding [*out* writer] ...) (uncompilable on the no-fallback
|
||||
# Chez back end; *out* isn't a bindable var — output always goes
|
||||
# through the host seam).
|
||||
#
|
||||
# Outputs are order-stable (value-equality / scalars) so set/map iteration order
|
||||
# — which legitimately differs from build/jolt — never masquerades as a divergence.
|
||||
# Oracle = build/jolt.
|
||||
#
|
||||
# janet test/chez/_stdlib.janet
|
||||
(def jolt-bin (or (os/getenv "JOLT_BIN") "bin/jolt-chez"))
|
||||
|
||||
(def cases
|
||||
[# --- clojure.math (jolt-22vo / jolt-h79) ---
|
||||
["(< 1.4142 (clojure.math/sqrt 2) 1.4143)" "true"]
|
||||
["(long (clojure.math/pow 2 10))" "1024"]
|
||||
["(long (clojure.math/tan 0))" "0"]
|
||||
["(clojure.math/round 2.6)" "3"]
|
||||
["(clojure.math/floor 2.9)" "2"]
|
||||
["(clojure.math/signum -7.2)" "-1"]
|
||||
["(< 3.14 (clojure.math/to-radians 180) 3.15)" "true"]
|
||||
["(< 3.14 clojure.math/PI 3.15)" "true"]
|
||||
["(< 2.71 clojure.math/E 2.72)" "true"]
|
||||
["(long (clojure.math/cbrt 27))" "3"]
|
||||
["(< 4.6 (clojure.math/log 100) 4.7)" "true"]
|
||||
# Chez has no native log10 (computed as log(x)/log(10)), so it can differ from
|
||||
# the seed's C log10 in the last ulp (3 vs 2.9999…); range-check, don't pin.
|
||||
["(< 2.99 (clojure.math/log10 1000) 3.01)" "true"]
|
||||
["(do (require (quote [clojure.math :as m])) (long (m/hypot 3 4)))" "5"]
|
||||
["(mapv (comp long clojure.math/sqrt) [1 4])" "[1 2]"]
|
||||
["(long (clojure.math/atan2 0 1))" "0"]
|
||||
# --- clojure.set (jolt-j5vg) ---
|
||||
["(do (require (quote [clojure.set :as s])) (= #{1 2 3 4} (s/union #{1 2} #{3 4})))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (= #{2} (s/intersection #{1 2} #{2 3})))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (= #{1} (s/difference #{1 2} #{2 3})))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (s/subset? #{1} #{1 2}))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (s/superset? #{1 2} #{1}))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (= {1 :a 2 :b} (s/map-invert {:a 1 :b 2})))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (= #{:a} (s/select keyword? #{:a})))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (= #{{:a 1 :b 2}} (s/join #{{:a 1}} #{{:b 2}})))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (= {:b 1} (s/rename-keys {:a 1} {:a :b})))" "true"]
|
||||
["(do (require (quote [clojure.set :as s])) (= 2 (count (s/index #{{:k 1} {:k 2}} [:k]))))" "true"]
|
||||
# --- clojure.pprint (minimal shim) ---
|
||||
["(do (require (quote [clojure.pprint :as pp])) (= \"[1 2 3]\\n\" (with-out-str (pp/pprint [1 2 3]))))" "true"]
|
||||
["(do (require (quote [clojure.pprint :as pp])) (pp/with-pprint-dispatch pp/code-dispatch 42))" "42"]])
|
||||
|
||||
(defn run-capture [bin expr]
|
||||
(def proc (os/spawn [bin "-e" expr] :p {:out :pipe :err :pipe}))
|
||||
(def out (ev/read (proc :out) 0x100000))
|
||||
(def err (ev/read (proc :err) 0x100000))
|
||||
(def code (os/proc-wait proc))
|
||||
(def lines (filter (fn [l] (not (empty? l)))
|
||||
(string/split "\n" (string/trim (if out (string out) "")))))
|
||||
[code (if (empty? lines) "" (last lines)) (string/trim (if err (string err) ""))])
|
||||
|
||||
(var pass 0)
|
||||
(def fails @[])
|
||||
(each [expr expected] cases
|
||||
(def [ocode oracle _] (run-capture "build/jolt" expr))
|
||||
(def [code got err] (run-capture jolt-bin expr))
|
||||
(cond
|
||||
(not= ocode 0) (array/push fails [expr (string "ORACLE FAILED exit " ocode)])
|
||||
(not= oracle expected) (array/push fails [expr (string "ORACLE MISMATCH want `" expected "` got `" oracle "`")])
|
||||
(not= code 0) (array/push fails [expr (string "exit " code "; err: " err)])
|
||||
(= got expected) (++ pass)
|
||||
(array/push fails [expr (string "want `" expected "`, got `" got "`")])))
|
||||
|
||||
(printf "\n_stdlib parity [%s]: %d/%d passed" jolt-bin pass (length cases))
|
||||
(when (> (length fails) 0)
|
||||
(printf "%d FAIL(s):" (length fails))
|
||||
(each [e m] fails (printf " FAIL %s\n %s" e m)))
|
||||
(flush)
|
||||
(os/exit (if (empty? fails) 0 1))
|
||||
|
|
@ -275,8 +275,14 @@
|
|||
# prelude. Lights up read / read+string / with-in-str (read) / read-string and
|
||||
# clojure.edn/read-string. (eval / load-string / runtime defmacro stay Phase-3 —
|
||||
# they need the compiler at runtime.) 2259.
|
||||
# Phase-2 stdlib closeout (jolt-j5vg / jolt-22vo / clojure.pprint): clojure.set +
|
||||
# clojure.pprint added to the prelude stdlib tier (driver.janet stdlib-ns-files),
|
||||
# clojure.math shimmed over Chez native flonum math (host/chez/math.ss), and the
|
||||
# missing `long` coercion def-var!'d (converters.ss). pprint's 2-arity dropped its
|
||||
# (binding [*out* writer] ...) (uncompilable on the no-fallback Chez back end —
|
||||
# *out* isn't a bindable var). 2280, crashes 191->170, 0 new divergences.
|
||||
# Strided runs scale down.
|
||||
(def base-floor (scan-number (or (os/getenv "JOLT_CHEZ_PRELUDE_FLOOR") "2259")))
|
||||
(def base-floor (scan-number (or (os/getenv "JOLT_CHEZ_PRELUDE_FLOOR") "2280")))
|
||||
(def floor (if (os/getenv "JOLT_CORPUS_LIMIT") 0 base-floor))
|
||||
(when (or (> (length diverged) 0) (< pass floor))
|
||||
(printf "REGRESSION: pass %d < floor %d or %d new divergence(s)" pass floor (length diverged)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue