6 OBJECT
object_create_metaclass(STATE
, OBJECT cls
, OBJECT sup
);
7 OBJECT
object_metaclass(STATE
, OBJECT obj
);
8 int object_kind_of_p(STATE
, OBJECT self
, OBJECT cls
);
9 int object_has_ivars(STATE
, OBJECT self
);
10 void object_set_has_ivars(STATE
, OBJECT self
);
11 OBJECT
object_get_ivar(STATE
, OBJECT self
, OBJECT sym
);
12 OBJECT
object_set_ivar(STATE
, OBJECT self
, OBJECT sym
, OBJECT val
);
13 OBJECT
object_get_ivars(STATE
, OBJECT self
);
14 OBJECT
object_new(STATE
);
15 int object_copy_bytes_into(STATE
, OBJECT self
, OBJECT dest
, int count
, int offset
);
16 unsigned int object_hash_int(STATE
, OBJECT self
);
17 int object_stores_bytes_p(STATE
, OBJECT self
);
18 void object_make_byte_storage(STATE
, OBJECT self
);
19 void object_initialize_bytes(STATE
, OBJECT self
);
20 void object_set_tainted(STATE
, OBJECT self
);
21 void object_set_untainted(STATE
, OBJECT self
);
22 int object_tainted_p(STATE
, OBJECT self
);
23 void object_set_frozen(STATE
, OBJECT self
);
24 int object_frozen_p(STATE
, OBJECT self
);
25 void object_copy_ivars(STATE
, OBJECT self
, OBJECT dest
);
26 void object_copy_metaclass(STATE
, OBJECT self
, OBJECT dest
);
28 OBJECT
object_make_weak_ref(STATE
, OBJECT self
);
29 void object_cleanup_weak_refs(STATE
, OBJECT self
);
31 static inline OBJECT
object_class(STATE
, OBJECT self
) {
32 if(REFERENCE_P(self
)) {
33 OBJECT cls
= self
->klass
;
34 while(REFERENCE_P(cls
) && (metaclass_s_metaclass_p(state
, cls
) || cls
->obj_type
!= ClassType
)) {
35 cls
= class_get_superclass(cls
);
41 return state
->global
->special_classes
[((uintptr_t)self
) & SPECIAL_CLASS_MASK
];
44 #define object_byte_start(st, self) ((char*)BYTES_OF(self))
45 #define object_size(st, self) SIZE_OF_BODY(self)
47 static inline void object_copy_body(STATE
, OBJECT self
, OBJECT dest
) {
48 size_t s1
= object_size(state
, self
);
49 size_t s2
= object_size(state
, dest
);
52 memcpy(object_byte_start(state
, dest
), object_byte_start(state
, self
), s1
);
56 #define ISA(o, c) object_kind_of_p(state, o, c)
58 static inline uintptr_t object_get_id(STATE
, OBJECT self
) {
59 if(REFERENCE_P(self
)) {
62 meta
= object_metaclass(state
, self
);
63 id
= object_get_ivar(state
, meta
, state
->global
->sym_object_id
);
65 /* Lazy allocate object's ids, since most don't need them. */
67 /* All references have an even object_id. last_object_id starts out at 0
68 * but we don't want to use 0 as an object_id, so we just add before using */
69 id
= I2N(state
->om
->last_object_id
+= 2);
70 object_set_ivar(state
, meta
, state
->global
->sym_object_id
, id
);
75 /* All non-references have an odd object_id */
76 return (((uintptr_t)self
<< 1) | 1);
80 static inline int object_copy_fields_shifted(STATE
, OBJECT self
, OBJECT dest
, int dist
) {
84 count
= NUM_FIELDS(self
);
86 for(i
= 0; i
< count
; i
++) {
87 SET_FIELD(dest
, dist
+ i
, NTH_FIELD(self
, i
));
92 static inline int object_copy_fields_from(STATE
, OBJECT self
, OBJECT dest
, int first
, int count
) {
94 int max
= NUM_FIELDS(self
);
96 for(i
= first
, j
= 0; j
< count
&& i
< max
; i
++, j
++) {
97 SET_FIELD(dest
, j
, NTH_FIELD(self
, i
));
102 static inline void object_copy_fields(STATE
, OBJECT self
, OBJECT dest
) {
105 max
= NUM_FIELDS(self
);
106 j
= NUM_FIELDS(dest
);
109 for(i
= 0; i
< max
; i
++) {
110 SET_FIELD(dest
, i
, NTH_FIELD(self
, i
));