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 (define-primitive-object (single-float :lowtag other-pointer-lowtag
70 :widetag single-float-widetag)
71 (value :c-type "float"))
73 (define-primitive-object (double-float :lowtag other-pointer-lowtag
74 :widetag double-float-widetag)
76 (value :c-type "double" :length 2))
79 (define-primitive-object (long-float :lowtag other-pointer-lowtag
80 :widetag long-float-widetag)
82 (value :c-type "long double" :length #!+x86 3 #!+sparc 4))
84 (define-primitive-object (complex :type complex
85 :lowtag other-pointer-lowtag
86 :widetag complex-widetag
87 :alloc-trans %make-complex)
89 :ref-known (flushable movable)
93 :ref-known (flushable movable)
97 (define-primitive-object (array :lowtag other-pointer-lowtag
99 (fill-pointer :type index
100 :ref-trans %array-fill-pointer
101 :ref-known (flushable foldable)
102 :set-trans (setf %array-fill-pointer)
104 (fill-pointer-p :type (member t nil)
105 :ref-trans %array-fill-pointer-p
106 :ref-known (flushable foldable)
107 :set-trans (setf %array-fill-pointer-p)
109 (elements :type index
110 :ref-trans %array-available-elements
111 :ref-known (flushable foldable)
112 :set-trans (setf %array-available-elements)
115 :ref-trans %array-data-vector
116 :ref-known (flushable foldable)
117 :set-trans (setf %array-data-vector)
119 (displacement :type (or index null)
120 :ref-trans %array-displacement
121 :ref-known (flushable foldable)
122 :set-trans (setf %array-displacement)
124 (displaced-p :type (member t nil)
125 :ref-trans %array-displaced-p
126 :ref-known (flushable foldable)
127 :set-trans (setf %array-displaced-p)
129 (dimensions :rest-p t))
131 (define-primitive-object (vector :type vector
132 :lowtag other-pointer-lowtag
134 (length :ref-trans sb!c::vector-length
136 (data :rest-p t :c-type #!-alpha "unsigned long" #!+alpha "u32"))
138 (define-primitive-object (code :type code-component
139 :lowtag other-pointer-lowtag
141 (code-size :type index
142 :ref-known (flushable movable)
143 :ref-trans %code-code-size)
144 (entry-points :type (or function null)
145 :ref-known (flushable)
146 :ref-trans %code-entry-points
148 :set-trans (setf %code-entry-points))
150 :ref-known (flushable)
151 :ref-trans %code-debug-info
153 :set-trans (setf %code-debug-info))
155 (constants :rest-p t))
157 (define-primitive-object (fdefn :type fdefn
158 :lowtag other-pointer-lowtag
159 :widetag fdefn-widetag)
160 (name :ref-trans fdefn-name)
161 (fun :type (or function null) :ref-trans fdefn-fun)
162 (raw-addr :c-type #!-alpha "char *" #!+alpha "u32"))
164 ;;; a simple function (as opposed to hairier things like closures
165 ;;; which are also subtypes of Common Lisp's FUNCTION type)
166 (define-primitive-object (simple-fun :type function
167 :lowtag fun-pointer-lowtag
168 :widetag simple-fun-header-widetag)
169 #!-x86 (self :ref-trans %simple-fun-self
170 :set-trans (setf %simple-fun-self))
172 ;; KLUDGE: There's no :SET-KNOWN, :SET-TRANS, :REF-KNOWN, or
173 ;; :REF-TRANS here in this case. Instead, there's separate
174 ;; DEFKNOWN/DEFINE-VOP/DEFTRANSFORM stuff in
175 ;; compiler/x86/system.lisp to define and declare them by
176 ;; hand. I don't know why this is, but that's (basically)
177 ;; the way it was done in CMU CL, and it works. (It's not
178 ;; exactly the same way it was done in CMU CL in that CMU
179 ;; CL's allows duplicate DEFKNOWNs, blithely overwriting any
180 ;; previous data associated with the previous DEFKNOWN, and
181 ;; that property was used to mask the definitions here. In
182 ;; SBCL as of 0.6.12.64 that's not allowed -- too confusing!
183 ;; -- so we have to explicitly suppress the DEFKNOWNish
184 ;; stuff here in order to allow this old hack to work in the
185 ;; new world. -- WHN 2001-08-82
187 (next :type (or function null)
188 :ref-known (flushable)
189 :ref-trans %simple-fun-next
191 :set-trans (setf %simple-fun-next))
192 (name :ref-known (flushable)
193 :ref-trans %simple-fun-name
195 :set-trans (setf %simple-fun-name))
196 (arglist :ref-known (flushable)
197 :ref-trans %simple-fun-arglist
199 :set-trans (setf %simple-fun-arglist))
200 (type :ref-known (flushable)
201 :ref-trans %simple-fun-type
203 :set-trans (setf %simple-fun-type))
204 ;; the SB!C::DEBUG-FUN object corresponding to this object, or NIL for none
205 #+nil ; FIXME: doesn't work (gotcha, lowly maintenoid!) See notes on bug 137.
206 (debug-fun :ref-known (flushable)
207 :ref-trans %simple-fun-debug-fun
209 :set-trans (setf %simple-fun-debug-fun))
210 (code :rest-p t :c-type "unsigned char"))
212 (define-primitive-object (return-pc :lowtag other-pointer-lowtag :widetag t)
213 (return-point :c-type "unsigned char" :rest-p t))
215 (define-primitive-object (closure :lowtag fun-pointer-lowtag
216 :widetag closure-header-widetag)
217 (fun :init :arg :ref-trans %closure-fun)
220 (define-primitive-object (funcallable-instance
221 :lowtag fun-pointer-lowtag
222 :widetag funcallable-instance-header-widetag
223 :alloc-trans %make-funcallable-instance)
226 :ref-known (flushable) :ref-trans %funcallable-instance-fun
227 :set-known (unsafe) :set-trans (setf %funcallable-instance-fun))
230 :ref-known (flushable) :ref-trans %funcallable-instance-fun
231 ;; KLUDGE: There's no :SET-KNOWN or :SET-TRANS in this case.
232 ;; Instead, later in compiler/x86/system.lisp there's a separate
233 ;; DEFKNOWN for (SETF %FUNCALLABLE-INSTANCE-FUN), and a weird
234 ;; unexplained DEFTRANSFORM from (SETF %SIMPLE-FUN-INSTANCE-FUN)
235 ;; into (SETF %SIMPLE-FUN-SELF). The #!+X86 wrapped around this case
236 ;; is a literal translation of the old CMU CL implementation into
237 ;; the new world of sbcl-0.6.12.63, where multiple DEFKNOWNs for
238 ;; the same operator cause an error (instead of silently deleting
239 ;; all information associated with the old DEFKNOWN, as before).
240 ;; It's definitely not very clean, with too many #!+ conditionals and
241 ;; too little documentation, but I have more urgent things to
242 ;; clean up right now, so I've just left it as a literal
243 ;; translation without trying to fix it. -- WHN 2001-08-02
245 (lexenv :ref-known (flushable) :ref-trans %funcallable-instance-lexenv
246 :set-known (unsafe) :set-trans (setf %funcallable-instance-lexenv))
248 :ref-known (flushable) :ref-trans %funcallable-instance-layout
249 :set-known (unsafe) :set-trans (setf %funcallable-instance-layout))
252 (define-primitive-object (value-cell :lowtag other-pointer-lowtag
253 :widetag value-cell-header-widetag
254 :alloc-trans make-value-cell)
255 (value :set-trans value-cell-set
257 :ref-trans value-cell-ref
258 :ref-known (flushable)
262 (define-primitive-object (sap :lowtag other-pointer-lowtag
263 :widetag sap-widetag)
265 (pointer :c-type "char *" :length 2))
268 (define-primitive-object (sap :lowtag other-pointer-lowtag
269 :widetag sap-widetag)
270 (pointer :c-type "char *"))
273 (define-primitive-object (weak-pointer :type weak-pointer
274 :lowtag other-pointer-lowtag
275 :widetag weak-pointer-widetag
276 :alloc-trans make-weak-pointer)
277 (value :ref-trans sb!c::%weak-pointer-value :ref-known (flushable)
279 (broken :type (member t nil)
280 :ref-trans sb!c::%weak-pointer-broken :ref-known (flushable)
282 (next :c-type #!-alpha "struct weak_pointer *" #!+alpha "u32"))
284 ;;;; other non-heap data blocks
286 (define-primitive-object (binding)
290 (define-primitive-object (unwind-block)
291 (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
292 (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
296 (define-primitive-object (catch-block)
297 (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
298 (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
302 (previous-catch :c-type #!-alpha "struct catch_block *" #!+alpha "u32")
305 ;;; (For an explanation of this, see the comments at the definition of
306 ;;; KLUDGE-NONDETERMINISTIC-CATCH-BLOCK-SIZE.)
307 (aver (= kludge-nondeterministic-catch-block-size catch-block-size))
312 (defknown symbol-hash (symbol) (integer 0 #.*target-most-positive-fixnum*)
315 (define-primitive-object (symbol :lowtag other-pointer-lowtag
316 :widetag symbol-header-widetag
317 #!-x86 :alloc-trans #!-x86 make-symbol)
318 (value :set-trans %set-symbol-value
321 (plist :ref-trans symbol-plist
322 :set-trans %set-symbol-plist
324 (name :ref-trans symbol-name :init :arg)
325 (package :ref-trans symbol-package
326 :set-trans %set-symbol-package
329 (define-primitive-object (complex-single-float
330 :lowtag other-pointer-lowtag
331 :widetag complex-single-float-widetag)
332 (real :c-type "float")
333 (imag :c-type "float"))
335 (define-primitive-object (complex-double-float
336 :lowtag other-pointer-lowtag
337 :widetag complex-double-float-widetag)
339 (real :c-type "double" :length 2)
340 (imag :c-type "double" :length 2))
343 (define-primitive-object (complex-long-float
344 :lowtag other-pointer-lowtag
345 :widetag complex-long-float-widetag)
347 (real :c-type "long double" :length #!+x86 3 #!+sparc 4)
348 (imag :c-type "long double" :length #!+x86 3 #!+sparc 4))