1 ;;;; machine-independent aspects of the object representation
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.
14 ;;;; KLUDGE: The primitive objects here may look like self-contained
15 ;;;; definitions, but in general they're not. In particular, if you
16 ;;;; try to add a slot to them, beware of the following:
17 ;;;; * (mysterious crashes which occur after changing the length
18 ;;;; of SIMPLE-FUN, just adding a new slot not even doing anything
19 ;;;; with it, still dunno why)
20 ;;;; * The GC scavenging code (and for all I know other GC code too)
21 ;;;; is not automatically generated from these layouts, but instead
22 ;;;; was hand-written to correspond to them. The offsets are
23 ;;;; automatically propagated into the GC scavenging code, but the
24 ;;;; existence of slots, and whether they should be scavenged, is
25 ;;;; not automatically propagated. Thus e.g. if you add a
26 ;;;; SIMPLE-FUN-DEBUG-INFO slot holding a tagged object which needs
27 ;;;; to be GCed, you need to tweak scav_code_header() and
28 ;;;; verify_space() in gencgc.c, and the corresponding code in gc.c.
29 ;;;; * The src/runtime/print.c code (used by LDB) is implemented
30 ;;;; using hand-written lists of slot names, which aren't automatically
31 ;;;; generated from the code in this file.
32 ;;;; * Various code (e.g. STATIC-FSET in genesis.lisp) is hard-wired
33 ;;;; to know the name of the last slot of the object the code works
34 ;;;; with, and implicitly to know that the last slot is special (being
35 ;;;; the beginning of an arbitrary-length sequence of bytes following
36 ;;;; the fixed-layout slots).
37 ;;;; -- WHN 2001-12-29
39 ;;;; the primitive objects themselves
41 (define-primitive-object (cons :lowtag list-pointer-lowtag
43 (car :ref-trans car :set-trans sb!c::%rplaca :init :arg)
44 (cdr :ref-trans cdr :set-trans sb!c::%rplacd :init :arg))
46 (define-primitive-object (instance :lowtag instance-pointer-lowtag
47 :widetag instance-header-widetag
48 :alloc-trans %make-instance)
51 (define-primitive-object (bignum :lowtag other-pointer-lowtag
52 :widetag bignum-widetag
53 :alloc-trans sb!bignum::%allocate-bignum)
54 (digits :rest-p t :c-type #!-alpha "long" #!+alpha "u32"))
56 (define-primitive-object (ratio :type ratio
57 :lowtag other-pointer-lowtag
58 :widetag ratio-widetag
59 :alloc-trans %make-ratio)
60 (numerator :type integer
61 :ref-known (flushable movable)
64 (denominator :type integer
65 :ref-known (flushable movable)
66 :ref-trans %denominator
69 #!+#.(cl:if (cl:= sb!vm:n-word-bits 32) '(and) '(or))
70 (define-primitive-object (single-float :lowtag other-pointer-lowtag
71 :widetag single-float-widetag)
72 (value :c-type "float"))
74 (define-primitive-object (double-float :lowtag other-pointer-lowtag
75 :widetag double-float-widetag)
77 (value :c-type "double" :length #!-x86-64 2 #!+x86-64 1))
80 (define-primitive-object (long-float :lowtag other-pointer-lowtag
81 :widetag long-float-widetag)
83 (value :c-type "long double" :length #!+x86 3 #!+sparc 4))
85 (define-primitive-object (complex :type complex
86 :lowtag other-pointer-lowtag
87 :widetag complex-widetag
88 :alloc-trans %make-complex)
90 :ref-known (flushable movable)
94 :ref-known (flushable movable)
98 (define-primitive-object (array :lowtag other-pointer-lowtag
100 ;; FILL-POINTER of an ARRAY is in the same place as LENGTH of a
101 ;; VECTOR -- see SHRINK-VECTOR.
102 (fill-pointer :type index
103 :ref-trans %array-fill-pointer
104 :ref-known (flushable foldable)
105 :set-trans (setf %array-fill-pointer)
107 (fill-pointer-p :type (member t nil)
108 :ref-trans %array-fill-pointer-p
109 :ref-known (flushable foldable)
110 :set-trans (setf %array-fill-pointer-p)
112 (elements :type index
113 :ref-trans %array-available-elements
114 :ref-known (flushable foldable)
115 :set-trans (setf %array-available-elements)
118 :ref-trans %array-data-vector
119 :ref-known (flushable foldable)
120 :set-trans (setf %array-data-vector)
122 (displacement :type (or index null)
123 :ref-trans %array-displacement
124 :ref-known (flushable foldable)
125 :set-trans (setf %array-displacement)
127 (displaced-p :type (member t nil)
128 :ref-trans %array-displaced-p
129 :ref-known (flushable foldable)
130 :set-trans (setf %array-displaced-p)
132 (dimensions :rest-p t))
134 (define-primitive-object (vector :type vector
135 :lowtag other-pointer-lowtag
137 ;; FILL-POINTER of an ARRAY is in the same place as LENGTH of a
138 ;; VECTOR -- see SHRINK-VECTOR.
139 (length :ref-trans sb!c::vector-length
141 (data :rest-p t :c-type #!-alpha "unsigned long" #!+alpha "u32"))
143 (define-primitive-object (code :type code-component
144 :lowtag other-pointer-lowtag
146 (code-size :type index
147 :ref-known (flushable movable)
148 :ref-trans %code-code-size)
149 (entry-points :type (or function null)
150 :ref-known (flushable)
151 :ref-trans %code-entry-points
153 :set-trans (setf %code-entry-points))
155 :ref-known (flushable)
156 :ref-trans %code-debug-info
158 :set-trans (setf %code-debug-info))
160 (constants :rest-p t))
162 (define-primitive-object (fdefn :type fdefn
163 :lowtag other-pointer-lowtag
164 :widetag fdefn-widetag)
165 (name :ref-trans fdefn-name)
166 (fun :type (or function null) :ref-trans fdefn-fun)
167 (raw-addr :c-type #!-alpha "char *" #!+alpha "u32"))
169 ;;; a simple function (as opposed to hairier things like closures
170 ;;; which are also subtypes of Common Lisp's FUNCTION type)
171 (define-primitive-object (simple-fun :type function
172 :lowtag fun-pointer-lowtag
173 :widetag simple-fun-header-widetag)
174 #!-(or x86 x86-64) (self :ref-trans %simple-fun-self
175 :set-trans (setf %simple-fun-self))
176 #!+(or x86 x86-64) (self
177 ;; KLUDGE: There's no :SET-KNOWN, :SET-TRANS, :REF-KNOWN, or
178 ;; :REF-TRANS here in this case. Instead, there's separate
179 ;; DEFKNOWN/DEFINE-VOP/DEFTRANSFORM stuff in
180 ;; compiler/x86/system.lisp to define and declare them by
181 ;; hand. I don't know why this is, but that's (basically)
182 ;; the way it was done in CMU CL, and it works. (It's not
183 ;; exactly the same way it was done in CMU CL in that CMU
184 ;; CL's allows duplicate DEFKNOWNs, blithely overwriting any
185 ;; previous data associated with the previous DEFKNOWN, and
186 ;; that property was used to mask the definitions here. In
187 ;; SBCL as of 0.6.12.64 that's not allowed -- too confusing!
188 ;; -- so we have to explicitly suppress the DEFKNOWNish
189 ;; stuff here in order to allow this old hack to work in the
190 ;; new world. -- WHN 2001-08-82
192 (next :type (or function null)
193 :ref-known (flushable)
194 :ref-trans %simple-fun-next
196 :set-trans (setf %simple-fun-next))
197 (name :ref-known (flushable)
198 :ref-trans %simple-fun-name
200 :set-trans (setf %simple-fun-name))
202 :ref-known (flushable)
203 :ref-trans %simple-fun-arglist
205 :set-trans (setf %simple-fun-arglist))
206 (type :ref-known (flushable)
207 :ref-trans %simple-fun-type
209 :set-trans (setf %simple-fun-type))
210 ;; the SB!C::DEBUG-FUN object corresponding to this object, or NIL for none
211 #+nil ; FIXME: doesn't work (gotcha, lowly maintenoid!) See notes on bug 137.
212 (debug-fun :ref-known (flushable)
213 :ref-trans %simple-fun-debug-fun
215 :set-trans (setf %simple-fun-debug-fun))
216 (code :rest-p t :c-type "unsigned char"))
218 (define-primitive-object (return-pc :lowtag other-pointer-lowtag :widetag t)
219 (return-point :c-type "unsigned char" :rest-p t))
221 (define-primitive-object (closure :lowtag fun-pointer-lowtag
222 :widetag closure-header-widetag)
223 (fun :init :arg :ref-trans %closure-fun)
226 (define-primitive-object (funcallable-instance
227 :lowtag fun-pointer-lowtag
228 :widetag funcallable-instance-header-widetag
229 :alloc-trans %make-funcallable-instance)
232 :ref-known (flushable) :ref-trans %funcallable-instance-fun
233 :set-known (unsafe) :set-trans (setf %funcallable-instance-fun))
236 :ref-known (flushable) :ref-trans %funcallable-instance-fun
237 ;; KLUDGE: There's no :SET-KNOWN or :SET-TRANS in this case.
238 ;; Instead, later in compiler/x86/system.lisp there's a separate
239 ;; DEFKNOWN for (SETF %FUNCALLABLE-INSTANCE-FUN), and a weird
240 ;; unexplained DEFTRANSFORM from (SETF %SIMPLE-FUN-INSTANCE-FUN)
241 ;; into (SETF %SIMPLE-FUN-SELF). The #!+X86 wrapped around this case
242 ;; is a literal translation of the old CMU CL implementation into
243 ;; the new world of sbcl-0.6.12.63, where multiple DEFKNOWNs for
244 ;; the same operator cause an error (instead of silently deleting
245 ;; all information associated with the old DEFKNOWN, as before).
246 ;; It's definitely not very clean, with too many #!+ conditionals and
247 ;; too little documentation, but I have more urgent things to
248 ;; clean up right now, so I've just left it as a literal
249 ;; translation without trying to fix it. -- WHN 2001-08-02
251 (lexenv :ref-known (flushable) :ref-trans %funcallable-instance-lexenv
252 :set-known (unsafe) :set-trans (setf %funcallable-instance-lexenv))
254 :ref-known (flushable) :ref-trans %funcallable-instance-layout
255 :set-known (unsafe) :set-trans (setf %funcallable-instance-layout))
258 (define-primitive-object (value-cell :lowtag other-pointer-lowtag
259 :widetag value-cell-header-widetag
260 :alloc-trans make-value-cell)
261 (value :set-trans value-cell-set
263 :ref-trans value-cell-ref
264 :ref-known (flushable)
268 (define-primitive-object (sap :lowtag other-pointer-lowtag
269 :widetag sap-widetag)
271 (pointer :c-type "char *" :length 2))
274 (define-primitive-object (sap :lowtag other-pointer-lowtag
275 :widetag sap-widetag)
276 (pointer :c-type "char *"))
279 (define-primitive-object (weak-pointer :type weak-pointer
280 :lowtag other-pointer-lowtag
281 :widetag weak-pointer-widetag
282 :alloc-trans make-weak-pointer)
283 (value :ref-trans sb!c::%weak-pointer-value :ref-known (flushable)
285 (broken :type (member t nil)
286 :ref-trans sb!c::%weak-pointer-broken :ref-known (flushable)
288 (next :c-type #!-alpha "struct weak_pointer *" #!+alpha "u32"))
290 ;;;; other non-heap data blocks
292 (define-primitive-object (binding)
296 (define-primitive-object (unwind-block)
297 (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
298 (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
299 #!-(or x86 x86-64) current-code
302 (define-primitive-object (catch-block)
303 (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
304 (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
305 #!-(or x86 x86-64) current-code
308 (previous-catch :c-type #!-alpha "struct catch_block *" #!+alpha "u32")
311 ;;; (For an explanation of this, see the comments at the definition of
312 ;;; KLUDGE-NONDETERMINISTIC-CATCH-BLOCK-SIZE.)
313 (aver (= kludge-nondeterministic-catch-block-size catch-block-size))
317 (define-primitive-object (symbol :lowtag other-pointer-lowtag
318 :widetag symbol-header-widetag
319 :alloc-trans make-symbol)
321 ;; Beware when changing this definition. NIL-the-symbol is defined
322 ;; using this layout, and NIL-the-end-of-list-marker is the cons
323 ;; ( NIL . NIL ), living in the first two slots of NIL-the-symbol
324 ;; (conses have no header). Careful selection of lowtags ensures
325 ;; that the same pointer can be used for both purposes:
326 ;; OTHER-POINTER-LOWTAG is 7, LIST-POINTER-LOWTAG is 3, so if you
327 ;; subtract 3 from (SB-KERNEL:GET-LISP-OBJ-ADDRESS 'NIL) you get the
328 ;; first data slot, and if you subtract 7 you get a symbol header.
330 ;; also the CAR of NIL-as-end-of-list
331 (value :init :unbound :ref-known (flushable) :ref-trans symbol-global-value)
332 ;; also the CDR of NIL-as-end-of-list. Its reffer needs special
333 ;; care for this reason, as hash values must be fixnums.
334 (hash :set-trans %set-symbol-hash)
336 (plist :ref-trans symbol-plist
337 :set-trans %set-symbol-plist
339 (name :ref-trans symbol-name :init :arg)
340 (package :ref-trans symbol-package
341 :set-trans %set-symbol-package
343 #!+sb-thread (tls-index :ref-known (flushable) :ref-trans symbol-tls-index))
345 (define-primitive-object (complex-single-float
346 :lowtag other-pointer-lowtag
347 :widetag complex-single-float-widetag)
348 (real :c-type "float")
349 (imag :c-type "float"))
351 (define-primitive-object (complex-double-float
352 :lowtag other-pointer-lowtag
353 :widetag complex-double-float-widetag)
355 (real :c-type "double" :length #!-x86-64 2 #!+x86-64 1)
356 (imag :c-type "double" :length #!-x86-64 2 #!+x86-64 1))
358 ;;; this isn't actually a lisp object at all, it's a c structure that lives
359 ;;; in c-land. However, we need sight of so many parts of it from Lisp that
360 ;;; it makes sense to define it here anyway, so that the GENESIS machinery
361 ;;; can take care of maintaining Lisp and C versions.
362 ;;; Hence the even-fixnum lowtag just so we don't get odd(sic) numbers
363 ;;; added to the slot offsets
364 (define-primitive-object (thread :lowtag even-fixnum-lowtag)
365 ;; unbound_marker is borrowed very briefly at thread startup to
366 ;; pass the address of initial-function into new_thread_trampoline
367 (unbound-marker :init :unbound) ; tls[0] = UNBOUND_MARKER_WIDETAG
368 (os-thread :c-type "os_thread_t")
369 (binding-stack-start :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
370 (binding-stack-pointer :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
371 (control-stack-start :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
372 (control-stack-end :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
373 (alien-stack-start :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
374 (alien-stack-pointer :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
375 #!+gencgc (alloc-region :c-type "struct alloc_region" :length 5)
376 (tls-cookie) ; on x86, the LDT index
377 (this :c-type "struct thread *" :length #!+alpha 2 #!-alpha 1)
378 (prev :c-type "struct thread *" :length #!+alpha 2 #!-alpha 1)
379 (next :c-type "struct thread *" :length #!+alpha 2 #!-alpha 1)
380 ;; starting, running, suspended, dead
382 #!+(or x86 x86-64) (pseudo-atomic-atomic)
383 #!+(or x86 x86-64) (pseudo-atomic-interrupted)
386 (interrupt-data :c-type "struct interrupt_data *"
387 :length #!+alpha 2 #!-alpha 1)
388 (interrupt-contexts :c-type "os_context_t *" :rest-p t))