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 template<typename Iterator> void each_slot(Iterator &iter);
109 /* Only valid for objects in tenured space; must cast to free_heap_block
110 to do anything with it if its free */
113 return (header & 1) == 1;
118 return (header >> 2) & TAG_MASK;
121 void initialize(cell type)
126 cell hashcode() const
128 return (header >> 6);
131 void set_hashcode(cell hashcode)
133 header = (header & 0x3f) | (hashcode << 6);
136 bool forwarding_pointer_p() const
138 return (header & 2) == 2;
141 object *forwarding_pointer() const
143 return (object *)UNTAG(header);
146 void forward_to(object *pointer)
148 header = ((cell)pointer | 2);
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() const { 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() const { 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;
194 template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); }
197 /* Assembly code makes assumptions about the layout of this struct */
198 struct string : public object {
199 static const cell type_number = STRING_TYPE;
200 /* tagged num of chars */
207 u8 *data() const { return (u8 *)(this + 1); }
209 cell nth(cell i) const;
214 /* Assembly code makes assumptions about the layout of this struct */
215 struct word : public object {
216 static const cell type_number = WORD_TYPE;
217 /* TAGGED hashcode */
219 /* TAGGED word name */
221 /* TAGGED word vocabulary */
223 /* TAGGED definition */
225 /* TAGGED property assoc for library code */
227 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
229 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
231 /* TAGGED call count for profiling */
233 /* TAGGED machine code for sub-primitive */
235 /* UNTAGGED execution token: jump here to execute word */
237 /* UNTAGGED compiled code block */
239 /* UNTAGGED profiler stub */
240 code_block *profiling;
243 /* Assembly code makes assumptions about the layout of this struct */
244 struct wrapper : public object {
245 static const cell type_number = WRAPPER_TYPE;
249 /* Assembly code makes assumptions about the layout of this struct */
250 struct boxed_float : object {
251 static const cell type_number = FLOAT_TYPE;
260 /* Assembly code makes assumptions about the layout of this struct */
261 struct quotation : public object {
262 static const cell type_number = QUOTATION_TYPE;
271 /* UNTAGGED compiled code block */
275 /* Assembly code makes assumptions about the layout of this struct */
276 struct alien : public object {
277 static const cell type_number = ALIEN_TYPE;
287 void update_address()
289 if(base == false_object)
290 address = displacement;
292 address = UNTAG(base) + sizeof(byte_array) + displacement;
296 struct dll : public object {
297 static const cell type_number = DLL_TYPE;
298 /* tagged byte array holding a C string */
300 /* OS-specific handle */
306 /* Frame size in bytes */
310 struct callstack : public object {
311 static const cell type_number = CALLSTACK_TYPE;
315 stack_frame *frame_at(cell offset) const
317 return (stack_frame *)((char *)(this + 1) + offset);
320 stack_frame *top() const { return (stack_frame *)(this + 1); }
321 stack_frame *bottom() const { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
324 struct tuple : public object {
325 static const cell type_number = TUPLE_TYPE;
329 cell *data() const { return (cell *)(this + 1); }
332 struct data_root_range {
336 explicit data_root_range(cell *start_, cell len_) :
337 start(start_), len(len_) {}