1 ;;;; This file contains implementation-dependent parts of the type
2 ;;;; support code. This is stuff which deals with the mapping from
3 ;;;; types defined in Common Lisp to types actually supported by an
6 ;;;; This software is part of the SBCL system. See the README file for
9 ;;;; This software is derived from the CMU CL system, which was
10 ;;;; written at Carnegie Mellon University and released into the
11 ;;;; public domain. The software is in the public domain and is
12 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
13 ;;;; files for more information.
15 (in-package "SB!KERNEL")
17 (/show0 "vm-type.lisp 17")
19 (!begin-collecting-cold-init-forms)
21 ;;;; FIXME: I'm not sure where to put this. -- WHN 19990817
23 (deftype sb!vm:word () `(unsigned-byte ,sb!vm:n-word-bits))
25 ;;;; implementation-dependent DEFTYPEs
27 ;;; Make DOUBLE-FLOAT a synonym for LONG-FLOAT, SINGLE-FLOAT for
28 ;;; SHORT-FLOAT. This is expanded before the translator gets a chance,
29 ;;; so we will get precedence.
31 (setf (info :type :kind 'long-float) :defined)
33 (sb!xc:deftype long-float (&optional low high)
34 `(double-float ,low ,high))
35 (setf (info :type :kind 'short-float) :defined)
36 (sb!xc:deftype short-float (&optional low high)
37 `(single-float ,low ,high))
39 ;;; an index into an integer
40 (sb!xc:deftype bit-index () `(integer 0 ,most-positive-fixnum))
42 ;;; worst-case values for float attributes
43 (sb!xc:deftype float-exponent ()
44 #!-long-float 'double-float-exponent
45 #!+long-float 'long-float-exponent)
46 (sb!xc:deftype float-digits ()
47 #!-long-float `(integer 0 ,sb!vm:double-float-digits)
48 #!+long-float `(integer 0 ,sb!vm:long-float-digits))
49 (sb!xc:deftype float-radix () '(integer 2 2))
52 (sb!xc:deftype boole-code () '(unsigned-byte 4))
54 ;;; a byte specifier (as generated by BYTE)
55 (sb!xc:deftype byte-specifier () 'cons)
57 ;;; result of CHAR-INT
58 (sb!xc:deftype char-int () 'char-code)
60 ;;; PATHNAME pieces, as returned by the PATHNAME-xxx functions
61 (sb!xc:deftype pathname-host () '(or sb!impl::host null))
62 (sb!xc:deftype pathname-device ()
63 '(or simple-string (member nil :unspecific)))
64 (sb!xc:deftype pathname-directory () 'list)
65 (sb!xc:deftype pathname-name ()
66 '(or simple-string sb!impl::pattern (member nil :unspecific :wild)))
67 (sb!xc:deftype pathname-type ()
68 '(or simple-string sb!impl::pattern (member nil :unspecific :wild)))
69 (sb!xc:deftype pathname-version ()
70 '(or integer (member nil :newest :wild :unspecific)))
72 ;;; internal time format. (Note: not a FIXNUM, ouch..)
73 (sb!xc:deftype internal-time () 'unsigned-byte)
75 (sb!xc:deftype bignum-element-type () `(unsigned-byte ,sb!vm:n-word-bits))
76 (sb!xc:deftype bignum-type () 'bignum)
77 (sb!xc:deftype bignum-index () 'index)
79 ;;;; hooks into the type system
81 ;;; the kinds of specialized array that actually exist in this implementation
82 (defvar *specialized-array-element-types*)
84 (setf *specialized-array-element-types*
95 (complex single-float)
96 (complex double-float)
97 #!+long-float (complex long-float)
101 #!+long-float long-float)))
103 (sb!xc:deftype unboxed-array (&optional dims)
104 (collect ((types (list 'or)))
105 (dolist (type *specialized-array-element-types*)
106 (when (subtypep type '(or integer character float (complex float)))
107 (types `(array ,type ,dims))))
110 (sb!xc:deftype simple-unboxed-array (&optional dims)
111 (collect ((types (list 'or)))
112 (dolist (type *specialized-array-element-types*)
113 (when (subtypep type '(or integer character float (complex float)))
114 (types `(simple-array ,type ,dims))))
117 ;;; Return the symbol that describes the format of FLOAT.
118 (declaim (ftype (function (float) symbol) float-format-name))
119 (defun float-format-name (x)
121 (single-float 'single-float)
122 (double-float 'double-float)
123 #!+long-float (long-float 'long-float)))
125 ;;; This function is called when the type code wants to find out how
126 ;;; an array will actually be implemented. We set the
127 ;;; SPECIALIZED-ELEMENT-TYPE to correspond to the actual
128 ;;; specialization used in this implementation.
129 (declaim (ftype (function (array-type) array-type) specialize-array-type))
130 (defun specialize-array-type (type)
131 (let ((eltype (array-type-element-type type)))
132 (setf (array-type-specialized-element-type type)
133 (if (eq eltype *wild-type*)
135 (dolist (stype-name *specialized-array-element-types*
137 ;; FIXME: Mightn't it be better to have
138 ;; *SPECIALIZED-ARRAY-ELEMENT-TYPES* be stored as precalculated
139 ;; SPECIFIER-TYPE results, instead of having to calculate
140 ;; them on the fly this way? (Call the new array
141 ;; *SPECIALIZED-ARRAY-ELEMENT-SPECIFIER-TYPES* or something..)
142 (let ((stype (specifier-type stype-name)))
143 (when (csubtypep eltype stype)
147 ;;; Return the most specific integer type that can be quickly checked that
148 ;;; includes the given type.
149 (defun containing-integer-type (subtype)
150 (dolist (type '(fixnum
154 (error "~S isn't an integer type?" subtype))
155 (when (csubtypep subtype (specifier-type type))
158 ;;; If TYPE has a CHECK-xxx template, but doesn't have a corresponding
159 ;;; PRIMITIVE-TYPE, then return the template's name. Otherwise, return NIL.
160 (defun hairy-type-check-template-name (type)
161 (declare (type ctype type))
164 (if (type= type (specifier-type 'cons))
168 (if (type= type (specifier-type 'symbol))
172 (cond ((type= type (specifier-type 'fixnum))
174 ((type= type (specifier-type '(signed-byte 32)))
175 'sb!c:check-signed-byte-32)
176 ((type= type (specifier-type '(unsigned-byte 32)))
177 'sb!c:check-unsigned-byte-32)
184 (!defun-from-collected-cold-init-forms !vm-type-cold-init)
186 (/show0 "vm-type.lisp end of file")