42bf1086805999ec71b79416ff91de052d77827b
[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   ;; FIXME: make this be FIXNUM-MASK
19   :mask 3)
20
21 (!define-type-vops functionp check-fun function object-not-fun-error
22   (fun-pointer-lowtag)
23   :mask lowtag-mask)
24
25 (!define-type-vops listp check-list list object-not-list-error
26   (list-pointer-lowtag)
27   :mask lowtag-mask)
28
29 (!define-type-vops %instancep check-instance instance object-not-instance-error
30   (instance-pointer-lowtag)
31   :mask lowtag-mask)
32
33 (!define-type-vops bignump check-bignum bignum object-not-bignum-error
34   (bignum-widetag))
35
36 (!define-type-vops ratiop check-ratio ratio object-not-ratio-error
37   (ratio-widetag))
38
39 (!define-type-vops complexp check-complex complex object-not-complex-error
40   (complex-widetag complex-single-float-widetag complex-double-float-widetag
41                    #!+long-float complex-long-float-widetag))
42
43 (!define-type-vops complex-rational-p check-complex-rational nil
44     object-not-complex-rational-error
45   (complex-widetag))
46
47 (!define-type-vops complex-float-p check-complex-float nil
48     object-not-complex-float-error
49   (complex-single-float-widetag complex-double-float-widetag
50                                 #!+long-float complex-long-float-widetag))
51
52 (!define-type-vops complex-single-float-p check-complex-single-float complex-single-float
53     object-not-complex-single-float-error
54   (complex-single-float-widetag))
55
56 (!define-type-vops complex-double-float-p check-complex-double-float complex-double-float
57     object-not-complex-double-float-error
58   (complex-double-float-widetag))
59
60 #!+long-float
61 (!define-type-vops complex-long-float-p check-complex-long-float complex-long-float
62     object-not-complex-long-float-error
63   (complex-long-float-widetag))
64
65 (!define-type-vops single-float-p check-single-float single-float
66     object-not-single-float-error
67   (single-float-widetag))
68
69 (!define-type-vops double-float-p check-double-float double-float
70     object-not-double-float-error
71   (double-float-widetag))
72
73 #!+long-float
74 (!define-type-vops long-float-p check-long-float long-float
75     object-not-long-float-error
76   (long-float-widetag))
77
78 (!define-type-vops simple-string-p check-simple-string nil
79     object-not-simple-string-error
80   (simple-base-string-widetag simple-array-nil-widetag))
81
82 (macrolet
83     ((define-simple-array-type-vops ()
84          `(progn
85            ,@(map 'list
86                   (lambda (saetp)
87                     (let ((primtype (saetp-primitive-type-name saetp)))
88                     `(!define-type-vops
89                       ,(symbolicate primtype "-P")
90                       ,(symbolicate "CHECK-" primtype)
91                       ,primtype
92                       ,(symbolicate "OBJECT-NOT-" primtype "-ERROR")
93                       (,(saetp-typecode saetp)))))
94                   *specialized-array-element-type-properties*))))
95   (define-simple-array-type-vops))
96
97 (!define-type-vops base-char-p check-base-char base-char
98     object-not-base-char-error
99   (base-char-widetag))
100
101 (!define-type-vops system-area-pointer-p check-system-area-pointer
102       system-area-pointer
103     object-not-sap-error
104   (sap-widetag))
105
106 (!define-type-vops weak-pointer-p check-weak-pointer weak-pointer
107     object-not-weak-pointer-error
108   (weak-pointer-widetag))
109
110 (!define-type-vops code-component-p nil nil nil
111   (code-header-widetag))
112
113 (!define-type-vops lra-p nil nil nil
114   (return-pc-header-widetag))
115
116 (!define-type-vops fdefn-p nil nil nil
117   (fdefn-widetag))
118
119 (!define-type-vops funcallable-instance-p nil nil nil
120   (funcallable-instance-header-widetag))
121
122 (!define-type-vops array-header-p nil nil nil
123   (simple-array-widetag 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   (simple-base-string-widetag complex-base-string-widetag
128    simple-array-nil-widetag complex-vector-nil-widetag))
129
130 (!define-type-vops base-string-p check-base-string nil object-not-base-string-error
131   (simple-base-string-widetag complex-base-string-widetag))
132
133 (!define-type-vops bit-vector-p check-bit-vector nil
134     object-not-bit-vector-error
135   (simple-bit-vector-widetag complex-bit-vector-widetag))
136
137 (!define-type-vops vector-nil-p check-vector-nil nil
138     object-not-vector-nil-error
139   (simple-array-nil-widetag complex-vector-nil-widetag))
140
141 (!define-type-vops vectorp check-vector nil object-not-vector-error
142   (complex-vector-widetag .
143    #.(append
144       (map 'list
145            #'saetp-typecode
146            *specialized-array-element-type-properties*)
147       (mapcan (lambda (saetp)
148                 (when (saetp-complex-typecode saetp)
149                   (list (saetp-complex-typecode saetp))))
150               (coerce *specialized-array-element-type-properties* 'list)))))
151
152 ;;; Note that this "type VOP" is sort of an oddball; it doesn't so
153 ;;; much test for a Lisp-level type as just expose a low-level type
154 ;;; code at the Lisp level. It is used as a building block to help us
155 ;;; to express things like the test for (TYPEP FOO '(VECTOR T))
156 ;;; efficiently in Lisp code, but it doesn't correspond to any type
157 ;;; expression which would actually occur in reasonable application
158 ;;; code. (Common Lisp doesn't have any natural way of expressing this
159 ;;; type.) Thus, there's no point in building up the full machinery of
160 ;;; associated backend type predicates and so forth as we do for
161 ;;; ordinary type VOPs.
162 (!define-type-vops complex-vector-p check-complex-vector nil
163     object-not-complex-vector-error
164   (complex-vector-widetag))
165
166 (!define-type-vops simple-array-p check-simple-array nil
167     object-not-simple-array-error
168   (simple-array-widetag .
169    #.(map 'list
170           #'saetp-typecode
171           *specialized-array-element-type-properties*)))
172
173 (!define-type-vops arrayp check-array nil object-not-array-error
174   (simple-array-widetag
175    complex-array-widetag
176    complex-vector-widetag .
177    #.(append
178       (map 'list
179            #'saetp-typecode
180            *specialized-array-element-type-properties*)
181       (mapcan (lambda (saetp)
182                 (when (saetp-complex-typecode saetp)
183                   (list (saetp-complex-typecode saetp))))
184               (coerce *specialized-array-element-type-properties* 'list)))))
185
186 (!define-type-vops numberp check-number nil object-not-number-error
187   (even-fixnum-lowtag
188    odd-fixnum-lowtag
189    bignum-widetag
190    ratio-widetag
191    single-float-widetag
192    double-float-widetag
193    #!+long-float long-float-widetag
194    complex-widetag
195    complex-single-float-widetag
196    complex-double-float-widetag
197    #!+long-float complex-long-float-widetag))
198
199 (!define-type-vops rationalp check-rational nil object-not-rational-error
200   (even-fixnum-lowtag odd-fixnum-lowtag ratio-widetag bignum-widetag))
201
202 (!define-type-vops integerp check-integer nil object-not-integer-error
203   (even-fixnum-lowtag odd-fixnum-lowtag bignum-widetag))
204
205 (!define-type-vops floatp check-float nil object-not-float-error
206   (single-float-widetag double-float-widetag #!+long-float long-float-widetag))
207
208 (!define-type-vops realp check-real nil object-not-real-error
209   (even-fixnum-lowtag
210    odd-fixnum-lowtag
211    ratio-widetag
212    bignum-widetag
213    single-float-widetag
214    double-float-widetag
215    #!+long-float long-float-widetag))