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 a real type, but code_block's type field can be set to this */
70 /* Constants used when floating-point trap exceptions are thrown */
73 FP_TRAP_INVALID_OPERATION = 1 << 0,
74 FP_TRAP_OVERFLOW = 1 << 1,
75 FP_TRAP_UNDERFLOW = 1 << 2,
76 FP_TRAP_ZERO_DIVIDE = 1 << 3,
77 FP_TRAP_INEXACT = 1 << 4,
80 inline static bool immediate_p(cell obj)
82 return (obj == F || TAG(obj) == FIXNUM_TYPE);
85 inline static fixnum untag_fixnum(cell tagged)
88 assert(TAG(tagged) == FIXNUM_TYPE);
90 return ((fixnum)tagged) >> TAG_BITS;
93 inline static cell tag_fixnum(fixnum untagged)
95 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
98 inline static cell tag_for(cell type)
100 return type < HEADER_TYPE ? type : OBJECT_TYPE;
108 /* Default ctor to make gcc 3.x happy */
109 header() { abort(); }
111 header(cell value_) : value(value_ << TAG_BITS) {}
113 void check_header() {
115 assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT);
121 return value >> TAG_BITS;
124 bool forwarding_pointer_p() {
125 return TAG(value) == GC_COLLECTED;
128 object *forwarding_pointer() {
129 return (object *)UNTAG(value);
132 void forward_to(object *pointer) {
133 value = RETAG(pointer,GC_COLLECTED);
137 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
142 cell *slots() { return (cell *)this; }
145 /* Assembly code makes assumptions about the layout of this struct */
146 struct array : public object {
147 static const cell type_number = ARRAY_TYPE;
148 static const cell element_size = sizeof(cell);
152 cell *data() { return (cell *)(this + 1); }
155 /* These are really just arrays, but certain elements have special
157 struct tuple_layout : public array {
167 struct bignum : public object {
168 static const cell type_number = BIGNUM_TYPE;
169 static const cell element_size = sizeof(cell);
173 cell *data() { return (cell *)(this + 1); }
176 struct byte_array : public object {
177 static const cell type_number = BYTE_ARRAY_TYPE;
178 static const cell element_size = 1;
182 template<typename T> T *data() { return (T *)(this + 1); }
185 /* Assembly code makes assumptions about the layout of this struct */
186 struct string : public object {
187 static const cell type_number = STRING_TYPE;
188 /* tagged num of chars */
195 u8 *data() { return (u8 *)(this + 1); }
198 /* The compiled code heap is structured into blocks. */
208 unsigned char status; /* free or allocated? */
209 unsigned char type; /* this is WORD_TYPE or QUOTATION_TYPE */
210 unsigned char last_scan; /* the youngest generation in which this block's literals may live */
211 unsigned char needs_fixup; /* is this a new block that needs full fixup? */
213 /* In bytes, includes this header */
217 struct free_heap_block : public heap_block
219 free_heap_block *next_free;
222 struct code_block : public heap_block
224 cell literals; /* # bytes */
225 cell relocation; /* tagged pointer to byte-array or f */
227 void *xt() { return (void *)(this + 1); }
230 /* Assembly code makes assumptions about the layout of this struct */
231 struct word : public object {
232 static const cell type_number = WORD_TYPE;
233 /* TAGGED hashcode */
235 /* TAGGED word name */
237 /* TAGGED word vocabulary */
239 /* TAGGED definition */
241 /* TAGGED property assoc for library code */
243 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
245 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
247 /* TAGGED call count for profiling */
249 /* TAGGED machine code for sub-primitive */
251 /* UNTAGGED execution token: jump here to execute word */
253 /* UNTAGGED compiled code block */
255 /* UNTAGGED profiler stub */
256 code_block *profiling;
259 /* Assembly code makes assumptions about the layout of this struct */
260 struct wrapper : public object {
261 static const cell type_number = WRAPPER_TYPE;
265 /* Assembly code makes assumptions about the layout of this struct */
266 struct boxed_float : object {
267 static const cell type_number = FLOAT_TYPE;
276 /* Assembly code makes assumptions about the layout of this struct */
277 struct quotation : public object {
278 static const cell type_number = QUOTATION_TYPE;
287 /* UNTAGGED compiled code block */
291 /* Assembly code makes assumptions about the layout of this struct */
292 struct alien : public object {
293 static const cell type_number = ALIEN_TYPE;
302 struct dll : public object {
303 static const cell type_number = DLL_TYPE;
304 /* tagged byte array holding a C string */
306 /* OS-specific handle */
313 /* Frame size in bytes */
317 struct callstack : public object {
318 static const cell type_number = CALLSTACK_TYPE;
322 stack_frame *frame_at(cell offset)
324 return (stack_frame *)((char *)(this + 1) + offset);
327 stack_frame *top() { return (stack_frame *)(this + 1); }
328 stack_frame *bottom() { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
331 struct tuple : public object {
332 static const cell type_number = TUPLE_TYPE;
336 cell *data() { return (cell *)(this + 1); }