4 * Copyright (C) 2008 Vincent Geddes
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #ifndef __ST_HEAP_OBJECT_H__
26 #define __ST_HEAP_OBJECT_H__
30 #include <st-descriptor.h>
31 #include <st-small-integer.h>
33 /* Every heap-allocated object starts with this layout */
35 * [ unused: 9 | mark: 1 | format: 6 | tag: 2 ]
37 * format: object format
38 * mark: object contains a forwarding pointer
39 * unused: not used yet (haven't implemented GC)
52 struct st_arrayed_object
54 struct st_header header
;
58 extern int st_current_hash
;
68 st_format_shift
= st_tag_bits
+ st_tag_shift
,
69 st_mark_shift
= st_format_bits
+ st_format_shift
,
70 st_unused_shift
= st_mark_bits
+ st_mark_shift
,
72 st_format_mask
= ST_NTH_MASK (st_format_bits
),
73 st_format_mask_in_place
= st_format_mask
<< st_format_shift
,
74 st_mark_mask
= ST_NTH_MASK (st_mark_bits
),
75 st_mark_mask_in_place
= st_mark_mask
<< st_mark_shift
,
76 st_unused_mask
= ST_NTH_MASK (st_unused_bits
),
77 st_unused_mask_in_place
= st_unused_mask
<< st_unused_shift
,
80 #define st_heap_object_class(oop) (ST_POINTER (oop)->class)
81 #define st_heap_object_body(oop) (ST_POINTER (oop)->fields)
83 #define ST_ARRAYED_OBJECT(oop) ((struct st_arrayed_object *) ST_POINTER (oop))
85 void st_heap_object_initialize_header (st_oop object
, st_oop
class);
86 void st_heap_object_initialize_body (st_oop object
, st_smi instance_size
);
87 st_uint
st_heap_object_hash (st_oop object
);
88 void st_heap_object_set_hash (st_oop object
, int hash
);
89 void st_heap_object_set_format (st_oop object
, st_uint format
);
90 st_uint
st_heap_object_format (st_oop object
);
91 bool st_heap_object_marked (st_oop object
);
92 void st_heap_object_set_marked (st_oop object
, bool mark
);
95 void st_object_verify (st_oop object
);
97 void st_heap_object_install_forwarding_pointer (st_oop object
, st_oop pointer
);
98 st_oop
st_heap_object_forwarding_pointer (st_oop object
);
100 st_descriptor
*st_heap_object_descriptor (void);
104 st_arrayed_object_size (st_oop object
)
106 return ST_ARRAYED_OBJECT (object
)->size
;
109 static inline st_descriptor
*
110 st_heap_object_descriptor_for_object (st_oop object
)
112 return st_descriptors
[st_heap_object_format (object
)];
115 #endif /* __ST_HEAP_OBJECT_H__ */