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
61 code_block_unoptimized,
67 /* Constants used when floating-point trap exceptions are thrown */
70 FP_TRAP_INVALID_OPERATION = 1 << 0,
71 FP_TRAP_OVERFLOW = 1 << 1,
72 FP_TRAP_UNDERFLOW = 1 << 2,
73 FP_TRAP_ZERO_DIVIDE = 1 << 3,
74 FP_TRAP_INEXACT = 1 << 4,
77 /* What Factor calls 'f' */
78 static const cell false_object = F_TYPE;
80 inline static bool immediate_p(cell obj)
82 /* We assume that fixnums have tag 0 and false_object has tag 1 */
83 return TAG(obj) <= F_TYPE;
86 inline static fixnum untag_fixnum(cell tagged)
89 assert(TAG(tagged) == FIXNUM_TYPE);
91 return ((fixnum)tagged) >> TAG_BITS;
94 inline static cell tag_fixnum(fixnum untagged)
96 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
99 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
106 template<typename Fixup> cell size(Fixup fixup) const;
108 cell binary_payload_start() const;
109 template<typename Fixup> cell binary_payload_start(Fixup fixup) const;
111 cell *slots() const { return (cell *)this; }
113 template<typename Iterator> void each_slot(Iterator &iter);
115 /* Only valid for objects in tenured space; must cast to free_heap_block
116 to do anything with it if its free */
119 return (header & 1) == 1;
124 return (header >> 2) & TAG_MASK;
127 void initialize(cell type)
132 cell hashcode() const
134 return (header >> 6);
137 void set_hashcode(cell hashcode)
139 header = (header & 0x3f) | (hashcode << 6);
142 bool forwarding_pointer_p() const
144 return (header & 2) == 2;
147 object *forwarding_pointer() const
149 return (object *)UNTAG(header);
152 void forward_to(object *pointer)
154 header = ((cell)pointer | 2);
158 /* Assembly code makes assumptions about the layout of this struct */
159 struct array : public object {
160 static const cell type_number = ARRAY_TYPE;
161 static const cell element_size = sizeof(cell);
165 cell *data() const { return (cell *)(this + 1); }
168 /* These are really just arrays, but certain elements have special
170 struct tuple_layout : public array {
180 struct bignum : public object {
181 static const cell type_number = BIGNUM_TYPE;
182 static const cell element_size = sizeof(cell);
186 cell *data() const { return (cell *)(this + 1); }
189 struct byte_array : public object {
190 static const cell type_number = BYTE_ARRAY_TYPE;
191 static const cell element_size = 1;
200 template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); }
203 /* Assembly code makes assumptions about the layout of this struct */
204 struct string : public object {
205 static const cell type_number = STRING_TYPE;
206 /* tagged num of chars */
213 u8 *data() const { return (u8 *)(this + 1); }
218 /* Assembly code makes assumptions about the layout of this struct */
219 struct word : public object {
220 static const cell type_number = WORD_TYPE;
221 /* TAGGED hashcode */
223 /* TAGGED word name */
225 /* TAGGED word vocabulary */
227 /* TAGGED definition */
229 /* TAGGED property assoc for library code */
231 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
233 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
235 /* TAGGED call count for profiling */
237 /* TAGGED machine code for sub-primitive */
239 /* UNTAGGED entry point: jump here to execute word */
241 /* UNTAGGED compiled code block */
243 /* UNTAGGED profiler stub */
244 code_block *profiling;
247 /* Assembly code makes assumptions about the layout of this struct */
248 struct wrapper : public object {
249 static const cell type_number = WRAPPER_TYPE;
253 /* Assembly code makes assumptions about the layout of this struct */
254 struct boxed_float : object {
255 static const cell type_number = FLOAT_TYPE;
264 /* Assembly code makes assumptions about the layout of this struct */
265 struct quotation : public object {
266 static const cell type_number = QUOTATION_TYPE;
273 /* UNTAGGED entry point; jump here to call quotation */
275 /* UNTAGGED compiled code block */
279 /* Assembly code makes assumptions about the layout of this struct */
280 struct alien : public object {
281 static const cell type_number = ALIEN_TYPE;
291 void update_address()
293 if(base == false_object)
294 address = displacement;
296 address = UNTAG(base) + sizeof(byte_array) + displacement;
300 struct dll : public object {
301 static const cell type_number = DLL_TYPE;
302 /* tagged byte array holding a C string */
304 /* OS-specific handle */
309 /* Updated by procedure prologue with procedure start address */
311 /* Frame size in bytes */
315 struct callstack : public object {
316 static const cell type_number = CALLSTACK_TYPE;
320 stack_frame *frame_at(cell offset) const
322 return (stack_frame *)((char *)(this + 1) + offset);
325 stack_frame *top() const { return (stack_frame *)(this + 1); }
326 stack_frame *bottom() const { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
329 struct tuple : public object {
330 static const cell type_number = TUPLE_TYPE;
334 cell *data() const { return (cell *)(this + 1); }
337 struct data_root_range {
341 explicit data_root_range(cell *start_, cell len_) :
342 start(start_), len(len_) {}