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
56 code_block_unoptimized,
62 /* Constants used when floating-point trap exceptions are thrown */
65 FP_TRAP_INVALID_OPERATION = 1 << 0,
66 FP_TRAP_OVERFLOW = 1 << 1,
67 FP_TRAP_UNDERFLOW = 1 << 2,
68 FP_TRAP_ZERO_DIVIDE = 1 << 3,
69 FP_TRAP_INEXACT = 1 << 4,
72 /* What Factor calls 'f' */
73 static const cell false_object = F_TYPE;
75 inline static bool immediate_p(cell obj)
77 /* We assume that fixnums have tag 0 and false_object has tag 1 */
78 return TAG(obj) <= F_TYPE;
81 inline static fixnum untag_fixnum(cell tagged)
84 assert(TAG(tagged) == FIXNUM_TYPE);
86 return ((fixnum)tagged) >> TAG_BITS;
89 inline static cell tag_fixnum(fixnum untagged)
91 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
96 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
103 cell binary_payload_start() const;
105 cell *slots() const { return (cell *)this; }
107 /* Only valid for objects in tenured space; must cast to free_heap_block
108 to do anything with it if its free */
111 return (header & 1) == 1;
116 return (header >> 2) & TAG_MASK;
119 void initialize(cell type)
124 cell hashcode() const
126 return (header >> 6);
129 void set_hashcode(cell hashcode)
131 header = (header & 0x3f) | (hashcode << 6);
134 bool forwarding_pointer_p() const
136 return (header & 2) == 2;
139 object *forwarding_pointer() const
141 return (object *)UNTAG(header);
144 void forward_to(object *pointer)
146 header = ((cell)pointer | 2);
150 /* Assembly code makes assumptions about the layout of this struct */
151 struct array : public object {
152 static const cell type_number = ARRAY_TYPE;
153 static const cell element_size = sizeof(cell);
157 cell *data() const { return (cell *)(this + 1); }
160 /* These are really just arrays, but certain elements have special
162 struct tuple_layout : public array {
172 struct bignum : public object {
173 static const cell type_number = BIGNUM_TYPE;
174 static const cell element_size = sizeof(cell);
178 cell *data() const { return (cell *)(this + 1); }
181 struct byte_array : public object {
182 static const cell type_number = BYTE_ARRAY_TYPE;
183 static const cell element_size = 1;
192 template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); }
195 /* Assembly code makes assumptions about the layout of this struct */
196 struct string : public object {
197 static const cell type_number = STRING_TYPE;
198 /* tagged num of chars */
205 u8 *data() const { return (u8 *)(this + 1); }
207 cell nth(cell i) const;
210 /* The compiled code heap is structured into blocks. */
214 cell owner; /* tagged pointer to word, quotation or f */
215 cell literals; /* tagged pointer to array or f */
216 cell relocation; /* tagged pointer to byte-array or f */
220 return (header & 1) == 1;
223 code_block_type type() const
225 return (code_block_type)((header >> 1) & 0x3);
228 void set_type(code_block_type type)
230 header = ((header & ~0x7) | (type << 1));
235 return type() == code_block_pic;
238 bool optimized_p() const
240 return type() == code_block_optimized;
250 return (void *)(this + 1);
254 /* Assembly code makes assumptions about the layout of this struct */
255 struct word : public object {
256 static const cell type_number = WORD_TYPE;
257 /* TAGGED hashcode */
259 /* TAGGED word name */
261 /* TAGGED word vocabulary */
263 /* TAGGED definition */
265 /* TAGGED property assoc for library code */
267 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
269 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
271 /* TAGGED call count for profiling */
273 /* TAGGED machine code for sub-primitive */
275 /* UNTAGGED execution token: jump here to execute word */
277 /* UNTAGGED compiled code block */
279 /* UNTAGGED profiler stub */
280 code_block *profiling;
283 /* Assembly code makes assumptions about the layout of this struct */
284 struct wrapper : public object {
285 static const cell type_number = WRAPPER_TYPE;
289 /* Assembly code makes assumptions about the layout of this struct */
290 struct boxed_float : object {
291 static const cell type_number = FLOAT_TYPE;
300 /* Assembly code makes assumptions about the layout of this struct */
301 struct quotation : public object {
302 static const cell type_number = QUOTATION_TYPE;
311 /* UNTAGGED compiled code block */
315 /* Assembly code makes assumptions about the layout of this struct */
316 struct alien : public object {
317 static const cell type_number = ALIEN_TYPE;
327 void update_address()
329 if(base == false_object)
330 address = displacement;
332 address = UNTAG(base) + sizeof(byte_array) + displacement;
336 struct dll : public object {
337 static const cell type_number = DLL_TYPE;
338 /* tagged byte array holding a C string */
340 /* OS-specific handle */
346 /* Frame size in bytes */
350 struct callstack : public object {
351 static const cell type_number = CALLSTACK_TYPE;
355 stack_frame *frame_at(cell offset) const
357 return (stack_frame *)((char *)(this + 1) + offset);
360 stack_frame *top() const { return (stack_frame *)(this + 1); }
361 stack_frame *bottom() const { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
364 struct tuple : public object {
365 static const cell type_number = TUPLE_TYPE;
369 cell *data() const { return (cell *)(this + 1); }
372 struct data_root_range {
376 explicit data_root_range(cell *start_, cell len_) :
377 start(start_), len(len_) {}