ef1aa306102b6bd359a6761e5acd9d98f4a7c3be
[sbcl.git] / src / compiler / generic / objdef.lisp
1 ;;;; machine-independent aspects of the object representation
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 \f
14 ;;;; the primitive objects themselves
15
16 (define-primitive-object (cons :lowtag list-pointer-type
17                                :alloc-trans cons)
18   (car :ref-trans car :set-trans sb!c::%rplaca :init :arg)
19   (cdr :ref-trans cdr :set-trans sb!c::%rplacd :init :arg))
20
21 (define-primitive-object (instance :lowtag instance-pointer-type
22                                    :header instance-header-type
23                                    :alloc-trans %make-instance)
24   (slots :rest-p t))
25
26 (define-primitive-object (bignum :lowtag other-pointer-type
27                                  :header bignum-type
28                                  :alloc-trans sb!bignum::%allocate-bignum)
29   (digits :rest-p t :c-type #!-alpha "long" #!+alpha "u32"))
30
31 (define-primitive-object (ratio :type ratio
32                                 :lowtag other-pointer-type
33                                 :header ratio-type
34                                 :alloc-trans %make-ratio)
35   (numerator :type integer
36              :ref-known (flushable movable)
37              :ref-trans %numerator
38              :init :arg)
39   (denominator :type integer
40                :ref-known (flushable movable)
41                :ref-trans %denominator
42                :init :arg))
43
44 (define-primitive-object (single-float :lowtag other-pointer-type
45                                        :header single-float-type)
46   (value :c-type "float"))
47
48 (define-primitive-object (double-float :lowtag other-pointer-type
49                                        :header double-float-type)
50   (filler)
51   (value :c-type "double" :length 2))
52
53 #!+long-float
54 (define-primitive-object (long-float :lowtag other-pointer-type
55                                      :header long-float-type)
56   #!+sparc (filler)
57   (value :c-type "long double" :length #!+x86 3 #!+sparc 4))
58
59 (define-primitive-object (complex :type complex
60                                   :lowtag other-pointer-type
61                                   :header complex-type
62                                   :alloc-trans %make-complex)
63   (real :type real
64         :ref-known (flushable movable)
65         :ref-trans %realpart
66         :init :arg)
67   (imag :type real
68         :ref-known (flushable movable)
69         :ref-trans %imagpart
70         :init :arg))
71
72 (define-primitive-object (array :lowtag other-pointer-type
73                                 :header t)
74   (fill-pointer :type index
75                 :ref-trans %array-fill-pointer
76                 :ref-known (flushable foldable)
77                 :set-trans (setf %array-fill-pointer)
78                 :set-known (unsafe))
79   (fill-pointer-p :type (member t nil)
80                   :ref-trans %array-fill-pointer-p
81                   :ref-known (flushable foldable)
82                   :set-trans (setf %array-fill-pointer-p)
83                   :set-known (unsafe))
84   (elements :type index
85             :ref-trans %array-available-elements
86             :ref-known (flushable foldable)
87             :set-trans (setf %array-available-elements)
88             :set-known (unsafe))
89   (data :type array
90         :ref-trans %array-data-vector
91         :ref-known (flushable foldable)
92         :set-trans (setf %array-data-vector)
93         :set-known (unsafe))
94   (displacement :type (or index null)
95                 :ref-trans %array-displacement
96                 :ref-known (flushable foldable)
97                 :set-trans (setf %array-displacement)
98                 :set-known (unsafe))
99   (displaced-p :type (member t nil)
100                :ref-trans %array-displaced-p
101                :ref-known (flushable foldable)
102                :set-trans (setf %array-displaced-p)
103                :set-known (unsafe))
104   (dimensions :rest-p t))
105
106 (define-primitive-object (vector :type vector
107                                  :lowtag other-pointer-type
108                                  :header t)
109   (length :ref-trans sb!c::vector-length
110           :type index)
111   (data :rest-p t :c-type #!-alpha "unsigned long" #!+alpha "u32"))
112
113 (define-primitive-object (code :type code-component
114                                :lowtag other-pointer-type
115                                :header t)
116   (code-size :type index
117              :ref-known (flushable movable)
118              :ref-trans %code-code-size)
119   (entry-points :type (or function null)
120                 :ref-known (flushable)
121                 :ref-trans %code-entry-points
122                 :set-known (unsafe)
123                 :set-trans (setf %code-entry-points))
124   (debug-info :type t
125               :ref-known (flushable)
126               :ref-trans %code-debug-info
127               :set-known (unsafe)
128               :set-trans (setf %code-debug-info))
129   (trace-table-offset)
130   (constants :rest-p t))
131
132 (define-primitive-object (fdefn :type fdefn
133                                 :lowtag other-pointer-type
134                                 :header fdefn-type)
135   (name :ref-trans fdefn-name)
136   (function :type (or function null) :ref-trans fdefn-function)
137   (raw-addr :c-type #!-alpha "char *" #!+alpha "u32"))
138
139 (define-primitive-object (function :type function
140                                    :lowtag function-pointer-type
141                                    :header function-header-type)
142   #!-x86 (self :ref-trans %function-self
143                :set-trans (setf %function-self))
144   #!+x86 (self
145           ;; KLUDGE: There's no :SET-KNOWN, :SET-TRANS, :REF-KNOWN, or
146           ;; :REF-TRANS here in this case. Instead, there's separate
147           ;; DEFKNOWN/DEFINE-VOP/DEFTRANSFORM stuff in
148           ;; compiler/x86/system.lisp to define and declare them by
149           ;; hand. I don't know why this is, but that's (basically)
150           ;; the way it was done in CMU CL, and it works. (It's not
151           ;; exactly the same way it was done in CMU CL in that CMU
152           ;; CL's allows duplicate DEFKNOWNs, blithely overwriting any
153           ;; previous data associated with the previous DEFKNOWN, and
154           ;; that property was used to mask the definitions here. In
155           ;; SBCL as of 0.6.12.64 that's not allowed -- too confusing!
156           ;; -- so we have to explicitly suppress the DEFKNOWNish
157           ;; stuff here in order to allow this old hack to work in the
158           ;; new world. -- WHN 2001-08-82
159           )
160   (next :type (or function null)
161         :ref-known (flushable)
162         :ref-trans %function-next
163         :set-known (unsafe)
164         :set-trans (setf %function-next))
165   (name :ref-known (flushable)
166         :ref-trans %function-name
167         :set-known (unsafe)
168         :set-trans (setf %function-name))
169   (arglist :ref-known (flushable)
170            :ref-trans %function-arglist
171            :set-known (unsafe)
172            :set-trans (setf %function-arglist))
173   (type :ref-known (flushable)
174         :ref-trans %function-type
175         :set-known (unsafe)
176         :set-trans (setf %function-type))
177   (code :rest-p t :c-type "unsigned char"))
178
179 (define-primitive-object (return-pc :lowtag other-pointer-type :header t)
180   (return-point :c-type "unsigned char" :rest-p t))
181
182 (define-primitive-object (closure :lowtag function-pointer-type
183                                   :header closure-header-type)
184   (function :init :arg :ref-trans %closure-function)
185   (info :rest-p t))
186
187 (define-primitive-object (funcallable-instance
188                           :lowtag function-pointer-type
189                           :header funcallable-instance-header-type
190                           :alloc-trans %make-funcallable-instance)
191   #!-x86
192   (function
193    :ref-known (flushable) :ref-trans %funcallable-instance-function
194    :set-known (unsafe) :set-trans (setf %funcallable-instance-function))
195   #!+x86
196   (function
197    :ref-known (flushable) :ref-trans %funcallable-instance-function
198    ;; KLUDGE: There's no :SET-KNOWN or :SET-TRANS in this case.
199    ;; Instead, later in compiler/x86/system.lisp there's a separate
200    ;; DEFKNOWN for (SETF %FUNCALLABLE-INSTANCE-FUNCTION), and a weird
201    ;; unexplained DEFTRANSFORM from (SETF %FUNCTION-INSTANCE-FUNCTION)
202    ;; into (SETF %FUNCTION-SELF). The #!+X86 wrapped around this case
203    ;; is a literal translation of the old CMU CL implementation into
204    ;; the new world of sbcl-0.6.12.63, where multiple DEFKNOWNs for
205    ;; the same operator cause an error (instead of silently deleting
206    ;; all information associated with the old DEFKNOWN, as before).
207    ;; It's definitely not very clean, with too many #!+ conditionals and
208    ;; too little documentation, but I have more urgent things to
209    ;; clean up right now, so I've just left it as a literal
210    ;; translation without trying to fix it. -- WHN 2001-08-02
211    )
212   (lexenv :ref-known (flushable) :ref-trans %funcallable-instance-lexenv
213           :set-known (unsafe) :set-trans (setf %funcallable-instance-lexenv))
214   (layout :init :arg
215           :ref-known (flushable) :ref-trans %funcallable-instance-layout
216           :set-known (unsafe) :set-trans (setf %funcallable-instance-layout))
217   (info :rest-p t))
218
219 (define-primitive-object (value-cell :lowtag other-pointer-type
220                                      :header value-cell-header-type
221                                      :alloc-trans make-value-cell)
222   (value :set-trans value-cell-set
223          :set-known (unsafe)
224          :ref-trans value-cell-ref
225          :ref-known (flushable)
226          :init :arg))
227
228 #!+alpha
229 (define-primitive-object (sap :lowtag other-pointer-type
230                               :header sap-type)
231   (padding)
232   (pointer :c-type "char *" :length 2))
233
234 #!-alpha
235 (define-primitive-object (sap :lowtag other-pointer-type
236                               :header sap-type)
237   (pointer :c-type "char *"))
238
239
240 (define-primitive-object (weak-pointer :type weak-pointer
241                                        :lowtag other-pointer-type
242                                        :header weak-pointer-type
243                                        :alloc-trans make-weak-pointer)
244   (value :ref-trans sb!c::%weak-pointer-value :ref-known (flushable)
245          :init :arg)
246   (broken :type (member t nil)
247           :ref-trans sb!c::%weak-pointer-broken :ref-known (flushable)
248           :init :null)
249   (next :c-type #!-alpha "struct weak_pointer *" #!+alpha "u32"))
250
251 ;;;; other non-heap data blocks
252
253 (define-primitive-object (binding)
254   value
255   symbol)
256
257 (define-primitive-object (unwind-block)
258   (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
259   (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
260   #!-x86 current-code
261   entry-pc)
262
263 (define-primitive-object (catch-block)
264   (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
265   (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
266   #!-x86 current-code
267   entry-pc
268   tag
269   (previous-catch :c-type #!-alpha "struct catch_block *" #!+alpha "u32")
270   size)
271
272 ;;; (For an explanation of this, see the comments at the definition of
273 ;;; KLUDGE-NONDETERMINISTIC-CATCH-BLOCK-SIZE.)
274 (aver (= sb!vm::kludge-nondeterministic-catch-block-size catch-block-size))
275 \f
276 ;;;; symbols
277
278 #!+x86
279 (defknown symbol-hash (symbol) (integer 0 #.*target-most-positive-fixnum*)
280   (flushable movable))
281
282 (define-primitive-object (symbol :lowtag other-pointer-type
283                                  :header symbol-header-type
284                                  #!-x86 :alloc-trans #!-x86 make-symbol)
285   (value :set-trans %set-symbol-value
286          :init :unbound)
287   #!+x86 (hash)
288   (plist :ref-trans symbol-plist
289          :set-trans %set-symbol-plist
290          :init :null)
291   (name :ref-trans symbol-name :init :arg)
292   (package :ref-trans symbol-package
293            :set-trans %set-symbol-package
294            :init :null))
295
296 (define-primitive-object (complex-single-float
297                           :lowtag other-pointer-type
298                           :header complex-single-float-type)
299   (real :c-type "float")
300   (imag :c-type "float"))
301
302 (define-primitive-object (complex-double-float
303                           :lowtag other-pointer-type
304                           :header complex-double-float-type)
305   (filler)
306   (real :c-type "double" :length 2)
307   (imag :c-type "double" :length 2))
308
309 #!+long-float
310 (define-primitive-object (complex-long-float
311                           :lowtag other-pointer-type
312                           :header complex-long-float-type)
313   #!+sparc (filler)
314   (real :c-type "long double" :length #!+x86 3 #!+sparc 4)
315   (imag :c-type "long double" :length #!+x86 3 #!+sparc 4))
316