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