63574ff36309b64efec408dd6fd8263453ab6e46
[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 \f
14 ;;;; Now that DEFTYPE is set up, any pending requests for it can
15 ;;;; be honored.
16
17 #+sb-xc-host
18 (progn
19   (/show "about to force delayed DEF!TYPEs")
20   (force-delayed-def!types)
21   (/show "done forcing delayed DEF!TYPEs"))
22 \f
23 ;;;; standard types
24
25 (sb!xc:deftype boolean () '(member t nil))
26
27 (sb!xc:deftype mod (n)
28   (unless (and (integerp n) (> n 0))
29     (error "bad modulus specified for MOD type specifier: ~S" n))
30   `(integer 0 ,(1- n)))
31
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))))
37         (t
38          (error "bad size specified for SIGNED-BYTE type specifier: ~S" s))))
39
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))))
44         (t
45          (error "bad size specified for UNSIGNED-BYTE type specifier: ~S" s))))
46
47 (sb!xc:deftype bit () '(integer 0 1))
48
49 (sb!xc:deftype compiled-function () 'function)
50
51 (sb!xc:deftype atom () '(not cons))
52
53 (sb!xc:deftype extended-char ()
54   #!+sb-doc
55   "Type of characters that aren't base-char's. None in CMU CL."
56   '(and character (not base-char)))
57
58 (sb!xc:deftype standard-char ()
59   #!+sb-doc
60   "Type corresponding to the characters required by the standard."
61   '(member
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 #\{
68     #\| #\} #\~))
69
70 (sb!xc:deftype keyword ()
71   ;; Defining this as (AND SYMBOL ..) lets (SUBTYPEP 'KEYWORD 'SYMBOL)=>T,T.
72   '(and symbol (satisfies keywordp)))
73
74 (sb!xc:deftype eql (n) `(member ,n))
75
76 (sb!xc:deftype vector (&optional element-type size)
77   `(array ,element-type (,size)))
78
79 (sb!xc:deftype simple-vector (&optional size)
80   `(simple-array t (,size)))
81
82 (sb!xc:deftype base-string (&optional size)
83   `(array base-char (,size)))
84 (sb!xc:deftype simple-base-string (&optional size)
85   `(simple-array base-char (,size)))
86 (sb!xc:deftype string (&optional size)
87   `(or (array character (,size))
88             (base-string ,size)))
89 (sb!xc:deftype simple-string (&optional size)
90   `(or (simple-array character (,size))
91             (simple-base-string ,size)))
92
93 (sb!xc:deftype bit-vector (&optional size)
94   `(array bit (,size)))
95
96 (sb!xc:deftype simple-bit-vector (&optional size)
97   `(simple-array bit (,size)))
98 \f
99 ;;;; some private types that we use in defining the standard functions
100
101 ;;; a type specifier
102 (sb!xc:deftype type-specifier () '(or list symbol sb!xc:class))
103
104 ;;; array rank, total size...
105 (sb!xc:deftype array-rank () `(integer 0 (,sb!xc:array-rank-limit)))
106 (sb!xc:deftype array-total-size ()
107   `(integer 0 (,sb!xc:array-total-size-limit)))
108
109 ;;; something legal in an evaluated context
110 ;;; FIXME: could probably go away
111 (sb!xc:deftype form () 't)
112
113 ;;; Maclisp compatibility...
114 ;;; FIXME: should be STRING-DESIGNATOR (the term used in the ANSI spec)
115 (sb!xc:deftype stringable () '(or string symbol character))
116
117 ;;; a thing legal in places where we want the name of a file
118 (sb!xc:deftype filename () '(or string pathname))
119
120 ;;; legal args to pathname functions
121 (sb!xc:deftype pathname-designator ()
122   '(or string pathname stream))
123 (sb!xc:deftype logical-host-designator ()
124   '(or host string))
125
126 ;;; a thing returned by the irrational functions. We assume that they
127 ;;; never compute a rational result.
128 (sb!xc:deftype irrational ()
129   '(or float (complex float)))
130
131 ;;; character components
132 (sb!xc:deftype char-code () `(integer 0 (,char-code-limit)))
133
134 ;;; a consed sequence result. If a vector, is a simple array.
135 (sb!xc:deftype consed-sequence () '(or list (simple-array * (*))))
136
137 ;;; the :END arg to a sequence
138 (sb!xc:deftype sequence-end () '(or null index))
139
140 ;;; a valid argument to a stream function
141 ;;;
142 ;;; FIXME: should probably be STREAM-DESIGNATOR, after the term
143 ;;; used in the ANSI spec (if this is in fact exactly the same thing)
144 (sb!xc:deftype streamlike () '(or stream (member nil t)))
145
146 ;;; a thing that can be passed to FUNCALL & friends
147 ;;;
148 ;;; FIXME: should be FUNCTION-DESIGNATOR?
149 (sb!xc:deftype callable () '(or function symbol))
150
151 ;;; decomposing floats into integers
152 (sb!xc:deftype single-float-exponent ()
153   `(integer ,(- sb!vm:single-float-normal-exponent-min
154                 sb!vm:single-float-bias
155                 sb!vm:single-float-digits)
156             ,(- sb!vm:single-float-normal-exponent-max
157                 sb!vm:single-float-bias)))
158 (sb!xc:deftype double-float-exponent ()
159   `(integer ,(- sb!vm:double-float-normal-exponent-min
160                 sb!vm:double-float-bias
161                 sb!vm:double-float-digits)
162             ,(- sb!vm:double-float-normal-exponent-max
163                 sb!vm:double-float-bias)))
164 (sb!xc:deftype single-float-int-exponent ()
165   `(integer ,(- sb!vm:single-float-normal-exponent-min
166                 sb!vm:single-float-bias
167                 (* sb!vm:single-float-digits 2))
168             ,(- sb!vm:single-float-normal-exponent-max
169                 sb!vm:single-float-bias
170                 sb!vm:single-float-digits)))
171 (sb!xc:deftype double-float-int-exponent ()
172   `(integer ,(- sb!vm:double-float-normal-exponent-min sb!vm:double-float-bias
173                 (* sb!vm:double-float-digits 2))
174             ,(- sb!vm:double-float-normal-exponent-max sb!vm:double-float-bias
175                 sb!vm:double-float-digits)))
176 (sb!xc:deftype single-float-significand ()
177   `(integer 0 (,(ash 1 sb!vm:single-float-digits))))
178 (sb!xc:deftype double-float-significand ()
179   `(integer 0 (,(ash 1 sb!vm:double-float-digits))))