Avoid use of private typedefs
[sbcl.git] / src / code / deftypes-for-target.lisp
blobee21f93c7661790ddf24255cf46a869f6a68bfc9
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
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.
12 (in-package "SB!KERNEL")
14 (/show0 "deftypes-for-target.lisp 14")
16 ;;;; Now that DEFTYPE is set up, any pending requests for it can
17 ;;;; be honored.
19 #+sb-xc-host
20 (progn
21 (/show "about to force delayed DEF!TYPEs")
22 (force-delayed-def!types)
23 (/show "done forcing delayed DEF!TYPEs"))
25 ;;;; standard types
27 (sb!xc:deftype boolean () '(member t nil))
29 (sb!xc:deftype mod (n)
30 (unless (and (integerp n) (> n 0))
31 (error "bad modulus specified for MOD type specifier: ~
32 ~/sb!impl:print-type-specifier/"
33 n))
34 `(integer 0 ,(1- n)))
36 (sb!xc:deftype signed-byte (&optional s)
37 (cond ((eq s '*) 'integer)
38 ((and (integerp s) (> s 0))
39 (let ((bound (ash 1 (1- s))))
40 `(integer ,(- bound) ,(1- bound))))
42 (error "bad size specified for SIGNED-BYTE type specifier: ~
43 ~/sb!impl:print-type-specifier/"
44 s))))
46 (sb!xc:deftype unsigned-byte (&optional s)
47 (cond ((eq s '*) '(integer 0))
48 ((and (integerp s) (> s 0))
49 `(integer 0 ,(1- (ash 1 s))))
51 (error "bad size specified for UNSIGNED-BYTE type specifier: ~
52 ~/sb!impl:print-type-specifier/"
53 s))))
55 ;;; ANSI got UNSIGNED-BYTE wrong, prohibiting (UNSIGNED-BYTE 0).
56 ;;; Since this is actually a substantial impediment to clarity...
57 (sb!xc:deftype unsigned-byte* (&optional s)
58 (cond
59 ((eq s '*) '(integer 0))
60 ((zerop s) '(integer 0 0))
61 (t `(unsigned-byte ,s))))
63 (sb!xc:deftype bit () '(integer 0 1))
65 (sb!xc:deftype atom () '(not cons))
67 (sb!xc:deftype base-char ()
68 '(character-set ((0 . #.(1- base-char-code-limit)))))
70 (sb!xc:deftype extended-char ()
71 "Type of CHARACTERs that aren't BASE-CHARs."
72 '(and character (not base-char)))
74 (sb!xc:deftype standard-char ()
75 "Type corresponding to the characters required by the standard."
76 '(member
77 #\Newline #\Space #\! #\" #\# #\$ #\% #\& #\' #\( #\) #\* #\+ #\,
78 #\- #\. #\/ #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\: #\; #\< #\=
79 #\> #\? #\@ #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
80 #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\[ #\\ #\]
81 #\^ #\_ #\` #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
82 #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{
83 #\| #\} #\~))
85 (sb!xc:deftype keyword ()
86 ;; Defining this as (AND SYMBOL ..) lets (SUBTYPEP 'KEYWORD 'SYMBOL)=>T,T.
87 '(and symbol (satisfies keywordp)))
89 (sb!xc:deftype eql (n) `(member ,n))
91 (sb!xc:deftype vector (&optional element-type size)
92 `(array ,element-type (,size)))
94 (sb!xc:deftype simple-vector (&optional size)
95 `(simple-array t (,size)))
97 (sb!xc:deftype base-string (&optional size)
98 `(array base-char (,size)))
99 (sb!xc:deftype simple-base-string (&optional size)
100 `(simple-array base-char (,size)))
101 (sb!xc:deftype string (&optional size)
102 `(or (array character (,size))
103 (array nil (,size))
104 (base-string ,size)))
105 (sb!xc:deftype simple-string (&optional size)
106 `(or (simple-array character (,size))
107 (simple-array nil (,size))
108 (simple-base-string ,size)))
109 ;;; On Unicode builds, SIMPLE-CHARACTER-STRING is a builtin type.
110 ;;; For non-Unicode it is convenient to be able to use the type name
111 ;;; as an alias of SIMPLE-BASE-STRING.
112 #!-sb-unicode
113 (sb!xc:deftype simple-character-string (&optional size)
114 `(simple-base-string ,size))
116 (sb!xc:deftype bit-vector (&optional size)
117 `(array bit (,size)))
119 (sb!xc:deftype simple-bit-vector (&optional size)
120 `(simple-array bit (,size)))
122 (sb!xc:deftype compiled-function ()
123 '(and function
124 #!+sb-fasteval (not sb!interpreter:interpreted-function)
125 #!+sb-eval (not sb!eval:interpreted-function)))
127 ;;;; some private types that we use in defining the standard functions,
128 ;;;; or implementing declarations in standard compiler transforms
130 ;;; semistandard types
131 (sb!xc:deftype generalized-boolean () t)
133 (sb!xc:deftype format-control ()
134 '(or string function))
136 (sb!xc:deftype condition-designator-head ()
137 '(or format-control symbol condition sb!pcl::condition-class))
139 (sb!xc:deftype restart-designator ()
140 '(or (and symbol (not null)) restart))
142 ;; FIXME: this fails to consider an EQL-SPECIALIZER a TYPE-SPECIFIER.
143 ;; SPECIFIER-TYPE has the explicit-check declaration, so that kinda works,
144 ;; because it doesn't check against this specifier.
145 ;; Somewhat miraculously, SB-C::CANONIZED-DECL-SPEC also works, so this works:
146 ;; (lambda (x) (declare (#.(sb-mop::intern-eql-specializer 'serial) x)) x)
147 ;; But I suspect this must be reverted to (OR LIST SYMBOL INSTANCE)
148 ;; or we have to hack EQL-SPECIALIZER into 'condition-boot', sad as that is.
149 (sb!xc:deftype type-specifier ()
150 '(or list symbol classoid class))
152 ;;; array rank, total size...
153 (sb!xc:deftype array-rank () `(integer 0 (,sb!xc:array-rank-limit)))
154 (sb!xc:deftype array-total-size ()
155 `(integer 0 (,sb!xc:array-total-size-limit)))
157 ;;; something legal in an evaluated context
158 ;;; FIXME: could probably go away
159 (sb!xc:deftype form () t)
161 (sb!xc:deftype string-designator () '(or string symbol character))
163 ;;; a thing legal in places where we want the name of a file
164 (sb!xc:deftype filename () '(or string pathname))
166 ;;; legal args to pathname functions
167 (sb!xc:deftype pathname-designator ()
168 '(or string pathname #+sb-xc-host stream #-sb-xc-host file-stream))
169 (sb!xc:deftype logical-host-designator ()
170 '(or host string))
172 (sb!xc:deftype package-designator () '(or string-designator package))
173 ;;; a designator for a list of symbols
174 (sb!xc:deftype symbols-designator () '(or list symbol))
176 ;;; a thing returned by the irrational functions. We assume that they
177 ;;; never compute a rational result.
178 (sb!xc:deftype irrational ()
179 '(or float (complex float)))
181 ;;; character components
182 (sb!xc:deftype char-code () `(integer 0 (,sb!xc:char-code-limit)))
184 ;;; a consed sequence result. If a vector, is a simple array.
185 (sb!xc:deftype consed-sequence ()
186 '(or (simple-array * (*)) list extended-sequence))
188 ;;; the :END arg to a sequence
189 (sb!xc:deftype sequence-end () '(or null index))
191 ;;; the :COUNT arg to a sequence
192 (sb!xc:deftype sequence-count ()
193 `(or null integer))
195 ;;; a valid argument to a stream function
196 (sb!xc:deftype stream-designator () '(or stream (member nil t)))
198 ;;; something valid as the :EXTERNAL-FORMAT argument to OPEN, LOAD,
199 ;;; COMPILE-FILE and friends.
200 (sb!xc:deftype external-format-designator ()
201 '(or keyword (cons keyword)))
203 ;;; a thing that can be passed to FUNCALL & friends
205 ;;; FIXME: should be FUNCTION-DESIGNATOR?
206 (sb!xc:deftype callable () '(or function symbol))
208 ;;; decomposing floats into integers
209 (sb!xc:deftype single-float-exponent ()
210 `(integer ,(- sb!vm:single-float-normal-exponent-min
211 sb!vm:single-float-bias
212 sb!vm:single-float-digits)
213 ,(- sb!vm:single-float-normal-exponent-max
214 sb!vm:single-float-bias)))
215 (sb!xc:deftype double-float-exponent ()
216 `(integer ,(- sb!vm:double-float-normal-exponent-min
217 sb!vm:double-float-bias
218 sb!vm:double-float-digits)
219 ,(- sb!vm:double-float-normal-exponent-max
220 sb!vm:double-float-bias)))
221 (sb!xc:deftype single-float-int-exponent ()
222 `(integer ,(- sb!vm:single-float-normal-exponent-min
223 sb!vm:single-float-bias
224 (* sb!vm:single-float-digits 2))
225 ,(- sb!vm:single-float-normal-exponent-max
226 sb!vm:single-float-bias
227 sb!vm:single-float-digits)))
228 (sb!xc:deftype double-float-int-exponent ()
229 `(integer ,(- sb!vm:double-float-normal-exponent-min sb!vm:double-float-bias
230 (* sb!vm:double-float-digits 2))
231 ,(- sb!vm:double-float-normal-exponent-max sb!vm:double-float-bias
232 sb!vm:double-float-digits)))
233 (sb!xc:deftype single-float-significand ()
234 `(integer 0 (,(ash 1 sb!vm:single-float-digits))))
235 (sb!xc:deftype double-float-significand ()
236 `(integer 0 (,(ash 1 sb!vm:double-float-digits))))
238 (/show0 "deftypes-for-target.lisp end of file")