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