1 ;;;; generic type testing and checking VOPs
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.
13 (!define-type-vops fixnump check-fixnum fixnum object-not-fixnum-error
15 ;; we can save a register on the x86.
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-fun-error
24 (!define-type-vops listp check-list list object-not-list-error
28 (!define-type-vops %instancep check-instance instance object-not-instance-error
29 (instance-pointer-lowtag)
32 (!define-type-vops %other-pointer-p nil nil nil
33 (other-pointer-lowtag)
36 (!define-type-vops bignump check-bignum bignum object-not-bignum-error
39 (!define-type-vops ratiop check-ratio ratio object-not-ratio-error
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
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))
77 ((define-simple-array-type-vops ()
81 (let ((primtype (saetp-primitive-type-name saetp)))
83 ,(symbolicate primtype "-P")
84 ,(symbolicate "CHECK-" primtype)
86 ,(symbolicate "OBJECT-NOT-" primtype "-ERROR")
87 (,(saetp-typecode saetp)))))
88 *specialized-array-element-type-properties*))))
89 (define-simple-array-type-vops))
91 (!define-type-vops characterp check-character character
92 object-not-character-error
95 (!define-type-vops system-area-pointer-p check-system-area-pointer
100 (!define-type-vops weak-pointer-p check-weak-pointer weak-pointer
101 object-not-weak-pointer-error
102 (weak-pointer-widetag))
104 (!define-type-vops code-component-p nil nil nil
105 (code-header-widetag))
107 (!define-type-vops lra-p nil nil nil
108 (return-pc-header-widetag))
110 (!define-type-vops fdefn-p nil nil nil
113 (!define-type-vops funcallable-instance-p nil nil nil
114 (funcallable-instance-header-widetag))
116 (!define-type-vops array-header-p nil nil nil
117 (simple-array-widetag
118 #!+sb-unicode complex-character-string-widetag
119 complex-base-string-widetag complex-bit-vector-widetag
120 complex-vector-widetag complex-array-widetag complex-vector-nil-widetag))
122 (!define-type-vops stringp check-string nil object-not-string-error
123 (#!+sb-unicode simple-character-string-widetag
124 #!+sb-unicode complex-character-string-widetag
125 simple-base-string-widetag complex-base-string-widetag
126 simple-array-nil-widetag complex-vector-nil-widetag))
128 (!define-type-vops base-string-p check-base-string nil object-not-base-string-error
129 (simple-base-string-widetag complex-base-string-widetag))
131 (!define-type-vops bit-vector-p check-bit-vector nil
132 object-not-bit-vector-error
133 (simple-bit-vector-widetag complex-bit-vector-widetag))
135 (!define-type-vops vector-nil-p check-vector-nil nil
136 object-not-vector-nil-error
137 (simple-array-nil-widetag complex-vector-nil-widetag))
140 (!define-type-vops character-string-p check-character-string nil
141 object-not-character-string-error
142 (simple-character-string-widetag complex-character-string-widetag))
144 (!define-type-vops vectorp check-vector nil object-not-vector-error
145 (complex-vector-widetag .
149 *specialized-array-element-type-properties*)
150 (mapcan (lambda (saetp)
151 (when (saetp-complex-typecode saetp)
152 (list (saetp-complex-typecode saetp))))
153 (coerce *specialized-array-element-type-properties* 'list)))))
155 ;;; Note that this "type VOP" is sort of an oddball; it doesn't so
156 ;;; much test for a Lisp-level type as just expose a low-level type
157 ;;; code at the Lisp level. It is used as a building block to help us
158 ;;; to express things like the test for (TYPEP FOO '(VECTOR T))
159 ;;; efficiently in Lisp code, but it doesn't correspond to any type
160 ;;; expression which would actually occur in reasonable application
161 ;;; code. (Common Lisp doesn't have any natural way of expressing this
162 ;;; type.) Thus, there's no point in building up the full machinery of
163 ;;; associated backend type predicates and so forth as we do for
164 ;;; ordinary type VOPs.
165 (!define-type-vops complex-vector-p check-complex-vector nil
166 object-not-complex-vector-error
167 (complex-vector-widetag))
169 (!define-type-vops simple-array-p check-simple-array nil
170 object-not-simple-array-error
171 (simple-array-widetag .
174 *specialized-array-element-type-properties*)))
176 (!define-type-vops arrayp check-array nil object-not-array-error
177 (simple-array-widetag
178 complex-array-widetag
179 complex-vector-widetag .
183 *specialized-array-element-type-properties*)
184 (mapcan (lambda (saetp)
185 (when (saetp-complex-typecode saetp)
186 (list (saetp-complex-typecode saetp))))
187 (coerce *specialized-array-element-type-properties* 'list)))))
189 (!define-type-vops numberp check-number nil object-not-number-error
194 #!+long-float long-float-widetag
196 complex-single-float-widetag
197 complex-double-float-widetag
198 #!+long-float complex-long-float-widetag
201 (!define-type-vops rationalp check-rational nil object-not-rational-error
202 (ratio-widetag bignum-widetag . #.fixnum-lowtags))
204 (!define-type-vops integerp check-integer nil object-not-integer-error
205 (bignum-widetag . #.fixnum-lowtags))
207 (!define-type-vops floatp check-float nil object-not-float-error
208 (single-float-widetag double-float-widetag #!+long-float long-float-widetag))
210 (!define-type-vops realp check-real nil object-not-real-error
215 #!+long-float long-float-widetag