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")
20 (!begin-collecting-cold-init-forms)
22 ;;;; FIXME: I'm not sure where to put this. -- WHN 19990817
24 (deftype sb!vm:word () `(unsigned-byte ,sb!vm:word-bits))
26 ;;;; implementation-dependent DEFTYPEs
28 ;;; Make DOUBLE-FLOAT a synonym for LONG-FLOAT, SINGLE-FLOAT for SHORT-FLOAT.
29 ;;; This is expanded before the translator gets a chance, so we will get
32 (setf (info :type :kind 'long-float) :defined)
34 (sb!xc:deftype long-float (&optional low high)
35 `(double-float ,low ,high))
36 (setf (info :type :kind 'short-float) :defined)
37 (sb!xc:deftype short-float (&optional low high)
38 `(single-float ,low ,high))
40 ;;; an index into an integer
41 (sb!xc:deftype bit-index () `(integer 0 ,most-positive-fixnum))
43 ;;; worst-case values for float attributes
44 (sb!xc:deftype float-exponent ()
45 #!-long-float 'double-float-exponent
46 #!+long-float 'long-float-exponent)
47 (sb!xc:deftype float-digits ()
48 #!-long-float `(integer 0 ,sb!vm:double-float-digits)
49 #!+long-float `(integer 0 ,sb!vm:long-float-digits))
50 (sb!xc:deftype float-radix () '(integer 2 2))
53 (sb!xc:deftype boole-code () '(unsigned-byte 4))
55 ;;; a byte specifier (as generated by BYTE)
56 (sb!xc:deftype byte-specifier () 'cons)
58 ;;; result of CHAR-INT
59 (sb!xc:deftype char-int () 'char-code)
61 ;;; PATHNAME pieces, as returned by the PATHNAME-xxx functions
62 (sb!xc:deftype pathname-host () '(or sb!impl::host null))
63 (sb!xc:deftype pathname-device ()
64 '(or simple-string (member nil :unspecific)))
65 (sb!xc:deftype pathname-directory () 'list)
66 (sb!xc:deftype pathname-name ()
67 '(or simple-string sb!impl::pattern (member nil :unspecific :wild)))
68 (sb!xc:deftype pathname-type ()
69 '(or simple-string sb!impl::pattern (member nil :unspecific :wild)))
70 (sb!xc:deftype pathname-version ()
71 '(or integer (member nil :newest :wild :unspecific)))
73 ;;; internal time format. (Note: not a FIXNUM, ouch..)
74 (sb!xc:deftype internal-time () 'unsigned-byte)
76 (sb!xc:deftype bignum-element-type () `(unsigned-byte ,sb!vm:word-bits))
77 (sb!xc:deftype bignum-type () 'bignum)
78 (sb!xc:deftype bignum-index () 'index)
80 ;;;; hooks into the type system
82 ;;; the kinds of specialized array that actually exist in this implementation
83 (defvar *specialized-array-element-types*)
85 (setf *specialized-array-element-types*
96 (complex single-float)
97 (complex double-float)
98 #!+long-float (complex long-float)
102 #!+long-float long-float)))
104 (sb!xc:deftype unboxed-array (&optional dims)
105 (collect ((types (list 'or)))
106 (dolist (type *specialized-array-element-types*)
107 (when (subtypep type '(or integer character float (complex float)))
108 (types `(array ,type ,dims))))
111 (sb!xc:deftype simple-unboxed-array (&optional dims)
112 (collect ((types (list 'or)))
113 (dolist (type *specialized-array-element-types*)
114 (when (subtypep type '(or integer character float (complex float)))
115 (types `(simple-array ,type ,dims))))
118 ;;; Return the symbol that describes the format of FLOAT.
119 (declaim (ftype (function (float) symbol) float-format-name))
120 (defun float-format-name (x)
122 (single-float 'single-float)
123 (double-float 'double-float)
124 #!+long-float (long-float 'long-float)))
126 ;;; This function is called when the type code wants to find out how
127 ;;; an array will actually be implemented. We set the
128 ;;; Specialized-Element-Type to correspond to the actual
129 ;;; specialization used in this implementation.
130 (declaim (ftype (function (array-type) array-type) specialize-array-type))
131 (defun specialize-array-type (type)
132 (let ((eltype (array-type-element-type type)))
133 (setf (array-type-specialized-element-type type)
134 (if (eq eltype *wild-type*)
136 (dolist (stype-name *specialized-array-element-types*
137 ;; FIXME: Use *UNIVERSAL-TYPE* here?
139 ;; FIXME: Mightn't it be better to have
140 ;; *SPECIALIZED-ARRAY-ELEMENT-TYPES* be stored as precalculated
141 ;; SPECIFIER-TYPE results, instead of having to calculate
142 ;; them on the fly this way? (Call the new array
143 ;; *SPECIALIZED-ARRAY-ELEMENT-SPECIFIER-TYPES* or something..)
144 (let ((stype (specifier-type stype-name)))
145 (when (csubtypep eltype stype)
149 ;;; Return the most specific integer type that can be quickly checked that
150 ;;; includes the given type.
151 (defun containing-integer-type (subtype)
152 (dolist (type '(fixnum
156 (error "~S isn't an integer type?" subtype))
157 (when (csubtypep subtype (specifier-type type))
160 ;;; If Type has a CHECK-xxx template, but doesn't have a corresponding
161 ;;; primitive-type, then return the template's name. Otherwise, return NIL.
162 (defun hairy-type-check-template-name (type)
163 (declare (type ctype type))
166 (case (named-type-name type)
167 (cons 'sb!c:check-cons)
168 (symbol 'sb!c:check-symbol)
171 (cond ((type= type (specifier-type 'fixnum))
173 ((type= type (specifier-type '(signed-byte 32)))
174 'sb!c:check-signed-byte-32)
175 ((type= type (specifier-type '(unsigned-byte 32)))
176 'sb!c:check-unsigned-byte-32)
179 'sb!c:check-function)
183 (!defun-from-collected-cold-init-forms !vm-type-cold-init)