3 typedef intptr_t fixnum;
4 typedef uintptr_t cell;
6 inline static cell align(cell a, cell b) { return (a + (b - 1)) & ~(b - 1); }
8 inline static cell alignment_for(cell a, cell b) { return align(a, b) - a; }
10 static const cell data_alignment = 16;
12 #define WORD_SIZE (signed)(sizeof(cell) * 8)
16 #define TAG(x) ((cell)(x) & TAG_MASK)
17 #define UNTAG(x) ((cell)(x) & ~TAG_MASK)
18 #define RETAG(x, tag) (UNTAG(x) | (tag))
25 #define QUOTATION_TYPE 4
29 #define WRAPPER_TYPE 8
30 #define BYTE_ARRAY_TYPE 9
31 #define CALLSTACK_TYPE 10
32 #define STRING_TYPE 11
38 static inline const char* type_name(cell type) {
74 enum code_block_type {
75 code_block_unoptimized,
80 /* Constants used when floating-point trap exceptions are thrown */
82 FP_TRAP_INVALID_OPERATION = 1 << 0,
83 FP_TRAP_OVERFLOW = 1 << 1,
84 FP_TRAP_UNDERFLOW = 1 << 2,
85 FP_TRAP_ZERO_DIVIDE = 1 << 3,
86 FP_TRAP_INEXACT = 1 << 4,
89 /* What Factor calls 'f' */
90 static const cell false_object = F_TYPE;
92 inline static bool immediate_p(cell obj) {
93 /* We assume that fixnums have tag 0 and false_object has tag 1 */
94 return TAG(obj) <= F_TYPE;
97 inline static fixnum untag_fixnum(cell tagged) {
98 FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE);
99 return ((fixnum)tagged) >> TAG_BITS;
102 inline static cell tag_fixnum(fixnum untagged) {
103 return (untagged << TAG_BITS) | FIXNUM_TYPE;
106 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
113 template <typename Fixup> cell size(Fixup fixup) const;
115 cell binary_payload_start() const;
116 template <typename Fixup> cell binary_payload_start(Fixup fixup) const;
118 cell* slots() const { return (cell*)this; }
120 template <typename Iterator> void each_slot(Iterator& iter);
122 /* Only valid for objects in tenured space; must cast to free_heap_block
123 to do anything with it if its free */
124 bool free_p() const { return (header & 1) == 1; }
126 cell type() const { return (header >> 2) & TAG_MASK; }
128 void initialize(cell type) { header = type << 2; }
130 cell hashcode() const { return (header >> 6); }
132 void set_hashcode(cell hashcode) {
133 header = (header & 0x3f) | (hashcode << 6);
136 bool forwarding_pointer_p() const { return (header & 2) == 2; }
138 object* forwarding_pointer() const { return (object*)UNTAG(header); }
140 void forward_to(object* pointer) { header = ((cell)pointer | 2); }
143 /* Assembly code makes assumptions about the layout of this struct */
144 struct array : public object {
145 static const cell type_number = ARRAY_TYPE;
146 static const cell element_size = sizeof(cell);
150 cell* data() const { return (cell*)(this + 1); }
153 /* These are really just arrays, but certain elements have special
155 struct tuple_layout : public array {
165 struct bignum : public object {
166 static const cell type_number = BIGNUM_TYPE;
167 static const cell element_size = sizeof(cell);
171 cell* data() const { return (cell*)(this + 1); }
174 struct byte_array : public object {
175 static const cell type_number = BYTE_ARRAY_TYPE;
176 static const cell element_size = 1;
185 template <typename Scalar> Scalar* data() const {
186 return (Scalar*)(this + 1);
190 /* Assembly code makes assumptions about the layout of this struct */
191 struct string : public object {
192 static const cell type_number = STRING_TYPE;
193 /* tagged num of chars */
200 uint8_t* data() const { return (uint8_t*)(this + 1); }
205 /* Assembly code makes assumptions about the layout of this struct:
206 basis/bootstrap/images/images.factor
207 basis/compiler/constants/constants.factor
208 core/bootstrap/primitives.factor
210 struct word : public object {
211 static const cell type_number = WORD_TYPE;
212 /* TAGGED hashcode */
214 /* TAGGED word name */
216 /* TAGGED word vocabulary */
218 /* TAGGED definition */
220 /* TAGGED property assoc for library code */
222 /* TAGGED alternative entry point for direct non-tail calls. Used for inline
225 /* TAGGED alternative entry point for direct tail calls. Used for inline
228 /* TAGGED machine code for sub-primitive */
230 /* UNTAGGED entry point: jump here to execute word */
232 /* UNTAGGED compiled code block */
234 /* defined in code_blocks.hpp */
235 code_block* code() const;
238 /* Assembly code makes assumptions about the layout of this struct */
239 struct wrapper : public object {
240 static const cell type_number = WRAPPER_TYPE;
244 /* Assembly code makes assumptions about the layout of this struct */
245 struct boxed_float : object {
246 static const cell type_number = FLOAT_TYPE;
255 /* Assembly code makes assumptions about the layout of this struct:
256 basis/bootstrap/images/images.factor
257 basis/compiler/constants/constants.factor
258 core/bootstrap/primitives.factor
260 struct quotation : public object {
261 static const cell type_number = QUOTATION_TYPE;
268 /* UNTAGGED entry point; jump here to call quotation */
271 /* defined in code_blocks.hpp */
272 code_block* code() const;
275 /* Assembly code makes assumptions about the layout of this struct */
276 struct alien : public object {
277 static const cell type_number = ALIEN_TYPE;
287 void update_address() {
288 if (base == false_object)
289 address = displacement;
291 address = UNTAG(base) + sizeof(byte_array) + displacement;
295 struct dll : public object {
296 static const cell type_number = DLL_TYPE;
297 /* tagged byte array holding a C string */
299 /* OS-specific handle */
303 struct callstack : public object {
304 static const cell type_number = CALLSTACK_TYPE;
308 void* frame_top_at(cell offset) const {
309 return (void*)((char*)(this + 1) + offset);
312 void* top() const { return (void*)(this + 1); }
313 void* bottom() const {
314 return (void*)((cell)(this + 1) + untag_fixnum(length));
318 struct tuple : public object {
319 static const cell type_number = TUPLE_TYPE;
323 cell* data() const { return (cell*)(this + 1); }
326 struct data_root_range {
330 data_root_range(cell* start, cell len)
331 : start(start), len(len) {}