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 /* Canonical F object */
52 #define HEADER_TYPE 8 /* anything less than this is a tag */
54 #define GC_COLLECTED 5 /* can be anything other than FIXNUM_TYPE */
56 /*** Header types ***/
57 #define WRAPPER_TYPE 8
58 #define BYTE_ARRAY_TYPE 9
59 #define CALLSTACK_TYPE 10
60 #define STRING_TYPE 11
67 /* Not real types, but code_block's type can be set to this */
69 #define FREE_BLOCK_TYPE 17
71 /* Constants used when floating-point trap exceptions are thrown */
74 FP_TRAP_INVALID_OPERATION = 1 << 0,
75 FP_TRAP_OVERFLOW = 1 << 1,
76 FP_TRAP_UNDERFLOW = 1 << 2,
77 FP_TRAP_ZERO_DIVIDE = 1 << 3,
78 FP_TRAP_INEXACT = 1 << 4,
81 inline static bool immediate_p(cell obj)
83 return (obj == F || TAG(obj) == FIXNUM_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 inline static cell tag_for(cell type)
101 return type < HEADER_TYPE ? type : OBJECT_TYPE;
109 /* Default ctor to make gcc 3.x happy */
110 explicit header() { abort(); }
112 explicit header(cell value_) : value(value_ << TAG_BITS) {}
114 void check_header() {
116 assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT);
122 return value >> TAG_BITS;
125 bool forwarding_pointer_p() {
126 return TAG(value) == GC_COLLECTED;
129 object *forwarding_pointer() {
130 return (object *)UNTAG(value);
133 void forward_to(object *pointer) {
134 value = RETAG(pointer,GC_COLLECTED);
138 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
143 cell *slots() { return (cell *)this; }
146 /* Assembly code makes assumptions about the layout of this struct */
147 struct array : public object {
148 static const cell type_number = ARRAY_TYPE;
149 static const cell element_size = sizeof(cell);
153 cell *data() { return (cell *)(this + 1); }
156 /* These are really just arrays, but certain elements have special
158 struct tuple_layout : public array {
168 struct bignum : public object {
169 static const cell type_number = BIGNUM_TYPE;
170 static const cell element_size = sizeof(cell);
174 cell *data() { return (cell *)(this + 1); }
177 struct byte_array : public object {
178 static const cell type_number = BYTE_ARRAY_TYPE;
179 static const cell element_size = 1;
183 template<typename Scalar> Scalar *data() { return (Scalar *)(this + 1); }
186 /* Assembly code makes assumptions about the layout of this struct */
187 struct string : public object {
188 static const cell type_number = STRING_TYPE;
189 /* tagged num of chars */
196 u8 *data() { return (u8 *)(this + 1); }
199 /* The compiled code heap is structured into blocks. */
204 bool marked_p() { return header & 1; }
205 void set_marked_p(bool marked)
213 cell type() { return (header >> 1) & 0x1f; }
214 void set_type(cell type)
216 header = ((header & ~(0x1f << 1)) | (type << 1));
219 cell size() { return (header >> 6); }
220 void set_size(cell size)
222 header = (header & 0x2f) | (size << 6);
226 struct free_heap_block : public heap_block
228 free_heap_block *next_free;
231 struct code_block : public heap_block
233 cell owner; /* tagged pointer to word, quotation or f */
234 cell literals; /* tagged pointer to array or f */
235 cell relocation; /* tagged pointer to byte-array or f */
237 void *xt() { return (void *)(this + 1); }
240 /* Assembly code makes assumptions about the layout of this struct */
241 struct word : public object {
242 static const cell type_number = WORD_TYPE;
243 /* TAGGED hashcode */
245 /* TAGGED word name */
247 /* TAGGED word vocabulary */
249 /* TAGGED definition */
251 /* TAGGED property assoc for library code */
253 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
255 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
257 /* TAGGED call count for profiling */
259 /* TAGGED machine code for sub-primitive */
261 /* UNTAGGED execution token: jump here to execute word */
263 /* UNTAGGED compiled code block */
265 /* UNTAGGED profiler stub */
266 code_block *profiling;
269 /* Assembly code makes assumptions about the layout of this struct */
270 struct wrapper : public object {
271 static const cell type_number = WRAPPER_TYPE;
275 /* Assembly code makes assumptions about the layout of this struct */
276 struct boxed_float : object {
277 static const cell type_number = FLOAT_TYPE;
286 /* Assembly code makes assumptions about the layout of this struct */
287 struct quotation : public object {
288 static const cell type_number = QUOTATION_TYPE;
297 /* UNTAGGED compiled code block */
301 /* Assembly code makes assumptions about the layout of this struct */
302 struct alien : public object {
303 static const cell type_number = ALIEN_TYPE;
312 struct dll : public object {
313 static const cell type_number = DLL_TYPE;
314 /* tagged byte array holding a C string */
316 /* OS-specific handle */
323 /* Frame size in bytes */
327 struct callstack : public object {
328 static const cell type_number = CALLSTACK_TYPE;
332 stack_frame *frame_at(cell offset)
334 return (stack_frame *)((char *)(this + 1) + offset);
337 stack_frame *top() { return (stack_frame *)(this + 1); }
338 stack_frame *bottom() { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
341 struct tuple : public object {
342 static const cell type_number = TUPLE_TYPE;
346 cell *data() { return (cell *)(this + 1); }