]> gitweb.factorcode.org Git - factor.git/blob - vm/layouts.h
Merge branch 'master' into experimental (untested!)
[factor.git] / vm / layouts.h
1 #define INLINE inline static
2
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;
11
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
19
20 #define CELLS ((signed)sizeof(CELL))
21
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)
25
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))
31
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
40
41 /* Canonical F object */
42 #define F_TYPE 7
43 #define F F_TYPE
44
45 #define HEADER_TYPE 7 /* anything less than or equal to this is a tag */
46
47 #define GC_COLLECTED 5 /* See gc.c */
48
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
59
60 #define TYPE_COUNT 17
61
62 INLINE bool immediate_p(CELL obj)
63 {
64         return (obj == F || TAG(obj) == FIXNUM_TYPE);
65 }
66
67 INLINE F_FIXNUM untag_fixnum_fast(CELL tagged)
68 {
69         return ((F_FIXNUM)tagged) >> TAG_BITS;
70 }
71
72 INLINE CELL tag_fixnum(F_FIXNUM untagged)
73 {
74         return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
75 }
76
77 INLINE void *untag_object(CELL tagged)
78 {
79         return (void *)UNTAG(tagged);
80 }
81
82 typedef void *XT;
83
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;
90
91 typedef F_ARRAY F_BYTE_ARRAY;
92
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;
103
104 /* The compiled code heap is structured into blocks. */
105 typedef struct
106 {
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_length; /* # bytes */
111         CELL relocation; /* tagged pointer to byte-array or f */
112 } F_COMPILED;
113
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, depending on if the word is compiled or not */
129         CELL compiledp;
130         /* TAGGED call count for profiling */
131         CELL counter;
132         /* TAGGED machine code for sub-primitive */
133         CELL subprimitive;
134         /* UNTAGGED execution token: jump here to execute word */
135         XT xt;
136         /* UNTAGGED compiled code block */
137         F_COMPILED *code;
138         /* UNTAGGED profiler stub */
139         F_COMPILED *profiling;
140 } F_WORD;
141
142 /* Assembly code makes assumptions about the layout of this struct */
143 typedef struct {
144         CELL header;
145         CELL object;
146 } F_WRAPPER;
147
148 /* Assembly code makes assumptions about the layout of this struct */
149 typedef struct {
150         CELL header;
151         CELL numerator;
152         CELL denominator;
153 } F_RATIO;
154
155 /* Assembly code makes assumptions about the layout of this struct */
156 typedef struct {
157 /* We use a union here to force the float value to be aligned on an
158 8-byte boundary. */
159         union {
160                 CELL header;
161                 long long padding;
162         };
163         double n;
164 } F_FLOAT;
165
166 /* Assembly code makes assumptions about the layout of this struct */
167 typedef struct {
168         CELL header;
169         /* tagged */
170         CELL array;
171         /* tagged */
172         CELL compiledp;
173         /* UNTAGGED */
174         XT xt;
175         /* UNTAGGED compiled code block */
176         F_COMPILED *code;
177 } F_QUOTATION;
178
179 /* Assembly code makes assumptions about the layout of this struct */
180 typedef struct {
181         CELL header;
182         CELL real;
183         CELL imaginary;
184 } F_COMPLEX;
185
186 /* Assembly code makes assumptions about the layout of this struct */
187 typedef struct {
188         CELL header;
189         /* tagged */
190         CELL alien;
191         /* tagged */
192         CELL expired;
193         /* untagged */
194         CELL displacement;
195 } F_ALIEN;
196
197 typedef struct {
198         CELL header;
199         /* tagged byte array holding a C string */
200         CELL path;
201         /* OS-specific handle */
202         void *dll;
203 } F_DLL;
204
205 typedef struct {
206         CELL header;
207         /* tagged */
208         CELL length;
209 } F_CALLSTACK;
210
211 typedef struct
212 {
213         XT xt;
214         /* Frame size in bytes */
215         CELL size;
216 } F_STACK_FRAME;
217
218 /* These are really just arrays, but certain elements have special
219 significance */
220 typedef struct
221 {
222         CELL header;
223         /* tagged */
224         CELL capacity;
225         /* tagged */
226         CELL class;
227         /* tagged fixnum */
228         CELL size;
229         /* tagged fixnum */
230         CELL echelon;
231 } F_TUPLE_LAYOUT;
232
233 typedef struct
234 {
235         CELL header;
236         /* tagged layout */
237         CELL layout;
238 } F_TUPLE;