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
54 #define FORWARDING_POINTER 5 /* can be anything other than FIXNUM_TYPE */
58 code_block_unoptimized,
64 /* Constants used when floating-point trap exceptions are thrown */
67 FP_TRAP_INVALID_OPERATION = 1 << 0,
68 FP_TRAP_OVERFLOW = 1 << 1,
69 FP_TRAP_UNDERFLOW = 1 << 2,
70 FP_TRAP_ZERO_DIVIDE = 1 << 3,
71 FP_TRAP_INEXACT = 1 << 4,
74 /* What Factor calls 'f' */
75 static const cell false_object = F_TYPE;
77 inline static bool immediate_p(cell obj)
79 /* We assume that fixnums have tag 0 and false_object has tag 1 */
80 return TAG(obj) <= F_TYPE;
83 inline static fixnum untag_fixnum(cell tagged)
86 assert(TAG(tagged) == FIXNUM_TYPE);
88 return ((fixnum)tagged) >> TAG_BITS;
91 inline static cell tag_fixnum(fixnum untagged)
93 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
101 /* Default ctor to make gcc 3.x happy */
102 explicit header() { abort(); }
104 explicit header(cell value_) : value(value_ << TAG_BITS) {}
106 void check_header() const
109 assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT);
116 return value >> TAG_BITS;
119 bool forwarding_pointer_p() const
121 return TAG(value) == FORWARDING_POINTER;
124 object *forwarding_pointer() const
126 return (object *)UNTAG(value);
129 void forward_to(object *pointer)
131 value = RETAG(pointer,FORWARDING_POINTER);
135 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
142 cell binary_payload_start() const;
144 cell *slots() const { return (cell *)this; }
146 /* Only valid for objects in tenured space; must fast to free_heap_block
147 to do anything with it if its free */
150 return h.value & 1 == 1;
154 /* Assembly code makes assumptions about the layout of this struct */
155 struct array : public object {
156 static const cell type_number = ARRAY_TYPE;
157 static const cell element_size = sizeof(cell);
161 cell *data() const { return (cell *)(this + 1); }
164 /* These are really just arrays, but certain elements have special
166 struct tuple_layout : public array {
176 struct bignum : public object {
177 static const cell type_number = BIGNUM_TYPE;
178 static const cell element_size = sizeof(cell);
182 cell *data() const { return (cell *)(this + 1); }
185 struct byte_array : public object {
186 static const cell type_number = BYTE_ARRAY_TYPE;
187 static const cell element_size = 1;
196 template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); }
199 /* Assembly code makes assumptions about the layout of this struct */
200 struct string : public object {
201 static const cell type_number = STRING_TYPE;
202 /* tagged num of chars */
209 u8 *data() const { return (u8 *)(this + 1); }
211 cell nth(cell i) const;
216 /* Assembly code makes assumptions about the layout of this struct */
217 struct word : public object {
218 static const cell type_number = WORD_TYPE;
219 /* TAGGED hashcode */
221 /* TAGGED word name */
223 /* TAGGED word vocabulary */
225 /* TAGGED definition */
227 /* TAGGED property assoc for library code */
229 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
231 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
233 /* TAGGED call count for profiling */
235 /* TAGGED machine code for sub-primitive */
237 /* UNTAGGED execution token: jump here to execute word */
239 /* UNTAGGED compiled code block */
241 /* UNTAGGED profiler stub */
242 code_block *profiling;
245 /* Assembly code makes assumptions about the layout of this struct */
246 struct wrapper : public object {
247 static const cell type_number = WRAPPER_TYPE;
251 /* Assembly code makes assumptions about the layout of this struct */
252 struct boxed_float : object {
253 static const cell type_number = FLOAT_TYPE;
262 /* Assembly code makes assumptions about the layout of this struct */
263 struct quotation : public object {
264 static const cell type_number = QUOTATION_TYPE;
273 /* UNTAGGED compiled code block */
277 /* Assembly code makes assumptions about the layout of this struct */
278 struct alien : public object {
279 static const cell type_number = ALIEN_TYPE;
289 void update_address()
291 if(base == false_object)
292 address = displacement;
294 address = UNTAG(base) + sizeof(byte_array) + displacement;
298 struct dll : public object {
299 static const cell type_number = DLL_TYPE;
300 /* tagged byte array holding a C string */
302 /* OS-specific handle */
308 /* Frame size in bytes */
312 struct callstack : public object {
313 static const cell type_number = CALLSTACK_TYPE;
317 stack_frame *frame_at(cell offset) const
319 return (stack_frame *)((char *)(this + 1) + offset);
322 stack_frame *top() const { return (stack_frame *)(this + 1); }
323 stack_frame *bottom() const { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
326 struct tuple : public object {
327 static const cell type_number = TUPLE_TYPE;
331 cell *data() const { return (cell *)(this + 1); }
334 struct data_root_range {
338 explicit data_root_range(cell *start_, cell len_) :
339 start(start_), len(len_) {}