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.
59 lines
2.5 KiB
Text
59 lines
2.5 KiB
Text
(use ../src/jolt/api)
|
|
(use ../src/jolt/reader)
|
|
(use ../src/jolt/evaluator)
|
|
|
|
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
|
|
|
(defn load-clj [ctx filepath]
|
|
(def source (slurp filepath))
|
|
(var remaining source)
|
|
(while (> (length (string/trim remaining)) 0)
|
|
(def fr (parse-next remaining))
|
|
(def form (fr 0))
|
|
(set remaining (fr 1))
|
|
(when (not (nil? form))
|
|
(eval-form ctx @{} form))))
|
|
|
|
(print "40: clojure.string...")
|
|
(let [ctx (init)]
|
|
(load-clj ctx "src/jolt/clojure/string.clj")
|
|
(assert (= true (ct-eval ctx "(blank? nil)")) "blank? nil")
|
|
(assert (= true (ct-eval ctx "(blank? \" \")")) "blank? whitespace")
|
|
(assert (= false (ct-eval ctx "(blank? \"a\")")) "blank? non-empty")
|
|
(assert (= "Abc" (ct-eval ctx "(capitalize \"abc\")")) "capitalize")
|
|
(assert (= "hello" (ct-eval ctx "(lower-case \"HELLO\")")) "lower-case")
|
|
(assert (= "HELLO" (ct-eval ctx "(upper-case \"hello\")")) "upper-case")
|
|
(assert (= true (ct-eval ctx "(includes? \"hello\" \"ell\")")) "includes? true")
|
|
(assert (= "foo" (ct-eval ctx "(trim \"foo\")")) "trim")
|
|
(assert (= true (ct-eval ctx "(starts-with? \"hello\" \"he\")")) "starts-with? true")
|
|
(assert (= true (ct-eval ctx "(ends-with? \"hello\" \"lo\")")) "ends-with? true"))
|
|
(print " passed")
|
|
|
|
(print "41: clojure.set...")
|
|
(let [ctx (init)]
|
|
(load-clj ctx "src/jolt/clojure/set.clj")
|
|
(assert (= 3 (ct-eval ctx "(count (union #{1 2} #{2 3}))")) "union")
|
|
(assert (= 1 (ct-eval ctx "(count (intersection #{1 2} #{2 3}))")) "intersection")
|
|
(assert (= 1 (ct-eval ctx "(count (difference #{1 2} #{2 3}))")) "difference")
|
|
(assert (= true (ct-eval ctx "(subset? #{1} #{1 2 3})")) "subset? true")
|
|
(assert (= true (ct-eval ctx "(superset? #{1 2 3} #{1})")) "superset? true"))
|
|
(print " passed")
|
|
|
|
(print "42: clojure.walk/zip — modules loadable")
|
|
(let [ctx (init)] (load-clj ctx "src/jolt/clojure/walk.clj") (print " walk: loaded"))
|
|
(let [ctx (init)] (load-clj ctx "src/jolt/clojure/zip.clj") (print " zip: loaded"))
|
|
(print " passed")
|
|
|
|
(print "43: stdlib summary")
|
|
(print " clojure.string — 19 functions")
|
|
(print " clojure.set — 10 functions")
|
|
(print " clojure.walk — 7 functions")
|
|
(print " clojure.zip — zipper data structure")
|
|
(print " clojure.edn — EDN reader/writer stubs")
|
|
(print " clojure.java-io — file I/O wrappers")
|
|
(print " jolt.interop — Janet interop")
|
|
(print " jolt.shell — shell command execution")
|
|
(print " jolt.http — HTTP client")
|
|
(print " passed")
|
|
|
|
(print "All Phase 10 tests passed!")
|