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 align8(cell a)
31 #define WORD_SIZE (signed)(sizeof(cell)*8)
35 #define TAG(x) ((cell)(x) & TAG_MASK)
36 #define UNTAG(x) ((cell)(x) & ~TAG_MASK)
37 #define RETAG(x,tag) (UNTAG(x) | (tag))
44 #define QUOTATION_TYPE 4
49 #define HEADER_TYPE 8 /* anything less than this is a tag */
51 #define GC_COLLECTED 5 /* can be anything other than FIXNUM_TYPE */
53 /*** Header types ***/
54 #define WRAPPER_TYPE 8
55 #define BYTE_ARRAY_TYPE 9
56 #define CALLSTACK_TYPE 10
57 #define STRING_TYPE 11
64 /* Not real types, but code_block's type can be set to this */
68 code_block_unoptimized,
74 /* Constants used when floating-point trap exceptions are thrown */
77 FP_TRAP_INVALID_OPERATION = 1 << 0,
78 FP_TRAP_OVERFLOW = 1 << 1,
79 FP_TRAP_UNDERFLOW = 1 << 2,
80 FP_TRAP_ZERO_DIVIDE = 1 << 3,
81 FP_TRAP_INEXACT = 1 << 4,
84 /* What Factor calls 'f' */
85 static const cell false_object = F_TYPE;
87 inline static bool immediate_p(cell obj)
89 return (obj == false_object || TAG(obj) == FIXNUM_TYPE);
92 inline static fixnum untag_fixnum(cell tagged)
95 assert(TAG(tagged) == FIXNUM_TYPE);
97 return ((fixnum)tagged) >> TAG_BITS;
100 inline static cell tag_fixnum(fixnum untagged)
102 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
105 inline static cell tag_for(cell type)
107 return type < HEADER_TYPE ? type : OBJECT_TYPE;
115 /* Default ctor to make gcc 3.x happy */
116 explicit header() { abort(); }
118 explicit header(cell value_) : value(value_ << TAG_BITS) {}
120 void check_header() {
122 assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT);
128 return value >> TAG_BITS;
131 bool forwarding_pointer_p() {
132 return TAG(value) == GC_COLLECTED;
135 object *forwarding_pointer() {
136 return (object *)UNTAG(value);
139 void forward_to(object *pointer) {
140 value = RETAG(pointer,GC_COLLECTED);
144 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
149 cell *slots() { return (cell *)this; }
152 /* Assembly code makes assumptions about the layout of this struct */
153 struct array : public object {
154 static const cell type_number = ARRAY_TYPE;
155 static const cell element_size = sizeof(cell);
159 cell *data() { return (cell *)(this + 1); }
162 /* These are really just arrays, but certain elements have special
164 struct tuple_layout : public array {
174 struct bignum : public object {
175 static const cell type_number = BIGNUM_TYPE;
176 static const cell element_size = sizeof(cell);
180 cell *data() { return (cell *)(this + 1); }
183 struct byte_array : public object {
184 static const cell type_number = BYTE_ARRAY_TYPE;
185 static const cell element_size = 1;
189 template<typename Scalar> Scalar *data() { return (Scalar *)(this + 1); }
192 /* Assembly code makes assumptions about the layout of this struct */
193 struct string : public object {
194 static const cell type_number = STRING_TYPE;
195 /* tagged num of chars */
202 u8 *data() { return (u8 *)(this + 1); }
205 /* The compiled code heap is structured into blocks. */
212 return header & 1 == 1;
230 void set_size(cell size)
232 header = (header & 0x7) | (size << 3);
236 struct free_heap_block : public heap_block
238 free_heap_block *next_free;
241 struct code_block : public heap_block
243 cell owner; /* tagged pointer to word, quotation or f */
244 cell literals; /* tagged pointer to array or f */
245 cell relocation; /* tagged pointer to byte-array or f */
249 return (void *)(this + 1);
254 return (header >> 1) & 0x3;
257 void set_type(code_block_type type)
259 header = ((header & ~0x7) | (type << 1));
264 return type() == code_block_pic;
269 return type() == code_block_optimized;
273 /* Assembly code makes assumptions about the layout of this struct */
274 struct word : public object {
275 static const cell type_number = WORD_TYPE;
276 /* TAGGED hashcode */
278 /* TAGGED word name */
280 /* TAGGED word vocabulary */
282 /* TAGGED definition */
284 /* TAGGED property assoc for library code */
286 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
288 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
290 /* TAGGED call count for profiling */
292 /* TAGGED machine code for sub-primitive */
294 /* UNTAGGED execution token: jump here to execute word */
296 /* UNTAGGED compiled code block */
298 /* UNTAGGED profiler stub */
299 code_block *profiling;
302 /* Assembly code makes assumptions about the layout of this struct */
303 struct wrapper : public object {
304 static const cell type_number = WRAPPER_TYPE;
308 /* Assembly code makes assumptions about the layout of this struct */
309 struct boxed_float : object {
310 static const cell type_number = FLOAT_TYPE;
319 /* Assembly code makes assumptions about the layout of this struct */
320 struct quotation : public object {
321 static const cell type_number = QUOTATION_TYPE;
330 /* UNTAGGED compiled code block */
334 /* Assembly code makes assumptions about the layout of this struct */
335 struct alien : public object {
336 static const cell type_number = ALIEN_TYPE;
345 struct dll : public object {
346 static const cell type_number = DLL_TYPE;
347 /* tagged byte array holding a C string */
349 /* OS-specific handle */
356 /* Frame size in bytes */
360 struct callstack : public object {
361 static const cell type_number = CALLSTACK_TYPE;
365 stack_frame *frame_at(cell offset)
367 return (stack_frame *)((char *)(this + 1) + offset);
370 stack_frame *top() { return (stack_frame *)(this + 1); }
371 stack_frame *bottom() { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
374 struct tuple : public object {
375 static const cell type_number = TUPLE_TYPE;
379 cell *data() { return (cell *)(this + 1); }