0.8.15.18: Linkage table tweaks & alien bugfix
[sbcl.git] / src / code / pprint.lisp
index b87e9ee..5032ecb 100644 (file)
@@ -44,7 +44,7 @@
               :type column)
   ;; A simple string holding all the text that has been output but not yet
   ;; printed.
-  (buffer (make-string initial-buffer-size) :type simple-string)
+  (buffer (make-string initial-buffer-size) :type (simple-array character (*)))
   ;; The index into BUFFER where more text should be put.
   (buffer-fill-pointer 0 :type index)
   ;; Whenever we output stuff from the buffer, we shift the remaining noise
   ;; Buffer holding the per-line prefix active at the buffer start.
   ;; Indentation is included in this. The length of this is stored
   ;; in the logical block stack.
-  (prefix (make-string initial-buffer-size) :type simple-string)
+  (prefix (make-string initial-buffer-size) :type (simple-array character (*)))
   ;; Buffer holding the total remaining suffix active at the buffer start.
   ;; The characters are right-justified in the buffer to make it easier
   ;; to output the buffer. The length is stored in the logical block
   ;; stack.
-  (suffix (make-string initial-buffer-size) :type simple-string)
+  (suffix (make-string initial-buffer-size) :type (simple-array character (*)))
   ;; Queue of pending operations. When empty, HEAD=TAIL=NIL. Otherwise,
   ;; TAIL holds the first (oldest) cons and HEAD holds the last (newest)
   ;; cons. Adding things to the queue is basically (setf (cdr head) (list
           (type simple-string string)
           (type index start)
           (type (or index null) end))
-  (let ((end (or end (length string))))
+  (let* ((string (if (typep string '(simple-array character (*)))
+                    string
+                    (coerce string '(simple-array character (*)))))
+        (end (or end (length string))))
     (unless (= start end)
       (let ((newline (position #\newline string :start start :end end)))
        (cond
 (defstruct (block-start (:include section-start)
                        (:copier nil))
   (block-end nil :type (or null block-end))
-  (prefix nil :type (or null simple-string))
-  (suffix nil :type (or null simple-string)))
+  (prefix nil :type (or null (simple-array character (*))))
+  (suffix nil :type (or null (simple-array character (*)))))
 
 (defun start-logical-block (stream prefix per-line-p suffix)
   ;; (In the PPRINT-LOGICAL-BLOCK form which calls us,
   ;; trivial, so it should always be a string.)
   (declare (type string suffix))
   (when prefix
-    (setq prefix (coerce prefix 'simple-string))
+    (setq prefix (coerce prefix '(simple-array character (*))))
     (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 (coerce suffix 'simple-string)
+                        :suffix (coerce suffix '(simple-array character (*)))
                         :depth (length pending-blocks))))
     (setf (pretty-stream-pending-blocks stream)
          (cons start pending-blocks))))
 
 (defstruct (block-end (:include queued-op)
                      (:copier nil))
-  (suffix nil :type (or null simple-string)))
+  (suffix nil :type (or null (simple-array character (*)))))
 
 (defun end-logical-block (stream)
   (let* ((start (pop (pretty-stream-pending-blocks stream)))
 ;;;; tab support
 
 (defun compute-tab-size (tab section-start column)
-  (let ((origin (if (tab-sectionp tab) section-start 0))
-       (colnum (tab-colnum tab))
-       (colinc (tab-colinc tab)))
+  (let* ((origin (if (tab-sectionp tab) section-start 0))
+         (colnum (tab-colnum tab))
+         (colinc (tab-colinc tab))
+         (position (- column origin)))
     (cond ((tab-relativep tab)
           (unless (<= colinc 1)
-            (let ((newposn (+ column colnum)))
+            (let ((newposn (+ position colnum)))
               (let ((rem (rem newposn colinc)))
                 (unless (zerop rem)
                   (incf colnum (- colinc rem))))))
           colnum)
-         ((<= column (+ colnum origin))
-          (- (+ colnum origin) column))
-         (t
+         ((< position colnum)
+           (- colnum position))
+         ((zerop colinc) 0)
+          (t
           (- colinc
-             (rem (- column origin) colinc))))))
+             (rem (- position colnum) colinc))))))
 
 (defun index-column (index stream)
   (let ((column (pretty-stream-buffer-start-column stream))
   #!+sb-doc
   "Specify the indentation to use in the current logical block if STREAM
    (which defaults to *STANDARD-OUTPUT*) is it is a pretty-printing stream
-   and do nothing if not. (See PPRINT-LOGICAL-BLOCK.)  N is the indention
+   and do nothing if not. (See PPRINT-LOGICAL-BLOCK.)  N is the indentation
    to use (in ems, the width of an ``m'') and RELATIVE-TO can be either:
      :BLOCK - Indent relative to the column the current logical block
        started on.
      :CURRENT - Indent relative to the current column.
-   The new indention value does not take effect until the following line
+   The new indentation value does not take effect until the following line
    break."
   (declare (type (member :block :current) relative-to)
-          (type integer n)
+          (type real n)
           (type (or stream (member t nil)) stream)
           (values null))
   (let ((stream (case stream
                  ((nil) *standard-output*)
                  (t stream))))
     (when (print-pretty-on-stream-p stream)
-      (enqueue-indent stream relative-to n)))
+      (enqueue-indent stream relative-to (truncate n))))
   nil)
 
 (defun pprint-tab (kind colnum colinc &optional stream)
   ;; T iff one of the original entries.
   (initial-p *building-initial-table* :type (member t nil))
   ;; and the associated function
-  (fun (missing-arg) :type function))
+  (fun (missing-arg) :type callable))
 (def!method print-object ((entry pprint-dispatch-entry) stream)
   (print-unreadable-object (entry stream :type t)
     (format stream "type=~S, priority=~S~@[ [initial]~]"
   (/show0 "entering SET-PPRINT-DISPATCH, TYPE=...")
   (/hexstr type)
   (if function
-      ;; KLUDGE: this impairs debuggability, and probably isn't even
-      ;; conforming -- maybe we should not coerce to function, but
-      ;; cater downstream (in PPRINT-DISPATCH-ENTRY) for having
-      ;; callables here.
-      (let ((function (%coerce-callable-to-fun 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
-                                             :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
-                         :fun function)))
-             (do ((prev nil next)
-                  (next list (cdr next)))
-                 ((null next)
-                  (if prev
-                      (setf (cdr prev) (list entry))
-                      (setf list (list entry))))
-               (when (entry< (car next) entry)
-                 (if prev
-                     (setf (cdr prev) (cons entry next))
-                     (setf list (cons entry next)))
-                 (return)))
-             (setf (pprint-dispatch-table-entries table) list))))
+      (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
+                                           :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
+                        :fun function)))
+           (do ((prev nil next)
+                (next list (cdr next)))
+               ((null next)
+                (if prev
+                     (setf (cdr prev) (list entry))
+                     (setf list (list entry))))
+              (when (entry< (car next) entry)
+                (if prev
+                    (setf (cdr prev) (cons entry next))
+                    (setf list (cons entry next)))
+                (return)))
+           (setf (pprint-dispatch-table-entries table) list)))
       (if (cons-type-specifier-p type)
          (remhash (second (second type))
                   (pprint-dispatch-table-cons-entries table))