From d2d33a2ea95944ada5af1db2386bd65b8d137968 Mon Sep 17 00:00:00 2001 From: Yogthos Date: Sun, 7 Jun 2026 08:37:19 -0400 Subject: [PATCH] =?UTF-8?q?core:=20syntax=20tier=20=E2=80=94=20move=20when?= =?UTF-8?q?=20to=20the=20overlay=20ahead=20of=20the=20kernel=20(jolt-1j0?= =?UTF-8?q?=20phase=203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New 00-syntax tier loaded FIRST (before 00-kernel), interpreted defmacros, so the control macros the compiler and every later tier depend on can live in Clojure. Validated by moving when: the kernel tier, self-hosted analyzer and seq/coll tiers all compile against the overlay when. Constraint: syntax-tier macros may use only special forms + core-renames seed primitives (not second/peek/kernel fns). conformance 228/228 x3, full suite green. --- jolt-core/clojure/core/00-syntax.clj | 13 +++++++++++++ src/jolt/api.janet | 3 ++- src/jolt/core.janet | 11 +---------- 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 jolt-core/clojure/core/00-syntax.clj diff --git a/jolt-core/clojure/core/00-syntax.clj b/jolt-core/clojure/core/00-syntax.clj new file mode 100644 index 0000000..cf732dd --- /dev/null +++ b/jolt-core/clojure/core/00-syntax.clj @@ -0,0 +1,13 @@ +;; clojure.core — syntax tier. The control macros the compiler and every later +;; tier depend on (when/cond/and/or/...), expressed as defmacro. Loaded FIRST +;; (before 00-kernel), interpreted, so the macros exist before any code that uses +;; them is compiled — including the kernel tier, the self-hosted analyzer, and the +;; seq/coll tiers. +;; +;; CONSTRAINT: a macro here may use ONLY special forms (if/do/let*/fn*/not) and +;; core-renames SEED primitives (first/next/rest/nth/count/empty?/...). It must +;; NOT use kernel-tier fns (second/peek/subvec/...) or anything defined later — +;; those don't exist yet when this tier loads. + +(defmacro when [test & body] + `(if ~test (do ~@body))) diff --git a/src/jolt/api.janet b/src/jolt/api.janet index 0290ed0..dee502d 100644 --- a/src/jolt/api.janet +++ b/src/jolt/api.janet @@ -37,7 +37,8 @@ # source (compiled when :compile?, interpreted otherwise — the analyzer, built # lazily on the first such form, sees the kernel tier already in place). (def- core-tiers - [{:ns "clojure.core.00-kernel" :kernel true} + [{:ns "clojure.core.00-syntax" :kernel false} + {:ns "clojure.core.00-kernel" :kernel true} {:ns "clojure.core.10-seq" :kernel false} {:ns "clojure.core.20-coll" :kernel false} {:ns "clojure.core.30-macros" :kernel false}]) diff --git a/src/jolt/core.janet b/src/jolt/core.janet index dad353b..c77601e 100644 --- a/src/jolt/core.janet +++ b/src/jolt/core.janet @@ -2092,14 +2092,6 @@ (build (tuple/slice cls 2))])))) @[{:jolt/type :symbol :ns nil :name "let*"} @[g expr] (build clauses)]) -(defn core-when - "Macro: (when test & body) -> (if test (do body...))" - [test & body] - (def arr (array ;body)) - (array/insert arr 0 {:jolt/type :symbol :ns nil :name "do"}) - @[{:jolt/type :symbol :ns nil :name "if"} - test - arr]) (defn core-when-not "Macro: (when-not test & body) -> (when (not test) & body)" @@ -3598,7 +3590,6 @@ "cond" core-cond "case" core-case "for" core-for - "when" core-when "when-not" core-when-not "when-let" core-when-let "->" core-thread-first @@ -3684,7 +3675,7 @@ (defn core-macro-names "Set of core binding names that are macros." [] - @{"and" true "or" true "cond" true "case" true "for" true "when" true "when-not" true "when-let" true "defn" true "defn-" true "declare" true "fn" true "let" true "loop" true "defrecord" true "defprotocol" true "extend-type" true "extend-protocol" true "extend" true "reify" true "proxy" true "definterface" true "lazy-seq" true "lazy-cat" true "cond->" true "->" true "->>" true "doseq" true}) + @{"and" true "or" true "cond" true "case" true "for" true "when-not" true "when-let" true "defn" true "defn-" true "declare" true "fn" true "let" true "loop" true "defrecord" true "defprotocol" true "extend-type" true "extend-protocol" true "extend" true "reify" true "proxy" true "definterface" true "lazy-seq" true "lazy-cat" true "cond->" true "->" true "->>" true "doseq" true}) (def init-core! (fn [& args]