4 typedef unsigned char u8;
5 typedef unsigned short u16;
6 typedef unsigned int u32;
7 typedef unsigned long long u64;
8 typedef signed char s8;
9 typedef signed short s16;
10 typedef signed int s32;
11 typedef signed long long s64;
14 typedef long long fixnum;
15 typedef unsigned long long cell;
18 typedef unsigned long cell;
21 inline static cell align(cell a, cell b)
23 return (a + (b-1)) & ~(b-1);
26 inline static cell alignment_for(cell a, cell b)
28 return align(a,b) - a;
31 static const cell data_alignment = 16;
33 #define WORD_SIZE (signed)(sizeof(cell)*8)
37 #define TAG(x) ((cell)(x) & TAG_MASK)
38 #define UNTAG(x) ((cell)(x) & ~TAG_MASK)
39 #define RETAG(x,tag) (UNTAG(x) | (tag))
46 #define QUOTATION_TYPE 4
50 #define WRAPPER_TYPE 8
51 #define BYTE_ARRAY_TYPE 9
52 #define CALLSTACK_TYPE 10
53 #define STRING_TYPE 11
59 static inline const char *type_name(cell type)
99 code_block_unoptimized,
100 code_block_optimized,
104 /* Constants used when floating-point trap exceptions are thrown */
107 FP_TRAP_INVALID_OPERATION = 1 << 0,
108 FP_TRAP_OVERFLOW = 1 << 1,
109 FP_TRAP_UNDERFLOW = 1 << 2,
110 FP_TRAP_ZERO_DIVIDE = 1 << 3,
111 FP_TRAP_INEXACT = 1 << 4,
114 /* What Factor calls 'f' */
115 static const cell false_object = F_TYPE;
117 inline static bool immediate_p(cell obj)
119 /* We assume that fixnums have tag 0 and false_object has tag 1 */
120 return TAG(obj) <= F_TYPE;
123 inline static fixnum untag_fixnum(cell tagged)
126 FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE);
128 return ((fixnum)tagged) >> TAG_BITS;
131 inline static cell tag_fixnum(fixnum untagged)
133 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
136 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
143 template<typename Fixup> cell size(Fixup fixup) const;
145 cell binary_payload_start() const;
146 template<typename Fixup> cell binary_payload_start(Fixup fixup) const;
148 cell *slots() const { return (cell *)this; }
150 template<typename Iterator> void each_slot(Iterator &iter);
152 /* Only valid for objects in tenured space; must cast to free_heap_block
153 to do anything with it if its free */
156 return (header & 1) == 1;
161 return (header >> 2) & TAG_MASK;
164 void initialize(cell type)
169 cell hashcode() const
171 return (header >> 6);
174 void set_hashcode(cell hashcode)
176 header = (header & 0x3f) | (hashcode << 6);
179 bool forwarding_pointer_p() const
181 return (header & 2) == 2;
184 object *forwarding_pointer() const
186 return (object *)UNTAG(header);
189 void forward_to(object *pointer)
191 header = ((cell)pointer | 2);
195 /* Assembly code makes assumptions about the layout of this struct */
196 struct array : public object {
197 static const cell type_number = ARRAY_TYPE;
198 static const cell element_size = sizeof(cell);
202 cell *data() const { return (cell *)(this + 1); }
205 /* These are really just arrays, but certain elements have special
207 struct tuple_layout : public array {
217 struct bignum : public object {
218 static const cell type_number = BIGNUM_TYPE;
219 static const cell element_size = sizeof(cell);
223 cell *data() const { return (cell *)(this + 1); }
226 struct byte_array : public object {
227 static const cell type_number = BYTE_ARRAY_TYPE;
228 static const cell element_size = 1;
237 template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); }
240 /* Assembly code makes assumptions about the layout of this struct */
241 struct string : public object {
242 static const cell type_number = STRING_TYPE;
243 /* tagged num of chars */
250 u8 *data() const { return (u8 *)(this + 1); }
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 word : public object {
261 static const cell type_number = WORD_TYPE;
262 /* TAGGED hashcode */
264 /* TAGGED word name */
266 /* TAGGED word vocabulary */
268 /* TAGGED definition */
270 /* TAGGED property assoc for library code */
272 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
274 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
276 /* TAGGED machine code for sub-primitive */
278 /* UNTAGGED entry point: jump here to execute word */
280 /* UNTAGGED compiled code block */
282 /* defined in code_blocks.hpp */
283 code_block *code() const;
286 /* Assembly code makes assumptions about the layout of this struct */
287 struct wrapper : public object {
288 static const cell type_number = WRAPPER_TYPE;
292 /* Assembly code makes assumptions about the layout of this struct */
293 struct boxed_float : object {
294 static const cell type_number = FLOAT_TYPE;
303 /* Assembly code makes assumptions about the layout of this struct:
304 basis/bootstrap/images/images.factor
305 basis/compiler/constants/constants.factor
306 core/bootstrap/primitives.factor
308 struct quotation : public object {
309 static const cell type_number = QUOTATION_TYPE;
316 /* UNTAGGED entry point; jump here to call quotation */
319 /* defined in code_blocks.hpp */
320 code_block *code() const;
323 /* Assembly code makes assumptions about the layout of this struct */
324 struct alien : public object {
325 static const cell type_number = ALIEN_TYPE;
335 void update_address()
337 if(base == false_object)
338 address = displacement;
340 address = UNTAG(base) + sizeof(byte_array) + displacement;
344 struct dll : public object {
345 static const cell type_number = DLL_TYPE;
346 /* tagged byte array holding a C string */
348 /* OS-specific handle */
353 /* Updated by procedure prologue with procedure start address */
355 /* Frame size in bytes */
359 struct callstack : public object {
360 static const cell type_number = CALLSTACK_TYPE;
364 stack_frame *frame_at(cell offset) const
366 return (stack_frame *)((char *)(this + 1) + offset);
369 stack_frame *top() const { return (stack_frame *)(this + 1); }
370 stack_frame *bottom() const { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
373 struct tuple : public object {
374 static const cell type_number = TUPLE_TYPE;
378 cell *data() const { return (cell *)(this + 1); }
381 struct data_root_range {
385 explicit data_root_range(cell *start_, cell len_) :
386 start(start_), len(len_) {}