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 inline static bool immediate_p(cell obj)
72 return (obj == F || TAG(obj) == FIXNUM_TYPE);
75 inline static fixnum untag_fixnum(cell tagged)
78 assert(TAG(tagged) == FIXNUM_TYPE);
80 return ((fixnum)tagged) >> TAG_BITS;
83 inline static cell tag_fixnum(fixnum untagged)
85 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
88 inline static cell tag_for(cell type)
90 return type < HEADER_TYPE ? type : OBJECT_TYPE;
98 /* Default ctor to make gcc 3.x happy */
101 header(cell value_) : value(value_ << TAG_BITS) {}
103 void check_header() {
105 assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT);
111 return value >> TAG_BITS;
114 bool forwarding_pointer_p() {
115 return TAG(value) == GC_COLLECTED;
118 object *forwarding_pointer() {
119 return (object *)UNTAG(value);
122 void forward_to(object *pointer) {
123 value = RETAG(pointer,GC_COLLECTED);
127 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
132 cell *slots() { return (cell *)this; }
135 /* Assembly code makes assumptions about the layout of this struct */
136 struct array : public object {
137 static const cell type_number = ARRAY_TYPE;
138 static const cell element_size = sizeof(cell);
142 cell *data() { return (cell *)(this + 1); }
145 /* These are really just arrays, but certain elements have special
147 struct tuple_layout : public array {
157 struct bignum : public object {
158 static const cell type_number = BIGNUM_TYPE;
159 static const cell element_size = sizeof(cell);
163 cell *data() { return (cell *)(this + 1); }
166 struct byte_array : public object {
167 static const cell type_number = BYTE_ARRAY_TYPE;
168 static const cell element_size = 1;
172 template<typename T> T *data() { return (T *)(this + 1); }
175 /* Assembly code makes assumptions about the layout of this struct */
176 struct string : public object {
177 static const cell type_number = STRING_TYPE;
178 /* tagged num of chars */
185 u8 *data() { return (u8 *)(this + 1); }
188 /* The compiled code heap is structured into blocks. */
198 unsigned char status; /* free or allocated? */
199 unsigned char type; /* this is WORD_TYPE or QUOTATION_TYPE */
200 unsigned char last_scan; /* the youngest generation in which this block's literals may live */
201 unsigned char needs_fixup; /* is this a new block that needs full fixup? */
203 /* In bytes, includes this header */
207 struct free_heap_block : public heap_block
209 free_heap_block *next_free;
212 struct code_block : public heap_block
214 cell literals; /* # bytes */
215 cell relocation; /* tagged pointer to byte-array or f */
217 void *xt() { return (void *)(this + 1); }
220 /* Assembly code makes assumptions about the layout of this struct */
221 struct word : public object {
222 static const cell type_number = WORD_TYPE;
223 /* TAGGED hashcode */
225 /* TAGGED word name */
227 /* TAGGED word vocabulary */
229 /* TAGGED definition */
231 /* TAGGED property assoc for library code */
233 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
235 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
237 /* TAGGED call count for profiling */
239 /* TAGGED machine code for sub-primitive */
241 /* UNTAGGED execution token: jump here to execute word */
243 /* UNTAGGED compiled code block */
245 /* UNTAGGED profiler stub */
246 code_block *profiling;
249 /* Assembly code makes assumptions about the layout of this struct */
250 struct wrapper : public object {
251 static const cell type_number = WRAPPER_TYPE;
255 /* Assembly code makes assumptions about the layout of this struct */
256 struct boxed_float : object {
257 static const cell type_number = FLOAT_TYPE;
266 /* Assembly code makes assumptions about the layout of this struct */
267 struct quotation : public object {
268 static const cell type_number = QUOTATION_TYPE;
277 /* UNTAGGED compiled code block */
281 /* Assembly code makes assumptions about the layout of this struct */
282 struct alien : public object {
283 static const cell type_number = ALIEN_TYPE;
292 struct dll : public object {
293 static const cell type_number = DLL_TYPE;
294 /* tagged byte array holding a C string */
296 /* OS-specific handle */
303 /* Frame size in bytes */
307 struct callstack : public object {
308 static const cell type_number = CALLSTACK_TYPE;
312 stack_frame *frame_at(cell offset)
314 return (stack_frame *)((char *)(this + 1) + offset);
317 stack_frame *top() { return (stack_frame *)(this + 1); }
318 stack_frame *bottom() { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
321 struct tuple : public object {
322 static const cell type_number = TUPLE_TYPE;
326 cell *data() { return (cell *)(this + 1); }