|
94 | 94 | (print-args o w)
|
95 | 95 | (.write w ")"))
|
96 | 96 |
|
97 |
| -(defn- print-object [o, ^Writer w] |
| 97 | +(defn- print-tagged-object [o rep ^Writer w] |
98 | 98 | (when (instance? clojure.lang.IMeta o)
|
99 | 99 | (print-meta o w))
|
100 | 100 | (.write w "#object[")
|
|
103 | 103 | (print-method (.getName c) w)
|
104 | 104 | (.write w (.getName c))))
|
105 | 105 | (.write w " ")
|
106 |
| - (print-method (str o) w) |
| 106 | + (.write w (format "0x%x " (System/identityHashCode o))) |
| 107 | + (print-method rep w) |
107 | 108 | (.write w "]"))
|
108 | 109 |
|
| 110 | +(defn- print-object [o, ^Writer w] |
| 111 | + (print-tagged-object o (str o) w)) |
| 112 | + |
109 | 113 | (defmethod print-method Object [o, ^Writer w]
|
110 | 114 | (print-object o w))
|
111 | 115 |
|
|
380 | 384 | (print-dup (.name n) w)
|
381 | 385 | (.write w ")"))
|
382 | 386 |
|
| 387 | +(defn- deref-as-map [^clojure.lang.IDeref o] |
| 388 | + (let [pending (and (instance? clojure.lang.IPending o) |
| 389 | + (not (.isRealized ^clojure.lang.IPending o))) |
| 390 | + [ex val] |
| 391 | + (when-not pending |
| 392 | + (try [false (deref o)] |
| 393 | + (catch Throwable e |
| 394 | + [true e])))] |
| 395 | + {:status |
| 396 | + (cond |
| 397 | + (or ex |
| 398 | + (and (instance? clojure.lang.Agent o) |
| 399 | + (agent-error o))) |
| 400 | + :failed |
| 401 | + |
| 402 | + pending |
| 403 | + :pending |
| 404 | + |
| 405 | + :else |
| 406 | + :ready) |
| 407 | + |
| 408 | + :val val})) |
| 409 | + |
383 | 410 | (defmethod print-method clojure.lang.IDeref [o ^Writer w]
|
384 |
| - (print-sequential (format "#<%s@%x%s: " |
385 |
| - (.getSimpleName (class o)) |
386 |
| - (System/identityHashCode o) |
387 |
| - (if (and (instance? clojure.lang.Agent o) |
388 |
| - (agent-error o)) |
389 |
| - " FAILED" |
390 |
| - "")) |
391 |
| - pr-on, "", ">", (list (if (and (instance? clojure.lang.IPending o) |
392 |
| - (not (.isRealized ^clojure.lang.IPending o))) |
393 |
| - :pending |
394 |
| - @o)), w)) |
| 411 | + (print-tagged-object o (deref-as-map o) w)) |
395 | 412 |
|
396 | 413 | (defmethod print-method StackTraceElement [^StackTraceElement o ^Writer w]
|
397 | 414 | (print-method [(symbol (.getClassName o)) (symbol (.getMethodName o)) (.getFileName o) (.getLineNumber o)] w))
|
398 | 415 |
|
399 |
| -(defn print-throwable [^Throwable o ^Writer w] |
400 |
| - (.write w "#error") |
| 416 | +(defn- throwable-as-map [^Throwable o] |
401 | 417 | (let [base (fn [^Throwable t]
|
402 | 418 | {:type (class t)
|
403 | 419 | :message (.getLocalizedMessage t)
|
404 | 420 | :at (get (.getStackTrace t) 0)})
|
405 | 421 | via (loop [via [], ^Throwable t o]
|
406 | 422 | (if t
|
407 | 423 | (recur (conj via t) (.getCause t))
|
408 |
| - via)) |
409 |
| - x {:cause (.getLocalizedMessage ^Throwable (last via)) |
| 424 | + via))] |
| 425 | + {:cause (.getLocalizedMessage ^Throwable (last via)) |
410 | 426 | :via (vec (map base via))
|
411 |
| - :trace (vec (.getStackTrace (or ^Throwable (last via) o)))}] |
412 |
| - (print-method x w))) |
| 427 | + :trace (vec (.getStackTrace (or ^Throwable (last via) o)))})) |
| 428 | + |
| 429 | +(defn- print-throwable [^Throwable o ^Writer w] |
| 430 | + (.write w "#error") |
| 431 | + (print-method (throwable-as-map o) w)) |
413 | 432 |
|
414 | 433 | (defmethod print-method Throwable [^Throwable o ^Writer w]
|
415 | 434 | (print-throwable o w))
|
|
0 commit comments