Replace str-render/instance-check set! chains with registries
jolt-str-render-one and instance-check were each extended by a chain of set!-wrapping closures spread across ~10 and ~5 host files, so the real behavior of either was scattered and load-order-dependent. Give each a registry the base file owns: converters.ss/records-interop.ss define the registry plus a register-* helper, and each extending file registers one arm instead of capturing %prev and set!-ing the global. str-render arms are type-disjoint; instance-check arms run newest-first (the old outermost-wins order) and may return 'pass to defer. The string-token -> symbol normalization the natives-array arm did for every inner arm moves to the dispatcher head; array tokens stay strings for that arm to decide. jolt-ogib.14. Runtime-only shims, no re-mint.
This commit is contained in:
parent
bc16513afd
commit
e434356590
14 changed files with 79 additions and 64 deletions
|
|
@ -255,8 +255,7 @@
|
|||
(set! jolt-pr-str (lambda (x) (if (jinst? x) (inst-pr x) (%it-pr-str x))))
|
||||
(define %it-pr-readable jolt-pr-readable)
|
||||
(set! jolt-pr-readable (lambda (x) (if (jinst? x) (inst-pr x) (%it-pr-readable x))))
|
||||
(define %it-str-render jolt-str-render-one)
|
||||
(set! jolt-str-render-one (lambda (x) (if (jinst? x) (inst-rfc3339 x) (%it-str-render x))))
|
||||
(register-str-render! jinst? inst-rfc3339)
|
||||
|
||||
(define %it-type jolt-type)
|
||||
(set! jolt-type (lambda (x) (if (jinst? x) inst-type-kw (%it-type x))))
|
||||
|
|
@ -266,8 +265,7 @@
|
|||
;; matching jhost tag. The instance? macro passes the class-name symbol.
|
||||
(define (class-short tn) (let loop ((i (- (string-length tn) 1)))
|
||||
(cond ((< i 0) tn) ((char=? (string-ref tn i) #\.) (substring tn (+ i 1) (string-length tn))) (else (loop (- i 1))))))
|
||||
(define %it-instance-check instance-check)
|
||||
(set! instance-check
|
||||
(register-instance-check-arm!
|
||||
(lambda (type-sym val)
|
||||
(let ((tn (class-short (symbol-t-name type-sym))))
|
||||
(cond
|
||||
|
|
@ -275,11 +273,10 @@
|
|||
;; (on the JVM a Date is not a Timestamp), so answer Timestamp explicitly #f.
|
||||
((jinst? val) (cond ((string=? tn "Date") #t)
|
||||
((string=? tn "Timestamp") #f)
|
||||
(else (%it-instance-check type-sym val))))
|
||||
((and (jhost? val) (string=? (jhost-tag val) "instant")) (if (string=? tn "Instant") #t (%it-instance-check type-sym val)))
|
||||
((and (jhost? val) (string=? (jhost-tag val) "local-dt")) (if (string=? tn "LocalDateTime") #t (%it-instance-check type-sym val)))
|
||||
(else (%it-instance-check type-sym val))))))
|
||||
(def-var! "clojure.core" "instance-check" instance-check)
|
||||
(else 'pass)))
|
||||
((and (jhost? val) (string=? (jhost-tag val) "instant")) (if (string=? tn "Instant") #t 'pass))
|
||||
((and (jhost? val) (string=? (jhost-tag val) "local-dt")) (if (string=? tn "LocalDateTime") #t 'pass))
|
||||
(else 'pass)))))
|
||||
|
||||
;; inst-ms* is a seed native (the overlay inst-ms reads (get x :ms), now answered).
|
||||
(def-var! "clojure.core" "inst-ms*" (lambda (i) (jinst-ms i)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue