2774689a7ea4897fdb48770f8a10501a40e02d0c
[sbcl.git] / src / compiler / generic / late-type-vops.lisp
1 ;;;; generic type testing and checking VOPs
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 (in-package "SB!VM")
12 \f
13 (!define-type-vops fixnump check-fixnum fixnum object-not-fixnum-error
14   (even-fixnum-lowtag odd-fixnum-lowtag)
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)
19
20 (!define-type-vops functionp check-fun function object-not-fun-error
21   (fun-pointer-lowtag)
22   :mask lowtag-mask)
23
24 (!define-type-vops listp check-list list object-not-list-error
25   (list-pointer-lowtag)
26   :mask lowtag-mask)
27
28 (!define-type-vops %instancep check-instance instance object-not-instance-error
29   (instance-pointer-lowtag)
30   :mask lowtag-mask)
31
32 (!define-type-vops %other-pointer-p nil nil nil
33   (other-pointer-lowtag)
34   :mask lowtag-mask)
35
36 (!define-type-vops bignump check-bignum bignum object-not-bignum-error
37   (bignum-widetag))
38
39 (!define-type-vops ratiop check-ratio ratio object-not-ratio-error
40   (ratio-widetag))
41
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))
45
46 (!define-type-vops complex-rational-p check-complex-rational nil
47     object-not-complex-rational-error
48   (complex-widetag))
49
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))
54
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))
58
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))
62
63 (!define-type-vops single-float-p check-single-float single-float
64     object-not-single-float-error
65   (single-float-widetag))
66
67 (!define-type-vops double-float-p check-double-float double-float
68     object-not-double-float-error
69   (double-float-widetag))
70
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))
75
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))
90
91 (!define-type-vops characterp check-character character
92     object-not-character-error
93   (character-widetag))
94
95 (!define-type-vops system-area-pointer-p check-system-area-pointer
96       system-area-pointer
97     object-not-sap-error
98   (sap-widetag))
99
100 (!define-type-vops weak-pointer-p check-weak-pointer weak-pointer
101     object-not-weak-pointer-error
102   (weak-pointer-widetag))
103
104 (!define-type-vops code-component-p nil nil nil
105   (code-header-widetag))
106
107 (!define-type-vops lra-p nil nil nil
108   (return-pc-header-widetag))
109
110 (!define-type-vops fdefn-p nil nil nil
111   (fdefn-widetag))
112
113 #!+(and sb-thread sb-lutex)
114 (!define-type-vops lutexp nil nil nil
115   (lutex-widetag))
116
117 (!define-type-vops funcallable-instance-p nil nil nil
118   (funcallable-instance-header-widetag))
119
120 (!define-type-vops array-header-p nil nil nil
121   (simple-array-widetag
122    #!+sb-unicode complex-character-string-widetag
123    complex-base-string-widetag complex-bit-vector-widetag
124    complex-vector-widetag complex-array-widetag complex-vector-nil-widetag))
125
126 (!define-type-vops stringp check-string nil object-not-string-error
127   (#!+sb-unicode simple-character-string-widetag
128    #!+sb-unicode complex-character-string-widetag
129    simple-base-string-widetag complex-base-string-widetag
130    simple-array-nil-widetag complex-vector-nil-widetag))
131
132 (!define-type-vops base-string-p check-base-string nil object-not-base-string-error
133   (simple-base-string-widetag complex-base-string-widetag))
134
135 (!define-type-vops bit-vector-p check-bit-vector nil
136     object-not-bit-vector-error
137   (simple-bit-vector-widetag complex-bit-vector-widetag))
138
139 (!define-type-vops vector-nil-p check-vector-nil nil
140     object-not-vector-nil-error
141   (simple-array-nil-widetag complex-vector-nil-widetag))
142
143 #!+sb-unicode
144 (!define-type-vops character-string-p check-character-string nil
145     object-not-character-string-error
146   (simple-character-string-widetag complex-character-string-widetag))
147
148 (!define-type-vops vectorp check-vector nil object-not-vector-error
149   (complex-vector-widetag .
150    #.(append
151       (map 'list
152            #'saetp-typecode
153            *specialized-array-element-type-properties*)
154       (mapcan (lambda (saetp)
155                 (when (saetp-complex-typecode saetp)
156                   (list (saetp-complex-typecode saetp))))
157               (coerce *specialized-array-element-type-properties* 'list)))))
158
159 ;;; Note that this "type VOP" is sort of an oddball; it doesn't so
160 ;;; much test for a Lisp-level type as just expose a low-level type
161 ;;; code at the Lisp level. It is used as a building block to help us
162 ;;; to express things like the test for (TYPEP FOO '(VECTOR T))
163 ;;; efficiently in Lisp code, but it doesn't correspond to any type
164 ;;; expression which would actually occur in reasonable application
165 ;;; code. (Common Lisp doesn't have any natural way of expressing this
166 ;;; type.) Thus, there's no point in building up the full machinery of
167 ;;; associated backend type predicates and so forth as we do for
168 ;;; ordinary type VOPs.
169 (!define-type-vops complex-vector-p check-complex-vector nil
170     object-not-complex-vector-error
171   (complex-vector-widetag))
172
173 (!define-type-vops simple-array-p check-simple-array nil
174     object-not-simple-array-error
175   (simple-array-widetag .
176    #.(map 'list
177           #'saetp-typecode
178           *specialized-array-element-type-properties*)))
179
180 (!define-type-vops arrayp check-array nil object-not-array-error
181   (simple-array-widetag
182    complex-array-widetag
183    complex-vector-widetag .
184    #.(append
185       (map 'list
186            #'saetp-typecode
187            *specialized-array-element-type-properties*)
188       (mapcan (lambda (saetp)
189                 (when (saetp-complex-typecode saetp)
190                   (list (saetp-complex-typecode saetp))))
191               (coerce *specialized-array-element-type-properties* 'list)))))
192
193 (!define-type-vops numberp check-number nil object-not-number-error
194   (even-fixnum-lowtag
195    odd-fixnum-lowtag
196    bignum-widetag
197    ratio-widetag
198    single-float-widetag
199    double-float-widetag
200    #!+long-float long-float-widetag
201    complex-widetag
202    complex-single-float-widetag
203    complex-double-float-widetag
204    #!+long-float complex-long-float-widetag))
205
206 (!define-type-vops rationalp check-rational nil object-not-rational-error
207   (even-fixnum-lowtag odd-fixnum-lowtag ratio-widetag bignum-widetag))
208
209 (!define-type-vops integerp check-integer nil object-not-integer-error
210   (even-fixnum-lowtag odd-fixnum-lowtag bignum-widetag))
211
212 (!define-type-vops floatp check-float nil object-not-float-error
213   (single-float-widetag double-float-widetag #!+long-float long-float-widetag))
214
215 (!define-type-vops realp check-real nil object-not-real-error
216   (even-fixnum-lowtag
217    odd-fixnum-lowtag
218    ratio-widetag
219    bignum-widetag
220    single-float-widetag
221    double-float-widetag
222    #!+long-float long-float-widetag))