Skip to content

Commit 4c6bdc6

Browse files
committed
Use Inravina pretty printer
1 parent 102f064 commit 4c6bdc6

File tree

12 files changed

+139
-1698
lines changed

12 files changed

+139
-1698
lines changed

repos.sexp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
:repository "https://github.com/trivial-gray-streams/trivial-gray-streams.git"
3333
:directory "src/lisp/kernel/contrib/trivial-gray-streams/"
3434
:branch "master")
35+
(:name :nontrivial-gray-streams
36+
:repository "https://github.com/yitzchak/nontrivial-gray-streams.git"
37+
:directory "src/lisp/kernel/contrib/nontrivial-gray-streams/"
38+
:branch "main")
3539
(:name :acclimation
3640
:repository "https://github.com/robert-strandh/Acclimation.git"
3741
:directory "src/lisp/kernel/contrib/Acclimation/"
@@ -135,6 +139,18 @@
135139
:directory "src/lisp/kernel/contrib/global-vars/"
136140
:commit "c749f32c9b606a1457daa47d59630708ac0c266e"
137141
:extension :cando)
142+
(:name :incless
143+
:repository "https://github.com/s-expressionists/Incless.git"
144+
:directory "src/lisp/kernel/contrib/Incless/"
145+
:commit "main")
146+
(:name :inravina
147+
:repository "https://github.com/s-expressionists/Inravina.git"
148+
:directory "src/lisp/kernel/contrib/Inravina/"
149+
:commit "main")
150+
(:name :trivial-package-locks
151+
:repository "https://github.com/yitzchak/trivial-package-locks.git"
152+
:directory "src/lisp/kernel/contrib/trivial-package-locks/"
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
@@ -120,6 +120,8 @@
120120
#~"kernel/lsp/source-location.lisp"
121121
#~"kernel/lsp/defvirtual.lisp"
122122
#~"kernel/clos/streams.lisp"
123+
#~"kernel/lsp/circle.lisp"
124+
:inravina-shim
123125
#~"kernel/lsp/pprint.lisp"
124126
#~"kernel/lsp/format-pprint.lisp"
125127
#~"kernel/clos/conditions.lisp"

src/lisp/kernel/cleavir/inline.lisp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -327,25 +327,6 @@
327327
)
328328
(declaim (ftype (function (t) function) core:coerce-to-function)))
329329

330-
;;; ------------------------------------------------------------
331-
;;;
332-
;;; Copied from clasp/src/lisp/kernel/lsp/pprint.lisp
333-
;;; and put here so that the inline definition is available
334-
;;;
335-
(in-package "SI")
336-
337-
#+(or)
338-
(progn (declaim (inline index-posn posn-index posn-column))
339-
(defun index-posn (index stream)
340-
(declare (type index index) (type pretty-stream stream))
341-
(+ index (pretty-stream-buffer-offset stream)))
342-
(defun posn-index (posn stream)
343-
(declare (type posn posn) (type pretty-stream stream))
344-
(- posn (pretty-stream-buffer-offset stream)))
345-
(defun posn-column (posn stream)
346-
(declare (type posn posn) (type pretty-stream stream))
347-
(index-column (posn-index posn stream) stream))
348-
349330
#+(or)
350331
(eval-when (:execute)
351332
(format t "Setting core:*echo-repl-read* to NIL~%")

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/clos/streams.lisp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,4 +934,7 @@ truename."))
934934

935935
(pushnew 'gray-streams-module-provider ext:*module-provider-functions*)
936936

937+
#-staging (eval-when (:compile-toplevel :load-toplevel :execute)
938+
(require '#:gray-streams))
939+
937940
#+(or cclasp eclasp) (eval-when (:load-toplevel) (setf clos:*clos-booted* t))

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)