]> gitweb.factorcode.org Git - factor.git/blob - vm/layouts.h
28fa5a7c82c9f32136375153a4eebd72b217e565
[factor.git] / vm / layouts.h
1 typedef unsigned char u8;
2 typedef unsigned short u16;
3 typedef unsigned int u32;
4 typedef unsigned long long u64;
5 typedef signed char s8;
6 typedef signed short s16;
7 typedef signed int s32;
8 typedef signed long long s64;
9
10 #ifdef _WIN64
11         typedef long long F_FIXNUM;
12         typedef unsigned long long CELL;
13 #else
14         typedef long F_FIXNUM;
15         typedef unsigned long CELL;
16 #endif
17
18 #define CELLS ((signed)sizeof(CELL))
19
20 /* must always be 16 bits */
21 #define CHARS ((signed)sizeof(u16))
22
23 #define WORD_SIZE (CELLS*8)
24 #define HALF_WORD_SIZE (CELLS*4)
25 #define HALF_WORD_MASK (((unsigned long)1<<HALF_WORD_SIZE)-1)
26
27 #define TAG_MASK 7
28 #define TAG_BITS 3
29 #define TAG(cell) ((CELL)(cell) & TAG_MASK)
30 #define RETAG(cell,tag) ((CELL)(cell) | (tag))
31 #define UNTAG(cell) ((CELL)(cell) & ~TAG_MASK)
32
33 /*** Tags ***/
34 #define FIXNUM_TYPE 0
35 #define BIGNUM_TYPE 1
36 #define WORD_TYPE 2
37 #define OBJECT_TYPE 3
38 #define RATIO_TYPE 4
39 #define FLOAT_TYPE 5
40 #define COMPLEX_TYPE 6
41 #define WRAPPER_TYPE 7
42
43 #define HEADER_TYPE 7 /* anything less than or equal to this is a tag */
44 #define GC_COLLECTED 0 /* See gc.c */
45
46 /*** Header types ***/
47 #define ARRAY_TYPE 8
48
49 /* Canonical F object */
50 #define F_TYPE 9
51 #define F RETAG(0,OBJECT_TYPE)
52
53 #define HASHTABLE_TYPE 10
54 #define VECTOR_TYPE 11
55 #define STRING_TYPE 12
56 #define SBUF_TYPE 13
57 #define QUOTATION_TYPE 14
58 #define DLL_TYPE 15
59 #define ALIEN_TYPE 16
60 #define TUPLE_TYPE 17
61 #define BYTE_ARRAY_TYPE 18
62
63 #define TYPE_COUNT 19
64
65 typedef struct {
66         CELL header;
67         /* tagged */
68         CELL capacity;
69 } F_ARRAY;
70
71 typedef struct {
72         /* always tag_header(VECTOR_TYPE) */
73         CELL header;
74         /* tagged */
75         CELL top;
76         /* tagged */
77         CELL array;
78 } F_VECTOR;
79
80 typedef struct {
81         CELL header;
82         /* tagged num of chars */
83         CELL length;
84         /* tagged */
85         CELL hashcode;
86 } F_STRING;
87
88 typedef struct {
89         /* always tag_header(SBUF_TYPE) */
90         CELL header;
91         /* tagged */
92         CELL top;
93         /* tagged */
94         CELL string;
95 } F_SBUF;
96
97 typedef struct {
98         /* always tag_header(HASHTABLE_TYPE) */
99         CELL header;
100         /* tagged */
101         CELL count;
102         /* tagged */
103         CELL deleted;
104         /* tagged */
105         CELL array;
106 } F_HASHTABLE;
107
108 /* When a word is executed we jump to the value of the XT field. However this
109 value is an unportable function pointer. Interpreted and primitive words will
110 have their XT set to a value in the 'primitives' global (see primitives.c).
111 Compiled words are marked as such and their XT, which point inside the code
112 heap, are instead relocated on startup, and also considered a code GC root. */
113 typedef struct {
114         /* TAGGED header */
115         CELL header;
116         /* TAGGED hashcode */
117         CELL hashcode;
118         /* TAGGED word name */
119         CELL name;
120         /* TAGGED word vocabulary */
121         CELL vocabulary;
122         /* TAGGED on-disk primitive number */
123         CELL primitive;
124         /* TAGGED parameter to xt; used for colon definitions */
125         CELL def;
126         /* TAGGED property hash for library code */
127         CELL props;
128         /* TAGGED t or f, depending on if the word is compiled or not */
129         CELL compiledp;
130         /* UNTAGGED execution token: jump here to execute word */
131         CELL xt;
132 } F_WORD;
133
134 typedef struct {
135         CELL header;
136         CELL object;
137 } F_WRAPPER;
138
139 typedef struct {
140         CELL header;
141         CELL numerator;
142         CELL denominator;
143 } F_RATIO;
144
145 typedef struct {
146 /* C sucks. */
147         union {
148                 CELL header;
149                 long long padding;
150         };
151         double n;
152 } F_FLOAT;
153
154 typedef struct {
155         CELL header;
156         CELL real;
157         CELL imaginary;
158 } F_COMPLEX;
159
160 typedef struct {
161         CELL header;
162         /* tagged */
163         CELL alien;
164         /* untagged */
165         CELL displacement;
166         /* untagged */
167         bool expired;
168 } F_ALIEN;
169
170 typedef struct {
171         CELL header;
172         /* tagged byte array holding a C string */
173         CELL path;
174         /* OS-specific handle */
175         void* dll;
176 } F_DLL;