1 ;;;; generic type testing and checking apparatus
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 (defparameter *immediate-types*
14 (list unbound-marker-widetag base-char-widetag))
16 (defparameter *fun-header-widetags*
17 (list funcallable-instance-header-widetag
18 simple-fun-header-widetag
19 closure-fun-header-widetag
20 closure-header-widetag))
22 (defun canonicalize-headers (headers)
26 (delta (- other-immediate-1-lowtag other-immediate-0-lowtag)))
28 (results (if (= start prev)
31 (dolist (header (sort headers #'<))
35 ((= header (+ prev delta))
44 (defmacro test-type (value target not-p
47 &key &allow-other-keys)
48 ;; Determine what interesting combinations we need to test for.
49 (let* ((type-codes (mapcar #'eval type-codes))
50 (fixnump (and (member even-fixnum-lowtag type-codes)
51 (member odd-fixnum-lowtag type-codes)
53 (lowtags (remove lowtag-limit type-codes :test #'<))
54 (extended (remove lowtag-limit type-codes :test #'>))
55 (immediates (intersection extended *immediate-types* :test #'eql))
56 (headers (set-difference extended *immediate-types* :test #'eql))
57 (function-p (if (intersection headers *fun-header-widetags*)
58 (if (subsetp headers *fun-header-widetags*)
60 (error "can't test for mix of function subtypes ~
61 and normal header types"))
64 (error "At least one type must be supplied for TEST-TYPE."))
67 (when (remove-if (lambda (x)
68 (or (= x even-fixnum-lowtag)
69 (= x odd-fixnum-lowtag)))
71 (error "can't mix fixnum testing with other lowtags"))
73 (error "can't mix fixnum testing with function subtype testing"))
75 (error "can't mix fixnum testing with other immediates"))
77 `(%test-fixnum-and-headers ,value ,target ,not-p
78 ',(canonicalize-headers headers)
80 `(%test-fixnum ,value ,target ,not-p
84 (error "can't mix testing of immediates with testing of headers"))
86 (error "can't mix testing of immediates with testing of lowtags"))
87 (when (cdr immediates)
88 (error "can't test multiple immediates at the same time"))
89 `(%test-immediate ,value ,target ,not-p ,(car immediates)
93 (error "can't test multiple lowtags at the same time"))
95 `(%test-lowtag-and-headers
96 ,value ,target ,not-p ,(car lowtags)
97 ,function-p ',(canonicalize-headers headers)
99 `(%test-lowtag ,value ,target ,not-p ,(car lowtags)
102 `(%test-headers ,value ,target ,not-p ,function-p
103 ',(canonicalize-headers headers)
106 (error "nothing to test?")))))