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 ;;;; FIXME: I'm not sure where to put this. -- WHN 19990817
19 (deftype sb!vm:word () `(unsigned-byte ,sb!vm:n-word-bits))
21 ;;;; implementation-dependent DEFTYPEs
23 ;;; Make DOUBLE-FLOAT a synonym for LONG-FLOAT, SINGLE-FLOAT for
24 ;;; SHORT-FLOAT. This is expanded before the translator gets a chance,
25 ;;; so we will get precedence.
27 (setf (info :type :kind 'long-float) :defined)
29 (sb!xc:deftype long-float (&optional low high)
30 `(double-float ,low ,high))
31 (setf (info :type :kind 'short-float) :defined)
32 (sb!xc:deftype short-float (&optional low high)
33 `(single-float ,low ,high))
35 ;;; an index into an integer
36 (sb!xc:deftype bit-index () `(integer 0 ,most-positive-fixnum))
38 ;;; worst-case values for float attributes
39 (sb!xc:deftype float-exponent ()
40 #!-long-float 'double-float-exponent
41 #!+long-float 'long-float-exponent)
42 (sb!xc:deftype float-digits ()
43 #!-long-float `(integer 0 ,sb!vm:double-float-digits)
44 #!+long-float `(integer 0 ,sb!vm:long-float-digits))
45 (sb!xc:deftype float-radix () '(integer 2 2))
48 (sb!xc:deftype boole-code () '(unsigned-byte 4))
50 ;;; a byte specifier (as generated by BYTE)
51 (sb!xc:deftype byte-specifier () 'cons)
53 ;;; result of CHAR-INT
54 (sb!xc:deftype char-int () 'char-code)
56 ;;; PATHNAME pieces, as returned by the PATHNAME-xxx functions
57 (sb!xc:deftype pathname-host () '(or sb!impl::host null))
58 (sb!xc:deftype pathname-device ()
59 '(or simple-string (member nil :unspecific)))
60 (sb!xc:deftype pathname-directory () 'list)
61 (sb!xc:deftype pathname-name ()
62 '(or simple-string sb!impl::pattern (member nil :unspecific :wild)))
63 (sb!xc:deftype pathname-type ()
64 '(or simple-string sb!impl::pattern (member nil :unspecific :wild)))
65 (sb!xc:deftype pathname-version ()
66 '(or integer (member nil :newest :wild :unspecific)))
68 ;;; internal time format. (Note: not a FIXNUM, ouch..)
69 (sb!xc:deftype internal-time () 'unsigned-byte)
71 (sb!xc:deftype bignum-element-type () `(unsigned-byte ,sb!vm:n-word-bits))
72 (sb!xc:deftype bignum-type () 'bignum)
73 (sb!xc:deftype bignum-index () 'index)
75 ;;;; hooks into the type system
77 (sb!xc:deftype unboxed-array (&optional dims)
78 (collect ((types (list 'or)))
79 (dolist (type *specialized-array-element-types*)
80 (when (subtypep type '(or integer character float (complex float)))
81 (types `(array ,type ,dims))))
84 (sb!xc:deftype simple-unboxed-array (&optional dims)
85 (collect ((types (list 'or)))
86 (dolist (type *specialized-array-element-types*)
87 (when (subtypep type '(or integer character float (complex float)))
88 (types `(simple-array ,type ,dims))))
91 ;;; Return the symbol that describes the format of FLOAT.
92 (declaim (ftype (function (float) symbol) float-format-name))
93 (defun float-format-name (x)
95 (single-float 'single-float)
96 (double-float 'double-float)
97 #!+long-float (long-float 'long-float)))
99 ;;; This function is called when the type code wants to find out how
100 ;;; an array will actually be implemented. We set the
101 ;;; SPECIALIZED-ELEMENT-TYPE to correspond to the actual
102 ;;; specialization used in this implementation.
103 (declaim (ftype (function (array-type) array-type) specialize-array-type))
104 (defun specialize-array-type (type)
105 (let ((eltype (array-type-element-type type)))
106 (setf (array-type-specialized-element-type type)
107 (if (or (eq eltype *wild-type*)
108 ;; This is slightly dubious, but not as dubious as
109 ;; assuming that the upgraded-element-type should be
110 ;; equal to T, given the way that the AREF
111 ;; DERIVE-TYPE optimizer works. -- CSR, 2002-08-19
112 (unknown-type-p eltype))
114 (dolist (stype-name *specialized-array-element-types*
116 ;; FIXME: Mightn't it be better to have
117 ;; *SPECIALIZED-ARRAY-ELEMENT-TYPES* be stored as precalculated
118 ;; SPECIFIER-TYPE results, instead of having to calculate
119 ;; them on the fly this way? (Call the new array
120 ;; *SPECIALIZED-ARRAY-ELEMENT-SPECIFIER-TYPES* or something..)
121 (let ((stype (specifier-type stype-name)))
122 (when (csubtypep eltype stype)
126 ;;; Return the most specific integer type that can be quickly checked that
127 ;;; includes the given type.
128 (defun containing-integer-type (subtype)
129 (dolist (type '(fixnum
133 (error "~S isn't an integer type?" subtype))
134 (when (csubtypep subtype (specifier-type type))
137 ;;; If TYPE has a CHECK-xxx template, but doesn't have a corresponding
138 ;;; PRIMITIVE-TYPE, then return the template's name. Otherwise, return NIL.
139 (defun hairy-type-check-template-name (type)
140 (declare (type ctype type))
143 (if (type= type (specifier-type 'cons))
147 (if (type= type (specifier-type 'symbol))
151 (cond ((type= type (specifier-type 'fixnum))
153 ((type= type (specifier-type '(signed-byte 32)))
154 'sb!c:check-signed-byte-32)
155 ((type= type (specifier-type '(unsigned-byte 32)))
156 'sb!c:check-unsigned-byte-32)