0.7.13.pcl-class.1
[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 1))
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 (sb!xc:deftype bit () '(integer 0 1))
50
51 (sb!xc:deftype compiled-function () 'function)
52
53 (sb!xc:deftype atom () '(not cons))
54
55 (sb!xc:deftype extended-char ()
56   #!+sb-doc
57   "Type of characters that aren't base-char's. None in CMU CL."
58   '(and character (not base-char)))
59
60 (sb!xc:deftype standard-char ()
61   #!+sb-doc
62   "Type corresponding to the characters required by the standard."
63   '(member
64     #\NEWLINE #\SPACE #\! #\" #\# #\$ #\% #\& #\' #\( #\) #\* #\+ #\,
65     #\- #\. #\/ #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\: #\; #\< #\=
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     #\^ #\_ #\` #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
69     #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{
70     #\| #\} #\~))
71
72 (sb!xc:deftype keyword ()
73   ;; Defining this as (AND SYMBOL ..) lets (SUBTYPEP 'KEYWORD 'SYMBOL)=>T,T.
74   '(and symbol (satisfies keywordp)))
75
76 (sb!xc:deftype eql (n) `(member ,n))
77
78 (sb!xc:deftype vector (&optional element-type size)
79   `(array ,element-type (,size)))
80
81 (sb!xc:deftype simple-vector (&optional size)
82   `(simple-array t (,size)))
83
84 (sb!xc:deftype base-string (&optional size)
85   `(array base-char (,size)))
86 (sb!xc:deftype simple-base-string (&optional size)
87   `(simple-array base-char (,size)))
88 (sb!xc:deftype string (&optional size)
89   `(or (array character (,size))
90             (base-string ,size)))
91 (sb!xc:deftype simple-string (&optional size)
92   `(or (simple-array character (,size))
93             (simple-base-string ,size)))
94
95 (sb!xc:deftype bit-vector (&optional size)
96   `(array bit (,size)))
97
98 (sb!xc:deftype simple-bit-vector (&optional size)
99   `(simple-array bit (,size)))
100 \f
101 ;;;; some private types that we use in defining the standard functions,
102 ;;;; or implementing declarations in standard compiler transforms
103
104 ;;; a type specifier
105 ;;;
106 ;;; FIXME: The SB!KERNEL:INSTANCE here really means CL:CLASS.
107 ;;; However, the CL:CLASS type is only defined once PCL is loaded,
108 ;;; which is before this is evaluated.  Once PCL is moved into cold
109 ;;; init, this might be fixable.
110 (sb!xc:deftype type-specifier () '(or list symbol sb!kernel:instance))
111
112 ;;; array rank, total size...
113 (sb!xc:deftype array-rank () `(integer 0 (,sb!xc:array-rank-limit)))
114 (sb!xc:deftype array-total-size ()
115   `(integer 0 (,sb!xc:array-total-size-limit)))
116
117 ;;; something legal in an evaluated context
118 ;;; FIXME: could probably go away
119 (sb!xc:deftype form () t)
120
121 ;;; Maclisp compatibility...
122 ;;; FIXME: should be STRING-DESIGNATOR (the term used in the ANSI spec)
123 (sb!xc:deftype stringable () '(or string symbol character))
124
125 ;;; a thing legal in places where we want the name of a file
126 (sb!xc:deftype filename () '(or string pathname))
127
128 ;;; legal args to pathname functions
129 (sb!xc:deftype pathname-designator ()
130   '(or string pathname #+sb-xc-host stream #-sb-xc-host file-stream))
131 (sb!xc:deftype logical-host-designator ()
132   '(or host string))
133
134 ;;; a thing returned by the irrational functions. We assume that they
135 ;;; never compute a rational result.
136 (sb!xc:deftype irrational ()
137   '(or float (complex float)))
138
139 ;;; character components
140 (sb!xc:deftype char-code () `(integer 0 (,sb!xc:char-code-limit)))
141
142 ;;; a consed sequence result. If a vector, is a simple array.
143 (sb!xc:deftype consed-sequence () '(or list (simple-array * (*))))
144
145 ;;; the :END arg to a sequence
146 (sb!xc:deftype sequence-end () '(or null index))
147
148 ;;; the :COUNT arg to a sequence
149 (sb!xc:deftype sequence-count ()
150   `(or null integer))
151
152 ;;; a valid argument to a stream function
153 ;;;
154 ;;; FIXME: should probably be STREAM-DESIGNATOR, after the term
155 ;;; used in the ANSI spec (if this is in fact exactly the same thing)
156 (sb!xc:deftype streamlike () '(or stream (member nil t)))
157
158 ;;; an object suitable for input to standard functions that accept
159 ;;; "environment objects" (of the ANSI glossary)
160 (sb!xc:deftype lexenv-designator () '(or lexenv null))
161
162 ;;; a thing that can be passed to FUNCALL & friends
163 ;;;
164 ;;; FIXME: should be FUNCTION-DESIGNATOR?
165 (sb!xc:deftype callable () '(or function symbol))
166
167 ;;; decomposing floats into integers
168 (sb!xc:deftype single-float-exponent ()
169   `(integer ,(- sb!vm:single-float-normal-exponent-min
170                 sb!vm:single-float-bias
171                 sb!vm:single-float-digits)
172             ,(- sb!vm:single-float-normal-exponent-max
173                 sb!vm:single-float-bias)))
174 (sb!xc:deftype double-float-exponent ()
175   `(integer ,(- sb!vm:double-float-normal-exponent-min
176                 sb!vm:double-float-bias
177                 sb!vm:double-float-digits)
178             ,(- sb!vm:double-float-normal-exponent-max
179                 sb!vm:double-float-bias)))
180 (sb!xc:deftype single-float-int-exponent ()
181   `(integer ,(- sb!vm:single-float-normal-exponent-min
182                 sb!vm:single-float-bias
183                 (* sb!vm:single-float-digits 2))
184             ,(- sb!vm:single-float-normal-exponent-max
185                 sb!vm:single-float-bias
186                 sb!vm:single-float-digits)))
187 (sb!xc:deftype double-float-int-exponent ()
188   `(integer ,(- sb!vm:double-float-normal-exponent-min sb!vm:double-float-bias
189                 (* sb!vm:double-float-digits 2))
190             ,(- sb!vm:double-float-normal-exponent-max sb!vm:double-float-bias
191                 sb!vm:double-float-digits)))
192 (sb!xc:deftype single-float-significand ()
193   `(integer 0 (,(ash 1 sb!vm:single-float-digits))))
194 (sb!xc:deftype double-float-significand ()
195   `(integer 0 (,(ash 1 sb!vm:double-float-digits))))
196
197 (/show0 "deftypes-for-target.lisp end of file")