Enforce consistency between DEFINE-COLD-FOP and DEFINE-FOP.
[sbcl.git] / src / compiler / generic / late-type-vops.lisp
blobd2cfef0ccce11eb5d420714606fe465440e958d6
1 ;;;; generic type testing and checking VOPs
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 (in-package "SB!VM")
13 (!define-type-vops fixnump check-fixnum fixnum object-not-fixnum-error
14 #.fixnum-lowtags
15 ;; we can save a register on the x86.
16 :variant simple
17 ;; we can save a couple of instructions and a branch on the ppc.
18 :mask fixnum-tag-mask)
20 (!define-type-vops functionp check-fun function object-not-function-error
21 (fun-pointer-lowtag)
22 :mask lowtag-mask)
24 (!define-type-vops listp check-list list object-not-list-error
25 (list-pointer-lowtag)
26 :mask lowtag-mask)
28 (!define-type-vops %instancep check-instance instance object-not-instance-error
29 (instance-pointer-lowtag)
30 :mask lowtag-mask)
32 (!define-type-vops %other-pointer-p nil nil nil
33 (other-pointer-lowtag)
34 :mask lowtag-mask)
36 (!define-type-vops bignump check-bignum bignum object-not-bignum-error
37 (bignum-widetag))
39 (!define-type-vops ratiop check-ratio ratio object-not-ratio-error
40 (ratio-widetag))
42 (!define-type-vops complexp check-complex complex object-not-complex-error
43 (complex-widetag complex-single-float-widetag complex-double-float-widetag
44 #!+long-float complex-long-float-widetag))
46 (!define-type-vops complex-rational-p check-complex-rational nil
47 object-not-complex-rational-error
48 (complex-widetag))
50 (!define-type-vops complex-float-p check-complex-float nil
51 object-not-complex-float-error
52 (complex-single-float-widetag complex-double-float-widetag
53 #!+long-float complex-long-float-widetag))
55 (!define-type-vops complex-single-float-p check-complex-single-float complex-single-float
56 object-not-complex-single-float-error
57 (complex-single-float-widetag))
59 (!define-type-vops complex-double-float-p check-complex-double-float complex-double-float
60 object-not-complex-double-float-error
61 (complex-double-float-widetag))
63 (!define-type-vops single-float-p check-single-float single-float
64 object-not-single-float-error
65 (single-float-widetag))
67 (!define-type-vops double-float-p check-double-float double-float
68 object-not-double-float-error
69 (double-float-widetag))
71 (!define-type-vops simple-string-p check-simple-string nil
72 object-not-simple-string-error
73 (#!+sb-unicode simple-character-string-widetag
74 simple-base-string-widetag simple-array-nil-widetag))
76 (macrolet
77 ((define-simple-array-type-vops ()
78 `(progn
79 ,@(map 'list
80 (lambda (saetp)
81 (let ((primtype (saetp-primitive-type-name saetp)))
82 `(!define-type-vops
83 ,(symbolicate primtype "-P")
84 ,(symbolicate "CHECK-" primtype)
85 ,primtype
86 ,(symbolicate "OBJECT-NOT-" primtype "-ERROR")
87 (,(saetp-typecode saetp)))))
88 *specialized-array-element-type-properties*))))
89 (define-simple-array-type-vops))
91 (macrolet
92 ((def ()
93 `(!define-type-vops simple-rank-1-array-*-p check-simple-rank-1-array-*
94 nil
95 ;; TODO: eliminate naming of errors. The error-emitting logic can find
96 ;; an error number from a type specifier. As impetus to remove them,
97 ;; I'm not adding a new exported symbol to sb-kernel.
98 sb!kernel::object-not-simple-rank-1-array-error
99 ,(map 'list #'saetp-typecode
100 *specialized-array-element-type-properties*))))
101 (def)) ; simple-rank-1-array-*-p
103 (!define-type-vops characterp check-character character
104 object-not-character-error
105 (character-widetag))
107 (!define-type-vops system-area-pointer-p check-system-area-pointer
108 system-area-pointer
109 object-not-sap-error
110 (sap-widetag))
112 (!define-type-vops weak-pointer-p check-weak-pointer weak-pointer
113 object-not-weak-pointer-error
114 (weak-pointer-widetag))
116 (!define-type-vops code-component-p nil nil nil
117 (code-header-widetag))
119 (!define-type-vops lra-p nil nil nil
120 (return-pc-header-widetag))
122 (!define-type-vops fdefn-p nil nil nil
123 (fdefn-widetag))
125 (!define-type-vops closurep nil nil nil (closure-header-widetag))
127 (!define-type-vops simple-fun-p nil nil nil
128 (simple-fun-header-widetag))
130 (!define-type-vops funcallable-instance-p nil nil nil
131 (funcallable-instance-header-widetag))
133 (!define-type-vops array-header-p nil nil nil
134 (simple-array-widetag
135 #!+sb-unicode complex-character-string-widetag
136 complex-base-string-widetag complex-bit-vector-widetag
137 complex-vector-widetag complex-array-widetag complex-vector-nil-widetag))
139 (!define-type-vops stringp check-string nil object-not-string-error
140 (#!+sb-unicode simple-character-string-widetag
141 #!+sb-unicode complex-character-string-widetag
142 simple-base-string-widetag complex-base-string-widetag
143 simple-array-nil-widetag complex-vector-nil-widetag))
145 (!define-type-vops base-string-p check-base-string nil object-not-base-string-error
146 (simple-base-string-widetag complex-base-string-widetag))
148 (!define-type-vops bit-vector-p check-bit-vector nil
149 object-not-bit-vector-error
150 (simple-bit-vector-widetag complex-bit-vector-widetag))
152 (!define-type-vops vector-nil-p check-vector-nil nil
153 object-not-vector-nil-error
154 (simple-array-nil-widetag complex-vector-nil-widetag))
156 #!+sb-unicode
157 (!define-type-vops character-string-p check-character-string nil
158 object-not-character-string-error
159 (simple-character-string-widetag complex-character-string-widetag))
161 (!define-type-vops vectorp check-vector nil object-not-vector-error
162 (complex-vector-widetag .
163 #.(append
164 (map 'list
165 #'saetp-typecode
166 *specialized-array-element-type-properties*)
167 (mapcan (lambda (saetp)
168 (when (saetp-complex-typecode saetp)
169 (list (saetp-complex-typecode saetp))))
170 (coerce *specialized-array-element-type-properties* 'list)))))
172 ;;; Note that this "type VOP" is sort of an oddball; it doesn't so
173 ;;; much test for a Lisp-level type as just expose a low-level type
174 ;;; code at the Lisp level. It is used as a building block to help us
175 ;;; to express things like the test for (TYPEP FOO '(VECTOR T))
176 ;;; efficiently in Lisp code, but it doesn't correspond to any type
177 ;;; expression which would actually occur in reasonable application
178 ;;; code. (Common Lisp doesn't have any natural way of expressing this
179 ;;; type.) Thus, there's no point in building up the full machinery of
180 ;;; associated backend type predicates and so forth as we do for
181 ;;; ordinary type VOPs.
182 (!define-type-vops complex-vector-p check-complex-vector nil
183 object-not-complex-vector-error
184 (complex-vector-widetag))
186 (!define-type-vops simple-array-p check-simple-array nil
187 object-not-simple-array-error
188 (simple-array-widetag .
189 #.(map 'list
190 #'saetp-typecode
191 *specialized-array-element-type-properties*)))
193 (!define-type-vops arrayp check-array nil object-not-array-error
194 (simple-array-widetag
195 complex-array-widetag
196 complex-vector-widetag .
197 #.(append
198 (map 'list
199 #'saetp-typecode
200 *specialized-array-element-type-properties*)
201 (mapcan (lambda (saetp)
202 (when (saetp-complex-typecode saetp)
203 (list (saetp-complex-typecode saetp))))
204 (coerce *specialized-array-element-type-properties* 'list)))))
206 (!define-type-vops numberp check-number nil object-not-number-error
207 (bignum-widetag
208 ratio-widetag
209 single-float-widetag
210 double-float-widetag
211 #!+long-float long-float-widetag
212 complex-widetag
213 complex-single-float-widetag
214 complex-double-float-widetag
215 #!+long-float complex-long-float-widetag
216 . #.fixnum-lowtags))
218 (!define-type-vops rationalp check-rational nil object-not-rational-error
219 (ratio-widetag bignum-widetag . #.fixnum-lowtags))
221 (!define-type-vops integerp check-integer nil object-not-integer-error
222 (bignum-widetag . #.fixnum-lowtags))
224 (!define-type-vops floatp check-float nil object-not-float-error
225 (single-float-widetag double-float-widetag #!+long-float long-float-widetag))
227 (!define-type-vops realp check-real nil object-not-real-error
228 (ratio-widetag
229 bignum-widetag
230 single-float-widetag
231 double-float-widetag
232 #!+long-float long-float-widetag
233 . #.fixnum-lowtags))