1.0.46.7: better error message for an invalid lambda in COMPILE, etc
[sbcl.git] / src / compiler / generic / early-objdef.lisp
1 ;;;; type-based constants
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
12 (in-package "SB!VM")
13
14 ;;; Tags for the main low-level types are stored in the low n (usually three)
15 ;;; bits to identify the type of a machine word.  Certain constraints
16 ;;; apply:
17 ;;;   * EVEN-FIXNUM-LOWTAG and ODD-FIXNUM-LOWTAG must be 0 and 4: code
18 ;;;     which shifts left two places to convert raw integers to tagged
19 ;;;     fixnums is ubiquitous.
20 ;;;   * LIST-POINTER-LOWTAG + N-WORD-BYTES = OTHER-POINTER-LOWTAG: NIL
21 ;;;     is both a cons and a symbol (at the same address) and depends on this.
22 ;;;     See the definition of SYMBOL in objdef.lisp
23 ;;;   * OTHER-POINTER-LOWTAG > 4: Some code in the SPARC backend,
24 ;;;     which uses bit 2 of the ALLOC register to indicate that
25 ;;;     PSEUDO-ATOMIC is on, doesn't strip the low bits of reg_ALLOC
26 ;;;     before ORing in OTHER-POINTER-LOWTAG within a PSEUDO-ATOMIC
27 ;;;     section.
28 ;;;   * OTHER-IMMEDIATE-0-LOWTAG are spaced 4 apart: various code wants to
29 ;;;     iterate through these
30 ;;;   * Allocation code on Alpha wants lowtags for heap-allocated
31 ;;;     objects to be odd.
32 ;;; (These are just the ones we know about as of sbcl-0.7.1.22. There
33 ;;; might easily be more, since these values have stayed highly
34 ;;; constrained for more than a decade, an inviting target for
35 ;;; inventive abstraction-phobic maintainers.:-)
36 (eval-when (:compile-toplevel :load-toplevel :execute)
37   ;; The EVAL-WHEN is necessary (at least for Lispworks), because the
38   ;; second DEFENUM uses the value of OTHER-IMMEDIATE-0-LOWTAG, which is
39   ;; defined in the first DEFENUM. -- AL 20000216
40   #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
41   (defenum ()
42     even-fixnum-lowtag
43     instance-pointer-lowtag
44     other-immediate-0-lowtag
45     pad0-lowtag
46     pad1-lowtag pad2-lowtag
47     other-immediate-1-lowtag
48     list-pointer-lowtag
49     odd-fixnum-lowtag
50     fun-pointer-lowtag
51     other-immediate-2-lowtag
52     pad3-lowtag
53     pad4-lowtag
54     pad5-lowtag
55     other-immediate-3-lowtag
56     other-pointer-lowtag)
57   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
58   (defenum ()
59     even-fixnum-lowtag
60     instance-pointer-lowtag
61     other-immediate-0-lowtag
62     list-pointer-lowtag
63     odd-fixnum-lowtag
64     fun-pointer-lowtag
65     other-immediate-1-lowtag
66     other-pointer-lowtag))
67
68 (def!constant nil-value
69     (+ static-space-start n-word-bytes other-pointer-lowtag))
70
71 ;;; the heap types, stored in 8 bits of the header of an object on the
72 ;;; heap, to identify the type of the heap object (which'll be at
73 ;;; least two machine words, often more)
74 ;;;
75 ;;; Note: the order specified here is not critical for correctness,
76 ;;; but (FIXME) with %TEST-HEADERS as currently defined, BIGNUM must
77 ;;; be first, and COMPLEX-ARRAY must be last.
78 ;;;
79 ;;; However, for efficiency, we prefer contiguous sets of widetags for
80 ;;; "similar" objects, so that type checking can be done with a range
81 ;;; check, rather than several individual checks.
82 ;;;
83 ;;; * BIGNUM + RATIO (+ FIXNUM) = RATIONAL
84 ;;;
85 ;;; * SINGLE-FLOAT + DOUBLE-FLOAT + LONG-FLOAT = FLOAT
86 ;;;
87 ;;; * RATIONAL + FLOAT = REAL
88 ;;;
89 ;;; * (FIXME: COMPLEX example, which needs fixing anyway -- see
90 ;;;   UPGRADED-COMPLEX-PART-TYPE)
91 ;;;
92 ;;; * SIMPLE-ARRAY-* = (SIMPLE-ARRAY * (*))
93 ;;;
94 ;;; * SIMPLE-ARRAY-NIL + SIMPLE-BASE-STRING = SIMPLE-STRING
95 ;;;
96 ;;; * SIMPLE-ARRAY + COMPLEX-ARRAYOID = (SATISFIES ARRAY-HEADER-P)
97 ;;;
98 ;;; In addition, with
99 ;;; sufficient care we can cause extra combinations to appear with
100 ;;; differences in only one bit, permitting a more efficient type
101 ;;; test.  As an example, if SIMPLE-BASE-STRING = 0xA6 and
102 ;;; COMPLEX-BASE-STRING = 0xE6, then the type test for BASE-STRING is
103 ;;;
104 ;;;   AND   tag, ~0x40, tag
105 ;;;   ANDcc tag,  0xA6, tag
106 ;;;   JNE   tag, label
107 ;;;
108 ;;; rather than two separate tests and jumps
109 (defenum (;; The first widetag must be greater than SB!VM:LOWTAG-LIMIT
110           ;; otherwise code in generic/early-type-vops will suffer
111           ;; a long, horrible death.  --njf, 2004-08-09
112           :start (+ (ash 1 n-lowtag-bits) other-immediate-0-lowtag)
113           :step 4)
114   ;; NOTE: the binary numbers off to the side are only valid for 32-bit
115   ;; ports; add #b1000 if you want to know the values for 64-bit ports.
116   ;; And note that the numbers get a little scrambled further down.
117   ;;   --njf, 2004-08-09
118   bignum-widetag                            ; 00001010
119   ratio-widetag                             ; 00001110
120   single-float-widetag                      ; 00010010
121   double-float-widetag                      ; 00010110
122   complex-widetag                           ; 00011010
123   complex-single-float-widetag              ; 00011110
124   complex-double-float-widetag              ; 00100010
125
126   code-header-widetag                       ; 00100110
127
128   simple-fun-header-widetag                 ; 00101010
129   closure-header-widetag                    ; 00101110
130   funcallable-instance-header-widetag       ; 00110010
131
132   return-pc-header-widetag                  ; 00110110
133   value-cell-header-widetag                 ; 00111010
134   symbol-header-widetag                     ; 00111110
135   character-widetag                         ; 01000010
136   sap-widetag                               ; 01000110
137   unbound-marker-widetag                    ; 01001010
138   weak-pointer-widetag                      ; 01001110
139   instance-header-widetag                   ; 01010010
140   fdefn-widetag                             ; 01010110
141
142   no-tls-value-marker-widetag               ; 01011010
143   #!-(and sb-lutex sb-thread)
144   unused01-widetag
145   #!+(and sb-lutex sb-thread)
146   lutex-widetag                             ; 01011110
147   unused02-widetag                          ; 01100010
148   unused03-widetag                          ; 01100110
149   unused04-widetag                          ; 01101010
150   unused05-widetag                          ; 01101110
151   unused06-widetag                          ; 01110010
152   unused07-widetag                          ; 01110110
153   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
154   unused08-widetag                          ; 01111010
155   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
156   unused09-widetag                          ; 01111110
157
158   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
159   unused10-widetag                          ; 10000010
160   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
161   unused11-widetag                          ; 10000110
162
163   simple-array-unsigned-byte-2-widetag      ; 10001010
164   simple-array-unsigned-byte-4-widetag      ; 10001110
165   simple-array-unsigned-byte-7-widetag      ; 10010010
166   simple-array-unsigned-byte-8-widetag      ; 10010110
167   simple-array-unsigned-byte-15-widetag     ; 10011010
168   simple-array-unsigned-byte-16-widetag     ; 10011110
169   simple-array-nil-widetag                  ; 10100010
170   simple-base-string-widetag                ; 10100110
171   #!+sb-unicode simple-character-string-widetag
172   simple-bit-vector-widetag                 ; 10101010
173   simple-vector-widetag                     ; 10101110
174   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
175   simple-array-unsigned-byte-29-widetag     ; 10110010
176   simple-array-unsigned-byte-31-widetag     ; 10110110
177   simple-array-unsigned-byte-32-widetag     ; 10111010
178   #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
179   simple-array-unsigned-byte-60-widetag
180   #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
181   simple-array-unsigned-byte-63-widetag
182   #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
183   simple-array-unsigned-byte-64-widetag
184   simple-array-signed-byte-8-widetag        ; 10111110
185   simple-array-signed-byte-16-widetag       ; 11000010
186   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
187   simple-array-signed-byte-30-widetag       ; 11000110
188   simple-array-signed-byte-32-widetag       ; 11001010
189   #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
190   simple-array-signed-byte-61-widetag
191   #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
192   simple-array-signed-byte-64-widetag
193   simple-array-single-float-widetag         ; 11001110
194   simple-array-double-float-widetag         ; 11010010
195   simple-array-complex-single-float-widetag ; 11010110
196   simple-array-complex-double-float-widetag ; 11011010
197   simple-array-widetag                      ; 11011110
198   complex-vector-nil-widetag                ; 11100010
199   complex-base-string-widetag               ; 11100110
200   #!+sb-unicode complex-character-string-widetag
201   complex-bit-vector-widetag                ; 11101010
202   complex-vector-widetag                    ; 11101110
203   complex-array-widetag                     ; 11110010
204
205   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
206   unused12-widetag                          ; 11110110
207   #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
208           (not sb-unicode))
209   unused13-widetag                          ; 11111010
210   #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
211           (not sb-unicode))
212   unused14-widetag                          ; 11111110
213 )
214
215 ;;; the different vector subtypes
216 (defenum ()
217   vector-normal-subtype
218   vector-unused-subtype
219   vector-valid-hashing-subtype)