Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Inravina pretty printer #1406

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
with:
images: ghcr.io/clasp-developers/clasp
tags: |
type=raw,value=latest

- name: Build and push Docker image
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
with:
context: docker/clasp/
push: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3.0.4
- uses: conda-incubator/setup-miniconda@v3.1.0
if: matrix.build == 'cando'

- name: Install AmberTools
Expand Down
16 changes: 16 additions & 0 deletions repos.sexp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
:repository "https://github.com/trivial-gray-streams/trivial-gray-streams.git"
:directory "src/lisp/kernel/contrib/trivial-gray-streams/"
:branch "master")
(:name :nontrivial-gray-streams
:repository "https://github.com/yitzchak/nontrivial-gray-streams.git"
:directory "src/lisp/kernel/contrib/nontrivial-gray-streams/"
:branch "main")
(:name :acclimation
:repository "https://github.com/robert-strandh/Acclimation.git"
:directory "src/lisp/kernel/contrib/Acclimation/"
Expand Down Expand Up @@ -135,6 +139,18 @@
: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/s-expressionists/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 :let-plus
:repository "https://github.com/sharplispers/let-plus.git"
:directory "src/lisp/kernel/contrib/let-plus/"
Expand Down
2 changes: 2 additions & 0 deletions src/lisp/cscript.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
#~"kernel/lsp/source-location.lisp"
#~"kernel/lsp/defvirtual.lisp"
#~"kernel/clos/streams.lisp"
#~"kernel/lsp/circle.lisp"
:inravina-shim
#~"kernel/lsp/pprint.lisp"
#~"kernel/lsp/format-pprint.lisp"
#~"kernel/clos/conditions.lisp"
Expand Down
19 changes: 0 additions & 19 deletions src/lisp/kernel/cleavir/inline.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,6 @@
)
(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")

#+(or)
(progn (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 @@ -279,6 +279,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
3 changes: 3 additions & 0 deletions src/lisp/kernel/clos/streams.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,7 @@ truename."))

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

#-staging (eval-when (:compile-toplevel :load-toplevel :execute)
(require '#:gray-streams))

#+(or cclasp eclasp) (eval-when (:load-toplevel) (setf clos:*clos-booted* t))
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
Loading