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_OBJECT_H__
26 #define __ST_OBJECT_H__
29 #include <st-small-integer.h>
33 #include <st-universe.h>
36 st_oop_t
st_object_new (st_oop_t klass
);
37 st_oop_t
st_object_new_arrayed (st_oop_t klass
, st_smi_t size
);
39 void st_object_initialize_header (st_oop_t object
, st_oop_t klass
);
40 void st_object_initialize_body (st_oop_t object
, st_smi_t instance_size
);
43 INLINE
int st_object_tag (st_oop_t object
);
44 INLINE
bool st_object_is_mark (st_oop_t object
);
45 INLINE
bool st_object_is_heap (st_oop_t object
);
46 INLINE
bool st_object_is_smi (st_oop_t object
);
49 INLINE st_oop_t
st_object_class (st_oop_t object
);
50 INLINE guint
st_object_hash (st_oop_t object
);
51 INLINE st_vtable_t
*st_object_virtual (st_oop_t object
);
52 INLINE st_vtable_t
*st_object_super_virtual (st_oop_t object
);
53 INLINE
bool st_object_equal (st_oop_t object
, st_oop_t another
);
54 INLINE
bool st_object_verify (st_oop_t object
);
57 INLINE
bool st_object_is_class (st_oop_t object
);
58 INLINE
bool st_object_is_metaclass (st_oop_t object
);
59 INLINE
bool st_object_is_association (st_oop_t object
);
60 INLINE
bool st_object_is_symbol (st_oop_t object
);
61 INLINE
bool st_object_is_compiled_method (st_oop_t object
);
62 INLINE
bool st_object_is_compiled_block (st_oop_t object
);
63 INLINE
bool st_object_is_block_closure (st_oop_t object
);
64 INLINE
bool st_object_is_method_context (st_oop_t object
);
65 INLINE
bool st_object_is_block_context (st_oop_t object
);
66 INLINE
bool st_object_is_arrayed (st_oop_t object
);
67 INLINE
bool st_object_is_array (st_oop_t object
);
68 INLINE
bool st_object_is_byte_array (st_oop_t object
);
70 st_vtable_t
*st_object_vtable (void);
73 /* inline definitions */
76 st_object_tag (st_oop_t object
)
78 return object
& st_tag_mask
;
82 st_object_is_mark (st_oop_t object
)
84 return st_object_tag (object
) == ST_MARK_TAG
;
88 st_object_is_heap (st_oop_t object
)
90 return st_object_tag (object
) == ST_POINTER_TAG
;
94 st_object_is_smi (st_oop_t object
)
96 return st_object_tag (object
) == ST_SMI_TAG
;
102 st_object_class (st_oop_t object
)
104 if (G_UNLIKELY (st_object_is_smi (object
)))
107 return st_heap_object_class (object
);
111 st_object_virtual (st_oop_t object
)
113 if (G_UNLIKELY (st_object_is_smi (object
)))
114 return st_smi_vtable ();
116 return (ST_CLASS_VTABLE (st_object_class (object
)));
120 st_object_super_virtual (st_oop_t object
)
122 if (G_UNLIKELY (st_object_is_smi (object
)))
123 return st_smi_vtable ()->parent_table
;
125 return ST_CLASS_VTABLE (st_object_class (object
))->parent_table
;
130 st_object_equal (st_oop_t object
, st_oop_t another
)
132 return st_object_virtual (object
)->equal (object
, another
);
136 st_object_hash (st_oop_t object
)
138 return st_object_virtual (object
)->hash (object
);
143 st_object_verify (st_oop_t object
)
145 return st_object_virtual (object
)->verify (object
);
149 st_object_describe (st_oop_t object
)
151 return st_object_virtual (object
)->describe (object
);
156 * We delegate the test to the vtable methods stored in object's class object
161 st_object_is_class (st_oop_t object
)
163 return st_object_is_heap (object
) &&
164 st_object_virtual (object
)->is_class ();
168 st_object_is_metaclass (st_oop_t object
)
170 return st_object_is_heap (object
) &&
171 st_object_virtual (object
)->is_metaclass ();
175 st_object_is_association (st_oop_t object
)
177 return st_object_is_heap (object
) &&
178 st_object_virtual (object
)->is_association ();
182 st_object_is_symbol (st_oop_t object
)
184 return st_object_is_heap (object
) &&
185 st_object_virtual (object
)->is_symbol ();
189 st_object_is_float (st_oop_t object
)
191 return st_object_is_heap (object
) &&
192 st_object_virtual (object
)->is_float ();
196 st_object_is_dictionary (st_oop_t object
)
198 return st_object_is_heap (object
) &&
199 st_object_virtual (object
)->is_dictionary ();
203 st_object_is_set (st_oop_t object
)
205 return st_object_is_heap (object
) &&
206 st_object_virtual (object
)->is_set ();
210 st_object_is_compiled_method (st_oop_t object
)
212 return st_object_is_heap (object
) &&
213 st_object_virtual (object
)->is_compiled_method ();
217 st_object_is_compiled_block (st_oop_t object
)
219 return st_object_is_heap (object
) &&
220 st_object_virtual (object
)->is_compiled_block ();
224 st_object_is_block_closure (st_oop_t object
)
226 return st_object_is_heap (object
) &&
227 st_object_virtual (object
)->is_block_closure ();
231 st_object_is_method_context (st_oop_t object
)
233 return st_object_is_heap (object
) &&
234 st_object_virtual (object
)->is_method_context ();
238 st_object_is_block_context (st_oop_t object
)
240 return st_object_is_heap (object
) &&
241 st_object_virtual (object
)->is_block_context ();
245 st_object_is_arrayed (st_oop_t object
)
247 return st_object_is_heap (object
) &&
248 st_object_virtual (object
)->is_arrayed ();
252 st_object_is_array (st_oop_t object
)
254 return st_object_is_heap (object
) &&
255 st_object_virtual (object
)->is_array ();
259 st_object_is_byte_array (st_oop_t object
)
261 return st_object_is_heap (object
) &&
262 st_object_virtual (object
)->is_byte_array ();
265 #endif /* __ST_OBJECT_H__ */