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 static const cell data_alignment = 16;
28 #define WORD_SIZE (signed)(sizeof(cell)*8)
32 #define TAG(x) ((cell)(x) & TAG_MASK)
33 #define UNTAG(x) ((cell)(x) & ~TAG_MASK)
34 #define RETAG(x,tag) (UNTAG(x) | (tag))
41 #define QUOTATION_TYPE 4
45 #define WRAPPER_TYPE 8
46 #define BYTE_ARRAY_TYPE 9
47 #define CALLSTACK_TYPE 10
48 #define STRING_TYPE 11
54 #define FORWARDING_POINTER 5 /* can be anything other than FIXNUM_TYPE */
58 code_block_unoptimized,
64 /* Constants used when floating-point trap exceptions are thrown */
67 FP_TRAP_INVALID_OPERATION = 1 << 0,
68 FP_TRAP_OVERFLOW = 1 << 1,
69 FP_TRAP_UNDERFLOW = 1 << 2,
70 FP_TRAP_ZERO_DIVIDE = 1 << 3,
71 FP_TRAP_INEXACT = 1 << 4,
74 /* What Factor calls 'f' */
75 static const cell false_object = F_TYPE;
77 inline static bool immediate_p(cell obj)
79 /* We assume that fixnums have tag 0 and false_object has tag 1 */
80 return TAG(obj) <= F_TYPE;
83 inline static fixnum untag_fixnum(cell tagged)
86 assert(TAG(tagged) == FIXNUM_TYPE);
88 return ((fixnum)tagged) >> TAG_BITS;
91 inline static cell tag_fixnum(fixnum untagged)
93 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
101 /* Default ctor to make gcc 3.x happy */
102 explicit header() { abort(); }
104 explicit header(cell value_) : value(value_ << TAG_BITS) {}
106 void check_header() const
109 assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT);
116 return value >> TAG_BITS;
119 bool forwarding_pointer_p() const
121 return TAG(value) == FORWARDING_POINTER;
124 object *forwarding_pointer() const
126 return (object *)UNTAG(value);
129 void forward_to(object *pointer)
131 value = RETAG(pointer,FORWARDING_POINTER);
135 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
142 cell binary_payload_start() const;
144 cell *slots() const { return (cell *)this; }
146 /* Only valid for objects in tenured space; must fast to free_heap_block
147 to do anything with it if its free */
150 return (h.value & 1) == 1;
154 /* Assembly code makes assumptions about the layout of this struct */
155 struct array : public object {
156 static const cell type_number = ARRAY_TYPE;
157 static const cell element_size = sizeof(cell);
161 cell *data() const { return (cell *)(this + 1); }
164 /* These are really just arrays, but certain elements have special
166 struct tuple_layout : public array {
176 struct bignum : public object {
177 static const cell type_number = BIGNUM_TYPE;
178 static const cell element_size = sizeof(cell);
182 cell *data() const { return (cell *)(this + 1); }
185 struct byte_array : public object {
186 static const cell type_number = BYTE_ARRAY_TYPE;
187 static const cell element_size = 1;
196 template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); }
199 /* Assembly code makes assumptions about the layout of this struct */
200 struct string : public object {
201 static const cell type_number = STRING_TYPE;
202 /* tagged num of chars */
209 u8 *data() const { return (u8 *)(this + 1); }
211 cell nth(cell i) const;
214 /* The compiled code heap is structured into blocks. */
218 cell owner; /* tagged pointer to word, quotation or f */
219 cell literals; /* tagged pointer to array or f */
220 cell relocation; /* tagged pointer to byte-array or f */
224 return (header & 1) == 1;
227 code_block_type type() const
229 return (code_block_type)((header >> 1) & 0x3);
232 void set_type(code_block_type type)
234 header = ((header & ~0x7) | (type << 1));
239 return type() == code_block_pic;
242 bool optimized_p() const
244 return type() == code_block_optimized;
254 return (void *)(this + 1);
258 /* Assembly code makes assumptions about the layout of this struct */
259 struct word : public object {
260 static const cell type_number = WORD_TYPE;
261 /* TAGGED hashcode */
263 /* TAGGED word name */
265 /* TAGGED word vocabulary */
267 /* TAGGED definition */
269 /* TAGGED property assoc for library code */
271 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
273 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
275 /* TAGGED call count for profiling */
277 /* TAGGED machine code for sub-primitive */
279 /* UNTAGGED execution token: jump here to execute word */
281 /* UNTAGGED compiled code block */
283 /* UNTAGGED profiler stub */
284 code_block *profiling;
287 /* Assembly code makes assumptions about the layout of this struct */
288 struct wrapper : public object {
289 static const cell type_number = WRAPPER_TYPE;
293 /* Assembly code makes assumptions about the layout of this struct */
294 struct boxed_float : object {
295 static const cell type_number = FLOAT_TYPE;
304 /* Assembly code makes assumptions about the layout of this struct */
305 struct quotation : public object {
306 static const cell type_number = QUOTATION_TYPE;
315 /* UNTAGGED compiled code block */
319 /* Assembly code makes assumptions about the layout of this struct */
320 struct alien : public object {
321 static const cell type_number = ALIEN_TYPE;
331 void update_address()
333 if(base == false_object)
334 address = displacement;
336 address = UNTAG(base) + sizeof(byte_array) + displacement;
340 struct dll : public object {
341 static const cell type_number = DLL_TYPE;
342 /* tagged byte array holding a C string */
344 /* OS-specific handle */
350 /* Frame size in bytes */
354 struct callstack : public object {
355 static const cell type_number = CALLSTACK_TYPE;
359 stack_frame *frame_at(cell offset) const
361 return (stack_frame *)((char *)(this + 1) + offset);
364 stack_frame *top() const { return (stack_frame *)(this + 1); }
365 stack_frame *bottom() const { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
368 struct tuple : public object {
369 static const cell type_number = TUPLE_TYPE;
373 cell *data() const { return (cell *)(this + 1); }
376 struct data_root_range {
380 explicit data_root_range(cell *start_, cell len_) :
381 start(start_), len(len_) {}