1 ;;;; definitions of types for the target (output of the compiler)
3 ;;;; This software is part of the SBCL system. See the README file for
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.
12 (in-package "SB!KERNEL")
17 ;;;; Now that DEFTYPE is set up, any pending requests for it can
22 (/show "about to force delayed DEF!TYPEs")
23 (force-delayed-def!types)
24 (/show "done forcing delayed DEF!TYPEs"))
28 (sb!xc:deftype boolean () '(member t nil))
30 (sb!xc:deftype mod (n)
31 (unless (and (integerp n) (> n 0))
32 (error "bad modulus specified for MOD type specifier: ~S" n))
35 (sb!xc:deftype signed-byte (&optional s)
36 (cond ((eq s '*) 'integer)
37 ((and (integerp s) (> s 1))
38 (let ((bound (ash 1 (1- s))))
39 `(integer ,(- bound) ,(1- bound))))
41 (error "bad size specified for SIGNED-BYTE type specifier: ~S" s))))
43 (sb!xc:deftype unsigned-byte (&optional s)
44 (cond ((eq s '*) '(integer 0))
45 ((and (integerp s) (> s 0))
46 `(integer 0 ,(1- (ash 1 s))))
48 (error "bad size specified for UNSIGNED-BYTE type specifier: ~S" s))))
50 (sb!xc:deftype bit () '(integer 0 1))
52 (sb!xc:deftype compiled-function () 'function)
54 (sb!xc:deftype atom () '(not cons))
56 (sb!xc:deftype extended-char ()
58 "Type of characters that aren't base-char's. None in CMU CL."
59 '(and character (not base-char)))
61 (sb!xc:deftype standard-char ()
63 "Type corresponding to the characters required by the standard."
65 #\NEWLINE #\SPACE #\! #\" #\# #\$ #\% #\& #\' #\( #\) #\* #\+ #\,
66 #\- #\. #\/ #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\: #\; #\< #\=
67 #\> #\? #\@ #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
68 #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\[ #\\ #\]
69 #\^ #\_ #\` #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
70 #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{
73 ;;; FIXME: Would type inference be able to get more traction on this
74 ;;; if it were defined as (AND SYMBOL (SATISFIES KEYWORDP))?
75 (sb!xc:deftype keyword ()
77 "Type for any keyword symbol."
78 '(satisfies keywordp))
80 (sb!xc:deftype eql (n) `(member ,n))
82 (sb!xc:deftype vector (&optional element-type size)
83 `(array ,element-type (,size)))
85 (sb!xc:deftype simple-vector (&optional size)
86 `(simple-array t (,size)))
88 (sb!xc:deftype base-string (&optional size)
89 `(array base-char (,size)))
90 (sb!xc:deftype simple-base-string (&optional size)
91 `(simple-array base-char (,size)))
92 (sb!xc:deftype string (&optional size)
93 `(or (array character (,size))
95 (sb!xc:deftype simple-string (&optional size)
96 `(or (simple-array character (,size))
97 (simple-base-string ,size)))
99 (sb!xc:deftype bit-vector (&optional size)
100 `(array bit (,size)))
102 (sb!xc:deftype simple-bit-vector (&optional size)
103 `(simple-array bit (,size)))
105 ;;;; some private types that we use in defining the standard functions
108 (sb!xc:deftype type-specifier () '(or list symbol sb!xc:class))
110 ;;; array rank, total size...
111 (sb!xc:deftype array-rank () `(integer 0 (,sb!xc:array-rank-limit)))
112 (sb!xc:deftype array-total-size ()
113 `(integer 0 (,sb!xc:array-total-size-limit)))
115 ;;; something legal in an evaluated context
116 ;;; FIXME: could probably go away
117 (sb!xc:deftype form () 't)
119 ;;; Maclisp compatibility...
120 ;;; FIXME: should be STRING-DESIGNATOR (the term used in the ANSI spec)
121 (sb!xc:deftype stringable () '(or string symbol character))
123 ;;; a thing legal in places where we want the name of a file
124 (sb!xc:deftype filename () '(or string pathname))
126 ;;; a legal arg to pathname functions
127 (sb!xc:deftype pathname-designator ()
128 '(or string pathname stream))
130 ;;; a thing returned by the irrational functions. We assume that they
131 ;;; never compute a rational result.
132 (sb!xc:deftype irrational ()
133 '(or float (complex float)))
135 ;;; character components
136 (sb!xc:deftype char-code () `(integer 0 (,char-code-limit)))
138 ;;; a consed sequence result. If a vector, is a simple array.
139 (sb!xc:deftype consed-sequence () '(or list (simple-array * (*))))
141 ;;; the :END arg to a sequence
142 (sb!xc:deftype sequence-end () '(or null index))
144 ;;; a valid argument to a stream function
146 ;;; FIXME: should probably be STREAM-DESIGNATOR, after the term
147 ;;; used in the ANSI spec (if this is in fact exactly the same thing)
148 (sb!xc:deftype streamlike () '(or stream (member nil t)))
150 ;;; a thing that can be passed to FUNCALL & friends
152 ;;; FIXME: should be FUNCTION-DESIGNATOR?
153 (sb!xc:deftype callable () '(or function symbol))
155 ;;; decomposing floats into integers
156 (sb!xc:deftype single-float-exponent ()
157 `(integer ,(- sb!vm:single-float-normal-exponent-min
158 sb!vm:single-float-bias
159 sb!vm:single-float-digits)
160 ,(- sb!vm:single-float-normal-exponent-max
161 sb!vm:single-float-bias)))
162 (sb!xc:deftype double-float-exponent ()
163 `(integer ,(- sb!vm:double-float-normal-exponent-min
164 sb!vm:double-float-bias
165 sb!vm:double-float-digits)
166 ,(- sb!vm:double-float-normal-exponent-max
167 sb!vm:double-float-bias)))
168 (sb!xc:deftype single-float-int-exponent ()
169 `(integer ,(- sb!vm:single-float-normal-exponent-min
170 sb!vm:single-float-bias
171 (* sb!vm:single-float-digits 2))
172 ,(- sb!vm:single-float-normal-exponent-max
173 sb!vm:single-float-bias
174 sb!vm:single-float-digits)))
175 (sb!xc:deftype double-float-int-exponent ()
176 `(integer ,(- sb!vm:double-float-normal-exponent-min sb!vm:double-float-bias
177 (* sb!vm:double-float-digits 2))
178 ,(- sb!vm:double-float-normal-exponent-max sb!vm:double-float-bias
179 sb!vm:double-float-digits)))
180 (sb!xc:deftype single-float-significand ()
181 `(integer 0 (,(ash 1 sb!vm:single-float-digits))))
182 (sb!xc:deftype double-float-significand ()
183 `(integer 0 (,(ash 1 sb!vm:double-float-digits))))