Skip to content

Commit 2d4e286

Browse files
committed
- experiments w/ lowering the machinery around printing
1 parent 0bf4c3f commit 2d4e286

File tree

1 file changed

+57
-15
lines changed

1 file changed

+57
-15
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,6 @@
181181
:jsdoc ["@type {*}"]}
182182
*loaded-libs* nil)
183183

184-
(defn- pr-opts []
185-
{:flush-on-newline *flush-on-newline*
186-
:readably *print-readably*
187-
:meta *print-meta*
188-
:dup *print-dup*
189-
:print-length *print-length*})
190-
191184
(declare into-array)
192185

193186
(defn enable-console-print!
@@ -896,6 +889,46 @@
896889

897890
;; Printing support
898891

892+
(defn- pr-opts*
893+
[flush-on-newline readably meta dup print-length]
894+
(reify
895+
ILookup
896+
(-lookup [this k]
897+
(-lookup this k nil))
898+
(-lookup [this k not-found]
899+
(case k
900+
:flush-on-newline flush-on-newline
901+
:readably readably
902+
:meta meta
903+
:dup dup
904+
:print-length print-length
905+
not-found))
906+
IAssociative
907+
(-contains-key? [coll k]
908+
(case k
909+
:flush-on-newline true
910+
:readably true
911+
:meta true
912+
:dup true
913+
:print-length true
914+
false))
915+
(-assoc [this k v]
916+
(case k
917+
:flush-on-newline (pr-opts* v readably meta dup print-length)
918+
:readably (pr-opts* flush-on-newline v meta dup print-length)
919+
:meta (pr-opts* flush-on-newline readably v dup print-length)
920+
:dup (pr-opts* flush-on-newline readably meta v print-length)
921+
:print-length (pr-opts* flush-on-newline readably meta dup v)
922+
this))))
923+
924+
(defn pr-opts []
925+
(pr-opts*
926+
*flush-on-newline*
927+
*print-readably*
928+
*print-meta*
929+
*print-dup*
930+
*print-length*))
931+
899932
(deftype StringBufferWriter [sb]
900933
IWriter
901934
(-write [_ s] (.append sb s))
@@ -10442,18 +10475,18 @@ reduces them without incurring seq initialization"
1044210475
(do
1044310476
(-write writer begin)
1044410477
(if (zero? (:print-length opts))
10445-
(when (seq coll)
10478+
(when (-seq coll)
1044610479
(-write writer (or (:more-marker opts) "...")))
10447-
(do
10448-
(when (seq coll)
10449-
(print-one (first coll) writer opts))
10450-
(loop [coll (next coll) n (dec (:print-length opts))]
10480+
(let [coll (-seq coll)]
10481+
(when coll
10482+
(print-one (-first coll) writer opts))
10483+
(loop [coll (-next coll) n (dec (:print-length opts))]
1045110484
(if (and coll (or (nil? n) (not (zero? n))))
1045210485
(do
1045310486
(-write writer sep)
10454-
(print-one (first coll) writer opts)
10455-
(recur (next coll) (dec n)))
10456-
(when (and (seq coll) (zero? n))
10487+
(print-one (-first coll) writer opts)
10488+
(recur (-next coll) (dec n)))
10489+
(when (and (-seq coll) (zero? n))
1045710490
(-write writer sep)
1045810491
(-write writer (or (:more-marker opts) "...")))))))
1045910492
(-write writer end)))))
@@ -11795,6 +11828,15 @@ reduces them without incurring seq initialization"
1179511828

1179611829
(set! (.. ExceptionInfo -prototype -__proto__) js/Error.prototype)
1179711830

11831+
(extend-protocol ISeqable
11832+
nil
11833+
(-seq [this] nil)
11834+
11835+
array
11836+
(-seq [this]
11837+
(when-not (zero? (alength this))
11838+
(IndexedSeq. this 0 nil))))
11839+
1179811840
(extend-type ExceptionInfo
1179911841
IPrintWithWriter
1180011842
(-pr-writer [obj writer opts]

0 commit comments

Comments
 (0)