Skip to content

Commit

Permalink
Use Inravina pretty printer
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Mar 1, 2023
1 parent 95e8ced commit b5ddf1a
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 1,665 deletions.
22 changes: 19 additions & 3 deletions repos.sexp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
((:name :ansi-test
:repository "https://gitlab.common-lisp.net/yitzchak/ansi-test"
:directory "dependencies/ansi-test/"
:branch "add-expected-failures")
:branch "inravina")
(:name :cl-bench
:repository "https://gitlab.common-lisp.net/ansi-test/cl-bench.git"
:directory "dependencies/cl-bench/"
Expand All @@ -30,7 +30,7 @@
:branch "master")
(:name :trivial-gray-streams
:repository "https://github.com/trivial-gray-streams/trivial-gray-streams.git"
:directory "dependencies/trivial-gray-streams/"
:directory "src/lisp/kernel/contrib/trivial-gray-streams/"
:branch "master")
(:name :acclimation
:repository "https://github.com/robert-strandh/Acclimation.git"
Expand Down Expand Up @@ -115,6 +115,22 @@
:directory "src/lisp/kernel/contrib/global-vars/"
:commit "c749f32c9b606a1457daa47d59630708ac0c266e"
:extension :cando)
(:name :incless
:repository "https://github.com/s-expressionists/Incless.git"
:directory "src/lisp/kernel/contrib/Incless/"
:commit "main")
(:name :inravina
:repository "https://github.com/yitzchak/Inravina.git"
:directory "src/lisp/kernel/contrib/Inravina/"
:commit "main")
(:name :trivial-package-locks
:repository "https://github.com/yitzchak/trivial-package-locks.git"
:directory "src/lisp/kernel/contrib/trivial-package-locks/"
:commit "main")
(:name :trivial-stream-column
:repository "https://github.com/yitzchak/trivial-stream-column.git"
:directory "src/lisp/kernel/contrib/trivial-stream-column/"
:commit "main")
(:name :let-plus
:repository "https://github.com/sharplispers/let-plus.git"
:directory "src/lisp/kernel/contrib/let-plus/"
Expand Down Expand Up @@ -205,4 +221,4 @@
:repository "https://github.com/seqan/seqan.git"
:directory "extensions/seqan-clasp/seqan/"
:branch "master"
:extension :seqan-clasp))
:extension :seqan-clasp))
3 changes: 3 additions & 0 deletions src/lisp/cscript.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
#~"kernel/lsp/source-location.lisp"
#~"kernel/lsp/defvirtual.lisp"
#~"kernel/clos/streams.lisp"
#~"kernel/lsp/circle.lisp"
:incless-native
:inravina-intrinsic
#~"kernel/lsp/pprint.lisp"
#~"kernel/lsp/format-pprint.lisp"
#~"kernel/clos/conditions.lisp"
Expand Down
18 changes: 0 additions & 18 deletions src/lisp/kernel/cleavir/inline.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -405,24 +405,6 @@
(symbol (fdefinition fdesignator))))
(declaim (ftype (function (t) function) core:coerce-to-function))

;;; ------------------------------------------------------------
;;;
;;; Copied from clasp/src/lisp/kernel/lsp/pprint.lisp
;;; and put here so that the inline definition is available
;;;
(in-package "SI")

(declaim (inline index-posn posn-index posn-column))
(defun index-posn (index stream)
(declare (type index index) (type pretty-stream stream))
(+ index (pretty-stream-buffer-offset stream)))
(defun posn-index (posn stream)
(declare (type posn posn) (type pretty-stream stream))
(- posn (pretty-stream-buffer-offset stream)))
(defun posn-column (posn stream)
(declare (type posn posn) (type pretty-stream stream))
(index-column (posn-index posn stream) stream))

#+(or)
(eval-when (:execute)
(format t "Setting core:*echo-repl-read* to NIL~%")
Expand Down
7 changes: 5 additions & 2 deletions src/lisp/kernel/clos/print.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ printer and we should rather use MAKE-LOAD-FORM."
(write (eql-specializer-object es) :stream stream))
es)

(defmethod print-object ((obj structure-object) stream)
(defun print-structure-object (obj stream)
(let* ((class (si:instance-class obj))
(slotds (class-slots class)))
(when (and ;; to fix ansi-tests PRINT-LEVEL.8 & PRINT-LEVEL.9
Expand All @@ -252,7 +252,7 @@ printer and we should rather use MAKE-LOAD-FORM."
*print-level*
(zerop *print-level*))
(write-string "#" stream)
(return-from print-object obj))
(return-from print-structure-object obj))
(write-string "#S(" stream)
(prin1 (class-name class) stream)
(do ((scan slotds (cdr scan))
Expand All @@ -278,6 +278,9 @@ printer and we should rather use MAKE-LOAD-FORM."
(write-string ")" stream)
obj))

(defmethod print-object ((obj structure-object) stream)
(print-structure-object obj stream))

(defmethod print-object ((object standard-object) stream)
(print-unreadable-object (object stream :type t :identity t))
object)
Expand Down
74 changes: 74 additions & 0 deletions src/lisp/kernel/lsp/circle.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(in-package "SI")

(defun search-print-circle (object)
(multiple-value-bind
(code present-p)
(gethash object *circle-stack*)
(if (not (fixnump *circle-counter*))
(cond ((not present-p)
;; Was not found before
(setf (gethash object *circle-stack*) nil)
0)
((null code)
;; Second reference
(setf (gethash object *circle-stack*) t)
1)
(t
;; Further references
2))
(cond ((or (not present-p) (null code))
;; Is not referenced or was not found before
0)
((eql code t)
;; Reference twice but had no code yet
(incf *circle-counter*)
(setf (gethash object *circle-stack*)
*circle-counter*)
(- *circle-counter*))
(t code)))))

(defun write-object-with-circle (object stream function)
(if (and *print-circle*
(not (null object))
(not (fixnump object))
(not (characterp object))
(or (not (symbolp object)) (null (symbol-package object))))
;;; *print-circle* and an object that might have a circle
(if (null *circle-counter*)
(let* ((hash (make-hash-table :test 'eq
:size 1024))
(*circle-counter* t)
(*circle-stack* hash))
(write-object-with-circle object (make-broadcast-stream) function)
(setf *circle-counter* 0)
(write-object-with-circle object stream function)
(clrhash hash)
object)
(let ((code (search-print-circle object)))
(cond ((not (fixnump *circle-counter*))
;; We are only inspecting the object to be printed.
;; Only print X if it was not referenced before
(if (not (zerop code))
object
(funcall function object stream)))
((zerop code)
;; Object is not referenced twice
(funcall function object stream))
((minusp code)
;; Object is referenced twice. We print its definition
(write-char #\# stream)
(let ((*print-radix* nil)
(*print-base* 10))
(write-ugly-object (- code) stream))
(write-char #\= stream)
(funcall function object stream))
(t
;; Second reference to the object
(write-char #\# stream)
(let ((*print-radix* nil)
(*print-base* 10))
(write-ugly-object code stream))
(write-char #\# stream)
object))))
;;; live is good, print simple
(funcall function object stream)))
Loading

0 comments on commit b5ddf1a

Please sign in to comment.