Compiler research (#10)
adds self-hosted compiler is functionally: - The default compile path is the portable pipeline using jolt.analyzer (Clojure) → host-neutral IR → backend.janet. - The analyzer is itself Clojure, compiled by jolt for true self-hosting. - bootstrap-fixpoint passes (stage1 == stage2 == stage3): rebuilding the compiler on its own output. - clojure.core is now self-hosted in the overlay. - Stateful forms (defmacro/ns/deftype/defmulti/require/in-ns) are interpreted by design.
This commit is contained in:
parent
607779866e
commit
d3194aae59
68 changed files with 6590 additions and 2019 deletions
|
|
@ -43,6 +43,14 @@
|
|||
["map" "[2 3 4]" "(map inc [1 2 3])"]
|
||||
["map two colls" "[5 7 9]" "(map + [1 2 3] [4 5 6])"]
|
||||
["map stops at shortest" "[5 7]" "(map + [1 2] [4 5 6])"]
|
||||
# nil elements are values, not end-of-seq: multi-coll map must not truncate.
|
||||
["map keeps nil elements" "[[1 :a] [nil :b] [3 nil]]" "(map vector [1 nil 3] [:a :b nil])"]
|
||||
["map 3 colls" "[12 15 18]" "(map + [1 2 3] [4 5 6] [7 8 9])"]
|
||||
["map 3 colls shortest" "[12 15]" "(map + [1 2] [4 5 6] [7 8 9])"]
|
||||
["map 4 colls" "[16 20]" "(map + [1 2] [3 4] [5 6] [7 8])"]
|
||||
["map 3 colls nils" "[[1 :a 10] [nil :b 20] [3 nil 30]]" "(map vector [1 nil 3] [:a :b nil] [10 20 30])"]
|
||||
["map empty coll" "()" "(map + [] [1 2 3] [4 5 6])"]
|
||||
["map lazy+concrete" "[11 22 33]" "(map + (map identity [1 2 3]) [10 20 30])"]
|
||||
["map-indexed" "[[0 :a] [1 :b]]" "(map-indexed vector [:a :b])"]
|
||||
["mapv" "[2 3 4]" "(mapv inc [1 2 3])"]
|
||||
["filter" "[2 4]" "(filter even? [1 2 3 4])"]
|
||||
|
|
@ -54,8 +62,15 @@
|
|||
["reduce single no init" "5" "(reduce + [5])"]
|
||||
["reduced short-circuits" "3" "(reduce (fn [a x] (if (> a 2) (reduced a) (+ a x))) 0 [1 2 3 4 5])"]
|
||||
["reduce-kv" "6" "(reduce-kv (fn [a k v] (+ a v)) 0 {:a 1 :b 2 :c 3})"]
|
||||
["reduce-kv on vector" "[[0 :a] [1 :b]]" "(reduce-kv (fn [a i v] (conj a [i v])) [] [:a :b])"]
|
||||
["reduce-kv honors reduced" "[:a]" "(reduce-kv (fn [a i v] (if (= i 1) (reduced a) (conj a v))) [] [:a :b :c])"]
|
||||
["reduce-kv on nil" "0" "(reduce-kv (fn [a k v] (+ a v)) 0 nil)"]
|
||||
["reductions" "[1 3 6]" "(reductions + [1 2 3])"]
|
||||
["mapcat" "[1 1 2 2]" "(mapcat (fn [x] [x x]) [1 2])"]
|
||||
["mapcat two colls" "[1 3 2 4]" "(mapcat vector [1 2] [3 4])"]
|
||||
["mapcat three colls" "[1 2 3]" "(mapcat vector [1] [2] [3])"]
|
||||
["mapcat empty coll" "()" "(mapcat vector [] [1 2] [3 4])"]
|
||||
["mapcat seqs" "[1 2 3 4]" "(mapcat identity [[1 2] [3 4]])"]
|
||||
["keep" "[1 3]" "(keep (fn [x] (if (odd? x) x nil)) [1 2 3 4])"]
|
||||
["some truthy" "true" "(some even? [1 2 3])"]
|
||||
["some nil" "nil" "(some even? [1 3 5])"]
|
||||
|
|
@ -197,3 +212,52 @@
|
|||
["nthnext nil count" :throws "(nthnext [0 1 2] nil)"]
|
||||
["update vec oob" :throws "(update [] 1 identity)"]
|
||||
["update vec kw key" :throws "(update [1 2 3] :k identity)"])
|
||||
|
||||
# Regression cases for clojure.core fns moved from Janet to the Clojure overlay
|
||||
# (jolt-1j0), plus two bugs fixed in the process: nthrest returns () (not nil)
|
||||
# for an exhausted n>0 walk, and distinct? compares by VALUE (equal collections
|
||||
# are not distinct).
|
||||
(defspec "seq / overlay-migrated fns"
|
||||
["nthrest exhausted -> ()" "()" "(nthrest nil 100)"]
|
||||
["nthrest vec exhausted" "()" "(nthrest [1 2 3] 100)"]
|
||||
["nthrest n<=0 keeps coll" "[1 2 3]" "(nthrest [1 2 3] 0)"]
|
||||
["nthrest drops n" "[3 4 5]" "(nthrest [1 2 3 4 5] 2)"]
|
||||
["nthnext exhausted -> nil" "nil" "(nthnext [1 2] 5)"]
|
||||
["nthnext surprising nil" "nil" "(nthnext nil nil)"]
|
||||
["nthnext drops n" "[3 4]" "(nthnext [1 2 3 4] 2)"]
|
||||
["distinct? distinct" "true" "(distinct? 1 2 3)"]
|
||||
["distinct? dup" "false" "(distinct? 1 2 1)"]
|
||||
["distinct? equal colls" "false" "(distinct? [1 2] [1 2])"]
|
||||
["distinct? single" "true" "(distinct? 5)"]
|
||||
["replace maps elements" "[:a 2 :c 2]" "(replace {1 :a 3 :c} [1 2 3 2])"]
|
||||
["replace preserves nil val" "[1 nil 3]" "(replace {2 nil} [1 2 3])"]
|
||||
["take-last" "[3 4]" "(take-last 2 [1 2 3 4])"]
|
||||
["take-last empty -> nil" "nil" "(take-last 2 [])"]
|
||||
["take-last n>len" "[1 2]" "(take-last 9 [1 2])"]
|
||||
["drop-last default 1" "[1 2]" "(drop-last [1 2 3])"]
|
||||
["drop-last n" "[1 2]" "(drop-last 2 [1 2 3 4])"]
|
||||
["split-with" "[[2 4] [5 6]]" "(split-with even? [2 4 5 6])"]
|
||||
["replicate" "[:x :x :x]" "(replicate 3 :x)"]
|
||||
["bounded-count" "3" "(bounded-count 3 [1 2 3 4 5])"]
|
||||
["run! side effects" "6" "(let [a (atom 0)] (run! (fn [x] (swap! a + x)) [1 2 3]) @a)"]
|
||||
["completing wraps rf" "3" "((completing +) 1 2)"]
|
||||
["comparator <" "[1 2 3]" "(sort (comparator <) [3 1 2])"]
|
||||
["comparator >" "[3 2 1]" "(sort (comparator >) [3 1 2])"]
|
||||
["reductions" "[1 3 6 10]" "(reductions + [1 2 3 4])"]
|
||||
["reductions with init" "[10 11 13 16]" "(reductions + 10 [1 2 3])"]
|
||||
["reductions empty calls f" "[0]" "(reductions + [])"]
|
||||
["reductions empty + init" "[5]" "(reductions + 5 [])"]
|
||||
["tree-seq pre-order" "[[1 [2] 3] 1 [2] 2 3]" "(tree-seq sequential? seq [1 [2] 3])"]
|
||||
["some found" "true" "(some even? [1 3 4])"]
|
||||
["some none -> nil" "nil" "(some even? [1 3 5])"]
|
||||
["some keyword pred" "7" "(some :a [{:b 1} {:a 7}])"]
|
||||
["some returns value" "4" "(some (fn [x] (when (even? x) x)) [1 3 4 5])"]
|
||||
["flatten nested" "[1 2 3 4 5]" "(flatten [1 [2 [3 4]] 5])"]
|
||||
["flatten lists too" "[1 2 3]" "(flatten [1 (list 2 3)])"]
|
||||
["flatten scalar -> empty" "[]" "(flatten 5)"]
|
||||
["interleave" "[1 :a 2 :b]" "(interleave [1 2 3] [:a :b])"]
|
||||
["interleave empty" "[]" "(interleave)"]
|
||||
["rationalize identity" "5" "(rationalize 5)"]
|
||||
["dedupe consecutive" "[1 2 3 1]" "(dedupe [1 1 2 2 3 1 1])"]
|
||||
["dedupe empty" "[]" "(dedupe [])"]
|
||||
["dedupe no dups" "[1 2 3]" "(dedupe [1 2 3])"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue