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 #include "st-heap-object.h"
26 #include "st-small-integer.h"
27 #include "st-byte-array.h"
28 #include "st-object.h"
29 #include "st-descriptor.h"
32 #define HEADER(object) (ST_POINTER (object)->header)
34 int st_current_hash
= 0;
37 st_heap_object_hash (st_oop object
)
39 return (guint
) ST_POINTER (object
)->hash
;
43 st_heap_object_set_hash (st_oop object
, int value
)
45 ST_POINTER (object
)->hash
= (st_smi
) value
;
49 st_heap_object_set_format (st_oop object
, guint format
)
51 HEADER (object
) = (HEADER (object
) & ~st_format_mask_in_place
) | (format
<< st_format_shift
);
55 st_heap_object_readonly (st_oop object
)
57 return (HEADER (object
) >> st_readonly_shift
) & st_readonly_mask
;
61 st_heap_object_set_readonly (st_oop object
, bool readonly
)
63 HEADER (object
) = (HEADER (object
) & ~st_readonly_mask_in_place
) | ((readonly
? 1 : 0) << st_readonly_shift
);
67 st_heap_object_nonpointer (st_oop object
)
69 return (HEADER (object
) >> st_nonpointer_shift
) & st_nonpointer_mask
;
73 st_heap_object_set_nonpointer (st_oop object
, bool nonpointer
)
75 HEADER (object
) = (HEADER (object
) & ~st_nonpointer_mask_in_place
) | ((nonpointer
? 1 : 0) << st_nonpointer_shift
);
79 st_heap_object_initialize_header (st_oop object
, st_oop klass
)
82 st_heap_object_set_format (object
, st_smi_value (st_behavior_format (klass
)));
83 st_heap_object_set_readonly (object
, false);
84 st_heap_object_set_nonpointer (object
, false);
87 st_heap_object_set_hash (object
, st_current_hash
++);
90 st_heap_object_class (object
) = klass
;
94 st_heap_object_initialize_body (st_oop object
, st_smi instance_size
)
96 st_oop
*instvars
= st_heap_object_body (object
);
98 for (st_smi i
= 0; i
< instance_size
; i
++)
104 allocate (st_oop klass
)
106 st_smi instance_size
= st_smi_value (st_behavior_instance_size (klass
));
108 st_oop object
= st_allocate_object (ST_TYPE_SIZE (STHeader
) + instance_size
);
110 st_heap_object_initialize_header (object
, klass
);
111 st_heap_object_initialize_body (object
, instance_size
);
117 st_heap_object_descriptor (void)
119 static const STDescriptor __descriptor
=
120 { .allocate
= allocate
,
121 .allocate_arrayed
= NULL
,
124 return & __descriptor
;