Refactor: extract PersistentHashSet from phm.janet into phs.janet
Completes the phm.janet decomposition (jolt-bvek): after lazyseq left, the set follows. phm.janet is now purely the PersistentHashMap; phs.janet is the thin set layer over it (members are keys -> true), and (use ./phm) for the builders. Importers using set?/phs-* via (use ./phm) add (use ./phs); backend's emitted set literal head changes phm/make-phs -> phs/make-phs. Behaviour unchanged (sets verified interpreted + compiled; full gate green).
This commit is contained in:
parent
7cffe85298
commit
bad418e917
6 changed files with 47 additions and 41 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
(use ./evaluator)
|
(use ./evaluator)
|
||||||
(import ./reader :as r)
|
(import ./reader :as r)
|
||||||
(import ./phm :as phm)
|
(import ./phm :as phm)
|
||||||
|
(import ./phs :as phs)
|
||||||
(import ./pv :as pv)
|
(import ./pv :as pv)
|
||||||
|
|
||||||
# The IR is portable data; reading its representation is a host-layer concern.
|
# The IR is portable data; reading its representation is a host-layer concern.
|
||||||
|
|
@ -584,7 +585,7 @@
|
||||||
# then the persistent set is constructed — mirrors compiler.janet's emit-set-expr.
|
# then the persistent set is constructed — mirrors compiler.janet's emit-set-expr.
|
||||||
(defn- emit-set [ctx node]
|
(defn- emit-set [ctx node]
|
||||||
(def items (map |(emit ctx $) (vview (node :items))))
|
(def items (map |(emit ctx $) (vview (node :items))))
|
||||||
(tuple/slice (array/concat @[phm/make-phs] items)))
|
(tuple/slice (array/concat @[phs/make-phs] items)))
|
||||||
|
|
||||||
(set emit
|
(set emit
|
||||||
(fn emit [ctx raw]
|
(fn emit [ctx raw]
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
(use ./types)
|
(use ./types)
|
||||||
(use ./phm)
|
(use ./phm)
|
||||||
|
(use ./phs)
|
||||||
(use ./lazyseq)
|
(use ./lazyseq)
|
||||||
(use ./regex)
|
(use ./regex)
|
||||||
(use ./config)
|
(use ./config)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
(use ./types)
|
(use ./types)
|
||||||
(use ./phm)
|
(use ./phm)
|
||||||
|
(use ./phs)
|
||||||
(use ./lazyseq)
|
(use ./lazyseq)
|
||||||
(use ./pv)
|
(use ./pv)
|
||||||
(use ./plist)
|
(use ./plist)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
(use ./api)
|
(use ./api)
|
||||||
(use ./types)
|
(use ./types)
|
||||||
(use ./phm)
|
(use ./phm)
|
||||||
|
(use ./phs)
|
||||||
(use ./lazyseq)
|
(use ./lazyseq)
|
||||||
(use ./pv)
|
(use ./pv)
|
||||||
(use ./plist)
|
(use ./plist)
|
||||||
|
|
|
||||||
|
|
@ -174,43 +174,3 @@
|
||||||
(while (< i n) (set m (phm-assoc m (kvs i) (kvs (+ i 1)))) (+= i 2)))
|
(while (< i n) (set m (phm-assoc m (kvs i) (kvs (+ i 1)))) (+= i 2)))
|
||||||
m)
|
m)
|
||||||
|
|
||||||
# ============================================================
|
|
||||||
# PersistentHashSet — backed by PersistentHashMap
|
|
||||||
# ============================================================
|
|
||||||
|
|
||||||
(defn set?
|
|
||||||
"Check if x is a PersistentHashSet."
|
|
||||||
[x]
|
|
||||||
(and (table? x) (= :jolt/set (x :jolt/type))))
|
|
||||||
|
|
||||||
(defn make-phs [& xs]
|
|
||||||
"Create a PersistentHashSet from items."
|
|
||||||
(var m (make-phm))
|
|
||||||
(each x xs (set m (phm-assoc m x true)))
|
|
||||||
@{:jolt/type :jolt/set :phm m :cnt (phm-count m)})
|
|
||||||
|
|
||||||
(defn phs-conj [s & xs]
|
|
||||||
(var m (s :phm))
|
|
||||||
(each x xs (set m (phm-assoc m x true)))
|
|
||||||
@{:jolt/type :jolt/set :phm m :cnt (phm-count m)})
|
|
||||||
|
|
||||||
(defn phs-disj [s & xs]
|
|
||||||
(var m (s :phm))
|
|
||||||
(each x xs (set m (phm-dissoc m x)))
|
|
||||||
@{:jolt/type :jolt/set :phm m :cnt (phm-count m)})
|
|
||||||
|
|
||||||
(defn phs-contains? [s x]
|
|
||||||
(phm-contains? (s :phm) x))
|
|
||||||
|
|
||||||
(defn phs-count [s]
|
|
||||||
(s :cnt))
|
|
||||||
|
|
||||||
(defn phs-empty? [s]
|
|
||||||
(= 0 (s :cnt)))
|
|
||||||
|
|
||||||
(defn phs-seq [s]
|
|
||||||
(tuple ;(keys (phm-to-struct (s :phm)))))
|
|
||||||
|
|
||||||
(defn phs-get [s x &opt default]
|
|
||||||
(default default nil)
|
|
||||||
(if (phm-contains? (s :phm) x) x default))
|
|
||||||
|
|
|
||||||
42
src/jolt/phs.janet
Normal file
42
src/jolt/phs.janet
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# PersistentHashSet — a set backed by a PersistentHashMap (members are keys
|
||||||
|
# mapped to true). Extracted from phm.janet (jolt-bvek) so phm.janet is purely
|
||||||
|
# the hash map; the set is a thin layer over it.
|
||||||
|
|
||||||
|
(use ./phm)
|
||||||
|
|
||||||
|
(defn set?
|
||||||
|
"Check if x is a PersistentHashSet."
|
||||||
|
[x]
|
||||||
|
(and (table? x) (= :jolt/set (x :jolt/type))))
|
||||||
|
|
||||||
|
(defn make-phs [& xs]
|
||||||
|
"Create a PersistentHashSet from items."
|
||||||
|
(var m (make-phm))
|
||||||
|
(each x xs (set m (phm-assoc m x true)))
|
||||||
|
@{:jolt/type :jolt/set :phm m :cnt (phm-count m)})
|
||||||
|
|
||||||
|
(defn phs-conj [s & xs]
|
||||||
|
(var m (s :phm))
|
||||||
|
(each x xs (set m (phm-assoc m x true)))
|
||||||
|
@{:jolt/type :jolt/set :phm m :cnt (phm-count m)})
|
||||||
|
|
||||||
|
(defn phs-disj [s & xs]
|
||||||
|
(var m (s :phm))
|
||||||
|
(each x xs (set m (phm-dissoc m x)))
|
||||||
|
@{:jolt/type :jolt/set :phm m :cnt (phm-count m)})
|
||||||
|
|
||||||
|
(defn phs-contains? [s x]
|
||||||
|
(phm-contains? (s :phm) x))
|
||||||
|
|
||||||
|
(defn phs-count [s]
|
||||||
|
(s :cnt))
|
||||||
|
|
||||||
|
(defn phs-empty? [s]
|
||||||
|
(= 0 (s :cnt)))
|
||||||
|
|
||||||
|
(defn phs-seq [s]
|
||||||
|
(tuple ;(keys (phm-to-struct (s :phm)))))
|
||||||
|
|
||||||
|
(defn phs-get [s x &opt default]
|
||||||
|
(default default nil)
|
||||||
|
(if (phm-contains? (s :phm) x) x default))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue