core: print-method is a real multimethod (jolt-g1r); records print canonically
print-method/print-dup are now multimethods in the io tier with Clojure's
exact dispatch ((:type meta) keyword, else type — core.clj 3693). On jolt the
dispatch value for a record is its quoted full-name symbol, since class names
aren't values here.
Records used to pr-str as the raw janet table; the renderer's record branch
now prints Clojure's #ns.Type{:k v} syntax, and first consults a callback the
api wires up after the overlay loads — so a user defmethod on a record type
fires everywhere: top level, nested in collections, through pr/prn/pr-str.
Builtin overrides (a :number method) fire only on direct print-method calls;
pr keeps the native fast path (documented divergence).
java.io.Writer arrives as a shim beside the StringReader/StringBuilder ones:
a :jolt/writer tagged value with write/append/flush/toString, a StringWriter
ctor, and a sink variant the renderer callback uses.
Two latent host bugs fixed on the way: the interpreted syntax-quote splice
blew up on ~@nil (an interpreted macro's empty & rest binds nil — first tier
user of defmulti found it; d-realize now treats nil as the empty seq), and
(print-method x nil) now throws like the JVM instead of returning nil.
10 spec rows; bench dead even (sandwich run); greeter green on a fresh
binary.
This commit is contained in:
parent
eff8cb99a5
commit
1e4a0a6d53
8 changed files with 131 additions and 9 deletions
|
|
@ -127,3 +127,32 @@
|
|||
(let [line ((:read-line-fn rdr))]
|
||||
(when line
|
||||
(cons line (line-seq rdr)))))))
|
||||
|
||||
;; --- print-method (jolt-g1r) ------------------------------------------------
|
||||
;; Canonical dispatch (clojure/core.clj 3693): the :type metadata when it's a
|
||||
;; keyword, else the value's type. On jolt, type is the keyword tag for
|
||||
;; builtins and the deftype name SYMBOL for records — so a record method is
|
||||
;; (defmethod print-method 'ns.Type [r w] ...) (class names aren't values
|
||||
;; here, the quoted full name is the dispatch value).
|
||||
;;
|
||||
;; The :default renders through the host's fast printer. The host renderer
|
||||
;; calls BACK into this table for records (the api wires the hook after the
|
||||
;; overlay loads), so a record method fires nested inside collections too.
|
||||
;; Builtin overrides (e.g. a :number method) fire only when print-method is
|
||||
;; called directly — pr/pr-str keep the native fast path for builtins (a
|
||||
;; documented jolt divergence).
|
||||
(defmulti print-method (fn [x writer]
|
||||
(let [t (get (meta x) :type)]
|
||||
(if (keyword? t) t (type x)))))
|
||||
|
||||
(defmethod print-method :default [o w]
|
||||
(.write w (__pr-str1 o))
|
||||
nil)
|
||||
|
||||
;; print-dup: jolt has one print representation, so dup routes to print-method
|
||||
;; (as Clojure's default does for most types).
|
||||
(defmulti print-dup (fn [x writer]
|
||||
(let [t (get (meta x) :type)]
|
||||
(if (keyword? t) t (type x)))))
|
||||
|
||||
(defmethod print-dup :default [o w] (print-method o w))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue