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]