-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.h
312 lines (289 loc) · 7.17 KB
/
lib.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include <stdlib.h>
#include <stdint.h>
static char *const builtin_files[] = {
"io.kan"
};
static size_t const len_builtin_files = sizeof(builtin_files) / sizeof(char *);
size_t num_builtin_files() {
return len_builtin_files;
}
char *const *get_builtin_files() {
return builtin_files;
}
// TOKEN types
static char *const token_strings[] = {
"unknown token",
"invalid char literal",
"invalid escape sequence",
"invalid identifier",
"integer",
"float",
"null",
"identifier",
"let",
"if",
"else",
"import",
"def",
"while",
"new",
"delete",
"return",
"type",
"struct",
"enum",
"union",
"as",
"extern",
"export",
"delegate",
"sizeof",
"for",
"undefined",
"continue",
"break",
"defer",
";",
",",
":",
".",
"...",
"!",
"!=",
"==",
"+",
"-",
"*",
"/",
"%",
"=",
"+=",
"-=",
"*=",
"/=",
"%=",
"&=",
"|=",
"^=",
"<",
"<=",
">",
">=",
"&",
"&&",
"|",
"||",
"^",
"~",
"<<",
">>",
"(",
")",
"{",
"}",
"[",
"]",
"string",
"char",
"EOF"
};
static size_t const len_token_strings = sizeof(token_strings) / sizeof(char *);
// BINARY types
static char *const binary_type_ops[] = {
"error",
"+", // BINARY_ADD
"-", // BINARY_SUB
"*", // BINARY_MUL
"/", // BINARY_DIV
"%", // BINARY_MOD
"&",
"|",
"^",
"<", // BINARY_ST
"<=", // BINARY_SE
">", // BINARY_GT
">=", // BINARY_GE
"==", // BINARY_EQ
"!=", // BINARY_NE
"&&", // BINARY_LOG_AND
"||", // BINARY_LOG_OR
"<<",
">>",
};
static size_t const len_binary_strings = sizeof(binary_type_ops) / sizeof(char *);
// UNARY types
static char *const unary_type_ops[] = {
"error",
"&",
"*",
"!",
"-",
"~"
};
static size_t const len_unary_strings = sizeof(unary_type_ops) / sizeof(char *);
// EXPR types
static char *const expr_type_strings[] = {
"error",
"int literal",
"float literal",
"null literal",
"undefined value",
"string literal",
"array string literal",
"char literal",
"binary expression",
"unary expression",
"identifier",
"assignment",
"function call",
"struct initialization",
"access expression",
"cast expression",
"new expression",
"sizeof expression",
"index expression"
};
static size_t const len_expr_strings = sizeof(expr_type_strings) / sizeof(char *);
// STMT types
static char *const stmt_type_strings[] = {
"error",
"expression",
"let",
"import",
"function declaration",
"structured type declaration",
"enum type declaration",
"union type declaration",
"block",
"if",
"while",
"delete",
"return",
"continue",
"break",
"defer",
"for"
};
static size_t const len_stmt_strings = sizeof(stmt_type_strings) / sizeof(char *);
// Type types
static char *const type_type_strings[] = {
"error",
"template",
"template parameter",
"pointer",
"array",
"slice",
"bool",
"int",
"f32",
"f64",
"void",
"function",
"function",
"module",
"struct",
"enum",
"union"
};
static size_t const len_type_strings = sizeof(type_type_strings) / sizeof(char *);
// ERROR types
static char *const error_texts[] = {
NULL,
"Internal error: '%s'",
// file errors
"Path was empty",
"Could not open file: '%s'",
"Could not allocate buffer",
"Could not read file: '%s'",
// parse errors
"Unexpected end of file",
"Expected '%s', but got '%s'",
"Unknown symbol: '%.*s'",
"Char literal with length %1$d: '%.*s'",
"Could not parse statement",
"Illegal identifier '%.*s'",
"Illegal type identifier '%.*s': %s",
"Invalid escape sequence '%.*s'",
"Expected 1 receiver for Method, but got %u",
"Expected at least 1 type parameter for function, but got %u",
// type errors
"Duplicate definition of '%.*s'",
"No %s called '%.*s' in %.*s",
"Type '%s' cannot be accessed with '%s' operator",
"Incomplete type '%.*s'",
"Invalid operator for types '%s' and '%s'",
"Pointers may only be compared or subtracted",
"Cannot take address of rvalue",
"Trying to dereference non pointer type '%s'",
"Unary operator '%s' not defined for '%s'",
"Wrong return type for function. Expected '%s', but got '%s'",
"Missing return statement",
"Trying to return a value inside a 'void' function",
"Illegal use of declared type",
"Type '%s' is not callable",
"Wrong number of arguments. Expected '%u', but got '%u'",
"Wrong argument type. Expected '%s', but got '%s'",
"Expected the name of a struct or union, but got '%s'",
"Array initializer must be an array/string literal",
"Array length must be an int literal or '_'",
"Unions can only be initialized with one value",
"The field '%.*s' in '%.*s' was declared with type '%s', but was initialized with '%s'",
"Could not infer type",
"'%s' cannot be casted into '%s'",
"Invalid type for condition. Expected 'bool', but got '%s'",
"Trying to delete non pointer type: '%s'",
"Variable was declared with type '%s', but initialized with type '%s'",
"The type '%s' is not assignable",
"Expression is not assignable",
"Invalid expression",
"Cannot use unsized type '%s' inside a struct",
"Cannot use unsized type '%s' as a function parameter",
"Cannot take the size of an unsized type '%s'",
"Unsized type '%s' cannot be dereferenced",
"Duplicate entry '%.*s' in enum '%.*s'",
"Invalid enum start value type '%s' in enum '%.*s'",
"Cannot declare method on primitive type '%s'",
"Methods can only be declare on types from the same module",
"Cannot take method pointer from instance. Use '&%s' instead",
"Cannot take the address of a type",
"Illegal expression for unary operand",
"Expression cannot be evaluated at compile time",
"Trying to access private symbol '%.*s' from '%.*s'",
"%s statements may not be used outside of loops",
"Wrong field. Expected '%.*s', but got '%.*s'",
"Expression of type '%s' cannot be indexed with type '%s'"
};
static size_t const len_err_strings = sizeof(error_texts) / sizeof(char *);
// MIR binary kinds
static char *const mir_binary_kind_strings[] = {
NULL,
"+", // MIR_BIN_ADD
"-", // MIR_BIN_SUB
"*", // MIR_BIN_MUL
"/", // MIR_BIN_DIV
"%", // MIR_BIN_MOD
"&",
"|",
"^",
"<", // MIR_BIN_ST
"<=", // MIR_BIN_SE
">", // MIR_BIN_GT
">=", // MIR_BIN_GE
"==", // MIR_BIN_EQ
"!=", // MIR_BIN_NE
"&&", // MIR_BIN_BOOL_AND
"||", // MIR_BIN_BOOL_OR
"<<",
">>",
"s+", // MIR_BIN_ADD_SCALAR
"s-", // MIR_BIN_SUB_SCALAR
};
static size_t const len_mir_binary_kind_strings = sizeof(mir_binary_kind_strings) / sizeof(char *);
// MIR unary kinds
static char *const mir_unary_kind_strings[] = {
NULL,
"!", // MIR_UNARY_BOOL_NEG
"-", // MIR_UNARY_INT_NEG
"*", // MIR_UNARY_DEREF
};
static size_t const len_mir_unary_kind_strings = sizeof(mir_unary_kind_strings) / sizeof(char *);