core: Phase 4 — move vreset!/vswap! to the overlay (reusing ref-put!)
vreset! sets the volatile's :val slot through the jolt.host/ref-put! primitive added in the last batch; vswap! is pure over vreset! + get. The volatile! constructor stays native (it builds the mutable box). Covered by the existing state spec.
This commit is contained in:
parent
4d5aa8c903
commit
a9403e26b0
2 changed files with 9 additions and 8 deletions
|
|
@ -286,3 +286,10 @@
|
||||||
(jolt.host/ref-put! (get a :watches) key nil) a)
|
(jolt.host/ref-put! (get a :watches) key nil) a)
|
||||||
(defn set-validator! [a f]
|
(defn set-validator! [a f]
|
||||||
(jolt.host/ref-put! a :validator f) nil)
|
(jolt.host/ref-put! a :validator f) nil)
|
||||||
|
|
||||||
|
;; Volatiles. The constructor (volatile!) stays native — it builds the mutable box —
|
||||||
|
;; but vreset! sets the box's slot through ref-put! and vswap! is pure over it + get.
|
||||||
|
(defn vreset! [vol newval]
|
||||||
|
(jolt.host/ref-put! vol :val newval) newval)
|
||||||
|
(defn vswap! [vol f & args]
|
||||||
|
(vreset! vol (apply f (get vol :val) args)))
|
||||||
|
|
|
||||||
|
|
@ -2087,12 +2087,8 @@
|
||||||
|
|
||||||
# Volatiles — typed box so deref/volatile? can recognize them.
|
# Volatiles — typed box so deref/volatile? can recognize them.
|
||||||
(defn core-volatile! [v] @{:jolt/type :jolt/volatile :val v})
|
(defn core-volatile! [v] @{:jolt/type :jolt/volatile :val v})
|
||||||
# volatile? now lives in the Clojure collection tier (tagged-value predicate).
|
# volatile? / vreset! / vswap! now live in the Clojure collection tier — vreset!
|
||||||
(defn core-vswap! [vol f & args]
|
# over jolt.host/ref-put!, vswap! over vreset! + get. The constructor stays native.
|
||||||
(def new-val (apply f (vol :val) args))
|
|
||||||
(put vol :val new-val)
|
|
||||||
new-val)
|
|
||||||
(defn core-vreset! [vol val] (put vol :val val) val)
|
|
||||||
|
|
||||||
# Delays — created lazily by the `delay` macro; forced once via force/deref.
|
# Delays — created lazily by the `delay` macro; forced once via force/deref.
|
||||||
(defn core-make-delay [thunk] @{:jolt/type :jolt/delay :fn thunk :realized false :val nil})
|
(defn core-make-delay [thunk] @{:jolt/type :jolt/delay :fn thunk :realized false :val nil})
|
||||||
|
|
@ -3022,8 +3018,6 @@
|
||||||
"implements?" core-implements?
|
"implements?" core-implements?
|
||||||
"type->str" core-type->str
|
"type->str" core-type->str
|
||||||
"volatile!" core-volatile!
|
"volatile!" core-volatile!
|
||||||
"vswap!" core-vswap!
|
|
||||||
"vreset!" core-vreset!
|
|
||||||
"Thread" core-Thread
|
"Thread" core-Thread
|
||||||
"ThreadLocal" core-ThreadLocal
|
"ThreadLocal" core-ThreadLocal
|
||||||
"IllegalStateException" core-IllegalStateException
|
"IllegalStateException" core-IllegalStateException
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue