First fractal turn of the multi-stage bootstrap (jolt-tzo). The Clojure part of clojure.core is now loaded in ordered tiers under jolt-core/clojure/core/. The kernel tier (00-kernel: second/peek/subvec/mapv/update) holds the structural fns the self-hosted compiler itself uses; in compile mode it is bootstrap-compiled into clojure.core BEFORE the analyzer is built, so the analyzer binds those names to the Clojure definitions instead of a not-yet-defined forward ref. That removes the circularity that previously forced these to stay in Janet — the five core-* primitives and their init-core! entries are gone. Mechanism: backend/bootstrap-load-source (generalized from compile-load) builds a source string into a target ns via the bootstrap; rebuild-compiler! recompiles the self-hosted compiler against the current core (the rail for future turns, exercised by the new fixpoint test). api/load-core-overlay! walks the ordered tiers, bootstrap-loading kernel tiers and self-hosting the rest. Also fixes a latent evaluator bug surfaced by the move: a fn rebinds current-ns to its defining ns while it runs and restores on normal return, but a fn that THREW unwound past its own restore, leaking the ns. try now restores the try-entry ns on the catch/finally path, so referred-symbol resolution survives a caught error (this was breaking is/testing in the suite harness after any thrown assertion). Net battery +3 (3913 -> 3916); conformance 218/218 in all three modes; binary builds and runs the embedded tiers.
24 lines
1 KiB
Clojure
24 lines
1 KiB
Clojure
;; clojure.core — seq tier. Pure-Clojure leaf sequence fns on top of the kernel
|
|
;; tier (00-kernel) and the Janet seed. Loaded after the kernel tier; in compile
|
|
;; mode these self-host through the now-built analyzer (interpreted otherwise).
|
|
;;
|
|
;; Migration rule for adding fns here: the fn must (1) NOT be in
|
|
;; compiler/core-renames (that map emits core-X Janet symbols directly), (2) have
|
|
;; no internal Janet callers of its core-X binding, and (3) NOT be used by the
|
|
;; self-hosted compiler (jolt-core/jolt/*.clj). Compiler-facing structural fns go
|
|
;; in the kernel tier (00-kernel) instead — see its header.
|
|
|
|
(defn ffirst [coll] (first (first coll)))
|
|
(defn nfirst [coll] (next (first coll)))
|
|
(defn fnext [coll] (first (next coll)))
|
|
(defn nnext [coll] (next (next coll)))
|
|
|
|
;; Canonical Clojure defs: pure first/next/loop/recur, no Janet realize-for-iteration.
|
|
(defn last [s]
|
|
(if (next s) (recur (next s)) (first s)))
|
|
|
|
(defn butlast [s]
|
|
(loop [ret [] s s]
|
|
(if (next s)
|
|
(recur (conj ret (first s)) (next s))
|
|
(seq ret))))
|