Round 2 of the persistent-collections work. Add a real 32-way branching-trie persistent vector (src/jolt/pv.janet) with a tail buffer: O(log32 n) conj/assoc/nth/pop, with unchanged subtrees shared by identity. Vector literals and vec/vector/conj/assoc/subvec/etc. now produce and maintain these in the default (immutable) build, replacing the old tuple-based vectors. Every core seq op, the destructurer, IFn application, the printers, =, and the evaluator's literal/splice paths were taught to handle the pvec type. Define several Clojure seq fns that were silently leaking to Janet builtins (some, keep, interleave, flatten, mapcat, interpose) and broke once vectors became tables; normalize collections through realize-for-iteration everywhere. Build-time JOLT_MUTABLE flag now selects fast Janet-native mutable collections: in that mode vectors are arrays (conj appends in place, vector? true, print []), sharing one representation with lists. Default build is immutable. Tests: conformance 206/206, features 71/71, jank 119 (baseline). Test helpers normalized so Janet-level = compares against tuple literals regardless of repr. The 2 test-load-sci failures (bit-clear/get-method) pre-date this work.
25 lines
1.2 KiB
Text
25 lines
1.2 KiB
Text
# Phase 7: LazySeq + PersistentHashSet completion
|
|
(use ../src/jolt/api)
|
|
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
|
|
|
(print "32: lazy-seq...")
|
|
(let [ctx (init)]
|
|
(let [ls (ct-eval ctx "(lazy-seq (cons 1 (lazy-seq (cons 2 nil))))")]
|
|
(assert (not (nil? ls)) "lazy-seq returns non-nil")
|
|
(assert (= 1 (ct-eval ctx "(first (lazy-seq (cons 1 nil)))")) "first of lazy"))
|
|
(assert (= true (ct-eval ctx "(= [1 2 3] (seq (lazy-seq [1 2 3])))")) "seq forces lazy")
|
|
(eval-string ctx "(def counter (atom 0))")
|
|
(def val (ct-eval ctx "(let [ls (lazy-seq (do (swap! counter inc) [1 2 3]))] (seq ls) (seq ls) @counter)"))
|
|
(assert (= 1 val) "realized once"))
|
|
(print " passed")
|
|
|
|
(print "33: PersistentHashSet...")
|
|
(let [ctx (init)]
|
|
(assert (= true (ct-eval ctx "(set? #{1 2 3})")) "set? true")
|
|
(assert (= false (ct-eval ctx "(set? [1 2 3])")) "set? false")
|
|
(assert (= 4 (ct-eval ctx "(count (conj #{1 2 3} 4))")) "conj add")
|
|
(assert (= 2 (ct-eval ctx "(count (disj #{1 2 3} 3))")) "disj")
|
|
(assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "count")
|
|
(assert (= true (ct-eval ctx "(= #{1 2 3} #{3 2 1})")) "= order-independent"))
|
|
|
|
(print "\nAll Phase 7 tests passed!")
|