3 typedef unsigned char u8;
4 typedef unsigned short u16;
5 typedef unsigned int u32;
6 typedef unsigned long long u64;
7 typedef signed char s8;
8 typedef signed short s16;
9 typedef signed int s32;
10 typedef signed long long s64;
13 typedef long long fixnum;
14 typedef unsigned long long cell;
17 typedef unsigned long cell;
20 inline static cell align(cell a, cell b) { return (a + (b - 1)) & ~(b - 1); }
22 inline static cell alignment_for(cell a, cell b) { return align(a, b) - a; }
24 static const cell data_alignment = 16;
26 #define WORD_SIZE (signed)(sizeof(cell) * 8)
30 #define TAG(x) ((cell)(x) & TAG_MASK)
31 #define UNTAG(x) ((cell)(x) & ~TAG_MASK)
32 #define RETAG(x, tag) (UNTAG(x) | (tag))
39 #define QUOTATION_TYPE 4
43 #define WRAPPER_TYPE 8
44 #define BYTE_ARRAY_TYPE 9
45 #define CALLSTACK_TYPE 10
46 #define STRING_TYPE 11
52 static inline const char* type_name(cell type) {
88 enum code_block_type {
89 code_block_unoptimized,
94 /* Constants used when floating-point trap exceptions are thrown */
96 FP_TRAP_INVALID_OPERATION = 1 << 0,
97 FP_TRAP_OVERFLOW = 1 << 1,
98 FP_TRAP_UNDERFLOW = 1 << 2,
99 FP_TRAP_ZERO_DIVIDE = 1 << 3,
100 FP_TRAP_INEXACT = 1 << 4,
103 /* What Factor calls 'f' */
104 static const cell false_object = F_TYPE;
106 inline static bool immediate_p(cell obj) {
107 /* We assume that fixnums have tag 0 and false_object has tag 1 */
108 return TAG(obj) <= F_TYPE;
111 inline static fixnum untag_fixnum(cell tagged) {
113 FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE);
115 return ((fixnum) tagged) >> TAG_BITS;
118 inline static cell tag_fixnum(fixnum untagged) {
119 return (untagged << TAG_BITS) | FIXNUM_TYPE;
122 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
129 template <typename Fixup> cell size(Fixup fixup) const;
131 cell binary_payload_start() const;
132 template <typename Fixup> cell binary_payload_start(Fixup fixup) const;
134 cell* slots() const { return (cell*)this; }
136 template <typename Iterator> void each_slot(Iterator& iter);
138 /* Only valid for objects in tenured space; must cast to free_heap_block
139 to do anything with it if its free */
140 bool free_p() const { return (header & 1) == 1; }
142 cell type() const { return (header >> 2) & TAG_MASK; }
144 void initialize(cell type) { header = type << 2; }
146 cell hashcode() const { return (header >> 6); }
148 void set_hashcode(cell hashcode) {
149 header = (header & 0x3f) | (hashcode << 6);
152 bool forwarding_pointer_p() const { return (header & 2) == 2; }
154 object* forwarding_pointer() const { return (object*)UNTAG(header); }
156 void forward_to(object* pointer) { header = ((cell) pointer | 2); }
159 /* Assembly code makes assumptions about the layout of this struct */
160 struct array : public object {
161 static const cell type_number = ARRAY_TYPE;
162 static const cell element_size = sizeof(cell);
166 cell* data() const { return (cell*)(this + 1); }
169 /* These are really just arrays, but certain elements have special
171 struct tuple_layout : public array {
181 struct bignum : public object {
182 static const cell type_number = BIGNUM_TYPE;
183 static const cell element_size = sizeof(cell);
187 cell* data() const { return (cell*)(this + 1); }
190 struct byte_array : public object {
191 static const cell type_number = BYTE_ARRAY_TYPE;
192 static const cell element_size = 1;
201 template <typename Scalar> Scalar* data() const {
202 return (Scalar*)(this + 1);
206 /* Assembly code makes assumptions about the layout of this struct */
207 struct string : public object {
208 static const cell type_number = STRING_TYPE;
209 /* tagged num of chars */
216 u8* data() const { return (u8*)(this + 1); }
221 /* Assembly code makes assumptions about the layout of this struct:
222 basis/bootstrap/images/images.factor
223 basis/compiler/constants/constants.factor
224 core/bootstrap/primitives.factor
226 struct word : public object {
227 static const cell type_number = WORD_TYPE;
228 /* TAGGED hashcode */
230 /* TAGGED word name */
232 /* TAGGED word vocabulary */
234 /* TAGGED definition */
236 /* TAGGED property assoc for library code */
238 /* TAGGED alternative entry point for direct non-tail calls. Used for inline
241 /* TAGGED alternative entry point for direct tail calls. Used for inline
244 /* TAGGED machine code for sub-primitive */
246 /* UNTAGGED entry point: jump here to execute word */
248 /* UNTAGGED compiled code block */
250 /* defined in code_blocks.hpp */
251 code_block* code() const;
254 /* Assembly code makes assumptions about the layout of this struct */
255 struct wrapper : public object {
256 static const cell type_number = WRAPPER_TYPE;
260 /* Assembly code makes assumptions about the layout of this struct */
261 struct boxed_float : object {
262 static const cell type_number = FLOAT_TYPE;
271 /* Assembly code makes assumptions about the layout of this struct:
272 basis/bootstrap/images/images.factor
273 basis/compiler/constants/constants.factor
274 core/bootstrap/primitives.factor
276 struct quotation : public object {
277 static const cell type_number = QUOTATION_TYPE;
284 /* UNTAGGED entry point; jump here to call quotation */
287 /* defined in code_blocks.hpp */
288 code_block* code() const;
291 /* Assembly code makes assumptions about the layout of this struct */
292 struct alien : public object {
293 static const cell type_number = ALIEN_TYPE;
303 void update_address() {
304 if (base == false_object)
305 address = displacement;
307 address = UNTAG(base) + sizeof(byte_array) + displacement;
311 struct dll : public object {
312 static const cell type_number = DLL_TYPE;
313 /* tagged byte array holding a C string */
315 /* OS-specific handle */
319 struct callstack : public object {
320 static const cell type_number = CALLSTACK_TYPE;
324 void* frame_top_at(cell offset) const {
325 return (void*)((char*)(this + 1) + offset);
328 void* top() const { return (void*)(this + 1); }
329 void* bottom() const {
330 return (void*)((cell)(this + 1) + untag_fixnum(length));
334 struct tuple : public object {
335 static const cell type_number = TUPLE_TYPE;
339 cell* data() const { return (cell*)(this + 1); }
342 struct data_root_range {
346 data_root_range(cell* start_, cell len_)
347 : start(start_), len(len_) {}