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 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 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: ~ 32 ~/sb!impl:print-type-specifier/" 33 n)) 34 `(integer 0 ,(1- n))) 35 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)))) 41 (t 42 (error "bad size specified for SIGNED-BYTE type specifier: ~ 43 ~/sb!impl:print-type-specifier/" 44 s)))) 45 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)))) 50 (t 51 (error "bad size specified for UNSIGNED-BYTE type specifier: ~ 52 ~/sb!impl:print-type-specifier/" 53 s)))) 54 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)))) 62 63(sb!xc:deftype bit () '(integer 0 1)) 64 65(sb!xc:deftype atom () '(not cons)) 66 67(sb!xc:deftype base-char () 68 '(character-set ((0 . #.(1- base-char-code-limit))))) 69 70(sb!xc:deftype extended-char () 71 #!+sb-doc 72 "Type of CHARACTERs that aren't BASE-CHARs." 73 '(and character (not base-char))) 74 75(sb!xc:deftype standard-char () 76 #!+sb-doc 77 "Type corresponding to the characters required by the standard." 78 '(member 79 #\Newline #\Space #\! #\" #\# #\$ #\% #\& #\' #\( #\) #\* #\+ #\, 80 #\- #\. #\/ #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\: #\; #\< #\= 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 #\^ #\_ #\` #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m 84 #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{ 85 #\| #\} #\~)) 86 87(sb!xc:deftype keyword () 88 ;; Defining this as (AND SYMBOL ..) lets (SUBTYPEP 'KEYWORD 'SYMBOL)=>T,T. 89 '(and symbol (satisfies keywordp))) 90 91(sb!xc:deftype eql (n) `(member ,n)) 92 93(sb!xc:deftype vector (&optional element-type size) 94 `(array ,element-type (,size))) 95 96(sb!xc:deftype simple-vector (&optional size) 97 `(simple-array t (,size))) 98 99(sb!xc:deftype base-string (&optional size) 100 `(array base-char (,size))) 101(sb!xc:deftype simple-base-string (&optional size) 102 `(simple-array base-char (,size))) 103(sb!xc:deftype string (&optional size) 104 `(or (array character (,size)) 105 (array nil (,size)) 106 (base-string ,size))) 107(sb!xc:deftype simple-string (&optional size) 108 `(or (simple-array character (,size)) 109 (simple-array nil (,size)) 110 (simple-base-string ,size))) 111 112(sb!xc:deftype bit-vector (&optional size) 113 `(array bit (,size))) 114 115(sb!xc:deftype simple-bit-vector (&optional size) 116 `(simple-array bit (,size))) 117 118(sb!xc:deftype compiled-function () 119 '(and function 120 #!+sb-fasteval (not sb!interpreter:interpreted-function) 121 #!+sb-eval (not sb!eval:interpreted-function))) 122 123;;;; some private types that we use in defining the standard functions, 124;;;; or implementing declarations in standard compiler transforms 125 126;;; semistandard types 127(sb!xc:deftype generalized-boolean () t) 128 129(sb!xc:deftype format-control () 130 '(or string function)) 131 132(sb!xc:deftype restart-designator () 133 '(or (and symbol (not null)) restart)) 134 135;; FIXME: this fails to consider an EQL-SPECIALIZER a TYPE-SPECIFIER. 136;; SPECIFIER-TYPE has the explicit-check declaration, so that kinda works, 137;; because it doesn't check against this specifier. 138;; Somewhat miraculously, SB-C::CANONIZED-DECL-SPEC also works, so this works: 139;; (lambda (x) (declare (#.(sb-mop::intern-eql-specializer 'serial) x)) x) 140;; But I suspect this must be reverted to (OR LIST SYMBOL INSTANCE) 141;; or we have to hack EQL-SPECIALIZER into 'condition-boot', sad as that is. 142(sb!xc:deftype type-specifier () 143 '(or list symbol classoid class)) 144 145;;; array rank, total size... 146(sb!xc:deftype array-rank () `(integer 0 (,sb!xc:array-rank-limit))) 147(sb!xc:deftype array-total-size () 148 `(integer 0 (,sb!xc:array-total-size-limit))) 149 150;;; something legal in an evaluated context 151;;; FIXME: could probably go away 152(sb!xc:deftype form () t) 153 154(sb!xc:deftype string-designator () '(or string symbol character)) 155 156;;; a thing legal in places where we want the name of a file 157(sb!xc:deftype filename () '(or string pathname)) 158 159;;; legal args to pathname functions 160(sb!xc:deftype pathname-designator () 161 '(or string pathname #+sb-xc-host stream #-sb-xc-host file-stream)) 162(sb!xc:deftype logical-host-designator () 163 '(or host string)) 164 165(sb!xc:deftype package-designator () '(or string-designator package)) 166;;; a designator for a list of symbols 167(sb!xc:deftype symbols-designator () '(or list symbol)) 168 169;;; a thing returned by the irrational functions. We assume that they 170;;; never compute a rational result. 171(sb!xc:deftype irrational () 172 '(or float (complex float))) 173 174;;; character components 175(sb!xc:deftype char-code () `(integer 0 (,sb!xc:char-code-limit))) 176 177;;; a consed sequence result. If a vector, is a simple array. 178(sb!xc:deftype consed-sequence () 179 '(or (simple-array * (*)) list extended-sequence)) 180 181;;; the :END arg to a sequence 182(sb!xc:deftype sequence-end () '(or null index)) 183 184;;; the :COUNT arg to a sequence 185(sb!xc:deftype sequence-count () 186 `(or null integer)) 187 188;;; a valid argument to a stream function 189(sb!xc:deftype stream-designator () '(or stream (member nil t))) 190 191;;; something valid as the :EXTERNAL-FORMAT argument to OPEN, LOAD, 192;;; COMPILE-FILE and friends. 193(sb!xc:deftype external-format-designator () 194 '(or keyword (cons keyword))) 195 196;;; a thing that can be passed to FUNCALL & friends 197;;; 198;;; FIXME: should be FUNCTION-DESIGNATOR? 199(sb!xc:deftype callable () '(or function symbol)) 200 201;;; decomposing floats into integers 202(sb!xc:deftype single-float-exponent () 203 `(integer ,(- sb!vm:single-float-normal-exponent-min 204 sb!vm:single-float-bias 205 sb!vm:single-float-digits) 206 ,(- sb!vm:single-float-normal-exponent-max 207 sb!vm:single-float-bias))) 208(sb!xc:deftype double-float-exponent () 209 `(integer ,(- sb!vm:double-float-normal-exponent-min 210 sb!vm:double-float-bias 211 sb!vm:double-float-digits) 212 ,(- sb!vm:double-float-normal-exponent-max 213 sb!vm:double-float-bias))) 214(sb!xc:deftype single-float-int-exponent () 215 `(integer ,(- sb!vm:single-float-normal-exponent-min 216 sb!vm:single-float-bias 217 (* sb!vm:single-float-digits 2)) 218 ,(- sb!vm:single-float-normal-exponent-max 219 sb!vm:single-float-bias 220 sb!vm:single-float-digits))) 221(sb!xc:deftype double-float-int-exponent () 222 `(integer ,(- sb!vm:double-float-normal-exponent-min sb!vm:double-float-bias 223 (* sb!vm:double-float-digits 2)) 224 ,(- sb!vm:double-float-normal-exponent-max sb!vm:double-float-bias 225 sb!vm:double-float-digits))) 226(sb!xc:deftype single-float-significand () 227 `(integer 0 (,(ash 1 sb!vm:single-float-digits)))) 228(sb!xc:deftype double-float-significand () 229 `(integer 0 (,(ash 1 sb!vm:double-float-digits)))) 230 231(/show0 "deftypes-for-target.lisp end of file") 232