Skip to content

Commit

Permalink
Save specifiers for nicer printing (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bike committed Jun 26, 2024
1 parent 0dd98d8 commit 8af5ce4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion classes.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(in-package #:ctype)

(defclass ctype () ())
(defclass ctype ()
((%specifier :accessor %specifier :initform nil)))
(defmethod make-load-form ((obj ctype) &optional env)
(make-load-form-saving-slots obj :environment env))

Expand Down
11 changes: 8 additions & 3 deletions generic-functions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,18 @@

(defgeneric unparse (ctype))

(defun specifier (ctype)
;; If we've saved the original specifier use that.
;; Otherwise try to compute a reasonable unparse.
(or (%specifier ctype) (unparse ctype)))

(defmethod print-object ((ct ctype) stream)
(multiple-value-bind (unparse failure)
(ignore-errors (unparse ct))
(multiple-value-bind (specifier failure)
(ignore-errors (specifier ct))
(if failure
(call-next-method)
(print-unreadable-object (ct stream :type t)
(write unparse :stream stream))))
(write specifier :stream stream))))
ct)

(macrolet
Expand Down
2 changes: 2 additions & 0 deletions parse.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,12 @@
(let ((ct (parse client specifier env)))
(when (typep ct 'cvalues)
(error "Found ~s in non-~s context" (unparse ct) 'values))
(setf (%specifier ct) specifier)
ct))

(defun values-specifier-ctype (client specifier &optional env)
(let ((ct (parse client specifier env)))
(setf (%specifier ct) specifier)
(if (typep ct 'cvalues)
ct
;; Treat X as (values X).
Expand Down

0 comments on commit 8af5ce4

Please sign in to comment.