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
|
|
@ -121,5 +121,8 @@
|
|||
(def-var! "clojure.core" "symbol" jolt-symbol-new)
|
||||
(def-var! "clojure.core" "gensym" jolt-gensym)
|
||||
(def-var! "clojure.core" "int" jolt-int)
|
||||
;; long: same truncation as int in jolt's all-flonum model (seed core-long =
|
||||
;; math/trunc; char -> code point). Distinct cell so (long ...) resolves.
|
||||
(def-var! "clojure.core" "long" jolt-int)
|
||||
(def-var! "clojure.core" "double" jolt-double)
|
||||
(def-var! "clojure.core" "compare" jolt-compare)
|
||||
|
|
|
|||
|
|
@ -115,7 +115,13 @@
|
|||
# clojure.edn requires clojure.string; read-string/__read-tagged are the
|
||||
# reader.ss seams. The reader-arity's drain-reader is Janet-coupled (janet/type)
|
||||
# so it's a lazy gap on Chez — read-string/edn->value are the live path. jolt-r8ku.
|
||||
["clojure.edn" "src/jolt/clojure/edn.clj"]])
|
||||
["clojure.edn" "src/jolt/clojure/edn.clj"]
|
||||
# clojure.set / clojure.pprint: pure Clojure over core. set = relational ops
|
||||
# (union/intersection/difference/join/index/...); pprint = the minimal jolt
|
||||
# shim (pprint -> prn + recognized dispatch vars, with-pprint-dispatch macro).
|
||||
# jolt-j5vg, clojure.pprint Phase-2 parity.
|
||||
["clojure.set" "src/jolt/clojure/set.clj"]
|
||||
["clojure.pprint" "src/jolt/clojure/pprint.clj"]])
|
||||
|
||||
(defn- sym-name [x]
|
||||
(when (and (struct? x) (= :symbol (get x :jolt/type))) (get x :name)))
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@
|
|||
"host/chez/ns.ss" "host/chez/post-prelude.ss" "host/chez/natives-meta.ss"
|
||||
"host/chez/natives-str.ss" "host/chez/records.ss"
|
||||
"host/chez/host-class.ss" "host/chez/io.ss"
|
||||
"host/chez/inst-time.ss" "host/chez/reader.ss"
|
||||
"host/chez/inst-time.ss" "host/chez/reader.ss" "host/chez/math.ss"
|
||||
"host/chez/host-static.ss" "host/chez/dot-forms.ss"
|
||||
"src/jolt/clojure/string.clj" "src/jolt/clojure/walk.clj"
|
||||
"src/jolt/clojure/template.clj" "src/jolt/clojure/edn.clj"]
|
||||
"src/jolt/clojure/template.clj" "src/jolt/clojure/edn.clj"
|
||||
"src/jolt/clojure/set.clj" "src/jolt/clojure/pprint.clj"]
|
||||
(array/push parts (slurp f)))
|
||||
(string/slice (string (hash (string/join parts))) 0))
|
||||
|
||||
|
|
|
|||
63
host/chez/math.ss
Normal file
63
host/chez/math.ss
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
;; clojure.math (jolt-22vo) — Chez host shim over native flonum math.
|
||||
;;
|
||||
;; On the Janet seed clojure.math is registered as native math/ bindings
|
||||
;; (api.janet install-clojure-math!, jolt-h79), NOT a .clj file — so there's no
|
||||
;; source tier to emit. Chez provides its own def-var! shims here, one per
|
||||
;; clojure.math fn, over Chez's native procedures. The analyzer already knows the
|
||||
;; clojure.math ns exists (init interns the same fns on the Janet side), so a ref
|
||||
;; like clojure.math/sqrt lowers to a var-deref; these cells back it at runtime.
|
||||
;;
|
||||
;; jolt is all-flonum, so every result is a flonum (inputs arrive as flonums; Chez
|
||||
;; sqrt/sin/expt/... return flonums for flonum args). Semantics match the seed
|
||||
;; (Clojure 1.11 clojure.math): round = floor(x+0.5), rint = round-half-even,
|
||||
;; floor/ceil/floor-div return doubles, to-degrees/to-radians via PI.
|
||||
|
||||
(define jolt-math-pi (acos -1.0))
|
||||
(define jolt-math-e (exp 1.0))
|
||||
|
||||
(define (jolt-math-cbrt x)
|
||||
;; sign-aware so negative inputs stay real (expt of a negative flonum to a
|
||||
;; fractional power goes complex).
|
||||
(if (< x 0.0)
|
||||
(- (expt (- x) (/ 1.0 3.0)))
|
||||
(expt x (/ 1.0 3.0))))
|
||||
|
||||
(define (jolt-math-round x) (floor (+ x 0.5)))
|
||||
(define (jolt-math-signum x) (cond ((< x 0.0) -1.0) ((> x 0.0) 1.0) (else 0.0)))
|
||||
(define (jolt-math-to-degrees r) (/ (* r 180.0) jolt-math-pi))
|
||||
(define (jolt-math-to-radians d) (/ (* d jolt-math-pi) 180.0))
|
||||
(define (jolt-math-hypot a b) (sqrt (+ (* a a) (* b b))))
|
||||
(define (jolt-math-floor-div a b) (floor (/ a b)))
|
||||
(define (jolt-math-floor-mod a b) (- a (* b (floor (/ a b)))))
|
||||
|
||||
(def-var! "clojure.math" "sqrt" sqrt)
|
||||
(def-var! "clojure.math" "cbrt" jolt-math-cbrt)
|
||||
(def-var! "clojure.math" "pow" expt)
|
||||
(def-var! "clojure.math" "exp" exp)
|
||||
(def-var! "clojure.math" "expm1" (lambda (x) (- (exp x) 1.0)))
|
||||
(def-var! "clojure.math" "log" log)
|
||||
(def-var! "clojure.math" "log10" (lambda (x) (log x 10.0)))
|
||||
(def-var! "clojure.math" "log1p" (lambda (x) (log (+ 1.0 x))))
|
||||
(def-var! "clojure.math" "sin" sin)
|
||||
(def-var! "clojure.math" "cos" cos)
|
||||
(def-var! "clojure.math" "tan" tan)
|
||||
(def-var! "clojure.math" "asin" asin)
|
||||
(def-var! "clojure.math" "acos" acos)
|
||||
(def-var! "clojure.math" "atan" atan)
|
||||
;; clojure.math/atan2 is atan2(y, x); Chez's 2-arg atan is (atan y x).
|
||||
(def-var! "clojure.math" "atan2" (lambda (y x) (atan y x)))
|
||||
(def-var! "clojure.math" "sinh" sinh)
|
||||
(def-var! "clojure.math" "cosh" cosh)
|
||||
(def-var! "clojure.math" "tanh" tanh)
|
||||
(def-var! "clojure.math" "floor" floor)
|
||||
(def-var! "clojure.math" "ceil" ceiling)
|
||||
(def-var! "clojure.math" "rint" round)
|
||||
(def-var! "clojure.math" "round" jolt-math-round)
|
||||
(def-var! "clojure.math" "signum" jolt-math-signum)
|
||||
(def-var! "clojure.math" "to-degrees" jolt-math-to-degrees)
|
||||
(def-var! "clojure.math" "to-radians" jolt-math-to-radians)
|
||||
(def-var! "clojure.math" "hypot" jolt-math-hypot)
|
||||
(def-var! "clojure.math" "floor-div" jolt-math-floor-div)
|
||||
(def-var! "clojure.math" "floor-mod" jolt-math-floor-mod)
|
||||
(def-var! "clojure.math" "E" jolt-math-e)
|
||||
(def-var! "clojure.math" "PI" jolt-math-pi)
|
||||
|
|
@ -304,3 +304,7 @@
|
|||
;; __read-tagged. Loads after inst-time.ss — __read-tagged reuses its #uuid/#inst
|
||||
;; constructors, and the reader needs the full value/collection layer above.
|
||||
(load "host/chez/reader.ss")
|
||||
|
||||
;; clojure.math (jolt-22vo): native flonum-math shims def-var!'d into the
|
||||
;; clojure.math ns. Self-contained (only def-var! + Chez math), order-independent.
|
||||
(load "host/chez/math.ss")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue