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 alignment_for(cell a, cell b)
28 return align(a,b) - a;
31 static const cell data_alignment = 16;
33 #define WORD_SIZE (signed)(sizeof(cell)*8)
37 #define TAG(x) ((cell)(x) & TAG_MASK)
38 #define UNTAG(x) ((cell)(x) & ~TAG_MASK)
39 #define RETAG(x,tag) (UNTAG(x) | (tag))
46 #define QUOTATION_TYPE 4
50 #define WRAPPER_TYPE 8
51 #define BYTE_ARRAY_TYPE 9
52 #define CALLSTACK_TYPE 10
53 #define STRING_TYPE 11
59 static inline const char *type_name(cell type)
99 code_block_unoptimized,
100 code_block_optimized,
101 code_block_counting_profiler,
105 /* Constants used when floating-point trap exceptions are thrown */
108 FP_TRAP_INVALID_OPERATION = 1 << 0,
109 FP_TRAP_OVERFLOW = 1 << 1,
110 FP_TRAP_UNDERFLOW = 1 << 2,
111 FP_TRAP_ZERO_DIVIDE = 1 << 3,
112 FP_TRAP_INEXACT = 1 << 4,
115 /* What Factor calls 'f' */
116 static const cell false_object = F_TYPE;
118 inline static bool immediate_p(cell obj)
120 /* We assume that fixnums have tag 0 and false_object has tag 1 */
121 return TAG(obj) <= F_TYPE;
124 inline static fixnum untag_fixnum(cell tagged)
127 assert(TAG(tagged) == FIXNUM_TYPE);
129 return ((fixnum)tagged) >> TAG_BITS;
132 inline static cell tag_fixnum(fixnum untagged)
134 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
137 #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
144 template<typename Fixup> cell size(Fixup fixup) const;
146 cell binary_payload_start() const;
147 template<typename Fixup> cell binary_payload_start(Fixup fixup) const;
149 cell *slots() const { return (cell *)this; }
151 template<typename Iterator> void each_slot(Iterator &iter);
153 /* Only valid for objects in tenured space; must cast to free_heap_block
154 to do anything with it if its free */
157 return (header & 1) == 1;
162 return (header >> 2) & TAG_MASK;
165 void initialize(cell type)
170 cell hashcode() const
172 return (header >> 6);
175 void set_hashcode(cell hashcode)
177 header = (header & 0x3f) | (hashcode << 6);
180 bool forwarding_pointer_p() const
182 return (header & 2) == 2;
185 object *forwarding_pointer() const
187 return (object *)UNTAG(header);
190 void forward_to(object *pointer)
192 header = ((cell)pointer | 2);
196 /* Assembly code makes assumptions about the layout of this struct */
197 struct array : public object {
198 static const cell type_number = ARRAY_TYPE;
199 static const cell element_size = sizeof(cell);
203 cell *data() const { return (cell *)(this + 1); }
206 /* These are really just arrays, but certain elements have special
208 struct tuple_layout : public array {
218 struct bignum : public object {
219 static const cell type_number = BIGNUM_TYPE;
220 static const cell element_size = sizeof(cell);
224 cell *data() const { return (cell *)(this + 1); }
227 struct byte_array : public object {
228 static const cell type_number = BYTE_ARRAY_TYPE;
229 static const cell element_size = 1;
238 template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); }
241 /* Assembly code makes assumptions about the layout of this struct */
242 struct string : public object {
243 static const cell type_number = STRING_TYPE;
244 /* tagged num of chars */
251 u8 *data() const { return (u8 *)(this + 1); }
256 /* Assembly code makes assumptions about the layout of this struct */
257 struct word : public object {
258 static const cell type_number = WORD_TYPE;
259 /* TAGGED hashcode */
261 /* TAGGED word name */
263 /* TAGGED word vocabulary */
265 /* TAGGED definition */
267 /* TAGGED property assoc for library code */
269 /* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */
271 /* TAGGED alternative entry point for direct tail calls. Used for inline caching */
273 /* TAGGED call count for counting_profiler */
275 /* TAGGED machine code for sub-primitive */
277 /* UNTAGGED entry point: jump here to execute word */
279 /* UNTAGGED compiled code block */
281 /* UNTAGGED counting_profiler stub */
282 code_block *counting_profiler;
285 /* Assembly code makes assumptions about the layout of this struct */
286 struct wrapper : public object {
287 static const cell type_number = WRAPPER_TYPE;
291 /* Assembly code makes assumptions about the layout of this struct */
292 struct boxed_float : object {
293 static const cell type_number = FLOAT_TYPE;
302 /* Assembly code makes assumptions about the layout of this struct */
303 struct quotation : public object {
304 static const cell type_number = QUOTATION_TYPE;
311 /* UNTAGGED entry point; jump here to call quotation */
313 /* UNTAGGED compiled code block */
317 /* Assembly code makes assumptions about the layout of this struct */
318 struct alien : public object {
319 static const cell type_number = ALIEN_TYPE;
329 void update_address()
331 if(base == false_object)
332 address = displacement;
334 address = UNTAG(base) + sizeof(byte_array) + displacement;
338 struct dll : public object {
339 static const cell type_number = DLL_TYPE;
340 /* tagged byte array holding a C string */
342 /* OS-specific handle */
347 /* Updated by procedure prologue with procedure start address */
349 /* Frame size in bytes */
353 struct callstack : public object {
354 static const cell type_number = CALLSTACK_TYPE;
358 stack_frame *frame_at(cell offset) const
360 return (stack_frame *)((char *)(this + 1) + offset);
363 stack_frame *top() const { return (stack_frame *)(this + 1); }
364 stack_frame *bottom() const { return (stack_frame *)((cell)(this + 1) + untag_fixnum(length)); }
367 struct tuple : public object {
368 static const cell type_number = TUPLE_TYPE;
372 cell *data() const { return (cell *)(this + 1); }
375 struct data_root_range {
379 explicit data_root_range(cell *start_, cell len_) :
380 start(start_), len(len_) {}