refactor: registry pattern for jolt-hash + jolt-class (jolt-lmot)
Replace the set!-capture-and-rebind chains extending jolt-hash (3 sites: inst-time/ host-table/records) and jolt-class (3 sites: bigdec/natives-queue/host-table) with a register-hash-arm! / register-class-arm! registry (the pattern already used by register-str-render!). The base dispatcher walks its arms — disjoint types, so order is immaterial — then falls to the base cases. The entry is stable, so the per-site (def-var! "clojure.core" "class" …) re-points are gone. Behaviour-preserving (runtime .ss, no re-mint): jinst hash, bigdec/queue/record class, record hash, and a sorted-map hashing as its plain map all verified; make test green, 0 new corpus divergences. First two of six dispatchers; get/=/pr-str follow.
This commit is contained in:
parent
bcd752717e
commit
d168d1195b
7 changed files with 34 additions and 19 deletions
|
|
@ -13,7 +13,13 @@
|
|||
;; (str (type x)) is the clean host taxonomy and
|
||||
;; is never compared against a class token in the corpus. Records yield their
|
||||
;; ns-qualified class name (= (str (type x))). Total — never crashes.
|
||||
(define (jolt-class x)
|
||||
;; A host shim (bigdec, queue, host-table) registers its type's class name via
|
||||
;; register-class-arm! instead of set!-wrapping jolt-class (cf. register-hash-arm!).
|
||||
;; The entry is stable, so the var cell bound below stays current as arms register.
|
||||
(define jolt-class-arms '())
|
||||
(define (register-class-arm! pred handler)
|
||||
(set! jolt-class-arms (cons (cons pred handler) jolt-class-arms)))
|
||||
(define (jolt-class-base x)
|
||||
(cond
|
||||
((jolt-nil? x) jolt-nil)
|
||||
((boolean? x) "java.lang.Boolean")
|
||||
|
|
@ -35,6 +41,11 @@
|
|||
;; (thrown? Class …) match (records.ss ex-info-map?/ex-info-class).
|
||||
((ex-info-map? x) (ex-info-class x))
|
||||
(else (jolt-str-render-one (jolt-type x)))))
|
||||
(define (jolt-class x)
|
||||
(let loop ((as jolt-class-arms))
|
||||
(cond ((null? as) (jolt-class-base x))
|
||||
(((caar as) x) ((cdar as) x))
|
||||
(else (loop (cdr as))))))
|
||||
|
||||
(def-var! "clojure.core" "class" jolt-class)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue