Clean up some duplication
[factor/jcg.git] / vm / layouts.h
bloba231cab873caa178a6ca6aa96c94b00c8d998d6e
1 #define INLINE inline static
3 typedef unsigned char u8;
4 typedef unsigned short u16;
5 typedef unsigned int u32;
6 typedef unsigned long long u64;
7 typedef signed char s8;
8 typedef signed short s16;
9 typedef signed int s32;
10 typedef signed long long s64;
12 #ifdef _WIN64
13 typedef long long F_FIXNUM;
14 typedef unsigned long long CELL;
15 #else
16 typedef long F_FIXNUM;
17 typedef unsigned long CELL;
18 #endif
20 #define CELLS ((signed)sizeof(CELL))
22 #define WORD_SIZE (CELLS*8)
23 #define HALF_WORD_SIZE (CELLS*4)
24 #define HALF_WORD_MASK (((unsigned long)1<<HALF_WORD_SIZE)-1)
26 #define TAG_MASK 7
27 #define TAG_BITS 3
28 #define TAG(cell) ((CELL)(cell) & TAG_MASK)
29 #define UNTAG(cell) ((CELL)(cell) & ~TAG_MASK)
30 #define RETAG(cell,tag) (UNTAG(cell) | (tag))
32 /*** Tags ***/
33 #define FIXNUM_TYPE 0
34 #define BIGNUM_TYPE 1
35 #define TUPLE_TYPE 2
36 #define OBJECT_TYPE 3
37 #define RATIO_TYPE 4
38 #define FLOAT_TYPE 5
39 #define COMPLEX_TYPE 6
41 /* Canonical F object */
42 #define F_TYPE 7
43 #define F F_TYPE
45 #define HEADER_TYPE 7 /* anything less than or equal to this is a tag */
47 #define GC_COLLECTED 5 /* See gc.c */
49 /*** Header types ***/
50 #define ARRAY_TYPE 8
51 #define WRAPPER_TYPE 9
52 #define BYTE_ARRAY_TYPE 10
53 #define CALLSTACK_TYPE 11
54 #define STRING_TYPE 12
55 #define WORD_TYPE 13
56 #define QUOTATION_TYPE 14
57 #define DLL_TYPE 15
58 #define ALIEN_TYPE 16
60 #define TYPE_COUNT 17
62 INLINE bool immediate_p(CELL obj)
64 return (obj == F || TAG(obj) == FIXNUM_TYPE);
67 INLINE F_FIXNUM untag_fixnum_fast(CELL tagged)
69 return ((F_FIXNUM)tagged) >> TAG_BITS;
72 INLINE CELL tag_fixnum(F_FIXNUM untagged)
74 return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
77 INLINE void *untag_object(CELL tagged)
79 return (void *)UNTAG(tagged);
82 typedef void *XT;
84 /* Assembly code makes assumptions about the layout of this struct */
85 typedef struct {
86 CELL header;
87 /* tagged */
88 CELL capacity;
89 } F_ARRAY;
91 typedef F_ARRAY F_BYTE_ARRAY;
93 /* Assembly code makes assumptions about the layout of this struct */
94 typedef struct {
95 CELL header;
96 /* tagged num of chars */
97 CELL length;
98 /* tagged */
99 CELL aux;
100 /* tagged */
101 CELL hashcode;
102 } F_STRING;
104 /* The compiled code heap is structured into blocks. */
105 typedef struct
107 char type; /* this is WORD_TYPE or QUOTATION_TYPE */
108 char last_scan; /* the youngest generation in which this block's literals may live */
109 CELL code_length; /* # bytes */
110 CELL literals; /* # bytes */
111 CELL relocation; /* tagged pointer to byte-array or f */
112 } F_COMPILED;
114 /* Assembly code makes assumptions about the layout of this struct */
115 typedef struct {
116 /* TAGGED header */
117 CELL header;
118 /* TAGGED hashcode */
119 CELL hashcode;
120 /* TAGGED word name */
121 CELL name;
122 /* TAGGED word vocabulary */
123 CELL vocabulary;
124 /* TAGGED definition */
125 CELL def;
126 /* TAGGED property assoc for library code */
127 CELL props;
128 /* TAGGED t or f, t means its compiled with the optimizing compiler,
129 f means its compiled with the non-optimizing compiler */
130 CELL optimizedp;
131 /* TAGGED call count for profiling */
132 CELL counter;
133 /* TAGGED machine code for sub-primitive */
134 CELL subprimitive;
135 /* UNTAGGED execution token: jump here to execute word */
136 XT xt;
137 /* UNTAGGED compiled code block */
138 F_COMPILED *code;
139 /* UNTAGGED profiler stub */
140 F_COMPILED *profiling;
141 } F_WORD;
143 /* Assembly code makes assumptions about the layout of this struct */
144 typedef struct {
145 CELL header;
146 CELL object;
147 } F_WRAPPER;
149 /* Assembly code makes assumptions about the layout of this struct */
150 typedef struct {
151 CELL header;
152 CELL numerator;
153 CELL denominator;
154 } F_RATIO;
156 /* Assembly code makes assumptions about the layout of this struct */
157 typedef struct {
158 /* We use a union here to force the float value to be aligned on an
159 8-byte boundary. */
160 union {
161 CELL header;
162 long long padding;
164 double n;
165 } F_FLOAT;
167 /* Assembly code makes assumptions about the layout of this struct */
168 typedef struct {
169 CELL header;
170 /* tagged */
171 CELL array;
172 /* tagged */
173 CELL compiledp;
174 /* UNTAGGED */
175 XT xt;
176 /* UNTAGGED compiled code block */
177 F_COMPILED *code;
178 } F_QUOTATION;
180 /* Assembly code makes assumptions about the layout of this struct */
181 typedef struct {
182 CELL header;
183 CELL real;
184 CELL imaginary;
185 } F_COMPLEX;
187 /* Assembly code makes assumptions about the layout of this struct */
188 typedef struct {
189 CELL header;
190 /* tagged */
191 CELL alien;
192 /* tagged */
193 CELL expired;
194 /* untagged */
195 CELL displacement;
196 } F_ALIEN;
198 typedef struct {
199 CELL header;
200 /* tagged byte array holding a C string */
201 CELL path;
202 /* OS-specific handle */
203 void *dll;
204 } F_DLL;
206 typedef struct {
207 CELL header;
208 /* tagged */
209 CELL length;
210 } F_CALLSTACK;
212 typedef struct
214 XT xt;
215 /* Frame size in bytes */
216 CELL size;
217 } F_STACK_FRAME;
219 /* These are really just arrays, but certain elements have special
220 significance */
221 typedef struct
223 CELL header;
224 /* tagged */
225 CELL capacity;
226 /* tagged */
227 CELL class;
228 /* tagged fixnum */
229 CELL size;
230 /* tagged fixnum */
231 CELL echelon;
232 } F_TUPLE_LAYOUT;
234 typedef struct
236 CELL header;
237 /* tagged layout */
238 CELL layout;
239 } F_TUPLE;