1.0.25.8: fix sxhash bug
[sbcl.git] / src / code / reader.lisp
1 ;;;; READ and friends
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!IMPL")
13 \f
14 ;;;; miscellaneous global variables
15
16 ;;; ANSI: "the floating-point format that is to be used when reading a
17 ;;; floating-point number that has no exponent marker or that has e or
18 ;;; E for an exponent marker"
19 (defvar *read-default-float-format* 'single-float)
20 (declaim (type (member short-float single-float double-float long-float)
21                *read-default-float-format*))
22
23 (defvar *readtable*)
24 (declaim (type readtable *readtable*))
25 #!+sb-doc
26 (setf (fdocumentation '*readtable* 'variable)
27       "Variable bound to current readtable.")
28
29 ;;; A standard Lisp readtable (once cold-init is through). This is for
30 ;;; recovery from broken read-tables (and for
31 ;;; WITH-STANDARD-IO-SYNTAX), and should not normally be user-visible.
32 (defvar *standard-readtable* nil)
33
34 (defvar *old-package* nil
35   #!+sb-doc
36   "the value of *PACKAGE* at the start of the last read, or NIL")
37
38 ;;; In case we get an error trying to parse a symbol, we want to rebind the
39 ;;; above stuff so it's cool.
40
41 ;;; FIXME: These forward declarations should be moved somewhere earlier,
42 ;;; or discarded.
43 (declaim (special *package* *keyword-package* *read-base*))
44 \f
45 ;;;; reader errors
46
47 (defun reader-eof-error (stream context)
48   (error 'reader-eof-error
49          :stream stream
50          :context context))
51
52 ;;; If The Gods didn't intend for us to use multiple namespaces, why
53 ;;; did They specify them?
54 (defun simple-reader-error (stream control &rest args)
55   (error 'simple-reader-error
56          :stream stream
57          :format-control control
58          :format-arguments args))
59 \f
60 ;;;; macros and functions for character tables
61
62 (defun get-cat-entry (char rt)
63   (declare (readtable rt))
64   (if (typep char 'base-char)
65       (elt (character-attribute-array rt) (char-code char))
66       (values (gethash char (character-attribute-hash-table rt)
67                        +char-attr-constituent+))))
68
69 (defun set-cat-entry (char newvalue &optional (rt *readtable*))
70   (declare (readtable rt))
71   (if (typep char 'base-char)
72       (setf (elt (character-attribute-array rt) (char-code char)) newvalue)
73       (if (= newvalue +char-attr-constituent+)
74           ;; Default value for the C-A-HASH-TABLE is +CHAR-ATTR-CONSTITUENT+.
75           (%remhash char (character-attribute-hash-table rt))
76           (setf (gethash char (character-attribute-hash-table rt)) newvalue)))
77   (values))
78
79 ;;; the value actually stored in the character macro table. As per
80 ;;; ANSI #'GET-MACRO-CHARACTER and #'SET-MACRO-CHARACTER, this can
81 ;;; be either a function or NIL.
82 (defun get-raw-cmt-entry (char readtable)
83   (declare (readtable readtable))
84   (if (typep char 'base-char)
85       (svref (character-macro-array readtable) (char-code char))
86       ;; Note: DEFAULT here is NIL, not #'UNDEFINED-MACRO-CHAR, so
87       ;; that everything above the base-char range is a non-macro
88       ;; constituent by default.
89       (values (gethash char (character-macro-hash-table readtable) nil))))
90
91 ;;; the value represented by whatever is stored in the character macro
92 ;;; table. As per ANSI #'GET-MACRO-CHARACTER and #'SET-MACRO-CHARACTER,
93 ;;; a function value represents itself, and a NIL value represents the
94 ;;; default behavior.
95 (defun get-coerced-cmt-entry (char readtable)
96   (the function
97     (or (get-raw-cmt-entry char readtable)
98         #'read-token)))
99
100 (defun set-cmt-entry (char new-value-designator &optional (rt *readtable*))
101   (let ((new (when new-value-designator
102                (%coerce-callable-to-fun new-value-designator))))
103     (if (typep char 'base-char)
104         (setf (svref (character-macro-array rt) (char-code char)) new)
105         (setf (gethash char (character-macro-hash-table rt)) new))))
106
107 (defun undefined-macro-char (stream char)
108   (unless *read-suppress*
109     (simple-reader-error stream "undefined read-macro character ~S" char)))
110
111 ;;; The character attribute table is a CHAR-CODE-LIMIT vector of integers.
112
113 (defmacro test-attribute (char whichclass rt)
114   `(= (the fixnum (get-cat-entry ,char ,rt)) ,whichclass))
115
116 ;;; predicates for testing character attributes
117
118 #!-sb-fluid
119 (progn
120   (declaim (inline whitespace[1]p whitespace[2]p))
121   (declaim (inline constituentp terminating-macrop))
122   (declaim (inline single-escape-p multiple-escape-p))
123   (declaim (inline token-delimiterp)))
124
125 ;;; the [1] and [2] here refer to ANSI glossary entries for
126 ;;; "whitespace".
127 (defun whitespace[1]p (char)
128   (test-attribute char +char-attr-whitespace+ *standard-readtable*))
129 (defun whitespace[2]p (char &optional (rt *readtable*))
130   (test-attribute char +char-attr-whitespace+ rt))
131
132 (defun constituentp (char &optional (rt *readtable*))
133   (test-attribute char +char-attr-constituent+ rt))
134
135 (defun terminating-macrop (char &optional (rt *readtable*))
136   (test-attribute char +char-attr-terminating-macro+ rt))
137
138 (defun single-escape-p (char &optional (rt *readtable*))
139   (test-attribute char +char-attr-single-escape+ rt))
140
141 (defun multiple-escape-p (char &optional (rt *readtable*))
142   (test-attribute char +char-attr-multiple-escape+ rt))
143
144 (defun token-delimiterp (char &optional (rt *readtable*))
145   ;; depends on actual attribute numbering in readtable.lisp.
146   (<= (get-cat-entry char rt) +char-attr-terminating-macro+))
147 \f
148 ;;;; constituent traits (see ANSI 2.1.4.2)
149
150 ;;; There are a number of "secondary" attributes which are constant
151 ;;; properties of characters (as long as they are constituents).
152
153 (defvar *constituent-trait-table*)
154 (declaim (type attribute-table *constituent-trait-table*))
155
156 (defun !set-constituent-trait (char trait)
157   (aver (typep char 'base-char))
158   (setf (elt *constituent-trait-table* (char-code char))
159         trait))
160
161 (defun !cold-init-constituent-trait-table ()
162   (setq *constituent-trait-table*
163         (make-array base-char-code-limit :element-type '(unsigned-byte 8)
164                     :initial-element +char-attr-constituent+))
165   (!set-constituent-trait #\: +char-attr-package-delimiter+)
166   (!set-constituent-trait #\. +char-attr-constituent-dot+)
167   (!set-constituent-trait #\+ +char-attr-constituent-sign+)
168   (!set-constituent-trait #\- +char-attr-constituent-sign+)
169   (!set-constituent-trait #\/ +char-attr-constituent-slash+)
170   (do ((i (char-code #\0) (1+ i)))
171       ((> i (char-code #\9)))
172     (!set-constituent-trait (code-char i) +char-attr-constituent-digit+))
173   (!set-constituent-trait #\E +char-attr-constituent-expt+)
174   (!set-constituent-trait #\F +char-attr-constituent-expt+)
175   (!set-constituent-trait #\D +char-attr-constituent-expt+)
176   (!set-constituent-trait #\S +char-attr-constituent-expt+)
177   (!set-constituent-trait #\L +char-attr-constituent-expt+)
178   (!set-constituent-trait #\e +char-attr-constituent-expt+)
179   (!set-constituent-trait #\f +char-attr-constituent-expt+)
180   (!set-constituent-trait #\d +char-attr-constituent-expt+)
181   (!set-constituent-trait #\s +char-attr-constituent-expt+)
182   (!set-constituent-trait #\l +char-attr-constituent-expt+)
183   (!set-constituent-trait #\Space +char-attr-invalid+)
184   (!set-constituent-trait #\Newline +char-attr-invalid+)
185   (dolist (c (list backspace-char-code tab-char-code form-feed-char-code
186                    return-char-code rubout-char-code))
187     (!set-constituent-trait (code-char c) +char-attr-invalid+)))
188
189 (declaim (inline get-constituent-trait))
190 (defun get-constituent-trait (char)
191   (if (typep char 'base-char)
192       (elt *constituent-trait-table* (char-code char))
193       +char-attr-constituent+))
194 \f
195 ;;;; Readtable Operations
196
197 (defun assert-not-standard-readtable (readtable operation)
198   (when (eq readtable *standard-readtable*)
199     (cerror "Frob it anyway!" 'standard-readtable-modified-error
200             :operation operation)))
201
202 (defun readtable-case (readtable)
203   (%readtable-case readtable))
204
205 (defun (setf readtable-case) (case readtable)
206   (assert-not-standard-readtable readtable '(setf readtable-case))
207   (setf (%readtable-case readtable) case))
208
209 (defun shallow-replace/eql-hash-table (to from)
210   (maphash (lambda (k v) (setf (gethash k to) v)) from))
211
212 (defun copy-readtable (&optional (from-readtable *readtable*) to-readtable)
213   (assert-not-standard-readtable to-readtable 'copy-readtable)
214   (let ((really-from-readtable (or from-readtable *standard-readtable*))
215         (really-to-readtable (or to-readtable (make-readtable))))
216     (replace (character-attribute-array really-to-readtable)
217              (character-attribute-array really-from-readtable))
218     (shallow-replace/eql-hash-table
219      (character-attribute-hash-table really-to-readtable)
220      (character-attribute-hash-table really-from-readtable))
221     (replace (character-macro-array really-to-readtable)
222              (character-macro-array really-from-readtable))
223     (shallow-replace/eql-hash-table
224      (character-macro-hash-table really-to-readtable)
225      (character-macro-hash-table really-from-readtable))
226     (setf (dispatch-tables really-to-readtable)
227           (mapcar (lambda (pair)
228                     (cons (car pair)
229                           (let ((table (make-hash-table)))
230                             (shallow-replace/eql-hash-table table (cdr pair))
231                             table)))
232                   (dispatch-tables really-from-readtable)))
233     (setf (readtable-case really-to-readtable)
234           (readtable-case really-from-readtable))
235     really-to-readtable))
236
237 (defun set-syntax-from-char (to-char from-char &optional
238                              (to-readtable *readtable*) (from-readtable nil))
239   #!+sb-doc
240   "Causes the syntax of TO-CHAR to be the same as FROM-CHAR in the optional
241 readtable (defaults to the current readtable). The FROM-TABLE defaults to the
242 standard Lisp readtable when NIL."
243   (assert-not-standard-readtable to-readtable 'set-syntax-from-char)
244   (let ((really-from-readtable (or from-readtable *standard-readtable*)))
245     (let ((att (get-cat-entry from-char really-from-readtable))
246           (mac (get-raw-cmt-entry from-char really-from-readtable))
247           (from-dpair (find from-char (dispatch-tables really-from-readtable)
248                             :test #'char= :key #'car))
249           (to-dpair (find to-char (dispatch-tables to-readtable)
250                           :test #'char= :key #'car)))
251       (set-cat-entry to-char att to-readtable)
252       (set-cmt-entry to-char mac to-readtable)
253       (when from-dpair
254         (cond
255           (to-dpair
256            (let ((table (cdr to-dpair)))
257              (clrhash table)
258              (shallow-replace/eql-hash-table table (cdr from-dpair))))
259           (t
260            (let ((pair (cons to-char (make-hash-table))))
261              (shallow-replace/eql-hash-table (cdr pair) (cdr from-dpair))
262              (setf (dispatch-tables to-readtable)
263                    (push pair (dispatch-tables to-readtable)))))))))
264   t)
265
266 (defun set-macro-character (char function &optional
267                                  (non-terminatingp nil)
268                                  (rt-designator *readtable*))
269   #!+sb-doc
270   "Causes CHAR to be a macro character which invokes FUNCTION when seen
271    by the reader. The NON-TERMINATINGP flag can be used to make the macro
272    character non-terminating, i.e. embeddable in a symbol name."
273   (let ((designated-readtable (or rt-designator *standard-readtable*)))
274     (assert-not-standard-readtable designated-readtable 'set-macro-character)
275     (set-cat-entry char (if non-terminatingp
276                             +char-attr-constituent+
277                             +char-attr-terminating-macro+)
278                    designated-readtable)
279     (set-cmt-entry char function designated-readtable)
280     t)) ; (ANSI-specified return value)
281
282 (defun get-macro-character (char &optional (rt-designator *readtable*))
283   #!+sb-doc
284   "Return the function associated with the specified CHAR which is a macro
285   character, or NIL if there is no such function. As a second value, return
286   T if CHAR is a macro character which is non-terminating, i.e. which can
287   be embedded in a symbol name."
288   (let* ((designated-readtable (or rt-designator *standard-readtable*))
289          ;; the first return value: a FUNCTION if CHAR is a macro
290          ;; character, or NIL otherwise
291          (fun-value (get-raw-cmt-entry char designated-readtable)))
292     (values fun-value
293             ;; NON-TERMINATING-P return value:
294             (if fun-value
295                 (or (constituentp char)
296                     (not (terminating-macrop char)))
297                 ;; ANSI's definition of GET-MACRO-CHARACTER says this
298                 ;; value is NIL when CHAR is not a macro character.
299                 ;; I.e. this value means not just "non-terminating
300                 ;; character?" but "non-terminating macro character?".
301                 nil))))
302
303
304 (defun make-char-dispatch-table ()
305   (make-hash-table))
306
307 (defun make-dispatch-macro-character (char &optional
308                                       (non-terminating-p nil)
309                                       (rt *readtable*))
310   #!+sb-doc
311   "Cause CHAR to become a dispatching macro character in readtable (which
312    defaults to the current readtable). If NON-TERMINATING-P, the char will
313    be non-terminating."
314   ;; Checks already for standard readtable modification.
315   (set-macro-character char #'read-dispatch-char non-terminating-p rt)
316   (let* ((dalist (dispatch-tables rt))
317          (dtable (cdr (find char dalist :test #'char= :key #'car))))
318     (cond (dtable
319            (error "The dispatch character ~S already exists." char))
320           (t
321            (setf (dispatch-tables rt)
322                  (push (cons char (make-char-dispatch-table)) dalist)))))
323   t)
324
325 (defun set-dispatch-macro-character (disp-char sub-char function
326                                      &optional (rt-designator *readtable*))
327   #!+sb-doc
328   "Cause FUNCTION to be called whenever the reader reads DISP-CHAR
329    followed by SUB-CHAR."
330   ;; Get the dispatch char for macro (error if not there), diddle
331   ;; entry for sub-char.
332   (let* ((sub-char (char-upcase sub-char))
333          (readtable (or rt-designator *standard-readtable*)))
334     (assert-not-standard-readtable readtable 'set-dispatch-macro-character)
335     (when (digit-char-p sub-char)
336       (error "SUB-CHAR must not be a decimal digit: ~S" sub-char))
337     (let ((dpair (find disp-char (dispatch-tables readtable)
338                        :test #'char= :key #'car)))
339       (if dpair
340           (setf (gethash sub-char (cdr dpair)) (coerce function 'function))
341           (error "~S is not a dispatch char." disp-char))))
342   t)
343
344 (defun get-dispatch-macro-character (disp-char sub-char
345                                      &optional (rt-designator *readtable*))
346   #!+sb-doc
347   "Return the macro character function for SUB-CHAR under DISP-CHAR
348    or NIL if there is no associated function."
349   (let* ((sub-char  (char-upcase sub-char))
350          (readtable (or rt-designator *standard-readtable*))
351          (dpair     (find disp-char (dispatch-tables readtable)
352                           :test #'char= :key #'car)))
353     (if dpair
354         (values (gethash sub-char (cdr dpair)))
355         (error "~S is not a dispatch char." disp-char))))
356
357 \f
358 ;;;; definitions to support internal programming conventions
359
360 (declaim (inline eofp))
361 (defun eofp (char)
362   (eq char *eof-object*))
363
364 (defun flush-whitespace (stream)
365   ;; This flushes whitespace chars, returning the last char it read (a
366   ;; non-white one). It always gets an error on end-of-file.
367   (let ((stream (in-synonym-of stream)))
368     (if (ansi-stream-p stream)
369         (prepare-for-fast-read-char stream
370           (do ((attribute-array (character-attribute-array *readtable*))
371                (attribute-hash-table
372                 (character-attribute-hash-table *readtable*))
373                (char (fast-read-char t) (fast-read-char t)))
374               ((/= (the fixnum
375                      (if (typep char 'base-char)
376                          (aref attribute-array (char-code char))
377                          (gethash char attribute-hash-table
378                                   +char-attr-constituent+)))
379                    +char-attr-whitespace+)
380                (done-with-fast-read-char)
381                char)))
382         ;; CLOS stream
383         (do ((attribute-array (character-attribute-array *readtable*))
384              (attribute-hash-table
385               (character-attribute-hash-table *readtable*))
386              (char (read-char stream nil :eof) (read-char stream nil :eof)))
387             ((or (eq char :eof)
388                  (/= (the fixnum
389                        (if (typep char 'base-char)
390                            (aref attribute-array (char-code char))
391                            (gethash char attribute-hash-table
392                                     +char-attr-constituent+)))
393                      +char-attr-whitespace+))
394              (if (eq char :eof)
395                  (error 'end-of-file :stream stream)
396                  char))))))
397 \f
398 ;;;; temporary initialization hack
399
400 ;; Install the (easy) standard macro-chars into *READTABLE*.
401 (defun !cold-init-standard-readtable ()
402   (/show0 "entering !cold-init-standard-readtable")
403   ;; All characters get boring defaults in MAKE-READTABLE. Now we
404   ;; override the boring defaults on characters which need more
405   ;; interesting behavior.
406   (flet ((whitespaceify (char)
407            (set-cmt-entry char nil)
408            (set-cat-entry char +char-attr-whitespace+)))
409     (whitespaceify (code-char tab-char-code))
410     (whitespaceify #\Newline)
411     (whitespaceify #\Space)
412     (whitespaceify (code-char form-feed-char-code))
413     (whitespaceify (code-char return-char-code)))
414
415   (set-cat-entry #\\ +char-attr-single-escape+)
416   (set-cmt-entry #\\ nil)
417
418   (set-cat-entry #\| +char-attr-multiple-escape+)
419   (set-cmt-entry #\| nil)
420
421   ;; Easy macro-character definitions are in this source file.
422   (set-macro-character #\" #'read-string)
423   (set-macro-character #\' #'read-quote)
424   (set-macro-character #\( #'read-list)
425   (set-macro-character #\) #'read-right-paren)
426   (set-macro-character #\; #'read-comment)
427   ;; (The hairier macro-character definitions, for #\# and #\`, are
428   ;; defined elsewhere, in their own source files.)
429
430   ;; all constituents
431   (do ((ichar 0 (1+ ichar))
432        (char))
433       ((= ichar base-char-code-limit))
434     (setq char (code-char ichar))
435     (when (constituentp char)
436       (set-cmt-entry char nil)))
437
438   (/show0 "leaving !cold-init-standard-readtable"))
439 \f
440 ;;;; implementation of the read buffer
441
442 (defvar *read-buffer*)
443 (defvar *read-buffer-length*)
444 ;;; FIXME: Is it really helpful to have *READ-BUFFER-LENGTH* be a
445 ;;; separate variable instead of just calculating it on the fly as
446 ;;; (LENGTH *READ-BUFFER*)?
447
448 (defvar *inch-ptr*) ; *OUCH-PTR* always points to next char to write.
449 (defvar *ouch-ptr*) ; *INCH-PTR* always points to next char to read.
450
451 (declaim (type index *read-buffer-length* *inch-ptr* *ouch-ptr*))
452 (declaim (type (simple-array character (*)) *read-buffer*))
453
454 (declaim (inline reset-read-buffer))
455 (defun reset-read-buffer ()
456   ;; Turn *READ-BUFFER* into an empty read buffer.
457   (setq *ouch-ptr* 0)
458   (setq *inch-ptr* 0))
459
460 (declaim (inline ouch-read-buffer))
461 (defun ouch-read-buffer (char)
462   ;; When buffer overflow
463   (when (>= *ouch-ptr* *read-buffer-length*)
464     ;; Size should be doubled.
465     (grow-read-buffer))
466   (setf (elt *read-buffer* *ouch-ptr*) char)
467   (setq *ouch-ptr* (1+ *ouch-ptr*)))
468
469 (defun grow-read-buffer ()
470   (let* ((rbl (length *read-buffer*))
471          (new-length (* 2 rbl))
472          (new-buffer (make-string new-length)))
473     (setq *read-buffer* (replace new-buffer *read-buffer*))
474     (setq *read-buffer-length* new-length)))
475
476 (defun inch-read-buffer ()
477   (if (>= *inch-ptr* *ouch-ptr*)
478       *eof-object*
479       (prog1
480           (elt *read-buffer* *inch-ptr*)
481         (incf *inch-ptr*))))
482
483 (declaim (inline unread-buffer))
484 (defun unread-buffer ()
485   (decf *inch-ptr*))
486
487 (declaim (inline read-unwind-read-buffer))
488 (defun read-unwind-read-buffer ()
489   ;; Keep contents, but make next (INCH..) return first character.
490   (setq *inch-ptr* 0))
491
492 (defun read-buffer-to-string ()
493   (subseq *read-buffer* 0 *ouch-ptr*))
494
495 (defmacro with-read-buffer (() &body body)
496   `(let* ((*read-buffer* (make-string 128))
497           (*read-buffer-length* 128)
498           (*ouch-ptr* 0)
499           (*inch-ptr* 0))
500      ,@body))
501
502 (defun check-for-recursive-read (recursive-p operator-name)
503   (when (and recursive-p
504              (not (and (boundp '*read-buffer*)
505                        (boundp '*read-buffer-length*)
506                        (boundp '*ouch-ptr*)
507                        (boundp '*inch-ptr*))))
508     (error 'simple-reader-error
509            :format-control "~A was invoked with RECURSIVE-P being true outside ~
510                             of a recursive read operation."
511            :format-arguments `(,operator-name))))
512
513 \f
514 ;;;; READ-PRESERVING-WHITESPACE, READ-DELIMITED-LIST, and READ
515
516 ;;; an alist for #=, used to keep track of objects with labels assigned that
517 ;;; have been completely read. Each entry is (integer-tag gensym-tag value).
518 ;;;
519 ;;; KLUDGE: Should this really be an alist? It seems as though users
520 ;;; could reasonably expect N log N performance for large datasets.
521 ;;; On the other hand, it's probably very very seldom a problem in practice.
522 ;;; On the third hand, it might be just as easy to use a hash table
523 ;;; as an alist, so maybe we should. -- WHN 19991202
524 (defvar *sharp-equal-alist* ())
525
526 (declaim (special *standard-input*))
527
528 ;;; Like READ-PRESERVING-WHITESPACE, but doesn't check the read buffer
529 ;;; for being set up properly.
530 (defun %read-preserving-whitespace (stream eof-error-p eof-value recursive-p)
531   (if recursive-p
532       ;; a loop for repeating when a macro returns nothing
533       (loop
534        (let ((char (read-char stream eof-error-p *eof-object*)))
535          (cond ((eofp char) (return eof-value))
536                ((whitespace[2]p char))
537                (t
538                 (let* ((macrofun (get-coerced-cmt-entry char *readtable*))
539                        (result (multiple-value-list
540                                 (funcall macrofun stream char))))
541                   ;; Repeat if macro returned nothing.
542                   (when result
543                     (return (unless *read-suppress* (car result)))))))))
544       (let ((*sharp-equal-alist* nil))
545         (with-read-buffer ()
546           (%read-preserving-whitespace stream eof-error-p eof-value t)))))
547
548 ;;; READ-PRESERVING-WHITESPACE behaves just like READ, only it makes
549 ;;; sure to leave terminating whitespace in the stream. (This is a
550 ;;; COMMON-LISP exported symbol.)
551 (defun read-preserving-whitespace (&optional (stream *standard-input*)
552                                              (eof-error-p t)
553                                              (eof-value nil)
554                                              (recursive-p nil))
555   #!+sb-doc
556   "Read from STREAM and return the value read, preserving any whitespace
557    that followed the object."
558   (check-for-recursive-read recursive-p 'read-preserving-whitespace)
559   (%read-preserving-whitespace stream eof-error-p eof-value recursive-p))
560
561 ;;; Return NIL or a list with one thing, depending.
562 ;;;
563 ;;; for functions that want comments to return so that they can look
564 ;;; past them. We assume CHAR is not whitespace.
565 (defun read-maybe-nothing (stream char)
566   (let ((retval (multiple-value-list
567                  (funcall (get-coerced-cmt-entry char *readtable*)
568                           stream
569                           char))))
570     (if retval (rplacd retval nil))))
571
572 (defun read (&optional (stream *standard-input*)
573                        (eof-error-p t)
574                        (eof-value nil)
575                        (recursive-p nil))
576   #!+sb-doc
577   "Read the next Lisp value from STREAM, and return it."
578   (check-for-recursive-read recursive-p 'read)
579   (let ((result (%read-preserving-whitespace stream eof-error-p eof-value
580                                              recursive-p)))
581     ;; This function generally discards trailing whitespace. If you
582     ;; don't want to discard trailing whitespace, call
583     ;; CL:READ-PRESERVING-WHITESPACE instead.
584     (unless (or (eql result eof-value) recursive-p)
585       (let ((next-char (read-char stream nil nil)))
586         (unless (or (null next-char)
587                     (whitespace[2]p next-char))
588           (unread-char next-char stream))))
589     result))
590
591 ;;; (This is a COMMON-LISP exported symbol.)
592 (defun read-delimited-list (endchar &optional
593                                     (input-stream *standard-input*)
594                                     recursive-p)
595   #!+sb-doc
596   "Read Lisp values from INPUT-STREAM until the next character after a
597    value's representation is ENDCHAR, and return the objects as a list."
598   (check-for-recursive-read recursive-p 'read-delimited-list)
599   (flet ((%read-delimited-list (endchar input-stream)
600            (do ((char (flush-whitespace input-stream)
601                       (flush-whitespace input-stream))
602                 (retlist ()))
603                ((char= char endchar)
604                 (unless *read-suppress* (nreverse retlist)))
605              (setq retlist (nconc (read-maybe-nothing input-stream char)
606                                   retlist)))))
607     (declare (inline %read-delimited-list))
608     (if recursive-p
609         (%read-delimited-list endchar input-stream)
610         (with-read-buffer ()
611           (%read-delimited-list endchar input-stream)))))
612 \f
613 ;;;; basic readmacro definitions
614 ;;;;
615 ;;;; Some large, hairy subsets of readmacro definitions (backquotes
616 ;;;; and sharp macros) are not here, but in their own source files.
617
618 (defun read-quote (stream ignore)
619   (declare (ignore ignore))
620   (list 'quote (read stream t nil t)))
621
622 (defun read-comment (stream ignore)
623   (declare (ignore ignore))
624   (handler-bind
625       ((character-decoding-error
626         #'(lambda (decoding-error)
627             (declare (ignorable decoding-error))
628             (style-warn
629              'sb!kernel::character-decoding-error-in-macro-char-comment
630              :position (file-position stream) :stream stream)
631             (invoke-restart 'attempt-resync))))
632     (let ((stream (in-synonym-of stream)))
633       (if (ansi-stream-p stream)
634           (prepare-for-fast-read-char stream
635            (do ((char (fast-read-char nil nil)
636                       (fast-read-char nil nil)))
637                ((or (not char) (char= char #\newline))
638                 (done-with-fast-read-char))))
639           ;; CLOS stream
640           (do ((char (read-char stream nil :eof) (read-char stream nil :eof)))
641               ((or (eq char :eof) (char= char #\newline)))))))
642   ;; Don't return anything.
643   (values))
644
645 (defun read-list (stream ignore)
646   (declare (ignore ignore))
647   (let* ((thelist (list nil))
648          (listtail thelist))
649     (do ((firstchar (flush-whitespace stream) (flush-whitespace stream)))
650         ((char= firstchar #\) ) (cdr thelist))
651       (when (char= firstchar #\.)
652             (let ((nextchar (read-char stream t)))
653               (cond ((token-delimiterp nextchar)
654                      (cond ((eq listtail thelist)
655                             (unless *read-suppress*
656                               (simple-reader-error
657                                stream
658                                "Nothing appears before . in list.")))
659                            ((whitespace[2]p nextchar)
660                             (setq nextchar (flush-whitespace stream))))
661                      (rplacd listtail
662                              ;; Return list containing last thing.
663                              (car (read-after-dot stream nextchar)))
664                      (return (cdr thelist)))
665                     ;; Put back NEXTCHAR so that we can read it normally.
666                     (t (unread-char nextchar stream)))))
667       ;; Next thing is not an isolated dot.
668       (let ((listobj (read-maybe-nothing stream firstchar)))
669         ;; allows the possibility that a comment was read
670         (when listobj
671               (rplacd listtail listobj)
672               (setq listtail listobj))))))
673
674 (defun read-after-dot (stream firstchar)
675   ;; FIRSTCHAR is non-whitespace!
676   (let ((lastobj ()))
677     (do ((char firstchar (flush-whitespace stream)))
678         ((char= char #\) )
679          (if *read-suppress*
680              (return-from read-after-dot nil)
681              (simple-reader-error stream "Nothing appears after . in list.")))
682       ;; See whether there's something there.
683       (setq lastobj (read-maybe-nothing stream char))
684       (when lastobj (return t)))
685     ;; At least one thing appears after the dot.
686     ;; Check for more than one thing following dot.
687     (do ((lastchar (flush-whitespace stream)
688                    (flush-whitespace stream)))
689         ((char= lastchar #\) ) lastobj) ;success!
690       ;; Try reading virtual whitespace.
691       (if (and (read-maybe-nothing stream lastchar)
692                (not *read-suppress*))
693           (simple-reader-error stream
694                                "More than one object follows . in list.")))))
695
696 (defun read-string (stream closech)
697   ;; This accumulates chars until it sees same char that invoked it.
698   ;; For a very long string, this could end up bloating the read buffer.
699   (reset-read-buffer)
700   (let ((stream (in-synonym-of stream)))
701     (if (ansi-stream-p stream)
702         (prepare-for-fast-read-char stream
703           (do ((char (fast-read-char t) (fast-read-char t)))
704               ((char= char closech)
705                (done-with-fast-read-char))
706             (if (single-escape-p char) (setq char (fast-read-char t)))
707             (ouch-read-buffer char)))
708         ;; CLOS stream
709         (do ((char (read-char stream nil :eof) (read-char stream nil :eof)))
710             ((or (eq char :eof) (char= char closech))
711              (if (eq char :eof)
712                  (error 'end-of-file :stream stream)))
713           (when (single-escape-p char)
714             (setq char (read-char stream nil :eof))
715             (if (eq char :eof)
716                 (error 'end-of-file :stream stream)))
717           (ouch-read-buffer char))))
718   (read-buffer-to-string))
719
720 (defun read-right-paren (stream ignore)
721   (declare (ignore ignore))
722   (simple-reader-error stream "unmatched close parenthesis"))
723
724 ;;; Read from the stream up to the next delimiter. Leave the resulting
725 ;;; token in *READ-BUFFER*, and return two values:
726 ;;; -- a list of the escaped character positions, and
727 ;;; -- The position of the first package delimiter (or NIL).
728 (defun internal-read-extended-token (stream firstchar escape-firstchar)
729   (reset-read-buffer)
730   (let ((escapes '()))
731     (when escape-firstchar
732       (push *ouch-ptr* escapes)
733       (ouch-read-buffer firstchar)
734       (setq firstchar (read-char stream nil *eof-object*)))
735   (do ((char firstchar (read-char stream nil *eof-object*))
736        (colon nil))
737       ((cond ((eofp char) t)
738              ((token-delimiterp char)
739               (unread-char char stream)
740               t)
741              (t nil))
742        (values escapes colon))
743     (cond ((single-escape-p char)
744            ;; It can't be a number, even if it's 1\23.
745            ;; Read next char here, so it won't be casified.
746            (push *ouch-ptr* escapes)
747            (let ((nextchar (read-char stream nil *eof-object*)))
748              (if (eofp nextchar)
749                  (reader-eof-error stream "after escape character")
750                  (ouch-read-buffer nextchar))))
751           ((multiple-escape-p char)
752            ;; Read to next multiple-escape, escaping single chars
753            ;; along the way.
754            (loop
755              (let ((ch (read-char stream nil *eof-object*)))
756                (cond
757                 ((eofp ch)
758                  (reader-eof-error stream "inside extended token"))
759                 ((multiple-escape-p ch) (return))
760                 ((single-escape-p ch)
761                  (let ((nextchar (read-char stream nil *eof-object*)))
762                    (cond ((eofp nextchar)
763                           (reader-eof-error stream "after escape character"))
764                          (t
765                           (push *ouch-ptr* escapes)
766                           (ouch-read-buffer nextchar)))))
767                 (t
768                  (push *ouch-ptr* escapes)
769                  (ouch-read-buffer ch))))))
770           (t
771            (when (and (constituentp char)
772                       (eql (get-constituent-trait char)
773                            +char-attr-package-delimiter+)
774                       (not colon))
775              (setq colon *ouch-ptr*))
776            (ouch-read-buffer char))))))
777 \f
778 ;;;; character classes
779
780 ;;; Return the character class for CHAR.
781 ;;;
782 ;;; FIXME: why aren't these ATT-getting forms using GET-CAT-ENTRY?
783 ;;; Because we've cached the readtable tables?
784 (defmacro char-class (char attarray atthash)
785   `(let ((att (if (typep ,char 'base-char)
786                   (aref ,attarray (char-code ,char))
787                   (gethash ,char ,atthash +char-attr-constituent+))))
788      (declare (fixnum att))
789      (cond
790        ((<= att +char-attr-terminating-macro+) +char-attr-delimiter+)
791        ((< att +char-attr-constituent+) att)
792        (t (setf att (get-constituent-trait ,char))
793           (if (= att +char-attr-invalid+)
794               (simple-reader-error stream "invalid constituent")
795               att)))))
796
797 ;;; Return the character class for CHAR, which might be part of a
798 ;;; rational number.
799 (defmacro char-class2 (char attarray atthash)
800   `(let ((att (if (typep ,char 'base-char)
801                   (aref ,attarray (char-code ,char))
802                   (gethash ,char ,atthash +char-attr-constituent+))))
803      (declare (fixnum att))
804      (cond
805        ((<= att +char-attr-terminating-macro+) +char-attr-delimiter+)
806        ((< att +char-attr-constituent+) att)
807        (t (setf att (get-constituent-trait ,char))
808           (cond
809             ((digit-char-p ,char *read-base*) +char-attr-constituent-digit+)
810             ((= att +char-attr-constituent-digit+) +char-attr-constituent+)
811             ((= att +char-attr-invalid+)
812              (simple-reader-error stream "invalid constituent"))
813             (t att))))))
814
815 ;;; Return the character class for a char which might be part of a
816 ;;; rational or floating number. (Assume that it is a digit if it
817 ;;; could be.)
818 (defmacro char-class3 (char attarray atthash)
819   `(let ((att (if (typep ,char 'base-char)
820                   (aref ,attarray (char-code ,char))
821                   (gethash ,char ,atthash +char-attr-constituent+))))
822      (declare (fixnum att))
823      (cond
824        ((<= att +char-attr-terminating-macro+) +char-attr-delimiter+)
825        ((< att +char-attr-constituent+) att)
826        (t (setf att (get-constituent-trait ,char))
827           (when possibly-rational
828             (setq possibly-rational
829                   (or (digit-char-p ,char *read-base*)
830                       (= att +char-attr-constituent-slash+))))
831           (when possibly-float
832             (setq possibly-float
833                   (or (digit-char-p ,char 10)
834                       (= att +char-attr-constituent-dot+))))
835           (cond
836             ((digit-char-p ,char (max *read-base* 10))
837              (if (digit-char-p ,char *read-base*)
838                  (if (= att +char-attr-constituent-expt+)
839                      +char-attr-constituent-digit-or-expt+
840                      +char-attr-constituent-digit+)
841                  +char-attr-constituent-decimal-digit+))
842             ((= att +char-attr-invalid+)
843              (simple-reader-error stream "invalid constituent"))
844             (t att))))))
845 \f
846 ;;;; token fetching
847
848 (defvar *read-suppress* nil
849   #!+sb-doc
850   "Suppress most interpreting in the reader when T.")
851
852 (defvar *read-base* 10
853   #!+sb-doc
854   "the radix that Lisp reads numbers in")
855 (declaim (type (integer 2 36) *read-base*))
856
857 ;;; Modify the read buffer according to READTABLE-CASE, ignoring
858 ;;; ESCAPES. ESCAPES is a list of the escaped indices, in reverse
859 ;;; order.
860 (defun casify-read-buffer (escapes)
861   (let ((case (readtable-case *readtable*)))
862     (cond
863      ((and (null escapes) (eq case :upcase))
864       ;; Pull the special variable access out of the loop.
865       (let ((buffer *read-buffer*))
866         (dotimes (i *ouch-ptr*)
867           (declare (optimize (sb!c::insert-array-bounds-checks 0)))
868           (setf (schar buffer i) (char-upcase (schar buffer i))))))
869      ((eq case :preserve))
870      (t
871       (macrolet ((skip-esc (&body body)
872                    `(do ((i (1- *ouch-ptr*) (1- i))
873                          (buffer *read-buffer*)
874                          (escapes escapes))
875                         ((minusp i))
876                       (declare (fixnum i)
877                                (optimize (sb!c::insert-array-bounds-checks 0)))
878                       (when (or (null escapes)
879                                 (let ((esc (first escapes)))
880                                   (declare (fixnum esc))
881                                   (cond ((< esc i) t)
882                                         (t
883                                          (aver (= esc i))
884                                          (pop escapes)
885                                          nil))))
886                         (let ((ch (schar buffer i)))
887                           ,@body)))))
888         (flet ((lower-em ()
889                  (skip-esc (setf (schar buffer i) (char-downcase ch))))
890                (raise-em ()
891                  (skip-esc (setf (schar buffer i) (char-upcase ch)))))
892           (ecase case
893             (:upcase (raise-em))
894             (:downcase (lower-em))
895             (:invert
896              (let ((all-upper t)
897                    (all-lower t))
898                (skip-esc
899                  (when (both-case-p ch)
900                    (if (upper-case-p ch)
901                        (setq all-lower nil)
902                        (setq all-upper nil))))
903                (cond (all-lower (raise-em))
904                      (all-upper (lower-em))))))))))))
905
906 (defun read-token (stream firstchar)
907   #!+sb-doc
908   "This function is just an fsm that recognizes numbers and symbols."
909   ;; Check explicitly whether FIRSTCHAR has an entry for
910   ;; NON-TERMINATING in CHARACTER-ATTRIBUTE-TABLE and
911   ;; READ-DOT-NUMBER-SYMBOL in CMT. Report an error if these are
912   ;; violated. (If we called this, we want something that is a
913   ;; legitimate token!) Read in the longest possible string satisfying
914   ;; the Backus-Naur form for "unqualified-token". Leave the result in
915   ;; the *READ-BUFFER*. Return next char after token (last char read).
916   (when *read-suppress*
917     (internal-read-extended-token stream firstchar nil)
918     (return-from read-token nil))
919   (let ((attribute-array (character-attribute-array *readtable*))
920         (attribute-hash-table (character-attribute-hash-table *readtable*))
921         (package-designator nil)
922         (colons 0)
923         (possibly-rational t)
924         (seen-digit-or-expt nil)
925         (possibly-float t)
926         (was-possibly-float nil)
927         (escapes ())
928         (seen-multiple-escapes nil))
929     (reset-read-buffer)
930     (prog ((char firstchar))
931       (case (char-class3 char attribute-array attribute-hash-table)
932         (#.+char-attr-constituent-sign+ (go SIGN))
933         (#.+char-attr-constituent-digit+ (go LEFTDIGIT))
934         (#.+char-attr-constituent-digit-or-expt+
935          (setq seen-digit-or-expt t)
936          (go LEFTDIGIT))
937         (#.+char-attr-constituent-decimal-digit+ (go LEFTDECIMALDIGIT))
938         (#.+char-attr-constituent-dot+ (go FRONTDOT))
939         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
940         (#.+char-attr-package-delimiter+ (go COLON))
941         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
942         (#.+char-attr-invalid+ (simple-reader-error stream
943                                                     "invalid constituent"))
944         ;; can't have eof, whitespace, or terminating macro as first char!
945         (t (go SYMBOL)))
946      SIGN ; saw "sign"
947       (ouch-read-buffer char)
948       (setq char (read-char stream nil nil))
949       (unless char (go RETURN-SYMBOL))
950       (setq possibly-rational t
951             possibly-float t)
952       (case (char-class3 char attribute-array attribute-hash-table)
953         (#.+char-attr-constituent-digit+ (go LEFTDIGIT))
954         (#.+char-attr-constituent-digit-or-expt+
955          (setq seen-digit-or-expt t)
956          (go LEFTDIGIT))
957         (#.+char-attr-constituent-decimal-digit+ (go LEFTDECIMALDIGIT))
958         (#.+char-attr-constituent-dot+ (go SIGNDOT))
959         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
960         (#.+char-attr-package-delimiter+ (go COLON))
961         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
962         (#.+char-attr-delimiter+ (unread-char char stream) (go RETURN-SYMBOL))
963         (t (go SYMBOL)))
964      LEFTDIGIT ; saw "[sign] {digit}+"
965       (ouch-read-buffer char)
966       (setq char (read-char stream nil nil))
967       (unless char (return (make-integer)))
968       (setq was-possibly-float possibly-float)
969       (case (char-class3 char attribute-array attribute-hash-table)
970         (#.+char-attr-constituent-digit+ (go LEFTDIGIT))
971         (#.+char-attr-constituent-decimal-digit+ (if possibly-float
972                                                      (go LEFTDECIMALDIGIT)
973                                                      (go SYMBOL)))
974         (#.+char-attr-constituent-dot+ (if possibly-float
975                                            (go MIDDLEDOT)
976                                            (go SYMBOL)))
977         (#.+char-attr-constituent-digit-or-expt+
978          (if (or seen-digit-or-expt (not was-possibly-float))
979              (progn (setq seen-digit-or-expt t) (go LEFTDIGIT))
980              (progn (setq seen-digit-or-expt t) (go LEFTDIGIT-OR-EXPT))))
981         (#.+char-attr-constituent-expt+
982          (if was-possibly-float
983              (go EXPONENT)
984              (go SYMBOL)))
985         (#.+char-attr-constituent-slash+ (if possibly-rational
986                                              (go RATIO)
987                                              (go SYMBOL)))
988         (#.+char-attr-delimiter+ (unread-char char stream)
989                                  (return (make-integer)))
990         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
991         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
992         (#.+char-attr-package-delimiter+ (go COLON))
993         (t (go SYMBOL)))
994      LEFTDIGIT-OR-EXPT
995       (ouch-read-buffer char)
996       (setq char (read-char stream nil nil))
997       (unless char (return (make-integer)))
998       (case (char-class3 char attribute-array attribute-hash-table)
999         (#.+char-attr-constituent-digit+ (go LEFTDIGIT))
1000         (#.+char-attr-constituent-decimal-digit+ (bug "impossible!"))
1001         (#.+char-attr-constituent-dot+ (go SYMBOL))
1002         (#.+char-attr-constituent-digit-or-expt+ (go LEFTDIGIT))
1003         (#.+char-attr-constituent-expt+ (go SYMBOL))
1004         (#.+char-attr-constituent-sign+ (go EXPTSIGN))
1005         (#.+char-attr-constituent-slash+ (if possibly-rational
1006                                              (go RATIO)
1007                                              (go SYMBOL)))
1008         (#.+char-attr-delimiter+ (unread-char char stream)
1009                                  (return (make-integer)))
1010         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1011         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1012         (#.+char-attr-package-delimiter+ (go COLON))
1013         (t (go SYMBOL)))
1014      LEFTDECIMALDIGIT ; saw "[sign] {decimal-digit}+"
1015       (aver possibly-float)
1016       (ouch-read-buffer char)
1017       (setq char (read-char stream nil nil))
1018       (unless char (go RETURN-SYMBOL))
1019       (case (char-class char attribute-array attribute-hash-table)
1020         (#.+char-attr-constituent-digit+ (go LEFTDECIMALDIGIT))
1021         (#.+char-attr-constituent-dot+ (go MIDDLEDOT))
1022         (#.+char-attr-constituent-expt+ (go EXPONENT))
1023         (#.+char-attr-constituent-slash+ (aver (not possibly-rational))
1024                                          (go SYMBOL))
1025         (#.+char-attr-delimiter+ (unread-char char stream)
1026                                  (go RETURN-SYMBOL))
1027         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1028         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1029         (#.+char-attr-package-delimiter+ (go COLON))
1030         (t (go SYMBOL)))
1031      MIDDLEDOT ; saw "[sign] {digit}+ dot"
1032       (ouch-read-buffer char)
1033       (setq char (read-char stream nil nil))
1034       (unless char (return (let ((*read-base* 10))
1035                              (make-integer))))
1036       (case (char-class char attribute-array attribute-hash-table)
1037         (#.+char-attr-constituent-digit+ (go RIGHTDIGIT))
1038         (#.+char-attr-constituent-expt+ (go EXPONENT))
1039         (#.+char-attr-delimiter+
1040          (unread-char char stream)
1041          (return (let ((*read-base* 10))
1042                    (make-integer))))
1043         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1044         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1045         (#.+char-attr-package-delimiter+ (go COLON))
1046         (t (go SYMBOL)))
1047      RIGHTDIGIT ; saw "[sign] {decimal-digit}* dot {digit}+"
1048       (ouch-read-buffer char)
1049       (setq char (read-char stream nil nil))
1050       (unless char (return (make-float stream)))
1051       (case (char-class char attribute-array attribute-hash-table)
1052         (#.+char-attr-constituent-digit+ (go RIGHTDIGIT))
1053         (#.+char-attr-constituent-expt+ (go EXPONENT))
1054         (#.+char-attr-delimiter+
1055          (unread-char char stream)
1056          (return (make-float stream)))
1057         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1058         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1059         (#.+char-attr-package-delimiter+ (go COLON))
1060         (t (go SYMBOL)))
1061      SIGNDOT ; saw "[sign] dot"
1062       (ouch-read-buffer char)
1063       (setq char (read-char stream nil nil))
1064       (unless char (go RETURN-SYMBOL))
1065       (case (char-class char attribute-array attribute-hash-table)
1066         (#.+char-attr-constituent-digit+ (go RIGHTDIGIT))
1067         (#.+char-attr-delimiter+ (unread-char char stream) (go RETURN-SYMBOL))
1068         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1069         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1070         (t (go SYMBOL)))
1071      FRONTDOT ; saw "dot"
1072       (ouch-read-buffer char)
1073       (setq char (read-char stream nil nil))
1074       (unless char (simple-reader-error stream "dot context error"))
1075       (case (char-class char attribute-array attribute-hash-table)
1076         (#.+char-attr-constituent-digit+ (go RIGHTDIGIT))
1077         (#.+char-attr-constituent-dot+ (go DOTS))
1078         (#.+char-attr-delimiter+  (simple-reader-error stream
1079                                                        "dot context error"))
1080         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1081         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1082         (#.+char-attr-package-delimiter+ (go COLON))
1083         (t (go SYMBOL)))
1084      EXPONENT
1085       (ouch-read-buffer char)
1086       (setq char (read-char stream nil nil))
1087       (unless char (go RETURN-SYMBOL))
1088       (setq possibly-float t)
1089       (case (char-class char attribute-array attribute-hash-table)
1090         (#.+char-attr-constituent-sign+ (go EXPTSIGN))
1091         (#.+char-attr-constituent-digit+ (go EXPTDIGIT))
1092         (#.+char-attr-delimiter+ (unread-char char stream) (go RETURN-SYMBOL))
1093         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1094         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1095         (#.+char-attr-package-delimiter+ (go COLON))
1096         (t (go SYMBOL)))
1097      EXPTSIGN ; got to EXPONENT, and saw a sign character
1098       (ouch-read-buffer char)
1099       (setq char (read-char stream nil nil))
1100       (unless char (go RETURN-SYMBOL))
1101       (case (char-class char attribute-array attribute-hash-table)
1102         (#.+char-attr-constituent-digit+ (go EXPTDIGIT))
1103         (#.+char-attr-delimiter+ (unread-char char stream) (go RETURN-SYMBOL))
1104         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1105         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1106         (#.+char-attr-package-delimiter+ (go COLON))
1107         (t (go SYMBOL)))
1108      EXPTDIGIT ; got to EXPONENT, saw "[sign] {digit}+"
1109       (ouch-read-buffer char)
1110       (setq char (read-char stream nil nil))
1111       (unless char (return (make-float stream)))
1112       (case (char-class char attribute-array attribute-hash-table)
1113         (#.+char-attr-constituent-digit+ (go EXPTDIGIT))
1114         (#.+char-attr-delimiter+
1115          (unread-char char stream)
1116          (return (make-float stream)))
1117         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1118         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1119         (#.+char-attr-package-delimiter+ (go COLON))
1120         (t (go SYMBOL)))
1121      RATIO ; saw "[sign] {digit}+ slash"
1122       (ouch-read-buffer char)
1123       (setq char (read-char stream nil nil))
1124       (unless char (go RETURN-SYMBOL))
1125       (case (char-class2 char attribute-array attribute-hash-table)
1126         (#.+char-attr-constituent-digit+ (go RATIODIGIT))
1127         (#.+char-attr-delimiter+ (unread-char char stream) (go RETURN-SYMBOL))
1128         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1129         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1130         (#.+char-attr-package-delimiter+ (go COLON))
1131         (t (go SYMBOL)))
1132      RATIODIGIT ; saw "[sign] {digit}+ slash {digit}+"
1133       (ouch-read-buffer char)
1134       (setq char (read-char stream nil nil))
1135       (unless char (return (make-ratio stream)))
1136       (case (char-class2 char attribute-array attribute-hash-table)
1137         (#.+char-attr-constituent-digit+ (go RATIODIGIT))
1138         (#.+char-attr-delimiter+
1139          (unread-char char stream)
1140          (return (make-ratio stream)))
1141         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1142         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1143         (#.+char-attr-package-delimiter+ (go COLON))
1144         (t (go SYMBOL)))
1145      DOTS ; saw "dot {dot}+"
1146       (ouch-read-buffer char)
1147       (setq char (read-char stream nil nil))
1148       (unless char (simple-reader-error stream "too many dots"))
1149       (case (char-class char attribute-array attribute-hash-table)
1150         (#.+char-attr-constituent-dot+ (go DOTS))
1151         (#.+char-attr-delimiter+
1152          (unread-char char stream)
1153          (simple-reader-error stream "too many dots"))
1154         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1155         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1156         (#.+char-attr-package-delimiter+ (go COLON))
1157         (t (go SYMBOL)))
1158      SYMBOL ; not a dot, dots, or number
1159       (let ((stream (in-synonym-of stream)))
1160         (if (ansi-stream-p stream)
1161             (prepare-for-fast-read-char stream
1162               (prog ()
1163                SYMBOL-LOOP
1164                (ouch-read-buffer char)
1165                (setq char (fast-read-char nil nil))
1166                (unless char (go RETURN-SYMBOL))
1167                (case (char-class char attribute-array attribute-hash-table)
1168                  (#.+char-attr-single-escape+ (done-with-fast-read-char)
1169                                               (go SINGLE-ESCAPE))
1170                  (#.+char-attr-delimiter+ (done-with-fast-read-char)
1171                                           (unread-char char stream)
1172                                           (go RETURN-SYMBOL))
1173                  (#.+char-attr-multiple-escape+ (done-with-fast-read-char)
1174                                                 (go MULT-ESCAPE))
1175                  (#.+char-attr-package-delimiter+ (done-with-fast-read-char)
1176                                                   (go COLON))
1177                  (t (go SYMBOL-LOOP)))))
1178             ;; CLOS stream
1179             (prog ()
1180              SYMBOL-LOOP
1181              (ouch-read-buffer char)
1182              (setq char (read-char stream nil :eof))
1183              (when (eq char :eof) (go RETURN-SYMBOL))
1184              (case (char-class char attribute-array attribute-hash-table)
1185                (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1186                (#.+char-attr-delimiter+ (unread-char char stream)
1187                             (go RETURN-SYMBOL))
1188                (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1189                (#.+char-attr-package-delimiter+ (go COLON))
1190                (t (go SYMBOL-LOOP))))))
1191      SINGLE-ESCAPE ; saw a single-escape
1192       ;; Don't put the escape character in the read buffer.
1193       ;; READ-NEXT CHAR, put in buffer (no case conversion).
1194       (let ((nextchar (read-char stream nil nil)))
1195         (unless nextchar
1196           (reader-eof-error stream "after single-escape character"))
1197         (push *ouch-ptr* escapes)
1198         (ouch-read-buffer nextchar))
1199       (setq char (read-char stream nil nil))
1200       (unless char (go RETURN-SYMBOL))
1201       (case (char-class char attribute-array attribute-hash-table)
1202         (#.+char-attr-delimiter+ (unread-char char stream) (go RETURN-SYMBOL))
1203         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1204         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1205         (#.+char-attr-package-delimiter+ (go COLON))
1206         (t (go SYMBOL)))
1207       MULT-ESCAPE
1208       (setq seen-multiple-escapes t)
1209       (do ((char (read-char stream t) (read-char stream t)))
1210           ((multiple-escape-p char))
1211         (if (single-escape-p char) (setq char (read-char stream t)))
1212         (push *ouch-ptr* escapes)
1213         (ouch-read-buffer char))
1214       (setq char (read-char stream nil nil))
1215       (unless char (go RETURN-SYMBOL))
1216       (case (char-class char attribute-array attribute-hash-table)
1217         (#.+char-attr-delimiter+ (unread-char char stream) (go RETURN-SYMBOL))
1218         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1219         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1220         (#.+char-attr-package-delimiter+ (go COLON))
1221         (t (go SYMBOL)))
1222       COLON
1223       (casify-read-buffer escapes)
1224       (unless (zerop colons)
1225         (simple-reader-error stream
1226                              "too many colons in ~S"
1227                              (read-buffer-to-string)))
1228       (setq colons 1)
1229       (setq package-designator
1230             (if (plusp *ouch-ptr*)
1231                 ;; FIXME: It seems inefficient to cons up a package
1232                 ;; designator string every time we read a symbol with an
1233                 ;; explicit package prefix. Perhaps we could implement
1234                 ;; a FIND-PACKAGE* function analogous to INTERN*
1235                 ;; and friends?
1236                 (read-buffer-to-string)
1237                 (if seen-multiple-escapes
1238                     (read-buffer-to-string)
1239                     *keyword-package*)))
1240       (reset-read-buffer)
1241       (setq escapes ())
1242       (setq char (read-char stream nil nil))
1243       (unless char (reader-eof-error stream "after reading a colon"))
1244       (case (char-class char attribute-array attribute-hash-table)
1245         (#.+char-attr-delimiter+
1246          (unread-char char stream)
1247          (simple-reader-error stream
1248                               "illegal terminating character after a colon: ~S"
1249                               char))
1250         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1251         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1252         (#.+char-attr-package-delimiter+ (go INTERN))
1253         (t (go SYMBOL)))
1254       INTERN
1255       (setq colons 2)
1256       (setq char (read-char stream nil nil))
1257       (unless char
1258         (reader-eof-error stream "after reading a colon"))
1259       (case (char-class char attribute-array attribute-hash-table)
1260         (#.+char-attr-delimiter+
1261          (unread-char char stream)
1262          (simple-reader-error stream
1263                               "illegal terminating character after a colon: ~S"
1264                               char))
1265         (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
1266         (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
1267         (#.+char-attr-package-delimiter+
1268          (simple-reader-error stream
1269                               "too many colons after ~S name"
1270                               package-designator))
1271         (t (go SYMBOL)))
1272       RETURN-SYMBOL
1273       (casify-read-buffer escapes)
1274       (let ((found (if package-designator
1275                        (find-package package-designator)
1276                        (sane-package))))
1277         (unless found
1278           (error 'simple-reader-package-error :stream stream
1279                  :format-arguments (list package-designator)
1280                  :format-control "package ~S not found"))
1281
1282         (if (or (zerop colons) (= colons 2) (eq found *keyword-package*))
1283             (return (intern* *read-buffer* *ouch-ptr* found))
1284             (multiple-value-bind (symbol test)
1285                 (find-symbol* *read-buffer* *ouch-ptr* found)
1286               (when (eq test :external) (return symbol))
1287               (let ((name (read-buffer-to-string)))
1288                 (with-simple-restart (continue "Use symbol anyway.")
1289                   (error 'simple-reader-package-error :stream stream
1290                          :format-arguments (list name (package-name found))
1291                          :format-control
1292                          (if test
1293                              "The symbol ~S is not external in the ~A package."
1294                              "Symbol ~S not found in the ~A package.")))
1295                 (return (intern name found)))))))))
1296
1297 ;;; for semi-external use:
1298 ;;;
1299 ;;; For semi-external use: Return 3 values: the string for the token,
1300 ;;; a flag for whether there was an escape char, and the position of
1301 ;;; any package delimiter.
1302 (defun read-extended-token (stream &optional (*readtable* *readtable*))
1303   (let ((first-char (read-char stream nil nil t)))
1304     (cond (first-char
1305            (multiple-value-bind (escapes colon)
1306                (internal-read-extended-token stream first-char nil)
1307              (casify-read-buffer escapes)
1308              (values (read-buffer-to-string) (not (null escapes)) colon)))
1309           (t
1310            (values "" nil nil)))))
1311
1312 ;;; for semi-external use:
1313 ;;;
1314 ;;; Read an extended token with the first character escaped. Return
1315 ;;; the string for the token.
1316 (defun read-extended-token-escaped (stream &optional (*readtable* *readtable*))
1317   (let ((first-char (read-char stream nil nil)))
1318     (cond (first-char
1319             (let ((escapes (internal-read-extended-token stream first-char t)))
1320               (casify-read-buffer escapes)
1321               (read-buffer-to-string)))
1322           (t
1323             (reader-eof-error stream "after escape")))))
1324 \f
1325 ;;;; number-reading functions
1326
1327 (defmacro digit* nil
1328   `(do ((ch char (inch-read-buffer)))
1329        ((or (eofp ch) (not (digit-char-p ch))) (setq char ch))
1330      ;; Report if at least one digit is seen.
1331      (setq one-digit t)))
1332
1333 (defmacro exponent-letterp (letter)
1334   `(memq ,letter '(#\E #\S #\F #\L #\D #\e #\s #\f #\l #\d)))
1335
1336 ;;; FIXME: It would be cleaner to have these generated automatically
1337 ;;; by compile-time code instead of having them hand-created like
1338 ;;; this. The !COLD-INIT-INTEGER-READER code below should be resurrected
1339 ;;; and tested.
1340 (defvar *integer-reader-safe-digits*
1341   #(nil nil
1342     26 17 13 11 10 9 8 8 8 7 7 7 7 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5)
1343   #!+sb-doc
1344   "the mapping of base to 'safe' number of digits to read for a fixnum")
1345 (defvar *integer-reader-base-power*
1346   #(nil nil
1347     67108864 129140163 67108864 48828125 60466176 40353607
1348     16777216 43046721 100000000 19487171 35831808 62748517 105413504 11390625
1349     16777216 24137569 34012224 47045881 64000000 85766121 113379904 6436343
1350     7962624 9765625 11881376 14348907 17210368 20511149 24300000 28629151
1351     33554432 39135393 45435424 52521875 60466176)
1352   #!+sb-doc
1353   "the largest fixnum power of the base for MAKE-INTEGER")
1354 (declaim (simple-vector *integer-reader-safe-digits*
1355                         *integer-reader-base-power*))
1356 #|
1357 (defun !cold-init-integer-reader ()
1358   (do ((base 2 (1+ base)))
1359       ((> base 36))
1360     (let ((digits
1361           (do ((fix (truncate most-positive-fixnum base)
1362                     (truncate fix base))
1363                (digits 0 (1+ digits)))
1364               ((zerop fix) digits))))
1365       (setf (aref *integer-reader-safe-digits* base)
1366             digits
1367             (aref *integer-reader-base-power* base)
1368             (expt base digits)))))
1369 |#
1370
1371 (defun make-integer ()
1372   #!+sb-doc
1373   "Minimizes bignum-fixnum multiplies by reading a 'safe' number of digits,
1374   then multiplying by a power of the base and adding."
1375   (let* ((base *read-base*)
1376          (digits-per (aref *integer-reader-safe-digits* base))
1377          (base-power (aref *integer-reader-base-power* base))
1378          (negativep nil)
1379          (number 0))
1380     (declare (type index digits-per base-power))
1381     (read-unwind-read-buffer)
1382     (let ((char (inch-read-buffer)))
1383       (cond ((char= char #\-)
1384              (setq negativep t))
1385             ((char= char #\+))
1386             (t (unread-buffer))))
1387     (loop
1388      (let ((num 0))
1389        (declare (type index num))
1390        (dotimes (digit digits-per)
1391          (let* ((ch (inch-read-buffer)))
1392            (cond ((or (eofp ch) (char= ch #\.))
1393                   (return-from make-integer
1394                                (let ((res
1395                                       (if (zerop number) num
1396                                           (+ num (* number
1397                                                     (expt base digit))))))
1398                                  (if negativep (- res) res))))
1399                  (t (setq num (+ (digit-char-p ch base)
1400                                  (the index (* num base))))))))
1401        (setq number (+ num (* number base-power)))))))
1402
1403 (defun make-float (stream)
1404   ;; Assume that the contents of *read-buffer* are a legal float, with nothing
1405   ;; else after it.
1406   (read-unwind-read-buffer)
1407   (let ((negative-fraction nil)
1408         (number 0)
1409         (divisor 1)
1410         (negative-exponent nil)
1411         (exponent 0)
1412         (float-char ())
1413         (char (inch-read-buffer)))
1414     (if (cond ((char= char #\+) t)
1415               ((char= char #\-) (setq negative-fraction t)))
1416         ;; Flush it.
1417         (setq char (inch-read-buffer)))
1418     ;; Read digits before the dot.
1419     (do* ((ch char (inch-read-buffer))
1420           (dig (digit-char-p ch) (digit-char-p ch)))
1421          ((not dig) (setq char ch))
1422       (setq number (+ (* number 10) dig)))
1423     ;; Deal with the dot, if it's there.
1424     (when (char= char #\.)
1425       (setq char (inch-read-buffer))
1426       ;; Read digits after the dot.
1427       (do* ((ch char (inch-read-buffer))
1428             (dig (and (not (eofp ch)) (digit-char-p ch))
1429                  (and (not (eofp ch)) (digit-char-p ch))))
1430            ((not dig) (setq char ch))
1431         (setq divisor (* divisor 10))
1432         (setq number (+ (* number 10) dig))))
1433     ;; Is there an exponent letter?
1434     (cond ((eofp char)
1435            ;; If not, we've read the whole number.
1436            (let ((num (make-float-aux number divisor
1437                                       *read-default-float-format*
1438                                       stream)))
1439              (return-from make-float (if negative-fraction (- num) num))))
1440           ((exponent-letterp char)
1441            (setq float-char char)
1442            ;; Build exponent.
1443            (setq char (inch-read-buffer))
1444            ;; Check leading sign.
1445            (if (cond ((char= char #\+) t)
1446                      ((char= char #\-) (setq negative-exponent t)))
1447                ;; Flush sign.
1448                (setq char (inch-read-buffer)))
1449            ;; Read digits for exponent.
1450            (do* ((ch char (inch-read-buffer))
1451                  (dig (and (not (eofp ch)) (digit-char-p ch))
1452                       (and (not (eofp ch)) (digit-char-p ch))))
1453                 ((not dig)
1454                  (setq exponent (if negative-exponent (- exponent) exponent)))
1455              (setq exponent (+ (* exponent 10) dig)))
1456            ;; Generate and return the float, depending on FLOAT-CHAR:
1457            (let* ((float-format (case (char-upcase float-char)
1458                                   (#\E *read-default-float-format*)
1459                                   (#\S 'short-float)
1460                                   (#\F 'single-float)
1461                                   (#\D 'double-float)
1462                                   (#\L 'long-float)))
1463                   (result (make-float-aux (* (expt 10 exponent) number)
1464                                           divisor float-format stream)))
1465              (return-from make-float
1466                (if negative-fraction (- result) result))))
1467           (t (bug "bad fallthrough in floating point reader")))))
1468
1469 (defun make-float-aux (number divisor float-format stream)
1470   (handler-case
1471       (coerce (/ number divisor) float-format)
1472     (type-error (c)
1473       (error 'reader-impossible-number-error
1474              :error c :stream stream
1475              :format-control "failed to build float"))))
1476
1477 (defun make-ratio (stream)
1478   ;; Assume *READ-BUFFER* contains a legal ratio. Build the number from
1479   ;; the string.
1480   ;;
1481   ;; Look for optional "+" or "-".
1482   (let ((numerator 0) (denominator 0) (char ()) (negative-number nil))
1483     (read-unwind-read-buffer)
1484     (setq char (inch-read-buffer))
1485     (cond ((char= char #\+)
1486            (setq char (inch-read-buffer)))
1487           ((char= char #\-)
1488            (setq char (inch-read-buffer))
1489            (setq negative-number t)))
1490     ;; Get numerator.
1491     (do* ((ch char (inch-read-buffer))
1492           (dig (digit-char-p ch *read-base*)
1493                (digit-char-p ch *read-base*)))
1494          ((not dig))
1495          (setq numerator (+ (* numerator *read-base*) dig)))
1496     ;; Get denominator.
1497     (do* ((ch (inch-read-buffer) (inch-read-buffer))
1498           (dig ()))
1499          ((or (eofp ch) (not (setq dig (digit-char-p ch *read-base*)))))
1500          (setq denominator (+ (* denominator *read-base*) dig)))
1501     (let ((num (handler-case
1502                    (/ numerator denominator)
1503                  (arithmetic-error (c)
1504                    (error 'reader-impossible-number-error
1505                           :error c :stream stream
1506                           :format-control "failed to build ratio")))))
1507       (if negative-number (- num) num))))
1508 \f
1509 ;;;; General reader for dispatch macros
1510
1511 (defun dispatch-char-error (stream sub-char ignore)
1512   (declare (ignore ignore))
1513   (if *read-suppress*
1514       (values)
1515       (simple-reader-error stream
1516                            "no dispatch function defined for ~S"
1517                            sub-char)))
1518
1519 (defun read-dispatch-char (stream char)
1520   ;; Read some digits.
1521   (let ((numargp nil)
1522         (numarg 0)
1523         (sub-char ()))
1524     (do* ((ch (read-char stream nil *eof-object*)
1525               (read-char stream nil *eof-object*))
1526           (dig ()))
1527          ((or (eofp ch)
1528               (not (setq dig (digit-char-p ch))))
1529           ;; Take care of the extra char.
1530           (if (eofp ch)
1531               (reader-eof-error stream "inside dispatch character")
1532               (setq sub-char (char-upcase ch))))
1533       (setq numargp t)
1534       (setq numarg (+ (* numarg 10) dig)))
1535     ;; Look up the function and call it.
1536     (let ((dpair (find char (dispatch-tables *readtable*)
1537                        :test #'char= :key #'car)))
1538       (if dpair
1539           (funcall (the function
1540                      (gethash sub-char (cdr dpair) #'dispatch-char-error))
1541                    stream sub-char (if numargp numarg nil))
1542           (simple-reader-error stream
1543                                "no dispatch table for dispatch char")))))
1544 \f
1545 ;;;; READ-FROM-STRING
1546
1547 (defun read-from-string (string &optional (eof-error-p t) eof-value
1548                                 &key (start 0) end
1549                                 preserve-whitespace)
1550   #!+sb-doc
1551   "The characters of string are successively given to the lisp reader
1552    and the lisp object built by the reader is returned. Macro chars
1553    will take effect."
1554   (declare (string string))
1555   (with-array-data ((string string :offset-var offset)
1556                     (start start)
1557                     (end end)
1558                     :check-fill-pointer t)
1559     (let ((stream (make-string-input-stream string start end)))
1560       (values (if preserve-whitespace
1561                   (%read-preserving-whitespace stream eof-error-p eof-value nil)
1562                   (read stream eof-error-p eof-value))
1563               (- (string-input-stream-current stream) offset)))))
1564 \f
1565 ;;;; PARSE-INTEGER
1566
1567 (defun parse-integer (string &key (start 0) end (radix 10) junk-allowed)
1568   #!+sb-doc
1569   "Examine the substring of string delimited by start and end
1570   (default to the beginning and end of the string)  It skips over
1571   whitespace characters and then tries to parse an integer. The
1572   radix parameter must be between 2 and 36."
1573   (macrolet ((parse-error (format-control)
1574                `(error 'simple-parse-error
1575                        :format-control ,format-control
1576                        :format-arguments (list string))))
1577     (with-array-data ((string string :offset-var offset)
1578                       (start start)
1579                       (end end)
1580                       :check-fill-pointer t)
1581       (let ((index (do ((i start (1+ i)))
1582                        ((= i end)
1583                         (if junk-allowed
1584                             (return-from parse-integer (values nil end))
1585                             (parse-error "no non-whitespace characters in string ~S.")))
1586                      (declare (fixnum i))
1587                      (unless (whitespace[1]p (char string i)) (return i))))
1588             (minusp nil)
1589             (found-digit nil)
1590             (result 0))
1591         (declare (fixnum index))
1592         (let ((char (char string index)))
1593           (cond ((char= char #\-)
1594                  (setq minusp t)
1595                  (incf index))
1596                 ((char= char #\+)
1597                  (incf index))))
1598         (loop
1599          (when (= index end) (return nil))
1600          (let* ((char (char string index))
1601                 (weight (digit-char-p char radix)))
1602            (cond (weight
1603                   (setq result (+ weight (* result radix))
1604                         found-digit t))
1605                  (junk-allowed (return nil))
1606                  ((whitespace[1]p char)
1607                   (loop
1608                    (incf index)
1609                    (when (= index end) (return))
1610                    (unless (whitespace[1]p (char string index))
1611                       (parse-error "junk in string ~S")))
1612                   (return nil))
1613                  (t
1614                   (parse-error "junk in string ~S"))))
1615          (incf index))
1616         (values
1617          (if found-digit
1618              (if minusp (- result) result)
1619              (if junk-allowed
1620                  nil
1621                  (parse-error "no digits in string ~S")))
1622          (- index offset))))))
1623 \f
1624 ;;;; reader initialization code
1625
1626 (defun !reader-cold-init ()
1627   (!cold-init-constituent-trait-table)
1628   (!cold-init-standard-readtable)
1629   ;; FIXME: This was commented out, but should probably be restored.
1630   #+nil (!cold-init-integer-reader))
1631 \f
1632 (def!method print-object ((readtable readtable) stream)
1633   (print-unreadable-object (readtable stream :identity t :type t)))