]> gitweb.factorcode.org Git - factor.git/blob - vm/layouts.h
Move call( and execute( to core
[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         char needs_fixup; /* is this a new block that needs full fixup? */
110         CELL code_length; /* # bytes */
111         CELL literals; /* # bytes */
112         CELL relocation; /* tagged pointer to byte-array or f */
113 } F_CODE_BLOCK;
114
115 /* Assembly code makes assumptions about the layout of this struct */
116 typedef struct {
117         /* TAGGED header */
118         CELL header;
119         /* TAGGED hashcode */
120         CELL hashcode;
121         /* TAGGED word name */
122         CELL name;
123         /* TAGGED word vocabulary */
124         CELL vocabulary;
125         /* TAGGED definition */
126         CELL def;
127         /* TAGGED property assoc for library code */
128         CELL props;
129         /* TAGGED t or f, t means its compiled with the optimizing compiler,
130         f means its compiled with the non-optimizing compiler */
131         CELL optimizedp;
132         /* TAGGED call count for profiling */
133         CELL counter;
134         /* TAGGED machine code for sub-primitive */
135         CELL subprimitive;
136         /* UNTAGGED execution token: jump here to execute word */
137         XT xt;
138         /* UNTAGGED compiled code block */
139         F_CODE_BLOCK *code;
140         /* UNTAGGED profiler stub */
141         F_CODE_BLOCK *profiling;
142 } F_WORD;
143
144 /* Assembly code makes assumptions about the layout of this struct */
145 typedef struct {
146         CELL header;
147         CELL object;
148 } F_WRAPPER;
149
150 /* Assembly code makes assumptions about the layout of this struct */
151 typedef struct {
152         CELL header;
153         CELL numerator;
154         CELL denominator;
155 } F_RATIO;
156
157 /* Assembly code makes assumptions about the layout of this struct */
158 typedef struct {
159 /* We use a union here to force the float value to be aligned on an
160 8-byte boundary. */
161         union {
162                 CELL header;
163                 long long padding;
164         };
165         double n;
166 } F_FLOAT;
167
168 /* Assembly code makes assumptions about the layout of this struct */
169 typedef struct {
170         CELL header;
171         /* tagged */
172         CELL array;
173         /* tagged */
174         CELL compiledp;
175         /* tagged */
176         CELL cached_effect;
177         /* tagged */
178         CELL cache_counter;
179         /* UNTAGGED */
180         XT xt;
181         /* UNTAGGED compiled code block */
182         F_CODE_BLOCK *code;
183 } F_QUOTATION;
184
185 /* Assembly code makes assumptions about the layout of this struct */
186 typedef struct {
187         CELL header;
188         CELL real;
189         CELL imaginary;
190 } F_COMPLEX;
191
192 /* Assembly code makes assumptions about the layout of this struct */
193 typedef struct {
194         CELL header;
195         /* tagged */
196         CELL alien;
197         /* tagged */
198         CELL expired;
199         /* untagged */
200         CELL displacement;
201 } F_ALIEN;
202
203 typedef struct {
204         CELL header;
205         /* tagged byte array holding a C string */
206         CELL path;
207         /* OS-specific handle */
208         void *dll;
209 } F_DLL;
210
211 typedef struct {
212         CELL header;
213         /* tagged */
214         CELL length;
215 } F_CALLSTACK;
216
217 typedef struct
218 {
219         XT xt;
220         /* Frame size in bytes */
221         CELL size;
222 } F_STACK_FRAME;
223
224 /* These are really just arrays, but certain elements have special
225 significance */
226 typedef struct
227 {
228         CELL header;
229         /* tagged */
230         CELL capacity;
231         /* tagged */
232         CELL class;
233         /* tagged fixnum */
234         CELL size;
235         /* tagged fixnum */
236         CELL echelon;
237 } F_TUPLE_LAYOUT;
238
239 typedef struct
240 {
241         CELL header;
242         /* tagged layout */
243         CELL layout;
244 } F_TUPLE;