-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnooc.h
271 lines (233 loc) · 3.35 KB
/
nooc.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#define TEXT_OFFSET 0x101000
#define DATA_OFFSET 0x102000
#define BLOCKSTACKSIZE 32
enum tokentype {
TOK_NONE = 0,
TOK_NAME,
TOK_LPAREN,
TOK_RPAREN,
TOK_LCURLY,
TOK_RCURLY,
TOK_LSQUARE,
TOK_RSQUARE,
TOK_PLUS,
TOK_MINUS,
TOK_GREATER,
TOK_NOT,
TOK_DOLLAR,
TOK_COMMA,
TOK_EQUAL,
TOK_NUM,
TOK_STRING,
TOK_LET,
TOK_IF,
TOK_ELSE,
TOK_LOOP,
TOK_RETURN,
TOK_BREAK
};
struct slice {
size_t cap;
size_t len;
char *data;
};
struct token {
enum tokentype type;
size_t line, col;
struct slice slice;
struct token *next;
};
struct fparams {
size_t cap;
size_t len;
size_t *data; // struct exprs
};
struct fcall {
struct slice name;
struct fparams params;
};
struct typelist {
size_t cap;
size_t len;
size_t *data; // struct types
};
enum typeclass {
TYPE_NONE,
TYPE_INT,
TYPE_ARRAY,
TYPE_REF,
TYPE_PROC,
};
struct type {
enum typeclass class;
size_t size;
union {
struct {
struct typelist in;
struct typelist out;
} params;
struct {
size_t len;
size_t subtype; // struct types
} arr;
size_t subtype; // struct types
} d;
};
struct nametype {
struct slice name;
size_t type; // struct types
};
struct types {
size_t cap;
size_t len;
struct type *data;
};
struct nametypes {
size_t cap;
size_t len;
struct nametype *data;
};
struct assgn {
struct slice s;
size_t val; // struct exprs
const struct token *start;
};
struct assgns {
size_t cap;
size_t len;
struct assgn *data;
};
struct decl {
struct slice s;
size_t type;
size_t val; // struct exprs
bool in;
bool out;
bool toplevel;
uint64_t index;
union {
int64_t offset;
uint64_t addr;
} w;
const struct token *start;
};
struct decls {
size_t cap;
size_t len;
struct decl *data;
};
struct data {
size_t cap;
size_t len;
char *data;
};
struct statement {
enum {
STMT_DECL,
STMT_ASSGN,
STMT_EXPR,
STMT_RETURN,
STMT_BREAK,
} kind;
size_t idx;
const struct token *start;
};
struct block {
struct {
size_t cap;
size_t len;
struct decl *data;
} decls;
size_t datasize;
size_t cap;
size_t len;
struct statement *data;
};
struct cond {
size_t cond; // struct exprs
struct block bif;
struct block belse;
};
struct loop {
struct block block;
};
struct proc {
struct nametypes in;
struct nametypes out;
struct block block;
};
struct access {
uint64_t index;
size_t array; // struct exprs
};
struct binop {
enum {
BOP_PLUS,
BOP_MINUS,
BOP_GREATER,
BOP_EQUAL,
} kind;
size_t left;
size_t right;
};
struct unop {
enum {
UOP_REF,
UOP_NOT,
} kind;
size_t expr;
};
struct value {
union {
int64_t i64;
int32_t i32;
struct slice s;
} v;
};
enum exprkind {
EXPR_LIT,
EXPR_IDENT,
EXPR_BINARY,
EXPR_UNARY,
EXPR_FCALL,
EXPR_COND,
EXPR_LOOP,
EXPR_PROC,
EXPR_ACCESS,
};
enum class {
C_INT = 1,
C_BOOL,
C_REF,
C_STR,
C_PROC,
};
struct expr {
enum exprkind kind;
enum class class;
union {
struct value v;
struct binop bop;
struct unop uop;
struct slice s;
struct fcall call;
struct cond cond;
struct loop loop;
struct proc proc;
struct access access;
} d;
const struct token *start;
};
struct exprs {
size_t cap;
size_t len;
struct expr *data;
};
extern const char *const tokenstr[];
extern struct assgns assgns;
extern struct exprs exprs;
extern struct target targ;
extern struct toplevel toplevel;
extern struct map *typesmap;
extern char *infile;
extern struct types types;