Skip to content

Commit ebaa43f

Browse files
committed
Use Inravina pretty printer
1 parent a91f0ce commit ebaa43f

File tree

7 files changed

+134
-1229
lines changed

7 files changed

+134
-1229
lines changed

repos.sexp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@
135135
:directory "src/lisp/kernel/contrib/global-vars/"
136136
:commit "c749f32c9b606a1457daa47d59630708ac0c266e"
137137
:extension :cando)
138+
(:name :incless
139+
:repository "https://github.com/s-expressionists/Incless.git"
140+
:directory "src/lisp/kernel/contrib/Incless/"
141+
:commit "main")
142+
(:name :inravina
143+
:repository "https://github.com/yitzchak/Inravina.git"
144+
:directory "src/lisp/kernel/contrib/Inravina/"
145+
:commit "main")
146+
(:name :trivial-package-locks
147+
:repository "https://github.com/yitzchak/trivial-package-locks.git"
148+
:directory "src/lisp/kernel/contrib/trivial-package-locks/"
149+
:commit "main")
150+
(:name :trivial-stream-column
151+
:repository "https://github.com/yitzchak/trivial-stream-column.git"
152+
:directory "src/lisp/kernel/contrib/trivial-stream-column/"
153+
:commit "main")
138154
(:name :let-plus
139155
:repository "https://github.com/sharplispers/let-plus.git"
140156
:directory "src/lisp/kernel/contrib/let-plus/"

src/lisp/cscript.lisp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
#~"kernel/lsp/source-location.lisp"
124124
#~"kernel/lsp/defvirtual.lisp"
125125
#~"kernel/clos/streams.lisp"
126+
#~"kernel/lsp/circle.lisp"
127+
:incless-native
128+
:inravina-intrinsic
126129
#~"kernel/lsp/pprint.lisp"
127130
#~"kernel/lsp/format-pprint.lisp"
128131
#~"kernel/clos/conditions.lisp"

src/lisp/kernel/clos/print.lisp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ printer and we should rather use MAKE-LOAD-FORM."
241241
(write (eql-specializer-object es) :stream stream))
242242
es)
243243

244-
(defmethod print-object ((obj structure-object) stream)
244+
(defun print-structure-object (obj stream)
245245
(let* ((class (si:instance-class obj))
246246
(slotds (class-slots class)))
247247
(when (and ;; to fix ansi-tests PRINT-LEVEL.8 & PRINT-LEVEL.9
@@ -252,7 +252,7 @@ printer and we should rather use MAKE-LOAD-FORM."
252252
*print-level*
253253
(zerop *print-level*))
254254
(write-string "#" stream)
255-
(return-from print-object obj))
255+
(return-from print-structure-object obj))
256256
(write-string "#S(" stream)
257257
(prin1 (class-name class) stream)
258258
(do ((scan slotds (cdr scan))
@@ -278,6 +278,9 @@ printer and we should rather use MAKE-LOAD-FORM."
278278
(write-string ")" stream)
279279
obj))
280280

281+
(defmethod print-object ((obj structure-object) stream)
282+
(print-structure-object obj stream))
283+
281284
(defmethod print-object ((object standard-object) stream)
282285
(print-unreadable-object (object stream :type t :identity t))
283286
object)

src/lisp/kernel/lsp/circle.lisp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
(in-package "SI")
2+
3+
(defun search-print-circle (object)
4+
(multiple-value-bind
5+
(code present-p)
6+
(gethash object *circle-stack*)
7+
(if (not (fixnump *circle-counter*))
8+
(cond ((not present-p)
9+
;; Was not found before
10+
(setf (gethash object *circle-stack*) nil)
11+
0)
12+
((null code)
13+
;; Second reference
14+
(setf (gethash object *circle-stack*) t)
15+
1)
16+
(t
17+
;; Further references
18+
2))
19+
(cond ((or (not present-p) (null code))
20+
;; Is not referenced or was not found before
21+
0)
22+
((eql code t)
23+
;; Reference twice but had no code yet
24+
(incf *circle-counter*)
25+
(setf (gethash object *circle-stack*)
26+
*circle-counter*)
27+
(- *circle-counter*))
28+
(t code)))))
29+
30+
(defun write-object-with-circle (object stream function)
31+
(if (and *print-circle*
32+
(not (null object))
33+
(not (fixnump object))
34+
(not (characterp object))
35+
(or (not (symbolp object)) (null (symbol-package object))))
36+
;;; *print-circle* and an object that might have a circle
37+
(if (null *circle-counter*)
38+
(let* ((hash (make-hash-table :test 'eq
39+
:size 1024))
40+
(*circle-counter* t)
41+
(*circle-stack* hash))
42+
(write-object-with-circle object (make-broadcast-stream) function)
43+
(setf *circle-counter* 0)
44+
(write-object-with-circle object stream function)
45+
(clrhash hash)
46+
object)
47+
(let ((code (search-print-circle object)))
48+
(cond ((not (fixnump *circle-counter*))
49+
;; We are only inspecting the object to be printed.
50+
;; Only print X if it was not referenced before
51+
(if (not (zerop code))
52+
object
53+
(funcall function object stream)))
54+
((zerop code)
55+
;; Object is not referenced twice
56+
(funcall function object stream))
57+
((minusp code)
58+
;; Object is referenced twice. We print its definition
59+
(write-char #\# stream)
60+
(let ((*print-radix* nil)
61+
(*print-base* 10))
62+
(write-ugly-object (- code) stream))
63+
(write-char #\= stream)
64+
(funcall function object stream))
65+
(t
66+
;; Second reference to the object
67+
(write-char #\# stream)
68+
(let ((*print-radix* nil)
69+
(*print-base* 10))
70+
(write-ugly-object code stream))
71+
(write-char #\# stream)
72+
object))))
73+
;;; live is good, print simple
74+
(funcall function object stream)))

src/lisp/kernel/lsp/format-pprint.lisp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
(write-string spaces stream :end n)))
7070

7171
(defun format-relative-tab (stream colrel colinc)
72-
(if (#-(or ecl clasp) pp:pretty-stream-p #+(or ecl clasp) sys::pretty-stream-p stream)
72+
(if (inravina:pretty-stream-p stream)
7373
(pprint-tab :line-relative colrel colinc stream)
7474
(let* ((cur (#-(or ecl clasp) sys::charpos #+(or ecl clasp) sys::file-column stream))
7575
(spaces (if (and cur (plusp colinc))
@@ -78,7 +78,7 @@
7878
(output-spaces stream spaces))))
7979

8080
(defun format-absolute-tab (stream colnum colinc)
81-
(if (#-(or ecl clasp) pp:pretty-stream-p #+(or ecl clasp) sys::pretty-stream-p stream)
81+
(if (inravina:pretty-stream-p stream)
8282
(pprint-tab :line colnum colinc stream)
8383
(let ((cur (#-(or ecl clasp) sys::charpos #+(or ecl clasp) sys:file-column stream)))
8484
(cond ((null cur)
@@ -419,7 +419,8 @@
419419
(results (make-format-directive
420420
:string string :character #\_
421421
:start (+ offset non-blank) :end (+ offset non-blank)
422-
:colonp t :atsignp nil :params nil))
422+
:colonp t :atsignp nil :params nil
423+
:virtual t))
423424
(setf posn non-blank))
424425
(when (= posn end)
425426
(return))))
@@ -467,19 +468,16 @@
467468
(error 'format-error
468469
:complaint "No corresponding open bracket."))
469470

470-
;;;; Standard pretty-printing routines.
471-
472-
(defun pprint-array (stream array)
473-
(cond ((or (and (null *print-array*) (null *print-readably*))
474-
(stringp array)
475-
(bit-vector-p array))
476-
(write-ugly-object array stream))
477-
(*print-readably*
478-
(pprint-raw-array stream array))
479-
((vectorp array)
480-
(pprint-vector stream array))
481-
(t
482-
(pprint-multi-dim-array stream array))))
471+
(defclass printer-client (incless-native:native-client inravina-intrinsic:intrinsic-client)
472+
())
473+
474+
(setf inravina-intrinsic:*client* (make-instance 'printer-client)
475+
(first (cdr si::+io-syntax-progv-list+)) inravina-intrinsic:*standard-pprint-dispatch*)
476+
477+
(defmethod print-object ((obj structure-object) stream)
478+
(if *print-pretty*
479+
(inravina:pprint-structure-object inravina-intrinsic:*client* stream obj)
480+
(clos::print-structure-object obj stream)))
483481

484482
(defun pprint-vector (stream vector)
485483
(write-object-with-circle

src/lisp/kernel/lsp/format.lisp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@
205205
(character #\Space :type base-char)
206206
(colonp nil :type (member t nil))
207207
(atsignp nil :type (member t nil))
208-
(params nil :type list))
208+
(params nil :type list)
209+
(virtual nil :type (member t nil)))
209210

210211
(deftype format-directive () 'vector)
211212

@@ -1590,9 +1591,15 @@
15901591
(if (and (not colonp)
15911592
directives
15921593
(simple-string-p (car directives)))
1593-
(cons (string-left-trim '(#\space #\newline #\tab)
1594-
(car directives))
1595-
(cdr directives))
1594+
(let ((trimmed-string (string-left-trim '(#\space #\newline #\tab)
1595+
(car directives))))
1596+
(cond ((not (zerop (length trimmed-string)))
1597+
(cons trimmed-string (cdr directives)))
1598+
((and (typep (cadr directives) 'format-directive)
1599+
(format-directive-virtual (cadr directives)))
1600+
(cddr directives))
1601+
(t
1602+
(cdr directives))))
15961603
directives)))
15971604

15981605
(def-complex-format-interpreter #\newline (colonp atsignp params directives)
@@ -1606,10 +1613,16 @@
16061613
(if (and (not colonp)
16071614
directives
16081615
(simple-string-p (car directives)))
1609-
(cons (string-left-trim '(#\space #\newline #\tab)
1610-
(car directives))
1611-
(cdr directives))
1612-
directives))
1616+
(let ((trimmed-string (string-left-trim '(#\space #\newline #\tab)
1617+
(car directives))))
1618+
(cond ((not (zerop (length trimmed-string)))
1619+
(cons trimmed-string (cdr directives)))
1620+
((and (typep (cadr directives) 'format-directive)
1621+
(format-directive-virtual (cadr directives)))
1622+
(cddr directives))
1623+
(t
1624+
(cdr directives))))
1625+
directives))
16131626

16141627
(def-complex-format-directive #\return (colonp atsignp params directives)
16151628
(when (and colonp atsignp)

0 commit comments

Comments
 (0)