Chez Phase 1 (increment 3g): letfn + declare/def-no-init
Closes the last two non-host-interop prelude emit gaps. letfn now analyzes to a :let node flagged :letrec — the binding fns are bound into the env together before any spec is analyzed, so siblings and self resolve. The Chez back end lowers it to letrec*; the Janet back end punts it at emit (its sequential let* can't express the mutual recursion — same interpreter fallback as before, just decided at emit-ir instead of analyze). (def x) with no init (declare) analyzes to a :def with :no-init instead of punting. Chez reserves the var cell via declare-var! (which doesn't clobber an existing root — (do (def x 7) (def x) x) => 7); the Janet back end still punts to the interpreter, which interns a genuinely-unbound var. fallback-zero-test now checks emit-ir too, not just analyze-form, so the real compile-vs-interpret decision is what it asserts (letfn/def-no-init analyze but the Janet back end punts them). letfn stays in must-punt with an updated note. Prelude emit reach 342 -> 348/355 (40-lazy now 13/13); Chez subset 664 -> 672, 0 divergences; emit-test 110 -> 117. Full gate green.
This commit is contained in:
parent
930800f9a6
commit
0f7d2753a8
8 changed files with 119 additions and 31 deletions
|
|
@ -48,13 +48,14 @@ compile-time signal) and are counted "out of subset", not as divergences.
|
|||
|
||||
JOLT_CHEZ_CORPUS=1 janet test/chez/run-corpus-chez.janet
|
||||
|
||||
Baseline after inc 3f (quoted literals): **664/664 compiled cases pass**, 0
|
||||
divergences; 1994/2658 out of subset (await clojure.core on Chez). Inc 3e
|
||||
Baseline after inc 3g (letfn + declare): **672/672 compiled cases pass**, 0
|
||||
divergences; 1986/2658 out of subset (await clojure.core on Chez). Inc 3e
|
||||
(throw/try + ex-info) was 632/632; inc 3f's quote support + a seq.ss fix (empty
|
||||
`map`/`filter` results are `()` not nil, matching Clojure) pulled 32 more corpus
|
||||
cases into the subset. `emit-fn` lowers multi-arity fns to a Scheme `case-lambda`
|
||||
and variadic fns to a rest-arg lambda (rest list coerced to a jolt seq, nil when
|
||||
empty).
|
||||
`map`/`filter` results are `()` not nil, matching Clojure) reached 664/664; inc 3g
|
||||
(letfn -> Scheme `letrec*`, declare/def-no-init -> a reserved var cell) pulled 8
|
||||
more corpus cases into the subset. `emit-fn` lowers multi-arity fns to a Scheme
|
||||
`case-lambda` and variadic fns to a rest-arg lambda (rest list coerced to a jolt
|
||||
seq, nil when empty).
|
||||
|
||||
## Phase 1 — clojure.core prelude emission (inc 3d, jolt-ocvi)
|
||||
The `-e`-capable jolt-chez path: emit the clojure.core tiers
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@
|
|||
|
||||
# Regression floor (raise it as new IR ops / RT shims land, like the suite
|
||||
# baseline). Fails if prelude emit reach drops below the recorded baseline.
|
||||
(def reach-floor 342)
|
||||
(def reach-floor 348)
|
||||
(when (< compiled reach-floor)
|
||||
(printf "REGRESSION: prelude emit reach %d < floor %d" compiled reach-floor)
|
||||
(os/exit 1))
|
||||
|
|
|
|||
|
|
@ -259,6 +259,28 @@
|
|||
(ok (string "quote: " src) (and (= code 0) (= out want))
|
||||
(string "chez=" out " janet=" want " | " err))))
|
||||
|
||||
# 3k) letfn + declare/def-no-init (inc 3g). letfn lowers to a Scheme `letrec*`
|
||||
# (mutual recursion between the named local fns — a plain let* can't forward-
|
||||
# ref a sibling). declare/(def x) with no init pre-creates the var cell so a
|
||||
# forward reference resolves; the real def runs before any call.
|
||||
(each src [# single local fn
|
||||
"(letfn [(twice [x] (* x 2))] (twice 5))"
|
||||
# self-recursion within a local fn
|
||||
"(letfn [(fact [n] (if (zero? n) 1 (* n (fact (dec n)))))] (fact 5))"
|
||||
# MUTUAL recursion — the letrec semantics a sequential let* lacks
|
||||
"(letfn [(ev? [n] (if (zero? n) true (od? (dec n)))) (od? [n] (if (zero? n) false (ev? (dec n))))] (ev? 10))"
|
||||
"(letfn [(ev? [n] (if (zero? n) true (od? (dec n)))) (od? [n] (if (zero? n) false (ev? (dec n))))] (od? 7))"
|
||||
# local fn passed to a higher-order fn
|
||||
"(letfn [(sq [x] (* x x))] (map sq [1 2 3]))"
|
||||
# declare + forward reference (the canonical mutually-recursive top-level use)
|
||||
"(declare is-ev) (defn is-od [n] (if (zero? n) false (is-ev (dec n)))) (defn is-ev [n] (if (zero? n) true (is-od (dec n)))) (is-ev 10)"
|
||||
# declare then redefine: the real def overwrites the reserved cell
|
||||
"(declare foo) (def foo 10) foo"]
|
||||
(let [[code out err] (d/run-on-chez ctx src)
|
||||
want (cli-oracle src)]
|
||||
(ok (string "letfn/declare: " src) (and (= code 0) (= out want))
|
||||
(string "chez=" out " janet=" want " | " err))))
|
||||
|
||||
# 3h) prelude mode (inc 3d): emitting clojure.core ITSELF, a core->core ref must
|
||||
# lower to a runtime var-deref instead of being rejected as "out of subset".
|
||||
# `frequencies` is a core fn but not a native-op, so it exercises the switch.
|
||||
|
|
|
|||
|
|
@ -21,8 +21,13 @@
|
|||
(def ctx (init-cached))
|
||||
|
||||
(defn- analyzes? [s]
|
||||
# true if the analyzer produced IR (compiled), false if it punted/uncompilable.
|
||||
(def r (protect (backend/analyze-form ctx (parse-string s))))
|
||||
# true if the form COMPILES end to end (analyzer IR + back end emit), false if
|
||||
# it punts to the interpreter. Checks emit-ir too, not just analyze-form: letfn
|
||||
# and (def x) with no init now ANALYZE to IR, but the Janet back end punts them
|
||||
# at emit time (sequential let* can't express mutual recursion; an unbound var
|
||||
# is not a compiled value) — so analyze-form alone would miss the real
|
||||
# compile-vs-interpret decision that compile-and-eval makes.
|
||||
(def r (protect (backend/emit-ir ctx (backend/analyze-form ctx (parse-string s)))))
|
||||
(and (r 0) true))
|
||||
|
||||
# --- Must compile: pure, non-stateful value production. NONE may punt. ---
|
||||
|
|
@ -80,8 +85,11 @@
|
|||
# defmacro — definitional host seam (the EXPANDERS are compiled;
|
||||
# see backend/recompile-macros!)
|
||||
# set! — host var-cell mutation special
|
||||
# letfn — needs letrec IR (sequential let* can't express mutual
|
||||
# recursion); permanent-interpret unless the IR gains it
|
||||
# letfn — analyzes to a :letrec IR node now (inc 3g), but the Janet
|
||||
# back end still punts it at emit: its sequential let* can't
|
||||
# express the mutual recursion. The Chez back end DOES
|
||||
# compile it (letrec*). Janet stays interpret until emit-let
|
||||
# gains a letrec lowering.
|
||||
# eval — compile-and-run entry (also loader stateful-head?)
|
||||
# . / new / Foo. / — thin host-interop heads the back end doesn't model
|
||||
# .method
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue