0.8.1.33:
[sbcl.git] / src / code / pprint.lisp
index d5ab150..d17ccfc 100644 (file)
 
 (defconstant default-line-length 80)
 
-(defstruct (pretty-stream (:include sb!kernel:lisp-stream
-                                   (:out #'pretty-out)
-                                   (:sout #'pretty-sout)
-                                   (:misc #'pretty-misc))
+(defstruct (pretty-stream (:include sb!kernel:ansi-stream
+                                   (out #'pretty-out)
+                                   (sout #'pretty-sout)
+                                   (misc #'pretty-misc))
                          (:constructor make-pretty-stream (target))
                          (:copier nil))
   ;; Where the output is going to finally go.
   ;; (In the PPRINT-LOGICAL-BLOCK form which calls us,
   ;; :PREFIX and :PER-LINE-PREFIX have hairy defaulting behavior,
   ;; and might end up being NIL.)
-  (declare (type (or null string prefix)))
+  (declare (type (or null string) prefix))
   ;; (But the defaulting behavior of PPRINT-LOGICAL-BLOCK :SUFFIX is
   ;; trivial, so it should always be a string.)
   (declare (type string suffix))
   (when prefix
+    (setq prefix (coerce prefix 'simple-string))
     (pretty-sout stream prefix 0 (length prefix)))
   (let* ((pending-blocks (pretty-stream-pending-blocks stream))
         (start (enqueue stream block-start
                         :prefix (and per-line-p prefix)
-                        :suffix suffix
+                        :suffix (coerce suffix 'simple-string)
                         :depth (length pending-blocks))))
     (setf (pretty-stream-pending-blocks stream)
          (cons start pending-blocks))))
   ;; T iff one of the original entries.
   (initial-p *building-initial-table* :type (member t nil))
   ;; and the associated function
-  (function (missing-arg) :type function))
+  (fun (missing-arg) :type function))
 (def!method print-object ((entry pprint-dispatch-entry) stream)
   (print-unreadable-object (entry stream :type t)
     (format stream "type=~S, priority=~S~@[ [initial]~]"
             (pprint-dispatch-entry-priority e2)))))
 
 (macrolet ((frob (x)
-            `(cons ',x #'(lambda (object) ,x))))
+            `(cons ',x (lambda (object) ,x))))
   (defvar *precompiled-pprint-dispatch-funs*
     (list (frob (typep object 'array))
          (frob (and (consp object)
-                    (and (typep (car object) 'symbol)
-                         (typep (car object) '(satisfies fboundp)))))
+                    (symbolp (car object))
+                    (fboundp (car object))))
          (frob (typep object 'cons)))))
 
 (defun compute-test-fn (type)
                      (destructuring-bind (type) (cdr type)
                        `(not ,(compute-test-expr type object))))
                     (and
-                     `(and ,@(mapcar #'(lambda (type)
-                                         (compute-test-expr type object))
+                     `(and ,@(mapcar (lambda (type)
+                                       (compute-test-expr type object))
                                      (cdr type))))
                     (or
-                     `(or ,@(mapcar #'(lambda (type)
-                                        (compute-test-expr type object))
+                     `(or ,@(mapcar (lambda (type)
+                                      (compute-test-expr type object))
                                     (cdr type))))
                     (t
                      `(typep ,object ',type)))
         (new (make-pprint-dispatch-table
               :entries (copy-list (pprint-dispatch-table-entries orig))))
         (new-cons-entries (pprint-dispatch-table-cons-entries new)))
-    (maphash #'(lambda (key value)
-                (setf (gethash key new-cons-entries) value))
+    (maphash (lambda (key value)
+              (setf (gethash key new-cons-entries) value))
             (pprint-dispatch-table-cons-entries orig))
     new))
 
            (when (funcall (pprint-dispatch-entry-test-fn entry) object)
              (return entry)))))
     (if entry
-       (values (pprint-dispatch-entry-function entry) t)
-       (values #'(lambda (stream object)
-                   (output-ugly-object object stream))
+       (values (pprint-dispatch-entry-fun entry) t)
+       (values (lambda (stream object)
+                 (output-ugly-object object stream))
                nil))))
 
 (defun set-pprint-dispatch (type function &optional
   (declare (type (or null function) function)
           (type real priority)
           (type pprint-dispatch-table table))
+  (/show0 "entering SET-PPRINT-DISPATCH, TYPE=...")
+  (/hexstr type)
   (if function
       (if (cons-type-specifier-p type)
          (setf (gethash (second (second type))
                         (pprint-dispatch-table-cons-entries table))
-               (make-pprint-dispatch-entry :type type :priority priority
-                                           :function function))
+               (make-pprint-dispatch-entry :type type
+                                           :priority priority
+                                           :fun function))
          (let ((list (delete type (pprint-dispatch-table-entries table)
                              :key #'pprint-dispatch-entry-type
                              :test #'equal))
                (entry (make-pprint-dispatch-entry
-                       :type type :test-fn (compute-test-fn type)
-                       :priority priority :function function)))
+                       :type type
+                       :test-fn (compute-test-fn type)
+                       :priority priority
+                       :fun function)))
            (do ((prev nil next)
                 (next list (cdr next)))
                ((null next)
                (delete type (pprint-dispatch-table-entries table)
                        :key #'pprint-dispatch-entry-type
                        :test #'equal))))
+  (/show0 "about to return NIL from SET-PPRINT-DISPATCH")
   nil)
 \f
 ;;;; standard pretty-printing routines
             (stringp array)
             (bit-vector-p array))
         (output-ugly-object array stream))
-       ((and *print-readably* (not (eq (array-element-type array) t)))
+       ((and *print-readably*
+             (not (array-readably-printable-p array)))
         (let ((*print-readably* nil))
           (error 'print-not-readable :object array)))
        ((vectorp array)
                                (index index)
                                (step (reduce #'* dims))
                                (count 0))
-                          (loop                                
+                          (loop
                             (pprint-pop)
                             (output-guts stream index dims)
                             (when (= (incf count) dim)
     (pprint-fill stream (pprint-pop))
     (pprint-tagbody-guts stream)))
 
-(defun pprint-function-call (stream list &rest noise)
+(defun pprint-fun-call (stream list &rest noise)
   (declare (ignore noise))
   (funcall (formatter "~:<~^~W~^ ~:_~:I~@{~W~^ ~_~}~:>")
           stream
 \f
 ;;;; the interface seen by regular (ugly) printer and initialization routines
 
-;;; OUTPUT-PRETTY-OBJECT is called by OUTPUT-OBJECT when *PRINT-PRETTY* is
-;;; bound to T.
+;;; OUTPUT-PRETTY-OBJECT is called by OUTPUT-OBJECT when
+;;; *PRINT-PRETTY* is true.
 (defun output-pretty-object (object stream)
   (with-pretty-stream (stream)
     (funcall (pprint-dispatch object) stream object)))
     ;; printers for regular types
     (/show0 "doing SET-PPRINT-DISPATCH for regular types")
     (set-pprint-dispatch 'array #'pprint-array)
-    (set-pprint-dispatch '(cons (and symbol (satisfies fboundp)))
-                        #'pprint-function-call -1)
+    (set-pprint-dispatch '(cons symbol)
+                        #'pprint-fun-call -1)
     (set-pprint-dispatch 'cons #'pprint-fill -2)
     ;; cons cells with interesting things for the car
     (/show0 "doing SET-PPRINT-DISPATCH for CONS with interesting CAR")
     (/show0 "leaving !PPRINT-COLD-INIT"))
 
   (setf *print-pprint-dispatch* (copy-pprint-dispatch nil))
-  (setf *pretty-printer* #'output-pretty-object)
   (setf *print-pretty* t))