-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtypes.h
More file actions
346 lines (321 loc) · 8.21 KB
/
types.h
File metadata and controls
346 lines (321 loc) · 8.21 KB
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
//
// Project: CMiniLang
// Author: bajdcc
//
#ifndef CMINILANG_TYPES_H
#define CMINILANG_TYPES_H
#include <string>
#include <unordered_map>
using string_t = std::string;
template<class K, class V> using map_t = std::unordered_map<K, V>;
namespace clib {
#if __APPLE__ && __MACH__
using int8 = int8_t;
using uint8 = uint8_t;
using int16 = int16_t;
using uint16 = uint16_t;
using int32 = int32_t;
using uint32 = uint32_t;
using int64 = int64_t;
using uint64 = uint64_t;
#else
using int8 = signed __int8;
using uint8 = unsigned __int8;
using int16 = signed __int16;
using uint16 = unsigned __int16;
using int32 = signed __int32;
using uint32 = unsigned __int32;
using int64 = signed __int64;
using uint64 = unsigned __int64;
#endif
using sint = signed int;
using uint = unsigned int;
using slong = long long;
using ulong = unsigned long long;
using byte = uint8;
using decimal = double; // 浮点类型
enum lexer_t {
l_none,
l_error,
l_char,
l_uchar,
l_short,
l_ushort,
l_int,
l_uint,
l_long,
l_ulong,
l_float,
l_double,
l_operator,
l_keyword,
l_identifier,
l_string,
l_comment,
l_space,
l_newline,
l_end,
};
enum keyword_t {
k__start,
k_auto,
k_bool,
k_break,
k_case,
k_char,
k_const,
k_continue,
k_default,
k_do,
k_double,
k_else,
k_enum,
k_extern,
k_false,
k_float,
k_for,
k_goto,
k_if,
k_int,
k_long,
k_register,
k_return,
k_short,
k_signed,
k_sizeof,
k_static,
k_struct,
k_switch,
k_true,
k_typedef,
k_union,
k_unsigned,
k_void,
k_volatile,
k_while,
k_interrupt,
k__end
};
enum operator_t {
op__start,
op_assign,
op_equal,
op_plus,
op_plus_assign,
op_minus,
op_minus_assign,
op_times,
op_times_assign,
op_divide,
op_div_assign,
op_bit_and,
op_and_assign,
op_bit_or,
op_or_assign,
op_bit_xor,
op_xor_assign,
op_mod,
op_mod_assign,
op_less_than,
op_less_than_or_equal,
op_greater_than,
op_greater_than_or_equal,
op_logical_not,
op_not_equal,
op_escape,
op_query,
op_bit_not,
op_lparan,
op_rparan,
op_lbrace,
op_rbrace,
op_lsquare,
op_rsquare,
op_comma,
op_dot,
op_semi,
op_colon,
op_plus_plus,
op_minus_minus,
op_logical_and,
op_logical_or,
op_pointer,
op_left_shift,
op_right_shift,
op_left_shift_assign,
op_right_shift_assign,
op_ellipsis,
op__end,
};
enum error_t {
e__start,
e_invalid_char,
e_invalid_operator,
e_invalid_digit,
e_invalid_string,
e__end
};
enum ins_t {
NOP, LEA, IMM, IMX, JMP, JZ, JNZ, ENT, LOAD, SAVE, INTR, CAST, ADJ, CALL, LEV,
PUSH, POP, OR, XOR, AND, EQ, CASE, NE, LT, GT, LE, GE, SHL, SHR, ADD, SUB, MUL, DIV, MOD, NEG, NOT, LNT,
EXIT,
};
template<lexer_t>
struct base_t {
using type = void *;
};
template<class T>
struct base_lexer_t {
static const lexer_t type = l_none;
};
#define DEFINE_BASE_TYPE(t, obj) \
template<> \
struct base_t<t> \
{ \
using type = obj; \
static const int size = sizeof(obj); \
};
DEFINE_BASE_TYPE(l_char, char)
DEFINE_BASE_TYPE(l_uchar, unsigned char)
DEFINE_BASE_TYPE(l_short, short)
DEFINE_BASE_TYPE(l_ushort, unsigned short)
DEFINE_BASE_TYPE(l_int, int)
DEFINE_BASE_TYPE(l_uint, unsigned int)
DEFINE_BASE_TYPE(l_long, slong)
DEFINE_BASE_TYPE(l_ulong, ulong)
DEFINE_BASE_TYPE(l_float, float)
DEFINE_BASE_TYPE(l_double, double)
DEFINE_BASE_TYPE(l_keyword, keyword_t)
DEFINE_BASE_TYPE(l_operator, operator_t)
DEFINE_BASE_TYPE(l_identifier, string_t)
DEFINE_BASE_TYPE(l_string, string_t)
DEFINE_BASE_TYPE(l_comment, string_t)
DEFINE_BASE_TYPE(l_space, uint)
DEFINE_BASE_TYPE(l_newline, uint)
DEFINE_BASE_TYPE(l_error, error_t)
#undef DEFINE_BASE_TYPE
#define DEFINE_CONV_TYPE(t, obj) \
template<> \
struct base_lexer_t<obj> \
{ \
static const lexer_t type = t; \
};
DEFINE_CONV_TYPE(l_char, char)
DEFINE_CONV_TYPE(l_uchar, unsigned char)
DEFINE_CONV_TYPE(l_short, short)
DEFINE_CONV_TYPE(l_ushort, unsigned short)
DEFINE_CONV_TYPE(l_int, int)
DEFINE_CONV_TYPE(l_uint, unsigned int)
DEFINE_CONV_TYPE(l_long, slong)
DEFINE_CONV_TYPE(l_ulong, ulong)
DEFINE_CONV_TYPE(l_float, float)
DEFINE_CONV_TYPE(l_double, double)
DEFINE_CONV_TYPE(l_string, string_t)
DEFINE_CONV_TYPE(l_error, error_t)
#undef DEFINE_CONV_TYPE
const string_t &lexer_typestr(lexer_t);
const string_t &lexer_keywordstr(keyword_t);
int lexer_prior(lexer_t);
int lexer_sizeof(lexer_t);
const string_t &lexer_opstr(operator_t);
const string_t &lexer_opnamestr(operator_t);
const string_t &lexer_errstr(error_t);
int lexer_operatorpred(operator_t);
ins_t lexer_op2ins(operator_t);
#define LEX_T(t) base_t<l_##t>::type
#define LEX_CONV_T(t) base_lexer_t<t>::type
#define LEX_SIZEOF(t) sizeof(LEX_T(t))
#define LEX_SIZE(t) lexer_sizeof(t)
#define LEX_STRING(t) lexer_typestr(t)
#define LEX_PRIOR(t) lexer_prior(t)
#define KEYWORD_STRING(t) lexer_keywordstr(t)
#define OPERATOR_STRING(t) lexer_opnamestr(t)
#define OP_STRING(t) lexer_opstr(t)
#define ERROR_STRING(t) lexer_errstr(t)
#define OPERATOR_PRED(t) lexer_operatorpred(t)
#define OP_INS(t) lexer_op2ins(t)
const string_t& ins_str(ins_t);
#define INS_STRING(t) ins_str(t)
enum coll_t {
c_program,
c_primaryExpression,
c_constant,
c_postfixExpression,
c_argumentExpressionList,
c_unaryExpression,
c_unaryOperator,
c_castExpression,
c_multiplicativeExpression,
c_additiveExpression,
c_shiftExpression,
c_relationalExpression,
c_equalityExpression,
c_andExpression,
c_exclusiveOrExpression,
c_inclusiveOrExpression,
c_logicalAndExpression,
c_logicalOrExpression,
c_conditionalExpression,
c_assignmentExpression,
c_assignmentOperator,
c_expression,
c_constantExpression,
c_declaration,
c_declarationSpecifiers,
c_declarationSpecifiers2,
c_declarationSpecifier,
c_initDeclaratorList,
c_initDeclarator,
c_storageClassSpecifier,
c_typeSpecifier,
c_structOrUnionSpecifier,
c_structOrUnion,
c_structDeclarationList,
c_structDeclaration,
c_specifierQualifierList,
c_structDeclaratorList,
c_structDeclarator,
c_enumSpecifier,
c_enumeratorList,
c_enumerator,
c_enumerationConstant,
c_typeQualifier,
c_declarator,
c_directDeclarator,
c_pointer,
c_typeQualifierList,
c_parameterTypeList,
c_parameterList,
c_parameterDeclaration,
c_identifierList,
c_typeName,
c_abstractDeclarator,
c_directAbstractDeclarator,
c_typedefName,
c_initializer,
c_initializerList,
c_designation,
c_designatorList,
c_designator,
c_statement,
c_labeledStatement,
c_compoundStatement,
c_blockItemList,
c_blockItem,
c_expressionStatement,
c_selectionStatement,
c_iterationStatement,
c_forCondition,
c_forDeclaration,
c_forExpression,
c_jumpStatement,
c_compilationUnit,
c_translationUnit,
c_externalDeclaration,
c_functionDefinition,
c_declarationList,
};
const string_t &coll_str(coll_t);
#define COLL_STRING(t) coll_str(t)
}
#endif //CMINILANG_TYPES_H