Skip to content

Commit ddcf248

Browse files
committed
Use Inravina pretty printer
1 parent e13c09f commit ddcf248

File tree

9 files changed

+134
-1673
lines changed

9 files changed

+134
-1673
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/s-expressionists/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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
#~"kernel/lsp/source-location.lisp"
124124
#~"kernel/lsp/defvirtual.lisp"
125125
#~"kernel/clos/streams.lisp"
126+
#~"kernel/lsp/circle.lisp"
127+
:inravina-shim
126128
#~"kernel/lsp/pprint.lisp"
127129
#~"kernel/lsp/format-pprint.lisp"
128130
#~"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))
@@ -279,6 +279,9 @@ printer and we should rather use MAKE-LOAD-FORM."
279279
(write-string ")" stream)
280280
obj))
281281

282+
(defmethod print-object ((obj structure-object) stream)
283+
(print-structure-object obj stream))
284+
282285
(defmethod print-object ((object standard-object) stream)
283286
(print-unreadable-object (object stream :type t :identity t))
284287
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)))

0 commit comments

Comments
 (0)