0.9.16.27:
[sbcl.git] / src / code / deftypes-for-target.lisp
1 ;;;; definitions of types for the target (output of the compiler)
2
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.
11
12 (in-package "SB!KERNEL")
13
14 (/show0 "deftypes-for-target.lisp 14")
15 \f
16 ;;;; Now that DEFTYPE is set up, any pending requests for it can
17 ;;;; be honored.
18
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"))
24 \f
25 ;;;; standard types
26
27 (sb!xc:deftype boolean () '(member t nil))
28
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)))
33
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))))
39         (t
40          (error "bad size specified for SIGNED-BYTE type specifier: ~S" s))))
41
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))))
46         (t
47          (error "bad size specified for UNSIGNED-BYTE type specifier: ~S" s))))
48
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))))
56
57 (sb!xc:deftype bit () '(integer 0 1))
58
59 (sb!xc:deftype compiled-function ()
60   '(and function #!+sb-eval (not sb!eval:interpreted-function)))
61
62 (sb!xc:deftype atom () '(not cons))
63
64 (sb!xc:deftype base-char ()
65   '(character-set ((0 . #.(1- base-char-code-limit)))))
66
67 (sb!xc:deftype extended-char ()
68   #!+sb-doc
69   "Type of CHARACTERs that aren't BASE-CHARs."
70   '(and character (not base-char)))
71
72 (sb!xc:deftype standard-char ()
73   #!+sb-doc
74   "Type corresponding to the characters required by the standard."
75   '(member
76     #\Newline #\Space #\! #\" #\# #\$ #\% #\& #\' #\( #\) #\* #\+ #\,
77     #\- #\. #\/ #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\: #\; #\< #\=
78     #\> #\? #\@ #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
79     #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\[ #\\ #\]
80     #\^ #\_ #\` #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
81     #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{
82     #\| #\} #\~))
83
84 (sb!xc:deftype keyword ()
85   ;; Defining this as (AND SYMBOL ..) lets (SUBTYPEP 'KEYWORD 'SYMBOL)=>T,T.
86   '(and symbol (satisfies keywordp)))
87
88 (sb!xc:deftype eql (n) `(member ,n))
89
90 (sb!xc:deftype vector (&optional element-type size)
91   `(array ,element-type (,size)))
92
93 (sb!xc:deftype simple-vector (&optional size)
94   `(simple-array t (,size)))
95
96 (sb!xc:deftype base-string (&optional size)
97   `(array base-char (,size)))
98 (sb!xc:deftype simple-base-string (&optional size)
99   `(simple-array base-char (,size)))
100 (sb!xc:deftype string (&optional size)
101   `(or (array character (,size))
102        (array nil (,size))
103        (base-string ,size)))
104 (sb!xc:deftype simple-string (&optional size)
105   `(or (simple-array character (,size))
106        (simple-array nil (,size))
107        (simple-base-string ,size)))
108
109 (sb!xc:deftype bit-vector (&optional size)
110   `(array bit (,size)))
111
112 (sb!xc:deftype simple-bit-vector (&optional size)
113   `(simple-array bit (,size)))
114 \f
115 ;;;; some private types that we use in defining the standard functions,
116 ;;;; or implementing declarations in standard compiler transforms
117
118 ;;; semistandard types
119 (sb!xc:deftype generalized-boolean () t)
120
121 (sb!xc:deftype format-control ()
122   '(or string function))
123
124 (sb!xc:deftype restart-designator ()
125   '(or (and symbol (not null)) restart))
126
127 ;;; array rank, total size...
128 (sb!xc:deftype array-rank () `(integer 0 (,sb!xc:array-rank-limit)))
129 (sb!xc:deftype array-total-size ()
130   `(integer 0 (,sb!xc:array-total-size-limit)))
131
132 ;;; something legal in an evaluated context
133 ;;; FIXME: could probably go away
134 (sb!xc:deftype form () t)
135
136 (sb!xc:deftype string-designator () '(or string symbol character))
137
138 ;;; a thing legal in places where we want the name of a file
139 (sb!xc:deftype filename () '(or string pathname))
140
141 ;;; legal args to pathname functions
142 (sb!xc:deftype pathname-designator ()
143   '(or string pathname #+sb-xc-host stream #-sb-xc-host file-stream))
144 (sb!xc:deftype logical-host-designator ()
145   '(or host string))
146
147 (sb!xc:deftype package-designator () '(or string-designator sb!xc:package))
148 ;;; a designator for a list of symbols
149 (sb!xc:deftype symbols-designator () '(or list symbol))
150
151 ;;; a thing returned by the irrational functions. We assume that they
152 ;;; never compute a rational result.
153 (sb!xc:deftype irrational ()
154   '(or float (complex float)))
155
156 ;;; character components
157 (sb!xc:deftype char-code () `(integer 0 (,sb!xc:char-code-limit)))
158
159 ;;; a consed sequence result. If a vector, is a simple array.
160 (sb!xc:deftype consed-sequence () '(or list (simple-array * (*))))
161
162 ;;; the :END arg to a sequence
163 (sb!xc:deftype sequence-end () '(or null index))
164
165 ;;; the :COUNT arg to a sequence
166 (sb!xc:deftype sequence-count ()
167   `(or null integer))
168
169 ;;; a valid argument to a stream function
170 (sb!xc:deftype stream-designator () '(or stream (member nil t)))
171
172 ;;; an object suitable for input to standard functions that accept
173 ;;; "environment objects" (of the ANSI glossary)
174 (sb!xc:deftype lexenv-designator () '(or lexenv null))
175
176 ;;; a thing that can be passed to FUNCALL & friends
177 ;;;
178 ;;; FIXME: should be FUNCTION-DESIGNATOR?
179 (sb!xc:deftype callable () '(or function symbol))
180
181 ;;; decomposing floats into integers
182 (sb!xc:deftype single-float-exponent ()
183   `(integer ,(- sb!vm:single-float-normal-exponent-min
184                 sb!vm:single-float-bias
185                 sb!vm:single-float-digits)
186             ,(- sb!vm:single-float-normal-exponent-max
187                 sb!vm:single-float-bias)))
188 (sb!xc:deftype double-float-exponent ()
189   `(integer ,(- sb!vm:double-float-normal-exponent-min
190                 sb!vm:double-float-bias
191                 sb!vm:double-float-digits)
192             ,(- sb!vm:double-float-normal-exponent-max
193                 sb!vm:double-float-bias)))
194 (sb!xc:deftype single-float-int-exponent ()
195   `(integer ,(- sb!vm:single-float-normal-exponent-min
196                 sb!vm:single-float-bias
197                 (* sb!vm:single-float-digits 2))
198             ,(- sb!vm:single-float-normal-exponent-max
199                 sb!vm:single-float-bias
200                 sb!vm:single-float-digits)))
201 (sb!xc:deftype double-float-int-exponent ()
202   `(integer ,(- sb!vm:double-float-normal-exponent-min sb!vm:double-float-bias
203                 (* sb!vm:double-float-digits 2))
204             ,(- sb!vm:double-float-normal-exponent-max sb!vm:double-float-bias
205                 sb!vm:double-float-digits)))
206 (sb!xc:deftype single-float-significand ()
207   `(integer 0 (,(ash 1 sb!vm:single-float-digits))))
208 (sb!xc:deftype double-float-significand ()
209   `(integer 0 (,(ash 1 sb!vm:double-float-digits))))
210
211 (/show0 "deftypes-for-target.lisp end of file")