run-program: support I/O redirection to binary streams on win32.
[sbcl.git] / src / code / deftypes-for-target.lisp
blobcea80ec1ecdcbe59a077cea38b6ebe813a99802a
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: ~S" n))
32 `(integer 0 ,(1- n)))
34 (sb!xc:deftype signed-byte (&optional s)
35 (cond ((eq s '*) 'integer)
36 ((and (integerp s) (> s 0))
37 (let ((bound (ash 1 (1- s))))
38 `(integer ,(- bound) ,(1- bound))))
40 (error "bad size specified for SIGNED-BYTE type specifier: ~S" s))))
42 (sb!xc:deftype unsigned-byte (&optional s)
43 (cond ((eq s '*) '(integer 0))
44 ((and (integerp s) (> s 0))
45 `(integer 0 ,(1- (ash 1 s))))
47 (error "bad size specified for UNSIGNED-BYTE type specifier: ~S" s))))
49 ;;; ANSI got UNSIGNED-BYTE wrong, prohibiting (UNSIGNED-BYTE 0).
50 ;;; Since this is actually a substantial impediment to clarity...
51 (sb!xc:deftype unsigned-byte* (&optional s)
52 (cond
53 ((eq s '*) '(integer 0))
54 ((zerop s) '(integer 0 0))
55 (t `(unsigned-byte ,s))))
57 (sb!xc:deftype bit () '(integer 0 1))
59 (sb!xc:deftype atom () '(not cons))
61 (sb!xc:deftype base-char ()
62 '(character-set ((0 . #.(1- base-char-code-limit)))))
64 (sb!xc:deftype extended-char ()
65 #!+sb-doc
66 "Type of CHARACTERs that aren't BASE-CHARs."
67 '(and character (not base-char)))
69 (sb!xc:deftype standard-char ()
70 #!+sb-doc
71 "Type corresponding to the characters required by the standard."
72 '(member
73 #\Newline #\Space #\! #\" #\# #\$ #\% #\& #\' #\( #\) #\* #\+ #\,
74 #\- #\. #\/ #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\: #\; #\< #\=
75 #\> #\? #\@ #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
76 #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\[ #\\ #\]
77 #\^ #\_ #\` #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
78 #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{
79 #\| #\} #\~))
81 (sb!xc:deftype keyword ()
82 ;; Defining this as (AND SYMBOL ..) lets (SUBTYPEP 'KEYWORD 'SYMBOL)=>T,T.
83 '(and symbol (satisfies keywordp)))
85 (sb!xc:deftype eql (n) `(member ,n))
87 (sb!xc:deftype vector (&optional element-type size)
88 `(array ,element-type (,size)))
90 (sb!xc:deftype simple-vector (&optional size)
91 `(simple-array t (,size)))
93 (sb!xc:deftype base-string (&optional size)
94 `(array base-char (,size)))
95 (sb!xc:deftype simple-base-string (&optional size)
96 `(simple-array base-char (,size)))
97 (sb!xc:deftype string (&optional size)
98 `(or (array character (,size))
99 (array nil (,size))
100 (base-string ,size)))
101 (sb!xc:deftype simple-string (&optional size)
102 `(or (simple-array character (,size))
103 (simple-array nil (,size))
104 (simple-base-string ,size)))
106 (sb!xc:deftype bit-vector (&optional size)
107 `(array bit (,size)))
109 (sb!xc:deftype simple-bit-vector (&optional size)
110 `(simple-array bit (,size)))
112 (sb!xc:deftype compiled-function ()
113 '(and function
114 #!+sb-fasteval (not sb!interpreter:interpreted-function)
115 #!+sb-eval (not sb!eval:interpreted-function)))
117 ;;;; some private types that we use in defining the standard functions,
118 ;;;; or implementing declarations in standard compiler transforms
120 ;;; semistandard types
121 (sb!xc:deftype generalized-boolean () t)
123 (sb!xc:deftype format-control ()
124 '(or string function))
126 (sb!xc:deftype restart-designator ()
127 '(or (and symbol (not null)) restart))
129 ;; FIXME: this fails to consider an EQL-SPECIALIZER a TYPE-SPECIFIER.
130 ;; SPECIFIER-TYPE has the explicit-check declaration, so that kinda works,
131 ;; because it doesn't check against this specifier.
132 ;; Somewhat miraculously, SB-C::CANONIZED-DECL-SPEC also works, so this works:
133 ;; (lambda (x) (declare (#.(sb-mop::intern-eql-specializer 'serial) x)) x)
134 ;; But I suspect this must be reverted to (OR LIST SYMBOL INSTANCE)
135 ;; or we have to hack EQL-SPECIALIZER into 'condition-boot', sad as that is.
136 (sb!xc:deftype type-specifier ()
137 '(or list symbol classoid class))
139 ;;; array rank, total size...
140 (sb!xc:deftype array-rank () `(integer 0 (,sb!xc:array-rank-limit)))
141 (sb!xc:deftype array-total-size ()
142 `(integer 0 (,sb!xc:array-total-size-limit)))
144 ;;; something legal in an evaluated context
145 ;;; FIXME: could probably go away
146 (sb!xc:deftype form () t)
148 (sb!xc:deftype string-designator () '(or string symbol character))
150 ;;; a thing legal in places where we want the name of a file
151 (sb!xc:deftype filename () '(or string pathname))
153 ;;; legal args to pathname functions
154 (sb!xc:deftype pathname-designator ()
155 '(or string pathname #+sb-xc-host stream #-sb-xc-host file-stream))
156 (sb!xc:deftype logical-host-designator ()
157 '(or host string))
159 (sb!xc:deftype package-designator () '(or string-designator package))
160 ;;; a designator for a list of symbols
161 (sb!xc:deftype symbols-designator () '(or list symbol))
163 ;;; a thing returned by the irrational functions. We assume that they
164 ;;; never compute a rational result.
165 (sb!xc:deftype irrational ()
166 '(or float (complex float)))
168 ;;; character components
169 (sb!xc:deftype char-code () `(integer 0 (,sb!xc:char-code-limit)))
171 ;;; a consed sequence result. If a vector, is a simple array.
172 (sb!xc:deftype consed-sequence ()
173 '(or (simple-array * (*)) list extended-sequence))
175 ;;; the :END arg to a sequence
176 (sb!xc:deftype sequence-end () '(or null index))
178 ;;; the :COUNT arg to a sequence
179 (sb!xc:deftype sequence-count ()
180 `(or null integer))
182 ;;; a valid argument to a stream function
183 (sb!xc:deftype stream-designator () '(or stream (member nil t)))
185 ;;; something valid as the :EXTERNAL-FORMAT argument to OPEN, LOAD,
186 ;;; COMPILE-FILE and friends.
187 (sb!xc:deftype external-format-designator ()
188 '(or keyword (cons keyword)))
190 ;;; a thing that can be passed to FUNCALL & friends
192 ;;; FIXME: should be FUNCTION-DESIGNATOR?
193 (sb!xc:deftype callable () '(or function symbol))
195 ;;; decomposing floats into integers
196 (sb!xc:deftype single-float-exponent ()
197 `(integer ,(- sb!vm:single-float-normal-exponent-min
198 sb!vm:single-float-bias
199 sb!vm:single-float-digits)
200 ,(- sb!vm:single-float-normal-exponent-max
201 sb!vm:single-float-bias)))
202 (sb!xc:deftype double-float-exponent ()
203 `(integer ,(- sb!vm:double-float-normal-exponent-min
204 sb!vm:double-float-bias
205 sb!vm:double-float-digits)
206 ,(- sb!vm:double-float-normal-exponent-max
207 sb!vm:double-float-bias)))
208 (sb!xc:deftype single-float-int-exponent ()
209 `(integer ,(- sb!vm:single-float-normal-exponent-min
210 sb!vm:single-float-bias
211 (* sb!vm:single-float-digits 2))
212 ,(- sb!vm:single-float-normal-exponent-max
213 sb!vm:single-float-bias
214 sb!vm:single-float-digits)))
215 (sb!xc:deftype double-float-int-exponent ()
216 `(integer ,(- sb!vm:double-float-normal-exponent-min sb!vm:double-float-bias
217 (* sb!vm:double-float-digits 2))
218 ,(- sb!vm:double-float-normal-exponent-max sb!vm:double-float-bias
219 sb!vm:double-float-digits)))
220 (sb!xc:deftype single-float-significand ()
221 `(integer 0 (,(ash 1 sb!vm:single-float-digits))))
222 (sb!xc:deftype double-float-significand ()
223 `(integer 0 (,(ash 1 sb!vm:double-float-digits))))
225 (/show0 "deftypes-for-target.lisp end of file")