line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
// Copyright (c) 2023 Yuki Kimoto |
2
|
|
|
|
|
|
|
// MIT License |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include |
5
|
|
|
|
|
|
|
#include |
6
|
|
|
|
|
|
|
#include |
7
|
|
|
|
|
|
|
#include |
8
|
|
|
|
|
|
|
#include |
9
|
|
|
|
|
|
|
#include |
10
|
|
|
|
|
|
|
#include |
11
|
|
|
|
|
|
|
#include "spvm_compiler.h" |
12
|
|
|
|
|
|
|
#include "spvm_list.h" |
13
|
|
|
|
|
|
|
#include "spvm_hash.h" |
14
|
|
|
|
|
|
|
#include "spvm_op.h" |
15
|
|
|
|
|
|
|
#include "spvm_method.h" |
16
|
|
|
|
|
|
|
#include "spvm_constant.h" |
17
|
|
|
|
|
|
|
#include "spvm_field.h" |
18
|
|
|
|
|
|
|
#include "spvm_var_decl.h" |
19
|
|
|
|
|
|
|
#include "spvm_var.h" |
20
|
|
|
|
|
|
|
#include "spvm_type.h" |
21
|
|
|
|
|
|
|
#include "spvm_field_access.h" |
22
|
|
|
|
|
|
|
#include "spvm_call_method.h" |
23
|
|
|
|
|
|
|
#include "spvm_type.h" |
24
|
|
|
|
|
|
|
#include "spvm_opcode_builder.h" |
25
|
|
|
|
|
|
|
#include "spvm_check.h" |
26
|
|
|
|
|
|
|
#include "spvm_switch_info.h" |
27
|
|
|
|
|
|
|
#include "spvm_attribute.h" |
28
|
|
|
|
|
|
|
#include "spvm_allocator.h" |
29
|
|
|
|
|
|
|
#include "spvm_use.h" |
30
|
|
|
|
|
|
|
#include "spvm_class_var.h" |
31
|
|
|
|
|
|
|
#include "spvm_class_var_access.h" |
32
|
|
|
|
|
|
|
#include "spvm_precompile.h" |
33
|
|
|
|
|
|
|
#include "spvm_block.h" |
34
|
|
|
|
|
|
|
#include "spvm_basic_type.h" |
35
|
|
|
|
|
|
|
#include "spvm_case_info.h" |
36
|
|
|
|
|
|
|
#include "spvm_array_field_access.h" |
37
|
|
|
|
|
|
|
#include "spvm_string_buffer.h" |
38
|
|
|
|
|
|
|
#include "spvm_allow.h" |
39
|
|
|
|
|
|
|
#include "spvm_interface.h" |
40
|
|
|
|
|
|
|
#include "spvm_string.h" |
41
|
|
|
|
|
|
|
#include "spvm_dumper.h" |
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
|
7550
|
|
|
|
|
|
const char* const* SPVM_OP_C_ID_NAMES(void) { |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
static const char* const id_names[] = { |
99
|
|
|
|
|
|
|
"GRAMMAR", |
100
|
|
|
|
|
|
|
"LIST", |
101
|
|
|
|
|
|
|
"PUSHMARK", |
102
|
|
|
|
|
|
|
"DO_NOTHING", |
103
|
|
|
|
|
|
|
"NAME", |
104
|
|
|
|
|
|
|
"ATTRIBUTE", |
105
|
|
|
|
|
|
|
"CURRENT_CLASS", |
106
|
|
|
|
|
|
|
"CLASS", |
107
|
|
|
|
|
|
|
"EXTENDS", |
108
|
|
|
|
|
|
|
"CLASS_BLOCK", |
109
|
|
|
|
|
|
|
"END_OF_FILE", |
110
|
|
|
|
|
|
|
"IF", |
111
|
|
|
|
|
|
|
"UNLESS", |
112
|
|
|
|
|
|
|
"ELSIF", |
113
|
|
|
|
|
|
|
"ELSE", |
114
|
|
|
|
|
|
|
"CONDITION", |
115
|
|
|
|
|
|
|
"CONDITION_NOT", |
116
|
|
|
|
|
|
|
"SWITCH", |
117
|
|
|
|
|
|
|
"CASE", |
118
|
|
|
|
|
|
|
"DEFAULT", |
119
|
|
|
|
|
|
|
"SWITCH_CONDITION", |
120
|
|
|
|
|
|
|
"BREAK", |
121
|
|
|
|
|
|
|
"FOR", |
122
|
|
|
|
|
|
|
"WHILE", |
123
|
|
|
|
|
|
|
"LOOP", |
124
|
|
|
|
|
|
|
"LOOP_INCREMENT", |
125
|
|
|
|
|
|
|
"LAST", |
126
|
|
|
|
|
|
|
"NEXT", |
127
|
|
|
|
|
|
|
"MY", |
128
|
|
|
|
|
|
|
"FIELD", |
129
|
|
|
|
|
|
|
"METHOD", |
130
|
|
|
|
|
|
|
"ENUM", |
131
|
|
|
|
|
|
|
"ENUMERATION_VALUE", |
132
|
|
|
|
|
|
|
"ENUM_BLOCK", |
133
|
|
|
|
|
|
|
"BLOCK", |
134
|
|
|
|
|
|
|
"EVAL", |
135
|
|
|
|
|
|
|
"TYPE", |
136
|
|
|
|
|
|
|
"MUTABLE", |
137
|
|
|
|
|
|
|
"VOID", |
138
|
|
|
|
|
|
|
"BYTE", |
139
|
|
|
|
|
|
|
"SHORT", |
140
|
|
|
|
|
|
|
"INT", |
141
|
|
|
|
|
|
|
"LONG", |
142
|
|
|
|
|
|
|
"FLOAT", |
143
|
|
|
|
|
|
|
"DOUBLE", |
144
|
|
|
|
|
|
|
"STRING", |
145
|
|
|
|
|
|
|
"OBJECT", |
146
|
|
|
|
|
|
|
"DOT3", |
147
|
|
|
|
|
|
|
"OF", |
148
|
|
|
|
|
|
|
"USE", |
149
|
|
|
|
|
|
|
"AS", |
150
|
|
|
|
|
|
|
"ALIAS", |
151
|
|
|
|
|
|
|
"REQUIRE", |
152
|
|
|
|
|
|
|
"IF_REQUIRE", |
153
|
|
|
|
|
|
|
"INIT", |
154
|
|
|
|
|
|
|
"INTERFACE", |
155
|
|
|
|
|
|
|
"RETURN", |
156
|
|
|
|
|
|
|
"CONSTANT", |
157
|
|
|
|
|
|
|
"INC", |
158
|
|
|
|
|
|
|
"DEC", |
159
|
|
|
|
|
|
|
"PRE_INC", |
160
|
|
|
|
|
|
|
"POST_INC", |
161
|
|
|
|
|
|
|
"PRE_DEC", |
162
|
|
|
|
|
|
|
"POST_DEC", |
163
|
|
|
|
|
|
|
"MINUS", |
164
|
|
|
|
|
|
|
"PLUS", |
165
|
|
|
|
|
|
|
"ADD", |
166
|
|
|
|
|
|
|
"SUBTRACT", |
167
|
|
|
|
|
|
|
"MULTIPLY", |
168
|
|
|
|
|
|
|
"DIVIDE", |
169
|
|
|
|
|
|
|
"BIT_AND", |
170
|
|
|
|
|
|
|
"BIT_OR", |
171
|
|
|
|
|
|
|
"BIT_XOR", |
172
|
|
|
|
|
|
|
"BIT_NOT", |
173
|
|
|
|
|
|
|
"REMAINDER", |
174
|
|
|
|
|
|
|
"LEFT_SHIFT", |
175
|
|
|
|
|
|
|
"RIGHT_ARITHMETIC_SHIFT", |
176
|
|
|
|
|
|
|
"RIGHT_LOGICAL_SHIFT", |
177
|
|
|
|
|
|
|
"LOGICAL_AND", |
178
|
|
|
|
|
|
|
"LOGICAL_OR", |
179
|
|
|
|
|
|
|
"LOGICAL_NOT", |
180
|
|
|
|
|
|
|
"ARRAY_ACCESS", |
181
|
|
|
|
|
|
|
"ASSIGN", |
182
|
|
|
|
|
|
|
"CALL_METHOD", |
183
|
|
|
|
|
|
|
"FIELD_ACCESS", |
184
|
|
|
|
|
|
|
"VAR", |
185
|
|
|
|
|
|
|
"TYPE_CAST", |
186
|
|
|
|
|
|
|
"UNDEF", |
187
|
|
|
|
|
|
|
"ARRAY_LENGTH", |
188
|
|
|
|
|
|
|
"DIE", |
189
|
|
|
|
|
|
|
"EXCEPTION_VAR", |
190
|
|
|
|
|
|
|
"NEW", |
191
|
|
|
|
|
|
|
"WEAKEN", |
192
|
|
|
|
|
|
|
"WEAKEN_FIELD", |
193
|
|
|
|
|
|
|
"UNWEAKEN", |
194
|
|
|
|
|
|
|
"UNWEAKEN_FIELD", |
195
|
|
|
|
|
|
|
"ISWEAK", |
196
|
|
|
|
|
|
|
"ISWEAK_FIELD", |
197
|
|
|
|
|
|
|
"SPECIAL_ASSIGN", |
198
|
|
|
|
|
|
|
"CONCAT", |
199
|
|
|
|
|
|
|
"CLASS_VAR", |
200
|
|
|
|
|
|
|
"CLASS_VAR_ACCESS", |
201
|
|
|
|
|
|
|
"ARRAY_INIT", |
202
|
|
|
|
|
|
|
"BOOL", |
203
|
|
|
|
|
|
|
"CHECK_CONVERT", |
204
|
|
|
|
|
|
|
"NUMERIC_EQ", |
205
|
|
|
|
|
|
|
"NUMERIC_NE", |
206
|
|
|
|
|
|
|
"NUMERIC_LT", |
207
|
|
|
|
|
|
|
"NUMERIC_LE", |
208
|
|
|
|
|
|
|
"NUMERIC_GT", |
209
|
|
|
|
|
|
|
"NUMERIC_GE", |
210
|
|
|
|
|
|
|
"NUMERIC_CMP", |
211
|
|
|
|
|
|
|
"STRING_EQ", |
212
|
|
|
|
|
|
|
"STRING_NE", |
213
|
|
|
|
|
|
|
"STRING_GT", |
214
|
|
|
|
|
|
|
"STRING_GE", |
215
|
|
|
|
|
|
|
"STRING_LT", |
216
|
|
|
|
|
|
|
"STRING_LE", |
217
|
|
|
|
|
|
|
"STRING_CMP", |
218
|
|
|
|
|
|
|
"ISA", |
219
|
|
|
|
|
|
|
"ISA_ERROR", |
220
|
|
|
|
|
|
|
"IS_TYPE", |
221
|
|
|
|
|
|
|
"IS_ERROR", |
222
|
|
|
|
|
|
|
"IS_COMPILE_TYPE", |
223
|
|
|
|
|
|
|
"SEQUENCE", |
224
|
|
|
|
|
|
|
"SCALAR", |
225
|
|
|
|
|
|
|
"ARRAY_FIELD_ACCESS", |
226
|
|
|
|
|
|
|
"REFERENCE", |
227
|
|
|
|
|
|
|
"DEREF", |
228
|
|
|
|
|
|
|
"STRING_LENGTH", |
229
|
|
|
|
|
|
|
"CURRENT_CLASS_NAME", |
230
|
|
|
|
|
|
|
"ALLOW", |
231
|
|
|
|
|
|
|
"WARN", |
232
|
|
|
|
|
|
|
"PRINT", |
233
|
|
|
|
|
|
|
"SAY", |
234
|
|
|
|
|
|
|
"TYPE_NAME", |
235
|
|
|
|
|
|
|
"COMPILE_TYPE_NAME", |
236
|
|
|
|
|
|
|
"DUMP", |
237
|
|
|
|
|
|
|
"TRUE", |
238
|
|
|
|
|
|
|
"FALSE", |
239
|
|
|
|
|
|
|
"DIVIDE_UNSIGNED_INT", |
240
|
|
|
|
|
|
|
"DIVIDE_UNSIGNED_LONG", |
241
|
|
|
|
|
|
|
"REMAINDER_UNSIGNED_INT", |
242
|
|
|
|
|
|
|
"REMAINDER_UNSIGNED_LONG", |
243
|
|
|
|
|
|
|
"NEW_STRING_LEN", |
244
|
|
|
|
|
|
|
"IS_READ_ONLY", |
245
|
|
|
|
|
|
|
"MAKE_READ_ONLY", |
246
|
|
|
|
|
|
|
"COPY", |
247
|
|
|
|
|
|
|
"CAN", |
248
|
|
|
|
|
|
|
"BASIC_TYPE_ID", |
249
|
|
|
|
|
|
|
"DIE_ERROR_ID", |
250
|
|
|
|
|
|
|
"SET_DIE_ERROR_ID", |
251
|
|
|
|
|
|
|
"EVAL_ERROR_ID", |
252
|
|
|
|
|
|
|
"ARGS_WIDTH", |
253
|
|
|
|
|
|
|
"VERSION", |
254
|
|
|
|
|
|
|
}; |
255
|
|
|
|
|
|
|
|
256
|
7550
|
|
|
|
|
|
return id_names; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
42486
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_class(SPVM_COMPILER* compiler, SPVM_OP* op_class, SPVM_OP* op_type, SPVM_OP* op_block, SPVM_OP* op_list_attributes, SPVM_OP* op_extends) { |
260
|
|
|
|
|
|
|
|
261
|
42486
|
|
|
|
|
|
const char* basic_type_name = op_type->uv.type->unresolved_basic_type_name; |
262
|
|
|
|
|
|
|
|
263
|
42486
|
|
|
|
|
|
SPVM_TYPE* type = op_type->uv.type; |
264
|
|
|
|
|
|
|
|
265
|
42486
|
|
|
|
|
|
SPVM_BASIC_TYPE* basic_type = SPVM_HASH_get(compiler->basic_type_symtable, basic_type_name, strlen(basic_type_name)); |
266
|
42486
|
100
|
|
|
|
|
if (!basic_type) { |
267
|
42485
|
|
|
|
|
|
basic_type = SPVM_COMPILER_add_basic_type(compiler, basic_type_name); |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
42486
|
|
|
|
|
|
type->basic_type = basic_type; |
271
|
|
|
|
|
|
|
|
272
|
42486
|
|
|
|
|
|
type->basic_type->op_class = op_class; |
273
|
42486
|
|
|
|
|
|
type->basic_type->op_extends = op_extends; |
274
|
|
|
|
|
|
|
|
275
|
42486
|
|
|
|
|
|
type->basic_type->class_dir = compiler->current_class_dir; |
276
|
42486
|
|
|
|
|
|
type->basic_type->class_rel_file = compiler->current_class_rel_file; |
277
|
42486
|
|
|
|
|
|
type->basic_type->class_file = compiler->current_file; |
278
|
|
|
|
|
|
|
|
279
|
42486
|
100
|
|
|
|
|
if (op_extends) { |
280
|
3093
|
|
|
|
|
|
SPVM_OP* op_type_parent_basic_type = op_extends->first; |
281
|
|
|
|
|
|
|
|
282
|
3093
|
|
|
|
|
|
SPVM_OP* op_name_parent_basic_type = SPVM_OP_new_op_name(compiler, op_type_parent_basic_type->uv.type->unresolved_basic_type_name, op_type_parent_basic_type->file, op_type_parent_basic_type->line); |
283
|
|
|
|
|
|
|
|
284
|
3093
|
|
|
|
|
|
type->basic_type->parent_name = op_name_parent_basic_type->uv.name; |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
// add use stack |
287
|
3093
|
|
|
|
|
|
SPVM_OP* op_use = SPVM_OP_new_op_use(compiler, op_name_parent_basic_type->file, op_name_parent_basic_type->line); |
288
|
3093
|
|
|
|
|
|
SPVM_OP* op_name_alias = NULL; |
289
|
3093
|
|
|
|
|
|
int32_t is_require = 0; |
290
|
3093
|
|
|
|
|
|
SPVM_OP_build_use(compiler, op_use, op_type_parent_basic_type, op_name_alias, is_require); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
42486
|
100
|
|
|
|
|
if (type->basic_type->class_dir) { |
294
|
24714
|
|
|
|
|
|
SPVM_STRING_new(compiler, type->basic_type->class_dir, strlen(type->basic_type->class_dir)); |
295
|
|
|
|
|
|
|
} |
296
|
42486
|
|
|
|
|
|
SPVM_STRING_new(compiler, type->basic_type->class_rel_file, strlen(type->basic_type->class_rel_file)); |
297
|
42486
|
|
|
|
|
|
SPVM_STRING_new(compiler, type->basic_type->class_file, strlen(type->basic_type->class_file)); |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
// Assert |
300
|
42486
|
|
|
|
|
|
SPVM_BASIC_TYPE* found_basic_type = SPVM_HASH_get(compiler->basic_type_symtable, basic_type_name, strlen(basic_type_name)); |
301
|
|
|
|
|
|
|
|
302
|
42486
|
100
|
|
|
|
|
if (strstr(basic_type_name, "::anon::")) { |
303
|
8093
|
|
|
|
|
|
type->basic_type->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
304
|
8093
|
|
|
|
|
|
basic_type->is_anon = 1; |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
42486
|
100
|
|
|
|
|
if (!basic_type->is_anon) { |
308
|
34393
|
50
|
|
|
|
|
assert(!islower(basic_type_name[0])); |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
// If class name is different from the class name corresponding to the class file, compile error occur. |
311
|
34393
|
100
|
|
|
|
|
if (strcmp(basic_type_name, compiler->current_outer_class_name) != 0) { |
312
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The class name \"%s\" must be \"%s\".\n at %s line %d", basic_type_name, compiler->current_outer_class_name, op_class->file, op_class->line); |
313
|
2
|
|
|
|
|
|
return op_class; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
34391
|
|
|
|
|
|
SPVM_LIST* anon_op_types = compiler->current_anon_op_types; |
317
|
42483
|
100
|
|
|
|
|
for (int32_t i = 0; i < anon_op_types->length; i++) { |
318
|
8092
|
|
|
|
|
|
SPVM_OP* anon_op_type = SPVM_LIST_get(anon_op_types, i); |
319
|
8092
|
|
|
|
|
|
const char* anon_unresolved_basic_type_name = anon_op_type->uv.type->unresolved_basic_type_name; |
320
|
8092
|
|
|
|
|
|
SPVM_BASIC_TYPE* anon_basic_type = SPVM_HASH_get(compiler->basic_type_symtable, anon_unresolved_basic_type_name, strlen(anon_unresolved_basic_type_name)); |
321
|
8092
|
50
|
|
|
|
|
assert(anon_basic_type); |
322
|
8092
|
|
|
|
|
|
SPVM_LIST_push(basic_type->anon_basic_types, anon_basic_type); |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
// Module attributes |
327
|
42484
|
|
|
|
|
|
int32_t class_attributes_count = 0; |
328
|
42484
|
|
|
|
|
|
int32_t access_control_attributes_count = 0; |
329
|
42484
|
100
|
|
|
|
|
if (op_list_attributes) { |
330
|
9517
|
|
|
|
|
|
SPVM_OP* op_attribute = op_list_attributes->first; |
331
|
19038
|
100
|
|
|
|
|
while ((op_attribute = SPVM_OP_sibling(compiler, op_attribute))) { |
332
|
9521
|
|
|
|
|
|
SPVM_ATTRIBUTE* attribute = op_attribute->uv.attribute; |
333
|
9521
|
|
|
|
|
|
switch (attribute->id) { |
334
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_POINTER: { |
335
|
2968
|
|
|
|
|
|
type->basic_type->category = SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_CLASS; |
336
|
2968
|
|
|
|
|
|
basic_type->is_pointer = 1; |
337
|
2968
|
|
|
|
|
|
class_attributes_count++; |
338
|
2968
|
|
|
|
|
|
break; |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_MULNUM_T: { |
341
|
285
|
|
|
|
|
|
type->basic_type->category = SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_MULNUM; |
342
|
285
|
|
|
|
|
|
basic_type->category = SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_MULNUM; |
343
|
285
|
|
|
|
|
|
class_attributes_count++; |
344
|
285
|
|
|
|
|
|
break; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PRIVATE: { |
347
|
2
|
|
|
|
|
|
basic_type->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
348
|
2
|
|
|
|
|
|
access_control_attributes_count++; |
349
|
2
|
|
|
|
|
|
break; |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PROTECTED: { |
352
|
1
|
|
|
|
|
|
basic_type->access_control_type = SPVM_ATTRIBUTE_C_ID_PROTECTED; |
353
|
1
|
|
|
|
|
|
access_control_attributes_count++; |
354
|
1
|
|
|
|
|
|
break; |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PUBLIC: { |
357
|
213
|
|
|
|
|
|
basic_type->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
358
|
213
|
|
|
|
|
|
access_control_attributes_count++; |
359
|
213
|
|
|
|
|
|
break; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PRECOMPILE: { |
362
|
262
|
|
|
|
|
|
basic_type->is_precompile = 1; |
363
|
262
|
|
|
|
|
|
break; |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_INTERFACE_T: { |
366
|
5789
|
|
|
|
|
|
type->basic_type->category = SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_INTERFACE; |
367
|
5789
|
|
|
|
|
|
basic_type->category = SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_INTERFACE; |
368
|
5789
|
|
|
|
|
|
class_attributes_count++; |
369
|
5789
|
|
|
|
|
|
break; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
default: { |
372
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Invalid class attribute \"%s\".\n at %s line %d", SPVM_ATTRIBUTE_get_name(compiler, attribute->id), op_class->file, op_class->line); |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
} |
376
|
9517
|
100
|
|
|
|
|
if (class_attributes_count > 1) { |
377
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of class attributes \"mulnum_t\", \"pointer\" or \"interface_t\" can be specified.\n at %s line %d", op_list_attributes->file, op_list_attributes->line); |
378
|
|
|
|
|
|
|
} |
379
|
9517
|
100
|
|
|
|
|
if (access_control_attributes_count > 1) { |
380
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of class attributes \"private\", \"protected\" or \"public\" can be specified.\n at %s line %d", op_list_attributes->file, op_list_attributes->line); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
|
384
|
42484
|
100
|
|
|
|
|
if (basic_type->category == 0) { |
385
|
33444
|
|
|
|
|
|
basic_type->category = SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_CLASS; |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
// The default of the access controll is private |
389
|
42484
|
100
|
|
|
|
|
if (basic_type->access_control_type == SPVM_ATTRIBUTE_C_ID_UNKNOWN) { |
390
|
34176
|
|
|
|
|
|
basic_type->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
391
|
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
// Declarations |
394
|
42484
|
100
|
|
|
|
|
if (op_block) { |
395
|
37979
|
|
|
|
|
|
SPVM_OP* op_decls = op_block->first; |
396
|
37979
|
|
|
|
|
|
SPVM_OP* op_decl = op_decls->first; |
397
|
349561
|
100
|
|
|
|
|
while ((op_decl = SPVM_OP_sibling(compiler, op_decl))) { |
398
|
|
|
|
|
|
|
// version declaration |
399
|
311589
|
100
|
|
|
|
|
if (op_decl->id == SPVM_OP_C_ID_VERSION_DECL) { |
400
|
210
|
100
|
|
|
|
|
if (type->basic_type->version_string) { |
401
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The version has already been declared.\n at %s line %d", op_decl->file, op_decl->line); |
402
|
1
|
|
|
|
|
|
break; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
209
|
|
|
|
|
|
SPVM_OP* op_version_string = op_decl->first; |
406
|
209
|
|
|
|
|
|
SPVM_CONSTANT* version_string_constant = op_version_string->uv.constant; |
407
|
209
|
|
|
|
|
|
const char* version_string = version_string_constant->value.oval; |
408
|
209
|
|
|
|
|
|
int32_t version_string_length = version_string_constant->string_length; |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
// Version string validation |
411
|
|
|
|
|
|
|
{ |
412
|
209
|
|
|
|
|
|
int32_t dot_count = 0; |
413
|
209
|
|
|
|
|
|
int32_t digits_after_dot = 0; |
414
|
209
|
|
|
|
|
|
int32_t invalid_char = 0; |
415
|
1667
|
100
|
|
|
|
|
for (int32_t version_global_string_address_id = 0; version_global_string_address_id < version_string_length; version_global_string_address_id++) { |
416
|
1459
|
|
|
|
|
|
char ch = version_string[version_global_string_address_id]; |
417
|
|
|
|
|
|
|
|
418
|
1459
|
100
|
|
|
|
|
if (!(ch == '.' || isdigit(ch))) { |
|
|
100
|
|
|
|
|
|
419
|
1
|
|
|
|
|
|
invalid_char = 1; |
420
|
1
|
|
|
|
|
|
break; |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
|
423
|
1458
|
100
|
|
|
|
|
if (ch == '.') { |
424
|
208
|
|
|
|
|
|
dot_count++; |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
1458
|
100
|
|
|
|
|
if (dot_count > 0 && isdigit(ch)) { |
|
|
100
|
|
|
|
|
|
428
|
1030
|
|
|
|
|
|
digits_after_dot++; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
|
432
|
209
|
100
|
|
|
|
|
if (invalid_char) { |
433
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "A character in a version string must be a number or \".\".\n at %s line %d", op_decl->file, op_decl->line); |
434
|
1
|
|
|
|
|
|
break; |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
208
|
100
|
|
|
|
|
if (!isdigit(version_string[0])) { |
438
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "A version string must begin with a number.\n at %s line %d", op_decl->file, op_decl->line); |
439
|
1
|
|
|
|
|
|
break; |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
|
442
|
207
|
100
|
|
|
|
|
if (!isdigit(version_string[version_string_length - 1])) { |
443
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "A version string must end with a number.\n at %s line %d", op_decl->file, op_decl->line); |
444
|
1
|
|
|
|
|
|
break; |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
|
447
|
206
|
100
|
|
|
|
|
if (!(dot_count <= 1)) { |
448
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The number of \".\" in a version string must be less than or equal to 1.\n at %s line %d", op_decl->file, op_decl->line); |
449
|
1
|
|
|
|
|
|
break; |
450
|
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
|
|
452
|
205
|
100
|
|
|
|
|
if (!(digits_after_dot % 3 == 0)) { |
453
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The length of characters after \".\" in a version string must be divisible by 3.\n at %s line %d", op_decl->file, op_decl->line); |
454
|
2
|
|
|
|
|
|
break; |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
{ |
458
|
|
|
|
|
|
|
char *end; |
459
|
203
|
|
|
|
|
|
double double_value = strtod(version_string, &end); |
460
|
203
|
50
|
|
|
|
|
if (*end != '\0') { |
461
|
0
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "A version string must be able to be parsed by the \"strtod\" C function.\n at %s line %d", compiler->current_file, compiler->current_line); |
462
|
0
|
|
|
|
|
|
break; |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
|
467
|
203
|
|
|
|
|
|
SPVM_STRING_new(compiler, version_string, version_string_length); |
468
|
203
|
|
|
|
|
|
type->basic_type->version_string = version_string; |
469
|
|
|
|
|
|
|
} |
470
|
|
|
|
|
|
|
// use statement |
471
|
311379
|
100
|
|
|
|
|
else if (op_decl->id == SPVM_OP_C_ID_USE) { |
472
|
28908
|
|
|
|
|
|
SPVM_OP* op_use = op_decl; |
473
|
|
|
|
|
|
|
|
474
|
28908
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->use_basic_type_names, (void*)op_use->uv.use->op_type->uv.type->unresolved_basic_type_name); |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
// Class alias |
477
|
28908
|
|
|
|
|
|
const char* alias_name = op_use->uv.use->alias_name; |
478
|
28908
|
100
|
|
|
|
|
if (alias_name) { |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
// Basic type name must begin with upper case, otherwise compiler error occur. |
481
|
|
|
|
|
|
|
// (Invalid example) Foo::bar |
482
|
16
|
100
|
|
|
|
|
if (islower(alias_name[0])) { |
483
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The alias name \"%s\" must begin with an upper case character.\n at %s line %d", alias_name, op_decl->file, op_decl->line); |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
else { |
486
|
15
|
|
|
|
|
|
const char* use_basic_type_name = op_use->uv.use->op_type->uv.type->unresolved_basic_type_name; |
487
|
15
|
|
|
|
|
|
const char* use_basic_type_name_exists = SPVM_HASH_get(type->basic_type->alias_symtable, alias_name, strlen(alias_name)); |
488
|
15
|
100
|
|
|
|
|
if (use_basic_type_name_exists) { |
489
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The alias name \"%s\" is already used.\n at %s line %d", alias_name, op_decl->file, op_decl->line); |
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
else { |
492
|
28908
|
|
|
|
|
|
SPVM_HASH_set(type->basic_type->alias_symtable, alias_name, strlen(alias_name), (void*)use_basic_type_name); |
493
|
|
|
|
|
|
|
} |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
// allow statement |
498
|
282471
|
100
|
|
|
|
|
else if (op_decl->id == SPVM_OP_C_ID_ALLOW) { |
499
|
525
|
|
|
|
|
|
SPVM_LIST_push(basic_type->allows, op_decl->uv.allow); |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
// interface statement |
502
|
281946
|
100
|
|
|
|
|
else if (op_decl->id == SPVM_OP_C_ID_INTERFACE) { |
503
|
1394
|
100
|
|
|
|
|
if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_MULNUM) { |
504
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The interface statement cannnot be used in the definition of the multi-numeric type.\n at %s line %d", op_decl->file, op_decl->line); |
505
|
|
|
|
|
|
|
} |
506
|
1394
|
|
|
|
|
|
const char* interface_name = op_decl->uv.interface->op_type->uv.type->unresolved_basic_type_name; |
507
|
|
|
|
|
|
|
|
508
|
1394
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->interface_decls, op_decl->uv.interface); |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
// Class var declarations |
511
|
280552
|
100
|
|
|
|
|
else if (op_decl->id == SPVM_OP_C_ID_CLASS_VAR) { |
512
|
8115
|
|
|
|
|
|
SPVM_CLASS_VAR* class_var = op_decl->uv.class_var; |
513
|
|
|
|
|
|
|
|
514
|
8115
|
100
|
|
|
|
|
if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_INTERFACE) { |
515
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The interface cannnot have class variables.\n at %s line %d", op_decl->file, op_decl->line); |
516
|
|
|
|
|
|
|
} |
517
|
8115
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->class_vars, op_decl->uv.class_var); |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
// Getter |
520
|
8115
|
100
|
|
|
|
|
if (class_var->has_getter) { |
521
|
|
|
|
|
|
|
// static method FOO : TYPE () { |
522
|
|
|
|
|
|
|
// return $FOO; |
523
|
|
|
|
|
|
|
// } |
524
|
|
|
|
|
|
|
|
525
|
7518
|
|
|
|
|
|
SPVM_OP* op_method = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_METHOD, op_decl->file, op_decl->line); |
526
|
7518
|
|
|
|
|
|
SPVM_STRING* method_name_string = SPVM_STRING_new(compiler, class_var->name + 1, strlen(class_var->name) - 1); |
527
|
7518
|
|
|
|
|
|
const char* method_name = method_name_string->value; |
528
|
7518
|
|
|
|
|
|
SPVM_OP* op_name_method = SPVM_OP_new_op_name(compiler, method_name, op_decl->file, op_decl->line); |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
// If the type of the class_var is byte or short, the return type becomes int |
531
|
7518
|
|
|
|
|
|
SPVM_TYPE* class_var_type = class_var->type; |
532
|
|
|
|
|
|
|
SPVM_TYPE* return_type; |
533
|
7518
|
100
|
|
|
|
|
if (SPVM_TYPE_is_byte_type(compiler, class_var_type->basic_type->id, class_var_type->dimension, class_var_type->flag) |
534
|
7516
|
100
|
|
|
|
|
|| SPVM_TYPE_is_short_type(compiler, class_var_type->basic_type->id, class_var_type->dimension, class_var_type->flag)) |
535
|
|
|
|
|
|
|
{ |
536
|
4
|
|
|
|
|
|
return_type = SPVM_OP_new_op_int_type(compiler, op_decl->file, op_decl->line)->uv.type; |
537
|
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
|
else { |
539
|
7514
|
|
|
|
|
|
return_type = class_var->type; |
540
|
|
|
|
|
|
|
} |
541
|
7518
|
|
|
|
|
|
SPVM_OP* op_return_type = SPVM_OP_new_op_type(compiler, return_type->unresolved_basic_type_name, return_type->basic_type, return_type->dimension, return_type->flag, op_decl->file, op_decl->line); |
542
|
|
|
|
|
|
|
|
543
|
7518
|
|
|
|
|
|
SPVM_OP* op_args = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
544
|
|
|
|
|
|
|
|
545
|
7518
|
|
|
|
|
|
SPVM_OP* op_block = SPVM_OP_new_op_block(compiler, op_decl->file, op_decl->line); |
546
|
7518
|
|
|
|
|
|
SPVM_OP* op_statements = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
547
|
7518
|
|
|
|
|
|
SPVM_OP* op_return = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_RETURN, op_decl->file, op_decl->line); |
548
|
|
|
|
|
|
|
|
549
|
7518
|
|
|
|
|
|
SPVM_OP* op_name_basic_type_var = SPVM_OP_new_op_name(compiler, class_var->name, op_decl->file, op_decl->line); |
550
|
7518
|
|
|
|
|
|
SPVM_OP* op_var_class_var = SPVM_OP_new_op_var(compiler, op_name_basic_type_var); |
551
|
|
|
|
|
|
|
|
552
|
7518
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_return, op_return->last, op_var_class_var); |
553
|
7518
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements, op_statements->last, op_return); |
554
|
7518
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block, op_block->last, op_statements); |
555
|
|
|
|
|
|
|
|
556
|
7518
|
|
|
|
|
|
SPVM_OP* op_list_attributes = SPVM_OP_new_op_list(compiler, compiler->current_file, compiler->current_line); |
557
|
7518
|
|
|
|
|
|
SPVM_OP* op_attribute_static = SPVM_OP_new_op_attribute(compiler, SPVM_ATTRIBUTE_C_ID_STATIC, compiler->current_file, compiler->current_line); |
558
|
7518
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_attributes, op_list_attributes->first, op_attribute_static); |
559
|
|
|
|
|
|
|
|
560
|
7518
|
|
|
|
|
|
SPVM_OP_build_method_definition(compiler, op_method, op_name_method, op_return_type, op_args, op_list_attributes, op_block, NULL, 0, 0); |
561
|
|
|
|
|
|
|
|
562
|
7518
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->methods, op_method->uv.method); |
563
|
|
|
|
|
|
|
} |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
// Setter |
566
|
8115
|
100
|
|
|
|
|
if (class_var->has_setter) { |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
// method SET_FOO : void ($value : TYPE) { |
569
|
|
|
|
|
|
|
// $FOO = $value; |
570
|
|
|
|
|
|
|
// } |
571
|
|
|
|
|
|
|
|
572
|
91
|
|
|
|
|
|
SPVM_OP* op_method = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_METHOD, op_decl->file, op_decl->line); |
573
|
91
|
|
|
|
|
|
char* method_name_tmp = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, 4 + strlen(class_var->name) - 1 + 1); |
574
|
91
|
|
|
|
|
|
memcpy(method_name_tmp, "SET_", 4); |
575
|
91
|
|
|
|
|
|
memcpy(method_name_tmp + 4, class_var->name + 1, strlen(class_var->name) - 1); |
576
|
|
|
|
|
|
|
|
577
|
91
|
|
|
|
|
|
SPVM_STRING* method_name_string = SPVM_STRING_new(compiler, method_name_tmp, strlen(method_name_tmp)); |
578
|
91
|
|
|
|
|
|
const char* method_name = method_name_string->value; |
579
|
|
|
|
|
|
|
|
580
|
91
|
|
|
|
|
|
SPVM_OP* op_name_method = SPVM_OP_new_op_name(compiler, method_name, op_decl->file, op_decl->line); |
581
|
91
|
|
|
|
|
|
SPVM_OP* op_return_type = SPVM_OP_new_op_void_type(compiler, op_decl->file, op_decl->line); |
582
|
91
|
|
|
|
|
|
SPVM_OP* op_args = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
// If the type of the class_var is byte or short, the arg type becomes int |
585
|
91
|
|
|
|
|
|
SPVM_TYPE* class_var_type = class_var->type; |
586
|
|
|
|
|
|
|
SPVM_TYPE* arg_type; |
587
|
91
|
100
|
|
|
|
|
if (SPVM_TYPE_is_byte_type(compiler, class_var_type->basic_type->id, class_var_type->dimension, class_var_type->flag) |
588
|
89
|
100
|
|
|
|
|
|| SPVM_TYPE_is_short_type(compiler, class_var_type->basic_type->id, class_var_type->dimension, class_var_type->flag)) |
589
|
|
|
|
|
|
|
{ |
590
|
4
|
|
|
|
|
|
arg_type = SPVM_OP_new_op_int_type(compiler, op_decl->file, op_decl->line)->uv.type; |
591
|
|
|
|
|
|
|
} |
592
|
|
|
|
|
|
|
else { |
593
|
87
|
|
|
|
|
|
arg_type = class_var->type; |
594
|
|
|
|
|
|
|
} |
595
|
91
|
|
|
|
|
|
SPVM_OP* op_type_value = SPVM_OP_new_op_type(compiler, arg_type->unresolved_basic_type_name, arg_type->basic_type, arg_type->dimension, arg_type->flag, op_decl->file, op_decl->line); |
596
|
|
|
|
|
|
|
|
597
|
91
|
|
|
|
|
|
SPVM_OP* op_var_value_name = SPVM_OP_new_op_name(compiler, "$value", op_decl->file, op_decl->line); |
598
|
91
|
|
|
|
|
|
SPVM_OP* op_var_value = SPVM_OP_new_op_var(compiler, op_var_value_name); |
599
|
91
|
|
|
|
|
|
SPVM_OP* op_arg_value = SPVM_OP_build_arg(compiler, op_var_value, op_type_value, NULL, NULL); |
600
|
|
|
|
|
|
|
|
601
|
91
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_args, op_args->last, op_arg_value); |
602
|
|
|
|
|
|
|
|
603
|
91
|
|
|
|
|
|
SPVM_OP* op_block = SPVM_OP_new_op_block(compiler, op_decl->file, op_decl->line); |
604
|
91
|
|
|
|
|
|
SPVM_OP* op_statements = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
605
|
|
|
|
|
|
|
|
606
|
91
|
|
|
|
|
|
SPVM_OP* op_name_basic_type_var = SPVM_OP_new_op_name(compiler, class_var->name, op_decl->file, op_decl->line); |
607
|
91
|
|
|
|
|
|
SPVM_OP* op_var_class_var = SPVM_OP_new_op_var(compiler, op_name_basic_type_var); |
608
|
|
|
|
|
|
|
|
609
|
91
|
|
|
|
|
|
SPVM_OP* op_var_assign_value_name = SPVM_OP_new_op_name(compiler, "$value", op_decl->file, op_decl->line); |
610
|
91
|
|
|
|
|
|
SPVM_OP* op_var_assign_value = SPVM_OP_new_op_var(compiler, op_var_assign_value_name); |
611
|
|
|
|
|
|
|
|
612
|
91
|
|
|
|
|
|
SPVM_OP* op_type_cast = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_TYPE_CAST, op_decl->file, op_decl->line); |
613
|
91
|
|
|
|
|
|
SPVM_OP* op_type_for_cast = SPVM_OP_new_op_type(compiler, class_var_type->unresolved_basic_type_name, class_var_type->basic_type, class_var_type->dimension, class_var_type->flag, op_decl->file, op_decl->line); |
614
|
|
|
|
|
|
|
|
615
|
91
|
|
|
|
|
|
SPVM_OP_build_type_cast(compiler, op_type_cast, op_type_for_cast, op_var_assign_value, NULL); |
616
|
|
|
|
|
|
|
|
617
|
91
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_decl->file, op_decl->line); |
618
|
91
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var_class_var, op_type_cast); |
619
|
|
|
|
|
|
|
|
620
|
91
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements, op_statements->last, op_assign); |
621
|
91
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block, op_block->last, op_statements); |
622
|
|
|
|
|
|
|
|
623
|
91
|
|
|
|
|
|
SPVM_OP* op_list_attributes = SPVM_OP_new_op_list(compiler, compiler->current_file, compiler->current_line); |
624
|
91
|
|
|
|
|
|
SPVM_OP* op_attribute_static = SPVM_OP_new_op_attribute(compiler, SPVM_ATTRIBUTE_C_ID_STATIC, compiler->current_file, compiler->current_line); |
625
|
91
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_attributes, op_list_attributes->first, op_attribute_static); |
626
|
|
|
|
|
|
|
|
627
|
91
|
|
|
|
|
|
op_method = SPVM_OP_build_method_definition(compiler, op_method, op_name_method, op_return_type, op_args, op_list_attributes, op_block, NULL, 0, 0); |
628
|
|
|
|
|
|
|
|
629
|
8115
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->methods, op_method->uv.method); |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
} |
632
|
|
|
|
|
|
|
// Field declarations |
633
|
272437
|
100
|
|
|
|
|
else if (op_decl->id == SPVM_OP_C_ID_FIELD) { |
634
|
27424
|
|
|
|
|
|
SPVM_FIELD* field = op_decl->uv.field; |
635
|
|
|
|
|
|
|
|
636
|
27424
|
100
|
|
|
|
|
if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_INTERFACE) { |
637
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The interface cannnot have fields.\n at %s line %d", op_decl->file, op_decl->line); |
638
|
|
|
|
|
|
|
} |
639
|
27424
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->unmerged_fields, field); |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
// Getter |
642
|
27424
|
100
|
|
|
|
|
if (field->has_getter) { |
643
|
|
|
|
|
|
|
// method foo : TYPE () { |
644
|
|
|
|
|
|
|
// return $self->{foo}; |
645
|
|
|
|
|
|
|
// } |
646
|
|
|
|
|
|
|
|
647
|
17351
|
|
|
|
|
|
SPVM_OP* op_method = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_METHOD, op_decl->file, op_decl->line); |
648
|
17351
|
|
|
|
|
|
SPVM_OP* op_name_method = SPVM_OP_new_op_name(compiler, field->name, op_decl->file, op_decl->line); |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
// If the type of the field is byte or short, the return type becomes int |
651
|
17351
|
|
|
|
|
|
SPVM_TYPE* field_type = field->type; |
652
|
|
|
|
|
|
|
SPVM_TYPE* return_type; |
653
|
17351
|
100
|
|
|
|
|
if (SPVM_TYPE_is_byte_type(compiler, field_type->basic_type->id, field_type->dimension, field_type->flag) |
654
|
15768
|
100
|
|
|
|
|
|| SPVM_TYPE_is_short_type(compiler, field_type->basic_type->id, field_type->dimension, field_type->flag)) |
655
|
|
|
|
|
|
|
{ |
656
|
3166
|
|
|
|
|
|
return_type = SPVM_OP_new_op_int_type(compiler, op_decl->file, op_decl->line)->uv.type; |
657
|
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
else { |
659
|
14185
|
|
|
|
|
|
return_type = field->type; |
660
|
|
|
|
|
|
|
} |
661
|
17351
|
|
|
|
|
|
SPVM_OP* op_return_type = SPVM_OP_new_op_type(compiler, return_type->unresolved_basic_type_name, return_type->basic_type, return_type->dimension, return_type->flag, op_decl->file, op_decl->line); |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
|
664
|
17351
|
|
|
|
|
|
SPVM_OP* op_args = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
665
|
|
|
|
|
|
|
|
666
|
17351
|
|
|
|
|
|
SPVM_OP* op_block = SPVM_OP_new_op_block(compiler, op_decl->file, op_decl->line); |
667
|
17351
|
|
|
|
|
|
SPVM_OP* op_statements = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
668
|
17351
|
|
|
|
|
|
SPVM_OP* op_return = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_RETURN, op_decl->file, op_decl->line); |
669
|
|
|
|
|
|
|
|
670
|
17351
|
|
|
|
|
|
SPVM_OP* op_var_name_invocant = SPVM_OP_new_op_name(compiler, "$self", op_decl->file, op_decl->line); |
671
|
17351
|
|
|
|
|
|
SPVM_OP* op_var_self_invocant = SPVM_OP_new_op_var(compiler, op_var_name_invocant); |
672
|
17351
|
|
|
|
|
|
SPVM_OP* op_name_field_access = SPVM_OP_new_op_name(compiler, field->name, op_decl->file, op_decl->line); |
673
|
|
|
|
|
|
|
|
674
|
17351
|
|
|
|
|
|
SPVM_OP* op_field_access = SPVM_OP_new_op_field_access(compiler, op_decl->file, op_decl->line); |
675
|
|
|
|
|
|
|
|
676
|
17351
|
|
|
|
|
|
SPVM_OP_build_field_access(compiler, op_field_access, op_var_self_invocant, op_name_field_access); |
677
|
|
|
|
|
|
|
|
678
|
17351
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_return, op_return->last, op_field_access); |
679
|
17351
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements, op_statements->last, op_return); |
680
|
17351
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block, op_block->last, op_statements); |
681
|
|
|
|
|
|
|
|
682
|
17351
|
|
|
|
|
|
SPVM_OP_build_method_definition(compiler, op_method, op_name_method, op_return_type, op_args, NULL, op_block, NULL, 0, 0); |
683
|
|
|
|
|
|
|
|
684
|
17351
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->methods, op_method->uv.method); |
685
|
|
|
|
|
|
|
} |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
// Setter |
688
|
27424
|
100
|
|
|
|
|
if (field->has_setter) { |
689
|
|
|
|
|
|
|
// method set_foo : void ($foo : TYPE) { |
690
|
|
|
|
|
|
|
// $self->{foo} = $foo; |
691
|
|
|
|
|
|
|
// } |
692
|
|
|
|
|
|
|
|
693
|
1481
|
|
|
|
|
|
SPVM_OP* op_method = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_METHOD, op_decl->file, op_decl->line); |
694
|
1481
|
|
|
|
|
|
char* method_name_tmp = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, 4 + strlen(field->name) + 1); |
695
|
1481
|
|
|
|
|
|
memcpy(method_name_tmp, "set_", 4); |
696
|
1481
|
|
|
|
|
|
memcpy(method_name_tmp + 4, field->name, strlen(field->name)); |
697
|
1481
|
|
|
|
|
|
SPVM_STRING* method_name_string = SPVM_STRING_new(compiler, method_name_tmp, strlen(method_name_tmp)); |
698
|
1481
|
|
|
|
|
|
const char* method_name = method_name_string->value; |
699
|
1481
|
|
|
|
|
|
SPVM_OP* op_name_method = SPVM_OP_new_op_name(compiler, method_name, op_decl->file, op_decl->line); |
700
|
1481
|
|
|
|
|
|
SPVM_OP* op_return_type = SPVM_OP_new_op_void_type(compiler, op_decl->file, op_decl->line); |
701
|
1481
|
|
|
|
|
|
SPVM_OP* op_args = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
// If the type of the field is byte or short, the arg type becomes int |
704
|
1481
|
|
|
|
|
|
SPVM_TYPE* field_type = field->type; |
705
|
|
|
|
|
|
|
SPVM_TYPE* arg_type; |
706
|
1481
|
100
|
|
|
|
|
if (SPVM_TYPE_is_byte_type(compiler, field_type->basic_type->id, field_type->dimension, field_type->flag) |
707
|
1379
|
100
|
|
|
|
|
|| SPVM_TYPE_is_short_type(compiler, field_type->basic_type->id, field_type->dimension, field_type->flag)) |
708
|
|
|
|
|
|
|
{ |
709
|
204
|
|
|
|
|
|
arg_type = SPVM_OP_new_op_int_type(compiler, op_decl->file, op_decl->line)->uv.type; |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
else { |
712
|
1277
|
|
|
|
|
|
arg_type = field->type; |
713
|
|
|
|
|
|
|
} |
714
|
1481
|
|
|
|
|
|
SPVM_OP* op_type_value = SPVM_OP_new_op_type(compiler, arg_type->unresolved_basic_type_name, arg_type->basic_type, arg_type->dimension, arg_type->flag, op_decl->file, op_decl->line); |
715
|
|
|
|
|
|
|
|
716
|
1481
|
|
|
|
|
|
char* arg_name_tmp = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, 1 + strlen(field->name) + 1); |
717
|
1481
|
|
|
|
|
|
memcpy(arg_name_tmp, "$", 1); |
718
|
1481
|
|
|
|
|
|
memcpy(arg_name_tmp + 1, field->name, strlen(field->name)); |
719
|
1481
|
|
|
|
|
|
SPVM_STRING* arg_name_string = SPVM_STRING_new(compiler, arg_name_tmp, strlen(arg_name_tmp)); |
720
|
1481
|
|
|
|
|
|
const char* arg_name = arg_name_string->value; |
721
|
1481
|
|
|
|
|
|
SPVM_OP* op_name_arg = SPVM_OP_new_op_name(compiler, arg_name, op_decl->file, op_decl->line); |
722
|
|
|
|
|
|
|
|
723
|
1481
|
|
|
|
|
|
SPVM_OP* op_var_value_name = SPVM_OP_new_op_name(compiler, arg_name, op_decl->file, op_decl->line); |
724
|
1481
|
|
|
|
|
|
SPVM_OP* op_var_value = SPVM_OP_new_op_var(compiler, op_var_value_name); |
725
|
1481
|
|
|
|
|
|
SPVM_OP* op_arg_value = SPVM_OP_build_arg(compiler, op_var_value, op_type_value, NULL, NULL); |
726
|
|
|
|
|
|
|
|
727
|
1481
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_args, op_args->last, op_arg_value); |
728
|
|
|
|
|
|
|
|
729
|
1481
|
|
|
|
|
|
SPVM_OP* op_block = SPVM_OP_new_op_block(compiler, op_decl->file, op_decl->line); |
730
|
1481
|
|
|
|
|
|
SPVM_OP* op_statements = SPVM_OP_new_op_list(compiler, op_decl->file, op_decl->line); |
731
|
|
|
|
|
|
|
|
732
|
1481
|
|
|
|
|
|
SPVM_OP* op_var_name_invocant = SPVM_OP_new_op_name(compiler, "$self", op_decl->file, op_decl->line); |
733
|
1481
|
|
|
|
|
|
SPVM_OP* op_var_self_invocant = SPVM_OP_new_op_var(compiler, op_var_name_invocant); |
734
|
1481
|
|
|
|
|
|
SPVM_OP* op_name_field_access = SPVM_OP_new_op_name(compiler, field->name, op_decl->file, op_decl->line); |
735
|
1481
|
|
|
|
|
|
SPVM_OP* op_field_access = SPVM_OP_new_op_field_access(compiler, op_decl->file, op_decl->line); |
736
|
1481
|
|
|
|
|
|
SPVM_OP_build_field_access(compiler, op_field_access, op_var_self_invocant, op_name_field_access); |
737
|
|
|
|
|
|
|
|
738
|
1481
|
|
|
|
|
|
SPVM_OP* op_var_assign_value_name = SPVM_OP_new_op_name(compiler, arg_name, op_decl->file, op_decl->line); |
739
|
1481
|
|
|
|
|
|
SPVM_OP* op_var_assign_value = SPVM_OP_new_op_var(compiler, op_var_assign_value_name); |
740
|
|
|
|
|
|
|
|
741
|
1481
|
|
|
|
|
|
SPVM_OP* op_type_cast = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_TYPE_CAST, op_decl->file, op_decl->line); |
742
|
1481
|
|
|
|
|
|
SPVM_OP* op_type_for_cast = SPVM_OP_new_op_type(compiler, field_type->unresolved_basic_type_name, field_type->basic_type, field_type->dimension, field_type->flag, op_decl->file, op_decl->line); |
743
|
|
|
|
|
|
|
|
744
|
1481
|
|
|
|
|
|
SPVM_OP_build_type_cast(compiler, op_type_cast, op_type_for_cast, op_var_assign_value, NULL); |
745
|
|
|
|
|
|
|
|
746
|
1481
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_decl->file, op_decl->line); |
747
|
1481
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_field_access, op_type_cast); |
748
|
|
|
|
|
|
|
|
749
|
1481
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements, op_statements->last, op_assign); |
750
|
1481
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block, op_block->last, op_statements); |
751
|
|
|
|
|
|
|
|
752
|
1481
|
|
|
|
|
|
SPVM_OP_build_method_definition(compiler, op_method, op_name_method, op_return_type, op_args, NULL, op_block, NULL, 0, 0); |
753
|
|
|
|
|
|
|
|
754
|
27424
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->methods, op_method->uv.method); |
755
|
|
|
|
|
|
|
} |
756
|
|
|
|
|
|
|
} |
757
|
|
|
|
|
|
|
// Enumeration definition |
758
|
245013
|
100
|
|
|
|
|
else if (op_decl->id == SPVM_OP_C_ID_ENUM) { |
759
|
3203
|
|
|
|
|
|
SPVM_OP* op_enum_block = op_decl->first; |
760
|
3203
|
|
|
|
|
|
SPVM_OP* op_enumeration_values = op_enum_block->first; |
761
|
3203
|
|
|
|
|
|
SPVM_OP* op_method = op_enumeration_values->first; |
762
|
6954
|
100
|
|
|
|
|
while ((op_method = SPVM_OP_sibling(compiler, op_method))) { |
763
|
3751
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->methods, op_method->uv.method); |
764
|
|
|
|
|
|
|
} |
765
|
|
|
|
|
|
|
} |
766
|
|
|
|
|
|
|
// Method definition |
767
|
241810
|
50
|
|
|
|
|
else if (op_decl->id == SPVM_OP_C_ID_METHOD) { |
768
|
241810
|
|
|
|
|
|
SPVM_METHOD* method = op_decl->uv.method; |
769
|
|
|
|
|
|
|
|
770
|
241810
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->methods, op_decl->uv.method); |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
// Fields of anon method |
773
|
241810
|
|
|
|
|
|
SPVM_LIST* anon_method_fields = op_decl->uv.method->anon_method_fields; |
774
|
241845
|
100
|
|
|
|
|
for (int32_t i = 0; i < anon_method_fields->length; i++) { |
775
|
35
|
|
|
|
|
|
SPVM_FIELD* anon_method_field = SPVM_LIST_get(anon_method_fields, i); |
776
|
|
|
|
|
|
|
|
777
|
35
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->unmerged_fields, anon_method_field); |
778
|
35
|
|
|
|
|
|
anon_method_field->is_anon_method_field = 1; |
779
|
|
|
|
|
|
|
} |
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
// INIT block |
782
|
241810
|
100
|
|
|
|
|
if (op_decl->uv.method->is_init) { |
783
|
241810
|
|
|
|
|
|
basic_type->has_init_block = 1; |
784
|
|
|
|
|
|
|
} |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
else { |
787
|
0
|
|
|
|
|
|
assert(0); |
788
|
|
|
|
|
|
|
} |
789
|
|
|
|
|
|
|
} |
790
|
|
|
|
|
|
|
} |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
// Field declarations |
793
|
69943
|
100
|
|
|
|
|
for (int32_t i = 0; i < type->basic_type->unmerged_fields->length; i++) { |
794
|
27459
|
|
|
|
|
|
SPVM_FIELD* field = SPVM_LIST_get(type->basic_type->unmerged_fields, i); |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
// The default of the access controll of the field is private. |
797
|
27459
|
100
|
|
|
|
|
if (field->access_control_type == SPVM_ATTRIBUTE_C_ID_UNKNOWN) { |
798
|
|
|
|
|
|
|
// If anon method, field is public |
799
|
26027
|
100
|
|
|
|
|
if (basic_type->is_anon) { |
800
|
35
|
|
|
|
|
|
field->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
801
|
|
|
|
|
|
|
} |
802
|
|
|
|
|
|
|
// If multi-numeric type, field is public |
803
|
25992
|
100
|
|
|
|
|
else if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_MULNUM) { |
804
|
1294
|
|
|
|
|
|
field->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
805
|
|
|
|
|
|
|
} |
806
|
|
|
|
|
|
|
// Default is private |
807
|
|
|
|
|
|
|
else { |
808
|
24698
|
|
|
|
|
|
field->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
809
|
|
|
|
|
|
|
} |
810
|
|
|
|
|
|
|
} |
811
|
|
|
|
|
|
|
|
812
|
27459
|
|
|
|
|
|
field->index = i; |
813
|
27459
|
|
|
|
|
|
const char* field_name = field->op_name->uv.name; |
814
|
|
|
|
|
|
|
|
815
|
27459
|
|
|
|
|
|
SPVM_FIELD* found_field = SPVM_HASH_get(type->basic_type->unmerged_field_symtable, field_name, strlen(field_name)); |
816
|
|
|
|
|
|
|
|
817
|
27459
|
100
|
|
|
|
|
if (found_field) { |
818
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Redeclaration of the \"%s\" field in the \"%s\" class.\n at %s line %d", field_name, basic_type_name, field->op_field->file, field->op_field->line); |
819
|
|
|
|
|
|
|
} |
820
|
|
|
|
|
|
|
else { |
821
|
27458
|
|
|
|
|
|
SPVM_HASH_set(type->basic_type->unmerged_field_symtable, field_name, strlen(field_name), field); |
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
// Add op class |
824
|
27458
|
|
|
|
|
|
field->current_basic_type = type->basic_type; |
825
|
|
|
|
|
|
|
} |
826
|
|
|
|
|
|
|
} |
827
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
// Class variable declarations |
829
|
50599
|
100
|
|
|
|
|
for (int32_t i = 0; i < type->basic_type->class_vars->length; i++) { |
830
|
8115
|
|
|
|
|
|
SPVM_CLASS_VAR* class_var = SPVM_LIST_get(type->basic_type->class_vars, i); |
831
|
8115
|
|
|
|
|
|
const char* class_var_name = class_var->name; |
832
|
|
|
|
|
|
|
|
833
|
8115
|
|
|
|
|
|
SPVM_CLASS_VAR* found_class_var = SPVM_HASH_get(type->basic_type->class_var_symtable, class_var_name, strlen(class_var_name)); |
834
|
|
|
|
|
|
|
|
835
|
8115
|
100
|
|
|
|
|
if (found_class_var) { |
836
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Redeclaration of the class variable \"$%s\" in the \"%s\" class.\n at %s line %d", class_var_name + 1, basic_type_name, class_var->op_class_var->file, class_var->op_class_var->line); |
837
|
|
|
|
|
|
|
} |
838
|
|
|
|
|
|
|
else { |
839
|
8114
|
|
|
|
|
|
SPVM_HASH_set(type->basic_type->class_var_symtable, class_var_name, strlen(class_var_name), class_var); |
840
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
// Add op class |
842
|
8114
|
|
|
|
|
|
class_var->current_basic_type = type->basic_type; |
843
|
|
|
|
|
|
|
} |
844
|
|
|
|
|
|
|
} |
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
// INIT block |
847
|
|
|
|
|
|
|
{ |
848
|
|
|
|
|
|
|
// Check INIT block existance |
849
|
42484
|
|
|
|
|
|
int32_t has_init_block = 0; |
850
|
302364
|
100
|
|
|
|
|
for (int32_t i = 0; i < type->basic_type->methods->length; i++) { |
851
|
261410
|
|
|
|
|
|
SPVM_METHOD* method = SPVM_LIST_get(type->basic_type->methods, i); |
852
|
261410
|
100
|
|
|
|
|
if (method->is_init) { |
853
|
1530
|
|
|
|
|
|
has_init_block = 1; |
854
|
1530
|
|
|
|
|
|
break; |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
} |
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
// Add an default INIT block |
859
|
42484
|
100
|
|
|
|
|
if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_CLASS && !has_init_block) { |
|
|
100
|
|
|
|
|
|
860
|
34882
|
|
|
|
|
|
SPVM_OP* op_init = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_INIT, op_class->file, op_class->line); |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
// Statements |
863
|
34882
|
|
|
|
|
|
SPVM_OP* op_list_statements = SPVM_OP_new_op_list(compiler, op_class->file, op_class->line); |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
// Block |
866
|
34882
|
|
|
|
|
|
SPVM_OP* op_block = SPVM_OP_new_op_block(compiler, op_class->file, op_class->line); |
867
|
34882
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block, op_block->last, op_list_statements); |
868
|
|
|
|
|
|
|
|
869
|
34882
|
|
|
|
|
|
SPVM_OP* op_method = SPVM_OP_build_init_block(compiler, op_init, op_block); |
870
|
|
|
|
|
|
|
|
871
|
34882
|
|
|
|
|
|
SPVM_LIST_push(type->basic_type->methods, op_method->uv.method); |
872
|
|
|
|
|
|
|
} |
873
|
|
|
|
|
|
|
} |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
// Method declarations |
876
|
349368
|
100
|
|
|
|
|
for (int32_t i = 0; i < type->basic_type->methods->length; i++) { |
877
|
306884
|
|
|
|
|
|
SPVM_METHOD* method = SPVM_LIST_get(type->basic_type->methods, i); |
878
|
|
|
|
|
|
|
|
879
|
306884
|
100
|
|
|
|
|
if (!method->is_class_method) { |
880
|
114271
|
|
|
|
|
|
SPVM_VAR_DECL* arg_var_decl_first = SPVM_LIST_get(method->var_decls, 0); |
881
|
114271
|
|
|
|
|
|
arg_var_decl_first->type->unresolved_basic_type_name = basic_type_name; |
882
|
|
|
|
|
|
|
} |
883
|
|
|
|
|
|
|
|
884
|
306884
|
|
|
|
|
|
SPVM_OP* op_name_method = method->op_name; |
885
|
306884
|
|
|
|
|
|
const char* method_name = op_name_method->uv.name; |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
int32_t must_have_block; |
888
|
306884
|
100
|
|
|
|
|
if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_INTERFACE) { |
889
|
6064
|
|
|
|
|
|
must_have_block = 0; |
890
|
|
|
|
|
|
|
} |
891
|
|
|
|
|
|
|
else { |
892
|
300820
|
100
|
|
|
|
|
if (method->is_native) { |
893
|
64985
|
|
|
|
|
|
must_have_block = 0; |
894
|
|
|
|
|
|
|
} |
895
|
|
|
|
|
|
|
else { |
896
|
235835
|
|
|
|
|
|
must_have_block = 1; |
897
|
|
|
|
|
|
|
} |
898
|
|
|
|
|
|
|
} |
899
|
|
|
|
|
|
|
|
900
|
306884
|
100
|
|
|
|
|
if (must_have_block && !method->op_block) { |
|
|
100
|
|
|
|
|
|
901
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The non-native method must have the block.\n at %s line %d", op_name_method->file, op_name_method->line); |
902
|
|
|
|
|
|
|
} |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
// Method check |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
// Set first argument type if not set |
907
|
306884
|
100
|
|
|
|
|
if (method->args_length > 0) { |
908
|
228178
|
|
|
|
|
|
SPVM_VAR_DECL* arg_var_decl_first = SPVM_LIST_get(method->var_decls, 0); |
909
|
228178
|
|
|
|
|
|
SPVM_OP* op_arg_first_type = NULL; |
910
|
228178
|
100
|
|
|
|
|
if (!method->is_class_method) { |
911
|
114271
|
|
|
|
|
|
SPVM_TYPE* arg_invocant_type = op_type->uv.type; |
912
|
114271
|
|
|
|
|
|
op_arg_first_type = SPVM_OP_new_op_type(compiler, arg_invocant_type->unresolved_basic_type_name, arg_invocant_type->basic_type, arg_invocant_type->dimension, arg_invocant_type->flag, arg_var_decl_first->op_var_decl->file, arg_var_decl_first->op_var_decl->line); |
913
|
114271
|
|
|
|
|
|
arg_var_decl_first->type = op_arg_first_type->uv.type; |
914
|
114271
|
50
|
|
|
|
|
assert(arg_invocant_type->basic_type); |
915
|
|
|
|
|
|
|
} |
916
|
|
|
|
|
|
|
else { |
917
|
113907
|
|
|
|
|
|
SPVM_OP* op_type_new_arg_var_decl_first = SPVM_OP_new_op_type(compiler, arg_var_decl_first->type->unresolved_basic_type_name, arg_var_decl_first->type->basic_type, arg_var_decl_first->type->dimension, arg_var_decl_first->type->flag, arg_var_decl_first->op_var_decl->file, arg_var_decl_first->op_var_decl->line); |
918
|
|
|
|
|
|
|
|
919
|
113907
|
|
|
|
|
|
op_arg_first_type = op_type_new_arg_var_decl_first; |
920
|
113907
|
50
|
|
|
|
|
assert(op_arg_first_type->uv.type->basic_type); |
921
|
|
|
|
|
|
|
} |
922
|
|
|
|
|
|
|
|
923
|
731544
|
100
|
|
|
|
|
for (int32_t arg_index = 0; arg_index < method->args_length; arg_index++) { |
924
|
503366
|
|
|
|
|
|
SPVM_VAR_DECL* arg_var_decl = SPVM_LIST_get(method->var_decls, arg_index); |
925
|
503366
|
|
|
|
|
|
SPVM_BASIC_TYPE_add_constant_string(compiler, basic_type, arg_var_decl->var->name, strlen(arg_var_decl->var->name)); |
926
|
503366
|
|
|
|
|
|
arg_var_decl->name = arg_var_decl->var->name; |
927
|
|
|
|
|
|
|
} |
928
|
|
|
|
|
|
|
} |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
// If Method is anon, method must be method |
931
|
306884
|
100
|
|
|
|
|
if (strlen(method_name) == 0 && method->is_class_method) { |
|
|
100
|
|
|
|
|
|
932
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The anon method must be an instance method.\n at %s line %d", method->op_method->file, method->op_method->line); |
933
|
|
|
|
|
|
|
} |
934
|
|
|
|
|
|
|
|
935
|
306884
|
100
|
|
|
|
|
if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_INTERFACE) { |
936
|
|
|
|
|
|
|
// Method having interface_t attribute must be method |
937
|
6064
|
100
|
|
|
|
|
if (method->is_class_method) { |
938
|
6064
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The method defined in the interface must be an instance method.\n at %s line %d", method->op_method->file, method->op_method->line); |
939
|
|
|
|
|
|
|
} |
940
|
|
|
|
|
|
|
} |
941
|
300820
|
100
|
|
|
|
|
else if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_CLASS) { |
942
|
300818
|
100
|
|
|
|
|
if (method->is_required) { |
943
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The method defined in the class cannnot have the method attribute \"required\".\n at %s line %d", method->op_method->file, method->op_method->line); |
944
|
|
|
|
|
|
|
} |
945
|
|
|
|
|
|
|
} |
946
|
|
|
|
|
|
|
|
947
|
306884
|
100
|
|
|
|
|
if (method->is_native) { |
948
|
64986
|
100
|
|
|
|
|
if (method->op_block) { |
949
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The native method cannnot have the block.\n at %s line %d", method->op_method->file, method->op_method->line); |
950
|
|
|
|
|
|
|
} |
951
|
|
|
|
|
|
|
} |
952
|
|
|
|
|
|
|
|
953
|
306884
|
|
|
|
|
|
SPVM_METHOD* found_method = SPVM_HASH_get(type->basic_type->method_symtable, method_name, strlen(method_name)); |
954
|
|
|
|
|
|
|
|
955
|
306884
|
100
|
|
|
|
|
if (found_method) { |
956
|
3
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Redeclaration of the \"%s\" method in the \"%s\" class.\n at %s line %d", method_name, basic_type_name, method->op_method->file, method->op_method->line); |
957
|
|
|
|
|
|
|
} |
958
|
|
|
|
|
|
|
// Unknown method |
959
|
|
|
|
|
|
|
else { |
960
|
306881
|
|
|
|
|
|
const char* found_method_name = SPVM_HASH_get(type->basic_type->method_symtable, method_name, strlen(method_name)); |
961
|
306881
|
50
|
|
|
|
|
if (found_method_name) { |
962
|
0
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Redeclaration of the \"%s\" method.\n at %s line %d", method_name, method->op_method->file, method->op_method->line); |
963
|
|
|
|
|
|
|
} |
964
|
|
|
|
|
|
|
else { |
965
|
|
|
|
|
|
|
// Bind standard functions |
966
|
306881
|
|
|
|
|
|
method->current_basic_type = type->basic_type; |
967
|
|
|
|
|
|
|
|
968
|
306881
|
100
|
|
|
|
|
if (method->is_destructor) { |
969
|
745
|
|
|
|
|
|
basic_type->destructor_method = method; |
970
|
|
|
|
|
|
|
} |
971
|
|
|
|
|
|
|
|
972
|
306881
|
100
|
|
|
|
|
if (method->is_init) { |
973
|
36410
|
|
|
|
|
|
basic_type->init_method = method; |
974
|
|
|
|
|
|
|
} |
975
|
|
|
|
|
|
|
|
976
|
306881
|
50
|
|
|
|
|
assert(method->op_method->file); |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
// Method absolute name |
979
|
306881
|
|
|
|
|
|
int32_t method_abs_name_length = strlen(type->unresolved_basic_type_name) + 2 + strlen(method->name); |
980
|
306881
|
|
|
|
|
|
char* method_abs_name = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, method_abs_name_length + 1); |
981
|
306881
|
|
|
|
|
|
memcpy(method_abs_name, type->unresolved_basic_type_name, strlen(type->unresolved_basic_type_name)); |
982
|
306881
|
|
|
|
|
|
memcpy(method_abs_name + strlen(basic_type_name), "->", 2); |
983
|
306881
|
|
|
|
|
|
memcpy(method_abs_name + strlen(basic_type_name) + 2, method_name, strlen(method_name)); |
984
|
306881
|
|
|
|
|
|
method->abs_name = method_abs_name; |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
// Add the method to the method symtable of the class |
987
|
306881
|
|
|
|
|
|
SPVM_HASH_set(type->basic_type->method_symtable, method->name, strlen(method->name), method); |
988
|
|
|
|
|
|
|
} |
989
|
|
|
|
|
|
|
} |
990
|
|
|
|
|
|
|
} |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
// mulnum_t |
993
|
42484
|
100
|
|
|
|
|
if (type->basic_type->category == SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_MULNUM) { |
994
|
284
|
100
|
|
|
|
|
if (type->basic_type->methods->length > 0) { |
995
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The multi-numeric type cannnot have methods.\n at %s line %d", op_class->file, op_class->line); |
996
|
|
|
|
|
|
|
} |
997
|
284
|
100
|
|
|
|
|
if (type->basic_type->class_vars->length > 0) { |
998
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The multi-numeric type cannnot have class variables.\n at %s line %d", op_class->file, op_class->line); |
999
|
|
|
|
|
|
|
} |
1000
|
284
|
100
|
|
|
|
|
if (type->basic_type->unmerged_fields->length == 0) { |
1001
|
8
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The multi-numeric type must have at least one field.\n at %s line %d", op_class->file, op_class->line); |
1002
|
|
|
|
|
|
|
} |
1003
|
276
|
100
|
|
|
|
|
else if (type->basic_type->unmerged_fields->length > 255) { |
1004
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The length of the fields defined in the multi-numeric type must be less than or equal to 255.\n at %s line %d", op_class->file, op_class->line); |
1005
|
|
|
|
|
|
|
} |
1006
|
|
|
|
|
|
|
} |
1007
|
|
|
|
|
|
|
|
1008
|
42484
|
|
|
|
|
|
return op_class; |
1009
|
|
|
|
|
|
|
} |
1010
|
|
|
|
|
|
|
|
1011
|
3093
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_extends(SPVM_COMPILER* compiler, SPVM_OP* op_extends, SPVM_OP* op_type_parent_basic_type) { |
1012
|
|
|
|
|
|
|
|
1013
|
3093
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_extends, op_extends->last, op_type_parent_basic_type); |
1014
|
|
|
|
|
|
|
|
1015
|
3093
|
|
|
|
|
|
return op_extends; |
1016
|
|
|
|
|
|
|
} |
1017
|
|
|
|
|
|
|
|
1018
|
210
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_version_decl(SPVM_COMPILER* compiler, SPVM_OP* op_version_decl, SPVM_OP* op_version_string) { |
1019
|
|
|
|
|
|
|
|
1020
|
210
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_version_decl, op_version_decl->last, op_version_string); |
1021
|
|
|
|
|
|
|
|
1022
|
210
|
|
|
|
|
|
return op_version_decl; |
1023
|
|
|
|
|
|
|
} |
1024
|
|
|
|
|
|
|
|
1025
|
525
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_allow(SPVM_COMPILER* compiler, SPVM_OP* op_allow, SPVM_OP* op_type) { |
1026
|
|
|
|
|
|
|
|
1027
|
525
|
|
|
|
|
|
SPVM_ALLOW* allow = SPVM_ALLOW_new(compiler); |
1028
|
525
|
|
|
|
|
|
op_allow->uv.allow = allow; |
1029
|
525
|
|
|
|
|
|
allow->op_allow = op_allow; |
1030
|
525
|
|
|
|
|
|
allow->basic_type_name = op_type->uv.type->unresolved_basic_type_name; |
1031
|
|
|
|
|
|
|
|
1032
|
|
|
|
|
|
|
// add use stack |
1033
|
525
|
|
|
|
|
|
SPVM_OP* op_use = SPVM_OP_new_op_use(compiler, op_allow->file, op_allow->line); |
1034
|
525
|
|
|
|
|
|
SPVM_OP* op_name_alias = NULL; |
1035
|
525
|
|
|
|
|
|
int32_t is_require = 0; |
1036
|
525
|
|
|
|
|
|
SPVM_OP_build_use(compiler, op_use, op_type, op_name_alias, is_require); |
1037
|
|
|
|
|
|
|
|
1038
|
525
|
|
|
|
|
|
return op_allow; |
1039
|
|
|
|
|
|
|
} |
1040
|
|
|
|
|
|
|
|
1041
|
2
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_alias(SPVM_COMPILER* compiler, SPVM_OP* op_use, SPVM_OP* op_type, SPVM_OP* op_name_alias) { |
1042
|
|
|
|
|
|
|
|
1043
|
2
|
|
|
|
|
|
SPVM_USE* use = op_use->uv.use; |
1044
|
2
|
|
|
|
|
|
use->op_use = op_use; |
1045
|
2
|
|
|
|
|
|
use->op_type = op_type; |
1046
|
2
|
|
|
|
|
|
const char* alias_name = op_name_alias->uv.name; |
1047
|
2
|
|
|
|
|
|
use->alias_name = alias_name; |
1048
|
|
|
|
|
|
|
|
1049
|
2
|
|
|
|
|
|
return op_use; |
1050
|
|
|
|
|
|
|
} |
1051
|
|
|
|
|
|
|
|
1052
|
80307
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_use(SPVM_COMPILER* compiler, SPVM_OP* op_use, SPVM_OP* op_type, SPVM_OP* op_name_alias, int32_t is_require) { |
1053
|
|
|
|
|
|
|
|
1054
|
80307
|
|
|
|
|
|
SPVM_USE* use = op_use->uv.use; |
1055
|
80307
|
|
|
|
|
|
use->op_use = op_use; |
1056
|
80307
|
|
|
|
|
|
use->op_type = op_type; |
1057
|
80307
|
|
|
|
|
|
use->is_require = is_require; |
1058
|
|
|
|
|
|
|
|
1059
|
80307
|
100
|
|
|
|
|
if (op_name_alias) { |
1060
|
14
|
|
|
|
|
|
const char* alias_name = op_name_alias->uv.name; |
1061
|
14
|
|
|
|
|
|
use->alias_name = alias_name; |
1062
|
|
|
|
|
|
|
} |
1063
|
|
|
|
|
|
|
|
1064
|
80307
|
|
|
|
|
|
SPVM_LIST_push(compiler->op_use_stack, op_use); |
1065
|
|
|
|
|
|
|
|
1066
|
80307
|
|
|
|
|
|
return op_use; |
1067
|
|
|
|
|
|
|
} |
1068
|
|
|
|
|
|
|
|
1069
|
3203
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_enumeration_definition(SPVM_COMPILER* compiler, SPVM_OP* op_enumeration, SPVM_OP* op_enumeration_block, SPVM_OP* op_attributes) { |
1070
|
|
|
|
|
|
|
|
1071
|
3203
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_enumeration, op_enumeration->last, op_enumeration_block); |
1072
|
|
|
|
|
|
|
|
1073
|
3203
|
|
|
|
|
|
SPVM_OP* op_enumeration_values = op_enumeration_block->first; |
1074
|
3203
|
|
|
|
|
|
SPVM_OP* op_method = op_enumeration_values->first; |
1075
|
6954
|
100
|
|
|
|
|
while ((op_method = SPVM_OP_sibling(compiler, op_method))) { |
1076
|
3751
|
|
|
|
|
|
SPVM_METHOD* method = op_method->uv.method; |
1077
|
|
|
|
|
|
|
|
1078
|
|
|
|
|
|
|
// Enumeration attributes |
1079
|
3751
|
|
|
|
|
|
int32_t access_control_attributes_count = 0; |
1080
|
3751
|
50
|
|
|
|
|
if (op_attributes) { |
1081
|
3751
|
|
|
|
|
|
SPVM_OP* op_attribute = op_attributes->first; |
1082
|
4283
|
100
|
|
|
|
|
while ((op_attribute = SPVM_OP_sibling(compiler, op_attribute))) { |
1083
|
532
|
|
|
|
|
|
SPVM_ATTRIBUTE* attribute = op_attribute->uv.attribute; |
1084
|
|
|
|
|
|
|
|
1085
|
532
|
|
|
|
|
|
switch (attribute->id) { |
1086
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PRIVATE: { |
1087
|
528
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
1088
|
528
|
|
|
|
|
|
access_control_attributes_count++; |
1089
|
528
|
|
|
|
|
|
break; |
1090
|
|
|
|
|
|
|
} |
1091
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PROTECTED: { |
1092
|
0
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PROTECTED; |
1093
|
0
|
|
|
|
|
|
access_control_attributes_count++; |
1094
|
0
|
|
|
|
|
|
break; |
1095
|
|
|
|
|
|
|
} |
1096
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PUBLIC: { |
1097
|
2
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
1098
|
2
|
|
|
|
|
|
access_control_attributes_count++; |
1099
|
2
|
|
|
|
|
|
break; |
1100
|
|
|
|
|
|
|
} |
1101
|
|
|
|
|
|
|
default: { |
1102
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Invalid enumeration attribute \"%s\".\n at %s line %d", SPVM_ATTRIBUTE_get_name(compiler, attribute->id), op_attributes->file, op_attributes->line); |
1103
|
|
|
|
|
|
|
} |
1104
|
|
|
|
|
|
|
} |
1105
|
|
|
|
|
|
|
} |
1106
|
3751
|
100
|
|
|
|
|
if (access_control_attributes_count > 1) { |
1107
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of enumeration attributes \"private\", \"protected\" or \"public\" can be specified.\n at %s line %d", op_method->file, op_method->line); |
1108
|
|
|
|
|
|
|
} |
1109
|
|
|
|
|
|
|
} |
1110
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
// The default of the access controll of the enumeration is public. |
1112
|
3751
|
50
|
|
|
|
|
if (method->access_control_type == SPVM_ATTRIBUTE_C_ID_UNKNOWN) { |
1113
|
0
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
1114
|
|
|
|
|
|
|
} |
1115
|
|
|
|
|
|
|
} |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
// Reset enum information |
1118
|
3203
|
|
|
|
|
|
compiler->current_enum_value = 0; |
1119
|
|
|
|
|
|
|
|
1120
|
3203
|
|
|
|
|
|
return op_enumeration; |
1121
|
|
|
|
|
|
|
} |
1122
|
|
|
|
|
|
|
|
1123
|
3751
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_enumeration_value(SPVM_COMPILER* compiler, SPVM_OP* op_name, SPVM_OP* op_constant) { |
1124
|
|
|
|
|
|
|
|
1125
|
3751
|
100
|
|
|
|
|
if (op_constant) { |
1126
|
|
|
|
|
|
|
|
1127
|
3698
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
1128
|
|
|
|
|
|
|
|
1129
|
3698
|
50
|
|
|
|
|
if (constant->type->dimension == 0 && constant->type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_INT) { |
|
|
100
|
|
|
|
|
|
1130
|
3697
|
|
|
|
|
|
compiler->current_enum_value = constant->value.ival; |
1131
|
|
|
|
|
|
|
} |
1132
|
|
|
|
|
|
|
else { |
1133
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The value of the enumeration must be int type.\n at %s line %d", op_constant->file, op_constant->line); |
1134
|
|
|
|
|
|
|
} |
1135
|
|
|
|
|
|
|
|
1136
|
3698
|
|
|
|
|
|
compiler->current_enum_value++; |
1137
|
|
|
|
|
|
|
} |
1138
|
|
|
|
|
|
|
else { |
1139
|
53
|
|
|
|
|
|
op_constant = SPVM_OP_new_op_constant_int(compiler, (int32_t)compiler->current_enum_value, op_name->file, op_name->line); |
1140
|
|
|
|
|
|
|
|
1141
|
53
|
|
|
|
|
|
compiler->current_enum_value++; |
1142
|
|
|
|
|
|
|
} |
1143
|
|
|
|
|
|
|
|
1144
|
|
|
|
|
|
|
// Return |
1145
|
3751
|
|
|
|
|
|
SPVM_OP* op_return = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_RETURN, op_name->file, op_name->line); |
1146
|
3751
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_return, op_return->last, op_constant); |
1147
|
|
|
|
|
|
|
|
1148
|
|
|
|
|
|
|
// Statements |
1149
|
3751
|
|
|
|
|
|
SPVM_OP* op_list_statements = SPVM_OP_new_op_list(compiler, op_name->file, op_name->line); |
1150
|
3751
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_statements, op_list_statements->last, op_return); |
1151
|
|
|
|
|
|
|
|
1152
|
|
|
|
|
|
|
// Block |
1153
|
3751
|
|
|
|
|
|
SPVM_OP* op_block = SPVM_OP_new_op_block(compiler, op_name->file, op_name->line); |
1154
|
3751
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block, op_block->last, op_list_statements); |
1155
|
|
|
|
|
|
|
|
1156
|
|
|
|
|
|
|
// method |
1157
|
3751
|
|
|
|
|
|
SPVM_OP* op_method = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_METHOD, op_name->file, op_name->line); |
1158
|
3751
|
|
|
|
|
|
op_method->file = op_name->file; |
1159
|
3751
|
|
|
|
|
|
op_method->line = op_name->line; |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
// Type |
1162
|
3751
|
|
|
|
|
|
SPVM_TYPE* return_type = op_constant->uv.constant->type; |
1163
|
3751
|
|
|
|
|
|
SPVM_OP* op_return_type = SPVM_OP_new_op_type(compiler, return_type->unresolved_basic_type_name, return_type->basic_type, return_type->dimension, return_type->flag, op_name->file, op_name->line); |
1164
|
|
|
|
|
|
|
|
1165
|
3751
|
|
|
|
|
|
SPVM_OP* op_list_attributes = SPVM_OP_new_op_list(compiler, compiler->current_file, compiler->current_line); |
1166
|
3751
|
|
|
|
|
|
SPVM_OP* op_attribute_static = SPVM_OP_new_op_attribute(compiler, SPVM_ATTRIBUTE_C_ID_STATIC, compiler->current_file, compiler->current_line); |
1167
|
3751
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_attributes, op_list_attributes->first, op_attribute_static); |
1168
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
// Build method |
1170
|
3751
|
|
|
|
|
|
op_method = SPVM_OP_build_method_definition(compiler, op_method, op_name, op_return_type, NULL, op_list_attributes, op_block, NULL, 0, 0); |
1171
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
// Set constant |
1173
|
3751
|
|
|
|
|
|
op_method->uv.method->enum_value = op_constant->uv.constant->value.ival; |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
// Method is enumeration |
1176
|
3751
|
|
|
|
|
|
op_method->uv.method->is_enum = 1; |
1177
|
|
|
|
|
|
|
|
1178
|
3751
|
|
|
|
|
|
return op_method; |
1179
|
|
|
|
|
|
|
} |
1180
|
|
|
|
|
|
|
|
1181
|
8115
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_class_var_definition(SPVM_COMPILER* compiler, SPVM_OP* op_class_var, SPVM_OP* op_name, SPVM_OP* op_attributes, SPVM_OP* op_type) { |
1182
|
|
|
|
|
|
|
|
1183
|
8115
|
|
|
|
|
|
SPVM_CLASS_VAR* class_var = SPVM_CLASS_VAR_new(compiler); |
1184
|
|
|
|
|
|
|
|
1185
|
8115
|
|
|
|
|
|
const char* name = op_name->uv.name; |
1186
|
8115
|
|
|
|
|
|
class_var->name = op_name->uv.name; |
1187
|
|
|
|
|
|
|
|
1188
|
8115
|
100
|
|
|
|
|
if (strstr(name, "::")) { |
1189
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The class varaible name \"%s\" cannnot contain \"::\".\n at %s line %d", class_var->name, op_name->file, op_name->line); |
1190
|
|
|
|
|
|
|
} |
1191
|
|
|
|
|
|
|
|
1192
|
8115
|
|
|
|
|
|
class_var->op_name = op_name; |
1193
|
8115
|
|
|
|
|
|
class_var->type = op_type->uv.type; |
1194
|
8115
|
|
|
|
|
|
class_var->op_class_var = op_class_var; |
1195
|
|
|
|
|
|
|
|
1196
|
8115
|
|
|
|
|
|
op_class_var->uv.class_var = class_var; |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
// Class variable attributes |
1199
|
8115
|
50
|
|
|
|
|
if (op_attributes) { |
1200
|
8115
|
|
|
|
|
|
int32_t field_method_attributes_count = 0; |
1201
|
8115
|
|
|
|
|
|
int32_t access_control_attributes_count = 0; |
1202
|
8115
|
|
|
|
|
|
SPVM_OP* op_attribute = op_attributes->first; |
1203
|
15772
|
100
|
|
|
|
|
while ((op_attribute = SPVM_OP_sibling(compiler, op_attribute))) { |
1204
|
7657
|
|
|
|
|
|
SPVM_ATTRIBUTE* attribute = op_attribute->uv.attribute; |
1205
|
|
|
|
|
|
|
|
1206
|
7657
|
|
|
|
|
|
switch (attribute->id) { |
1207
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PRIVATE: { |
1208
|
67
|
|
|
|
|
|
class_var->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
1209
|
67
|
|
|
|
|
|
access_control_attributes_count++; |
1210
|
67
|
|
|
|
|
|
break; |
1211
|
|
|
|
|
|
|
} |
1212
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PROTECTED: { |
1213
|
0
|
|
|
|
|
|
class_var->access_control_type = SPVM_ATTRIBUTE_C_ID_PROTECTED; |
1214
|
0
|
|
|
|
|
|
access_control_attributes_count++; |
1215
|
0
|
|
|
|
|
|
break; |
1216
|
|
|
|
|
|
|
} |
1217
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PUBLIC: { |
1218
|
69
|
|
|
|
|
|
class_var->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
1219
|
69
|
|
|
|
|
|
access_control_attributes_count++; |
1220
|
69
|
|
|
|
|
|
break; |
1221
|
|
|
|
|
|
|
} |
1222
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_RW: { |
1223
|
91
|
|
|
|
|
|
class_var->has_setter = 1; |
1224
|
91
|
|
|
|
|
|
class_var->has_getter = 1; |
1225
|
91
|
|
|
|
|
|
field_method_attributes_count++; |
1226
|
91
|
|
|
|
|
|
break; |
1227
|
|
|
|
|
|
|
} |
1228
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_RO: { |
1229
|
7428
|
|
|
|
|
|
class_var->has_getter = 1; |
1230
|
7428
|
|
|
|
|
|
field_method_attributes_count++; |
1231
|
7428
|
|
|
|
|
|
break; |
1232
|
|
|
|
|
|
|
} |
1233
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_WO: { |
1234
|
1
|
|
|
|
|
|
class_var->has_setter = 1; |
1235
|
1
|
|
|
|
|
|
field_method_attributes_count++; |
1236
|
1
|
|
|
|
|
|
break; |
1237
|
|
|
|
|
|
|
} |
1238
|
|
|
|
|
|
|
default: { |
1239
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Invalid class variable attribute \"%s\".\n at %s line %d", SPVM_ATTRIBUTE_get_name(compiler, attribute->id), op_attributes->file, op_attributes->line); |
1240
|
|
|
|
|
|
|
} |
1241
|
|
|
|
|
|
|
} |
1242
|
7657
|
100
|
|
|
|
|
if (field_method_attributes_count > 1) { |
1243
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of class variable attributes \"rw\", \"ro\", \"wo\" can be specifed.\n at %s line %d", op_class_var->file, op_class_var->line); |
1244
|
|
|
|
|
|
|
} |
1245
|
7657
|
100
|
|
|
|
|
if (access_control_attributes_count > 1) { |
1246
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of class variable attributes \"private\", \"protected\" or \"public\" can be specified.\n at %s line %d", op_class_var->file, op_class_var->line); |
1247
|
|
|
|
|
|
|
} |
1248
|
|
|
|
|
|
|
} |
1249
|
|
|
|
|
|
|
} |
1250
|
|
|
|
|
|
|
|
1251
|
|
|
|
|
|
|
// The default of the access controll of the class variable is private. |
1252
|
8115
|
100
|
|
|
|
|
if (class_var->access_control_type == SPVM_ATTRIBUTE_C_ID_UNKNOWN) { |
1253
|
7980
|
|
|
|
|
|
class_var->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
1254
|
|
|
|
|
|
|
} |
1255
|
|
|
|
|
|
|
|
1256
|
8115
|
|
|
|
|
|
return op_class_var; |
1257
|
|
|
|
|
|
|
} |
1258
|
|
|
|
|
|
|
|
1259
|
27459
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_field_definition(SPVM_COMPILER* compiler, SPVM_OP* op_field, SPVM_OP* op_name_field, SPVM_OP* op_attributes, SPVM_OP* op_type) { |
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
// Create field information |
1262
|
27459
|
|
|
|
|
|
SPVM_FIELD* field = SPVM_FIELD_new(compiler); |
1263
|
|
|
|
|
|
|
|
1264
|
|
|
|
|
|
|
// Field Name |
1265
|
27459
|
|
|
|
|
|
field->op_name = op_name_field; |
1266
|
27459
|
|
|
|
|
|
field->name = op_name_field->uv.name; |
1267
|
|
|
|
|
|
|
|
1268
|
27459
|
100
|
|
|
|
|
if (strstr(field->op_name->uv.name, "::")) { |
1269
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The field name \"%s\" cannnot contain \"::\".\n at %s line %d", field->name, op_name_field->file, op_name_field->line); |
1270
|
|
|
|
|
|
|
} |
1271
|
|
|
|
|
|
|
|
1272
|
|
|
|
|
|
|
// Type |
1273
|
27459
|
|
|
|
|
|
field->type = op_type->uv.type; |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
// Set field informaiton |
1276
|
27459
|
|
|
|
|
|
op_field->uv.field = field; |
1277
|
|
|
|
|
|
|
|
1278
|
|
|
|
|
|
|
// Field attributes |
1279
|
27459
|
50
|
|
|
|
|
if (op_attributes) { |
1280
|
27459
|
|
|
|
|
|
SPVM_OP* op_attribute = op_attributes->first; |
1281
|
27459
|
|
|
|
|
|
int32_t field_method_attributes_count = 0; |
1282
|
27459
|
|
|
|
|
|
int32_t access_control_attributes_count = 0; |
1283
|
46246
|
100
|
|
|
|
|
while ((op_attribute = SPVM_OP_sibling(compiler, op_attribute))) { |
1284
|
18787
|
|
|
|
|
|
SPVM_ATTRIBUTE* attribute = op_attribute->uv.attribute; |
1285
|
|
|
|
|
|
|
|
1286
|
18787
|
|
|
|
|
|
switch (attribute->id) { |
1287
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PRIVATE: { |
1288
|
37
|
|
|
|
|
|
field->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
1289
|
37
|
|
|
|
|
|
access_control_attributes_count++; |
1290
|
37
|
|
|
|
|
|
break; |
1291
|
|
|
|
|
|
|
} |
1292
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PROTECTED: { |
1293
|
4
|
|
|
|
|
|
field->access_control_type = SPVM_ATTRIBUTE_C_ID_PROTECTED; |
1294
|
4
|
|
|
|
|
|
access_control_attributes_count++; |
1295
|
4
|
|
|
|
|
|
break; |
1296
|
|
|
|
|
|
|
} |
1297
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PUBLIC: { |
1298
|
1392
|
|
|
|
|
|
field->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
1299
|
1392
|
|
|
|
|
|
access_control_attributes_count++; |
1300
|
1392
|
|
|
|
|
|
break; |
1301
|
|
|
|
|
|
|
} |
1302
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_RW: { |
1303
|
1481
|
|
|
|
|
|
field->has_setter = 1; |
1304
|
1481
|
|
|
|
|
|
field->has_getter = 1; |
1305
|
1481
|
|
|
|
|
|
field_method_attributes_count++; |
1306
|
1481
|
|
|
|
|
|
break; |
1307
|
|
|
|
|
|
|
} |
1308
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_RO: { |
1309
|
15871
|
|
|
|
|
|
field->has_getter = 1; |
1310
|
15871
|
|
|
|
|
|
field_method_attributes_count++; |
1311
|
15871
|
|
|
|
|
|
break; |
1312
|
|
|
|
|
|
|
} |
1313
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_WO: { |
1314
|
1
|
|
|
|
|
|
field->has_setter = 1; |
1315
|
1
|
|
|
|
|
|
field_method_attributes_count++; |
1316
|
1
|
|
|
|
|
|
break; |
1317
|
|
|
|
|
|
|
} |
1318
|
|
|
|
|
|
|
default: { |
1319
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Invalid field attribute \"%s\".\n at %s line %d", SPVM_ATTRIBUTE_get_name(compiler, attribute->id), op_attributes->file, op_attributes->line); |
1320
|
|
|
|
|
|
|
} |
1321
|
|
|
|
|
|
|
} |
1322
|
|
|
|
|
|
|
|
1323
|
18787
|
100
|
|
|
|
|
if (field_method_attributes_count > 1) { |
1324
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of field attributes \"rw\", \"ro\" or \"wo\" can be specifed.\n at %s line %d", op_field->file, op_field->line); |
1325
|
|
|
|
|
|
|
} |
1326
|
18787
|
100
|
|
|
|
|
if (access_control_attributes_count > 1) { |
1327
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of field attributes \"private\", \"protected\" or \"public\" can be specified.\n at %s line %d", op_field->file, op_field->line); |
1328
|
|
|
|
|
|
|
} |
1329
|
|
|
|
|
|
|
} |
1330
|
|
|
|
|
|
|
} |
1331
|
|
|
|
|
|
|
|
1332
|
27459
|
|
|
|
|
|
field->op_field = op_field; |
1333
|
|
|
|
|
|
|
|
1334
|
27459
|
|
|
|
|
|
return op_field; |
1335
|
|
|
|
|
|
|
} |
1336
|
|
|
|
|
|
|
|
1337
|
306890
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_method_definition(SPVM_COMPILER* compiler, SPVM_OP* op_method, SPVM_OP* op_name_method, SPVM_OP* op_return_type, SPVM_OP* op_args, SPVM_OP* op_attributes, SPVM_OP* op_block, SPVM_OP* op_anon_method_fields, int32_t is_init, int32_t is_anon) { |
1338
|
306890
|
|
|
|
|
|
SPVM_METHOD* method = SPVM_METHOD_new(compiler); |
1339
|
|
|
|
|
|
|
|
1340
|
|
|
|
|
|
|
// Is anon method |
1341
|
306890
|
100
|
|
|
|
|
if (is_anon) { |
1342
|
8093
|
|
|
|
|
|
method->is_anon = 1; |
1343
|
|
|
|
|
|
|
} |
1344
|
|
|
|
|
|
|
|
1345
|
306890
|
100
|
|
|
|
|
if (op_name_method == NULL) { |
1346
|
12902
|
|
|
|
|
|
SPVM_STRING* anon_method_name_string = SPVM_STRING_new(compiler, "", strlen("")); |
1347
|
12902
|
|
|
|
|
|
const char* anon_method_name = anon_method_name_string->value; |
1348
|
12902
|
|
|
|
|
|
op_name_method = SPVM_OP_new_op_name(compiler, anon_method_name, op_method->file, op_method->line); |
1349
|
|
|
|
|
|
|
} |
1350
|
306890
|
|
|
|
|
|
const char* method_name = op_name_method->uv.name; |
1351
|
306890
|
100
|
|
|
|
|
if (strstr(method_name, "::")) { |
1352
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The method name \"%s\" cannnot contain \"::\".\n at %s line %d", method_name, op_name_method->file, op_name_method->line); |
1353
|
|
|
|
|
|
|
} |
1354
|
|
|
|
|
|
|
|
1355
|
|
|
|
|
|
|
// Block is method block |
1356
|
306890
|
100
|
|
|
|
|
if (op_block) { |
1357
|
235975
|
|
|
|
|
|
op_block->uv.block->id = SPVM_BLOCK_C_ID_METHOD; |
1358
|
|
|
|
|
|
|
} |
1359
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
// Create method information |
1361
|
306890
|
|
|
|
|
|
method->op_name = op_name_method; |
1362
|
|
|
|
|
|
|
|
1363
|
306890
|
|
|
|
|
|
method->name = method->op_name->uv.name; |
1364
|
|
|
|
|
|
|
|
1365
|
306890
|
|
|
|
|
|
method->is_init = is_init; |
1366
|
306890
|
100
|
|
|
|
|
if (!is_init && strcmp(method_name, "INIT") == 0) { |
|
|
100
|
|
|
|
|
|
1367
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "\"INIT\" cannnot be used as a method name.\n at %s line %d", op_name_method->file, op_name_method->line); |
1368
|
|
|
|
|
|
|
} |
1369
|
|
|
|
|
|
|
|
1370
|
|
|
|
|
|
|
// Method attributes |
1371
|
306890
|
|
|
|
|
|
int32_t access_control_attributes_count = 0; |
1372
|
306890
|
100
|
|
|
|
|
if (op_attributes) { |
1373
|
288058
|
|
|
|
|
|
SPVM_OP* op_attribute = op_attributes->first; |
1374
|
605100
|
100
|
|
|
|
|
while ((op_attribute = SPVM_OP_sibling(compiler, op_attribute))) { |
1375
|
317042
|
|
|
|
|
|
SPVM_ATTRIBUTE* attribute = op_attribute->uv.attribute; |
1376
|
|
|
|
|
|
|
|
1377
|
317042
|
|
|
|
|
|
switch (attribute->id) { |
1378
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PRIVATE: { |
1379
|
14667
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PRIVATE; |
1380
|
14667
|
|
|
|
|
|
access_control_attributes_count++; |
1381
|
14667
|
|
|
|
|
|
break; |
1382
|
|
|
|
|
|
|
} |
1383
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PROTECTED: { |
1384
|
226
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PROTECTED; |
1385
|
226
|
|
|
|
|
|
access_control_attributes_count++; |
1386
|
226
|
|
|
|
|
|
break; |
1387
|
|
|
|
|
|
|
} |
1388
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PUBLIC: { |
1389
|
0
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
1390
|
0
|
|
|
|
|
|
access_control_attributes_count++; |
1391
|
0
|
|
|
|
|
|
break; |
1392
|
|
|
|
|
|
|
} |
1393
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_PRECOMPILE: { |
1394
|
38770
|
|
|
|
|
|
method->is_precompile = 1; |
1395
|
38770
|
|
|
|
|
|
break; |
1396
|
|
|
|
|
|
|
} |
1397
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_REQUIRED: { |
1398
|
5773
|
|
|
|
|
|
method->is_required = 1; |
1399
|
5773
|
|
|
|
|
|
break; |
1400
|
|
|
|
|
|
|
} |
1401
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_NATIVE: { |
1402
|
64986
|
|
|
|
|
|
method->is_native = 1; |
1403
|
64986
|
|
|
|
|
|
break; |
1404
|
|
|
|
|
|
|
} |
1405
|
|
|
|
|
|
|
case SPVM_ATTRIBUTE_C_ID_STATIC: { |
1406
|
192619
|
|
|
|
|
|
method->is_class_method = 1; |
1407
|
192619
|
|
|
|
|
|
break; |
1408
|
|
|
|
|
|
|
} |
1409
|
|
|
|
|
|
|
default: { |
1410
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Invalid method attribute \"%s\".\n at %s line %d", SPVM_ATTRIBUTE_get_name(compiler, attribute->id), op_attributes->file, op_attributes->line); |
1411
|
|
|
|
|
|
|
} |
1412
|
|
|
|
|
|
|
} |
1413
|
|
|
|
|
|
|
} |
1414
|
|
|
|
|
|
|
|
1415
|
288058
|
100
|
|
|
|
|
if (method->is_native && method->is_precompile) { |
|
|
100
|
|
|
|
|
|
1416
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of method attributes \"native\" and \"precompile\" can be specified.\n at %s line %d", op_attributes->file, op_attributes->line); |
1417
|
|
|
|
|
|
|
} |
1418
|
288058
|
50
|
|
|
|
|
if (access_control_attributes_count > 1) { |
1419
|
0
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Only one of method attributes \"private\", \"protected\" or \"public\" can be specified.\n at %s line %d", op_method->file, op_method->line); |
1420
|
|
|
|
|
|
|
} |
1421
|
|
|
|
|
|
|
} |
1422
|
|
|
|
|
|
|
|
1423
|
|
|
|
|
|
|
// The default of the access controll of the method is publice. |
1424
|
306890
|
100
|
|
|
|
|
if (method->access_control_type == SPVM_ATTRIBUTE_C_ID_UNKNOWN) { |
1425
|
291997
|
|
|
|
|
|
method->access_control_type = SPVM_ATTRIBUTE_C_ID_PUBLIC; |
1426
|
|
|
|
|
|
|
} |
1427
|
|
|
|
|
|
|
|
1428
|
|
|
|
|
|
|
// Native method cannnot have block |
1429
|
306890
|
100
|
|
|
|
|
if ((method->is_native) && op_block) { |
|
|
100
|
|
|
|
|
|
1430
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The native method cannnot have the block.\n at %s line %d", op_block->file, op_block->line); |
1431
|
|
|
|
|
|
|
} |
1432
|
|
|
|
|
|
|
|
1433
|
|
|
|
|
|
|
// method args |
1434
|
306890
|
100
|
|
|
|
|
if (!op_args) { |
1435
|
40163
|
|
|
|
|
|
op_args = SPVM_OP_new_op_list(compiler, op_method->file, op_method->line); |
1436
|
|
|
|
|
|
|
} |
1437
|
|
|
|
|
|
|
|
1438
|
|
|
|
|
|
|
// Add $self : self before the first argument |
1439
|
306890
|
100
|
|
|
|
|
if (!method->is_class_method) { |
1440
|
114271
|
|
|
|
|
|
SPVM_OP* op_arg_var_name_self = SPVM_OP_new_op_name(compiler, "$self", op_method->file, op_method->line); |
1441
|
114271
|
|
|
|
|
|
SPVM_OP* op_arg_var_self = SPVM_OP_new_op_var(compiler, op_arg_var_name_self); |
1442
|
114271
|
|
|
|
|
|
SPVM_OP* op_self_type = SPVM_OP_new_op_unresolved_type(compiler, NULL, 0, 0, op_method->file, op_method->line); |
1443
|
114271
|
|
|
|
|
|
SPVM_TYPE* self_type = op_self_type->uv.type; |
1444
|
114271
|
|
|
|
|
|
SPVM_OP* op_arg_self = SPVM_OP_build_arg(compiler, op_arg_var_self, op_self_type, NULL, NULL); |
1445
|
114271
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_args, op_args->first, op_arg_self); |
1446
|
|
|
|
|
|
|
} |
1447
|
|
|
|
|
|
|
|
1448
|
|
|
|
|
|
|
// Add method arguments |
1449
|
|
|
|
|
|
|
{ |
1450
|
306890
|
|
|
|
|
|
int32_t found_optional_arg = 0; |
1451
|
306890
|
|
|
|
|
|
int32_t required_args_length = 0; |
1452
|
306890
|
|
|
|
|
|
int32_t args_length = 0; |
1453
|
306890
|
|
|
|
|
|
SPVM_OP* op_arg = op_args->first; |
1454
|
810256
|
100
|
|
|
|
|
while ((op_arg = SPVM_OP_sibling(compiler, op_arg))) { |
1455
|
503366
|
|
|
|
|
|
SPVM_VAR_DECL* arg_var_decl = op_arg->uv.var->var_decl; |
1456
|
503366
|
100
|
|
|
|
|
if (!found_optional_arg) { |
1457
|
475383
|
100
|
|
|
|
|
if (arg_var_decl->op_optional_arg_default) { |
1458
|
31935
|
|
|
|
|
|
found_optional_arg = 1; |
1459
|
|
|
|
|
|
|
} |
1460
|
|
|
|
|
|
|
else { |
1461
|
443448
|
|
|
|
|
|
required_args_length++; |
1462
|
|
|
|
|
|
|
} |
1463
|
|
|
|
|
|
|
} |
1464
|
503366
|
|
|
|
|
|
args_length++; |
1465
|
|
|
|
|
|
|
} |
1466
|
306890
|
|
|
|
|
|
method->args_length = args_length; |
1467
|
306890
|
|
|
|
|
|
method->required_args_length = required_args_length; |
1468
|
|
|
|
|
|
|
} |
1469
|
|
|
|
|
|
|
|
1470
|
|
|
|
|
|
|
// Capture variables |
1471
|
306890
|
100
|
|
|
|
|
if (op_anon_method_fields) { |
1472
|
22
|
|
|
|
|
|
SPVM_OP* op_anon_method_field = op_anon_method_fields->first; |
1473
|
57
|
100
|
|
|
|
|
while ((op_anon_method_field = SPVM_OP_sibling(compiler, op_anon_method_field))) { |
1474
|
35
|
|
|
|
|
|
SPVM_LIST_push(method->anon_method_fields, op_anon_method_field->uv.field); |
1475
|
|
|
|
|
|
|
} |
1476
|
|
|
|
|
|
|
} |
1477
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
// Variable declarations of arguments |
1479
|
306890
|
|
|
|
|
|
SPVM_OP* op_arg = op_args->first; |
1480
|
810256
|
100
|
|
|
|
|
while ((op_arg = SPVM_OP_sibling(compiler, op_arg))) { |
1481
|
503366
|
|
|
|
|
|
SPVM_LIST_push(method->var_decls, op_arg->uv.var->var_decl); |
1482
|
|
|
|
|
|
|
} |
1483
|
|
|
|
|
|
|
|
1484
|
|
|
|
|
|
|
// return type |
1485
|
306890
|
|
|
|
|
|
method->return_type = op_return_type->uv.type; |
1486
|
|
|
|
|
|
|
|
1487
|
306890
|
100
|
|
|
|
|
if (strcmp(method->op_name->uv.name, "DESTROY") == 0) { |
1488
|
745
|
|
|
|
|
|
method->is_destructor = 1; |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
// DESTROY return type must be void |
1491
|
745
|
50
|
|
|
|
|
if (!(method->return_type->dimension == 0 && method->return_type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_VOID)) { |
|
|
100
|
|
|
|
|
|
1492
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The return type of the DESTROY destructor method must be the void type.\n at %s line %d", op_method->file, op_method->line); |
1493
|
|
|
|
|
|
|
} |
1494
|
|
|
|
|
|
|
|
1495
|
|
|
|
|
|
|
// DESTROY is instance method |
1496
|
745
|
100
|
|
|
|
|
if (method->is_class_method) { |
1497
|
2
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The DESTROY destructor method must be an instance method.\n at %s line %d", op_method->file, op_method->line); |
1498
|
|
|
|
|
|
|
} |
1499
|
|
|
|
|
|
|
|
1500
|
|
|
|
|
|
|
// DESTROY doesn't have arguments without invocant |
1501
|
745
|
100
|
|
|
|
|
if (method->args_length != 1) { |
1502
|
4
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The DESTROY destructor method cannnot have arguments.\n at %s line %d", op_method->file, op_method->line); |
1503
|
|
|
|
|
|
|
} |
1504
|
|
|
|
|
|
|
} |
1505
|
|
|
|
|
|
|
|
1506
|
306890
|
100
|
|
|
|
|
if (op_block) { |
1507
|
|
|
|
|
|
|
|
1508
|
235975
|
|
|
|
|
|
SPVM_OP* op_list_statement = op_block->first; |
1509
|
|
|
|
|
|
|
|
1510
|
|
|
|
|
|
|
// Add variable declarations before the first of the statements |
1511
|
621142
|
100
|
|
|
|
|
for (int32_t i = method->args_length - 1; i >= 0; i--) { |
1512
|
385167
|
|
|
|
|
|
SPVM_VAR_DECL* arg_var_decl = SPVM_LIST_get(method->var_decls, i); |
1513
|
385167
|
50
|
|
|
|
|
assert(arg_var_decl); |
1514
|
385167
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, arg_var_decl->var->name, arg_var_decl->op_var_decl->file, arg_var_decl->op_var_decl->line); |
1515
|
385167
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
1516
|
385167
|
|
|
|
|
|
op_var->uv.var->var_decl = arg_var_decl; |
1517
|
385167
|
|
|
|
|
|
op_var->uv.var->is_declaration = 1; |
1518
|
385167
|
|
|
|
|
|
op_var->uv.var->var_decl = arg_var_decl; |
1519
|
|
|
|
|
|
|
|
1520
|
385167
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_statement, op_list_statement->first, op_var); |
1521
|
|
|
|
|
|
|
} |
1522
|
|
|
|
|
|
|
|
1523
|
|
|
|
|
|
|
// Add condition_flag variable to first of block |
1524
|
|
|
|
|
|
|
{ |
1525
|
235975
|
|
|
|
|
|
char* name = "$.condition_flag"; |
1526
|
235975
|
|
|
|
|
|
SPVM_OP* op_name = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NAME, op_list_statement->file, op_list_statement->last->line + 1); |
1527
|
235975
|
|
|
|
|
|
op_name->uv.name = name; |
1528
|
235975
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_build_var(compiler, op_name); |
1529
|
235975
|
|
|
|
|
|
SPVM_OP* op_var_decl = SPVM_OP_new_op_var_decl(compiler, op_list_statement->file, op_list_statement->last->line + 1); |
1530
|
235975
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_int_type(compiler, op_list_statement->file, op_list_statement->line); |
1531
|
235975
|
|
|
|
|
|
op_var = SPVM_OP_build_var_decl(compiler, op_var_decl, op_var, op_type, NULL); |
1532
|
235975
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_statement, op_list_statement->first, op_var); |
1533
|
|
|
|
|
|
|
} |
1534
|
|
|
|
|
|
|
|
1535
|
|
|
|
|
|
|
// Add return statement after the last of the statements |
1536
|
|
|
|
|
|
|
{ |
1537
|
235975
|
|
|
|
|
|
SPVM_OP* op_return = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_RETURN, op_list_statement->file, op_list_statement->last->line + 1); |
1538
|
235975
|
|
|
|
|
|
SPVM_TYPE* return_type = method->return_type; |
1539
|
235975
|
100
|
|
|
|
|
if (SPVM_TYPE_is_void_type(compiler, return_type->basic_type->id, return_type->dimension, return_type->flag)) { |
1540
|
90873
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_statement, op_list_statement->last, op_return); |
1541
|
|
|
|
|
|
|
} |
1542
|
|
|
|
|
|
|
else { |
1543
|
|
|
|
|
|
|
// Return variable name |
1544
|
145102
|
|
|
|
|
|
char* name = "$.return"; |
1545
|
145102
|
|
|
|
|
|
SPVM_OP* op_name = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NAME, op_list_statement->file, op_list_statement->last->line + 1); |
1546
|
145102
|
|
|
|
|
|
op_name->uv.name = name; |
1547
|
145102
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_build_var(compiler, op_name); |
1548
|
145102
|
|
|
|
|
|
SPVM_OP* op_var_decl = SPVM_OP_new_op_var_decl(compiler, op_list_statement->file, op_list_statement->last->line + 1); |
1549
|
145102
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, return_type->unresolved_basic_type_name, return_type->basic_type, return_type->dimension, return_type->flag, op_list_statement->file, op_list_statement->last->line + 1); |
1550
|
|
|
|
|
|
|
|
1551
|
145102
|
|
|
|
|
|
op_var = SPVM_OP_build_var_decl(compiler, op_var_decl, op_var, op_type, NULL); |
1552
|
145102
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_return, op_return->last, op_var); |
1553
|
145102
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_statement, op_list_statement->last, op_return); |
1554
|
|
|
|
|
|
|
} |
1555
|
|
|
|
|
|
|
} |
1556
|
|
|
|
|
|
|
} |
1557
|
|
|
|
|
|
|
|
1558
|
|
|
|
|
|
|
// Save block |
1559
|
306890
|
|
|
|
|
|
method->op_block = op_block; |
1560
|
|
|
|
|
|
|
|
1561
|
306890
|
|
|
|
|
|
method->op_method = op_method; |
1562
|
|
|
|
|
|
|
|
1563
|
306890
|
|
|
|
|
|
op_method->uv.method = method; |
1564
|
|
|
|
|
|
|
|
1565
|
306890
|
|
|
|
|
|
return op_method; |
1566
|
|
|
|
|
|
|
} |
1567
|
|
|
|
|
|
|
|
1568
|
503366
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_arg(SPVM_COMPILER* compiler, SPVM_OP* op_var, SPVM_OP* op_type, SPVM_OP* op_attributes, SPVM_OP* op_optional_arg_default) { |
1569
|
|
|
|
|
|
|
|
1570
|
503366
|
|
|
|
|
|
SPVM_OP* op_var_decl = SPVM_OP_new_op_var_decl_arg(compiler, op_var->file, op_var->line); |
1571
|
|
|
|
|
|
|
|
1572
|
503366
|
|
|
|
|
|
op_var_decl->uv.var_decl->op_optional_arg_default = op_optional_arg_default; |
1573
|
|
|
|
|
|
|
|
1574
|
503366
|
|
|
|
|
|
op_var = SPVM_OP_build_var_decl(compiler, op_var_decl, op_var, op_type, op_attributes); |
1575
|
|
|
|
|
|
|
|
1576
|
503366
|
|
|
|
|
|
op_type->uv.type->resolved_in_ast = 0; |
1577
|
|
|
|
|
|
|
|
1578
|
503366
|
|
|
|
|
|
return op_var; |
1579
|
|
|
|
|
|
|
} |
1580
|
|
|
|
|
|
|
|
1581
|
8093
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_anon_method(SPVM_COMPILER* compiler, SPVM_OP* op_method) { |
1582
|
|
|
|
|
|
|
|
1583
|
|
|
|
|
|
|
// Class |
1584
|
8093
|
|
|
|
|
|
SPVM_OP* op_class = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_CLASS, op_method->file, op_method->line); |
1585
|
|
|
|
|
|
|
|
1586
|
8093
|
|
|
|
|
|
SPVM_OP* op_class_block = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_CLASS_BLOCK, op_method->file, op_method->line); |
1587
|
8093
|
|
|
|
|
|
SPVM_OP* op_list_definitions = SPVM_OP_new_op_list(compiler, compiler->current_file, compiler->current_line); |
1588
|
8093
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_definitions, op_list_definitions->last, op_method); |
1589
|
8093
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_class_block, op_class_block->last, op_list_definitions); |
1590
|
|
|
|
|
|
|
|
1591
|
|
|
|
|
|
|
// int32_t max length is 10(2147483647) |
1592
|
8093
|
|
|
|
|
|
int32_t int32_max_length = 10; |
1593
|
|
|
|
|
|
|
|
1594
|
|
|
|
|
|
|
// Create anon method class name |
1595
|
|
|
|
|
|
|
// If Foo::Bar anon method is defined line 123, method keyword start pos 32, the anon method class name become Foo::Bar::anon::123::32. This is uniqe in whole program. |
1596
|
8093
|
|
|
|
|
|
const char* outer_basic_type_name = compiler->current_outer_class_name; |
1597
|
8093
|
|
|
|
|
|
int32_t anon_method_defined_line = op_method->line; |
1598
|
8093
|
|
|
|
|
|
int32_t anon_method_defined_column = op_method->column; |
1599
|
8093
|
|
|
|
|
|
int32_t anon_method_basic_type_name_length = 6 + strlen(outer_basic_type_name) + 2 + int32_max_length + 2 + int32_max_length; |
1600
|
|
|
|
|
|
|
|
1601
|
|
|
|
|
|
|
// Anon class name |
1602
|
8093
|
|
|
|
|
|
char* name_basic_type_tmp = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, anon_method_basic_type_name_length + 1); |
1603
|
8093
|
|
|
|
|
|
sprintf(name_basic_type_tmp, "%s::anon::%d::%d", outer_basic_type_name, anon_method_defined_line, anon_method_defined_column); |
1604
|
|
|
|
|
|
|
|
1605
|
8093
|
|
|
|
|
|
SPVM_STRING* name_basic_type_string = SPVM_STRING_new(compiler, name_basic_type_tmp, strlen(name_basic_type_tmp)); |
1606
|
8093
|
|
|
|
|
|
const char* name_basic_type = name_basic_type_string->value; |
1607
|
|
|
|
|
|
|
|
1608
|
8093
|
|
|
|
|
|
SPVM_OP* op_name_basic_type = SPVM_OP_new_op_name(compiler, name_basic_type, op_method->file, op_method->line); |
1609
|
8093
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_build_basic_type(compiler, op_name_basic_type); |
1610
|
|
|
|
|
|
|
|
1611
|
8093
|
|
|
|
|
|
op_method->uv.method->outer_basic_type_name = outer_basic_type_name; |
1612
|
|
|
|
|
|
|
|
1613
|
8093
|
|
|
|
|
|
SPVM_OP_build_class(compiler, op_class, op_type, op_class_block, NULL, NULL); |
1614
|
|
|
|
|
|
|
|
1615
|
|
|
|
|
|
|
// Type |
1616
|
8093
|
|
|
|
|
|
SPVM_OP* op_name_new = SPVM_OP_new_op_name(compiler, name_basic_type, op_method->file, op_method->line); |
1617
|
8093
|
|
|
|
|
|
SPVM_OP* op_type_new = SPVM_OP_build_basic_type(compiler, op_name_new); |
1618
|
|
|
|
|
|
|
|
1619
|
|
|
|
|
|
|
// New |
1620
|
8093
|
|
|
|
|
|
SPVM_OP* op_new = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NEW, op_method->file, op_method->line); |
1621
|
|
|
|
|
|
|
|
1622
|
8093
|
|
|
|
|
|
SPVM_OP* op_anon_method = SPVM_OP_build_new(compiler, op_new, op_type_new, NULL); |
1623
|
|
|
|
|
|
|
|
1624
|
8093
|
|
|
|
|
|
SPVM_LIST_push(compiler->current_anon_op_types, op_type); |
1625
|
|
|
|
|
|
|
|
1626
|
8093
|
|
|
|
|
|
return op_anon_method; |
1627
|
|
|
|
|
|
|
} |
1628
|
|
|
|
|
|
|
|
1629
|
35
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_anon_method_field_definition(SPVM_COMPILER* compiler, SPVM_OP* op_field_definition, SPVM_OP* op_default) { |
1630
|
|
|
|
|
|
|
|
1631
|
35
|
|
|
|
|
|
op_field_definition->uv.field->op_anon_method_field_default = op_default; |
1632
|
|
|
|
|
|
|
|
1633
|
35
|
|
|
|
|
|
return op_field_definition; |
1634
|
|
|
|
|
|
|
} |
1635
|
|
|
|
|
|
|
|
1636
|
36412
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_init_block(SPVM_COMPILER* compiler, SPVM_OP* op_init, SPVM_OP* op_block) { |
1637
|
|
|
|
|
|
|
|
1638
|
36412
|
|
|
|
|
|
SPVM_OP* op_method = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_METHOD, op_init->file, op_init->line); |
1639
|
36412
|
|
|
|
|
|
SPVM_STRING* method_name_string = SPVM_STRING_new(compiler, "INIT", strlen("INIT")); |
1640
|
36412
|
|
|
|
|
|
const char* method_name = method_name_string->value; |
1641
|
36412
|
|
|
|
|
|
SPVM_OP* op_method_name = SPVM_OP_new_op_name(compiler, "INIT", op_init->file, op_init->line); |
1642
|
36412
|
|
|
|
|
|
SPVM_OP* op_void_type = SPVM_OP_new_op_void_type(compiler, op_init->file, op_init->line); |
1643
|
|
|
|
|
|
|
|
1644
|
36412
|
|
|
|
|
|
SPVM_OP* op_list_attributes = SPVM_OP_new_op_list(compiler, op_init->file, op_init->line); |
1645
|
36412
|
|
|
|
|
|
SPVM_OP* op_attribute_static = SPVM_OP_new_op_attribute(compiler, SPVM_ATTRIBUTE_C_ID_STATIC, op_init->file, op_init->line); |
1646
|
36412
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_attributes, op_list_attributes->first, op_attribute_static); |
1647
|
|
|
|
|
|
|
|
1648
|
36412
|
|
|
|
|
|
int32_t is_init = 1; |
1649
|
36412
|
|
|
|
|
|
SPVM_OP_build_method_definition(compiler, op_method, op_method_name, op_void_type, NULL, op_list_attributes, op_block, NULL, is_init, 0); |
1650
|
|
|
|
|
|
|
|
1651
|
36412
|
|
|
|
|
|
return op_method; |
1652
|
|
|
|
|
|
|
} |
1653
|
|
|
|
|
|
|
|
1654
|
4670728
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_var(SPVM_COMPILER* compiler, SPVM_OP* op_var_name) { |
1655
|
|
|
|
|
|
|
|
1656
|
4670728
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_var_name); |
1657
|
|
|
|
|
|
|
|
1658
|
4670728
|
|
|
|
|
|
return op_var; |
1659
|
|
|
|
|
|
|
} |
1660
|
|
|
|
|
|
|
|
1661
|
2153
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_eval(SPVM_COMPILER* compiler, SPVM_OP* op_eval, SPVM_OP* op_eval_block) { |
1662
|
|
|
|
|
|
|
|
1663
|
2153
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_eval, op_eval->last, op_eval_block); |
1664
|
|
|
|
|
|
|
|
1665
|
|
|
|
|
|
|
// eval block |
1666
|
2153
|
|
|
|
|
|
op_eval_block->uv.block->id = SPVM_BLOCK_C_ID_EVAL; |
1667
|
|
|
|
|
|
|
|
1668
|
2153
|
|
|
|
|
|
return op_eval; |
1669
|
|
|
|
|
|
|
} |
1670
|
|
|
|
|
|
|
|
1671
|
1651
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_switch_statement(SPVM_COMPILER* compiler, SPVM_OP* op_switch, SPVM_OP* op_switch_operand, SPVM_OP* op_switch_block) { |
1672
|
|
|
|
|
|
|
|
1673
|
1651
|
|
|
|
|
|
SPVM_OP* op_switch_condition = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_SWITCH_CONDITION, op_switch_operand->file, op_switch_operand->line); |
1674
|
1651
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_switch_condition, op_switch_condition->last, op_switch_operand); |
1675
|
|
|
|
|
|
|
|
1676
|
1651
|
|
|
|
|
|
SPVM_OP* op_switch_condition_do_nothing = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_DO_NOTHING, op_switch_condition->file, op_switch_condition->line); |
1677
|
1651
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_switch_condition_do_nothing, op_switch_condition_do_nothing->last, op_switch_condition); |
1678
|
|
|
|
|
|
|
|
1679
|
1651
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_switch, op_switch->last, op_switch_condition_do_nothing); |
1680
|
1651
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_switch, op_switch->last, op_switch_block); |
1681
|
|
|
|
|
|
|
|
1682
|
1651
|
|
|
|
|
|
SPVM_SWITCH_INFO* switch_info = SPVM_SWITCH_INFO_new(compiler); |
1683
|
1651
|
|
|
|
|
|
op_switch->uv.switch_info = switch_info; |
1684
|
|
|
|
|
|
|
|
1685
|
1651
|
|
|
|
|
|
op_switch_condition->uv.switch_info = switch_info; |
1686
|
|
|
|
|
|
|
|
1687
|
1651
|
|
|
|
|
|
return op_switch; |
1688
|
|
|
|
|
|
|
} |
1689
|
|
|
|
|
|
|
|
1690
|
1651
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_switch_block(SPVM_COMPILER* compiler, SPVM_OP* op_switch_block, SPVM_OP* op_case_statements, SPVM_OP* op_default_statement) { |
1691
|
|
|
|
|
|
|
|
1692
|
1651
|
50
|
|
|
|
|
if (op_case_statements->id != SPVM_OP_C_ID_LIST) { |
1693
|
0
|
|
|
|
|
|
SPVM_OP* op_list = SPVM_OP_new_op_list(compiler, op_case_statements->file, op_case_statements->line); |
1694
|
0
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list, op_list->last, op_case_statements); |
1695
|
0
|
|
|
|
|
|
op_case_statements = op_list; |
1696
|
|
|
|
|
|
|
} |
1697
|
|
|
|
|
|
|
|
1698
|
1651
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_switch_block, op_switch_block->last, op_case_statements); |
1699
|
1651
|
100
|
|
|
|
|
if (op_default_statement) { |
1700
|
568
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_switch_block, op_switch_block->last, op_default_statement); |
1701
|
|
|
|
|
|
|
} |
1702
|
|
|
|
|
|
|
|
1703
|
1651
|
|
|
|
|
|
return op_switch_block; |
1704
|
|
|
|
|
|
|
} |
1705
|
|
|
|
|
|
|
|
1706
|
9575
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_case_statement(SPVM_COMPILER* compiler, SPVM_OP* op_case_info, SPVM_OP* op_case_operand, SPVM_OP* op_block) { |
1707
|
|
|
|
|
|
|
|
1708
|
9575
|
|
|
|
|
|
SPVM_CASE_INFO* case_info = SPVM_CASE_INFO_new(compiler); |
1709
|
|
|
|
|
|
|
|
1710
|
9575
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_case_info, op_case_info->last, op_case_operand); |
1711
|
|
|
|
|
|
|
|
1712
|
9575
|
100
|
|
|
|
|
if (op_block) { |
1713
|
7481
|
|
|
|
|
|
SPVM_OP* op_statements = op_block->first; |
1714
|
7481
|
50
|
|
|
|
|
if (op_statements) { |
1715
|
7481
|
|
|
|
|
|
SPVM_OP* op_last_statement = op_statements->last; |
1716
|
|
|
|
|
|
|
|
1717
|
|
|
|
|
|
|
// Add "break" statement if it doesn't exist |
1718
|
|
|
|
|
|
|
{ |
1719
|
|
|
|
|
|
|
// No statement |
1720
|
7481
|
50
|
|
|
|
|
if (!op_last_statement) { |
1721
|
0
|
|
|
|
|
|
SPVM_OP* op_break = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_BREAK, op_statements->file, op_statements->line); |
1722
|
0
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements, op_statements->last, op_break); |
1723
|
|
|
|
|
|
|
} |
1724
|
|
|
|
|
|
|
// The last statement is not "break" statement |
1725
|
7481
|
100
|
|
|
|
|
else if (op_last_statement->id != SPVM_OP_C_ID_BREAK) { |
1726
|
28
|
|
|
|
|
|
SPVM_OP* op_break = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_BREAK, op_last_statement->file, op_last_statement->line + 1); |
1727
|
28
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements, op_statements->last, op_break); |
1728
|
|
|
|
|
|
|
} |
1729
|
|
|
|
|
|
|
} |
1730
|
|
|
|
|
|
|
} |
1731
|
7481
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_case_info, op_case_info->last, op_block); |
1732
|
|
|
|
|
|
|
} |
1733
|
|
|
|
|
|
|
|
1734
|
9575
|
|
|
|
|
|
case_info->op_case_info = op_case_info; |
1735
|
|
|
|
|
|
|
|
1736
|
9575
|
|
|
|
|
|
op_case_info->uv.case_info = case_info; |
1737
|
|
|
|
|
|
|
|
1738
|
9575
|
|
|
|
|
|
return op_case_info; |
1739
|
|
|
|
|
|
|
} |
1740
|
|
|
|
|
|
|
|
1741
|
1630
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_default_statement(SPVM_COMPILER* compiler, SPVM_OP* op_default, SPVM_OP* op_block) { |
1742
|
|
|
|
|
|
|
|
1743
|
1630
|
100
|
|
|
|
|
if (op_block) { |
1744
|
1610
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_default, op_default->last, op_block); |
1745
|
|
|
|
|
|
|
} |
1746
|
|
|
|
|
|
|
|
1747
|
1630
|
|
|
|
|
|
return op_default; |
1748
|
|
|
|
|
|
|
} |
1749
|
|
|
|
|
|
|
|
1750
|
506018
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_condition(SPVM_COMPILER* compiler, SPVM_OP* op_condition_operand, int32_t is_not) { |
1751
|
|
|
|
|
|
|
// Condition |
1752
|
|
|
|
|
|
|
int32_t id; |
1753
|
506018
|
100
|
|
|
|
|
if (is_not) { |
1754
|
225775
|
|
|
|
|
|
id = SPVM_OP_C_ID_CONDITION_NOT; |
1755
|
|
|
|
|
|
|
} |
1756
|
|
|
|
|
|
|
else { |
1757
|
280243
|
|
|
|
|
|
id = SPVM_OP_C_ID_CONDITION; |
1758
|
|
|
|
|
|
|
} |
1759
|
506018
|
|
|
|
|
|
SPVM_OP* op_condition = SPVM_OP_new_op(compiler, id, op_condition_operand->file, op_condition_operand->line); |
1760
|
|
|
|
|
|
|
|
1761
|
506018
|
50
|
|
|
|
|
if (SPVM_OP_is_comparison_op(compiler, op_condition_operand)) { |
1762
|
0
|
0
|
|
|
|
|
assert(op_condition_operand->moresib == 0); |
1763
|
0
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_condition, op_condition->last, op_condition_operand); |
1764
|
|
|
|
|
|
|
} |
1765
|
|
|
|
|
|
|
else { |
1766
|
506018
|
|
|
|
|
|
SPVM_OP* op_assign_bool = SPVM_OP_new_op_assign_bool(compiler, op_condition_operand, op_condition_operand->file, op_condition_operand->line); |
1767
|
506018
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_condition, op_condition->last, op_assign_bool); |
1768
|
|
|
|
|
|
|
} |
1769
|
|
|
|
|
|
|
|
1770
|
506018
|
|
|
|
|
|
return op_condition; |
1771
|
|
|
|
|
|
|
} |
1772
|
|
|
|
|
|
|
|
1773
|
42609
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_for_statement(SPVM_COMPILER* compiler, SPVM_OP* op_for, SPVM_OP* op_init, SPVM_OP* op_condition_operand, SPVM_OP* op_increment, SPVM_OP* op_block_statements) { |
1774
|
|
|
|
|
|
|
|
1775
|
|
|
|
|
|
|
// Loop |
1776
|
42609
|
|
|
|
|
|
SPVM_OP* op_loop = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_LOOP, op_for->file, op_for->line); |
1777
|
|
|
|
|
|
|
|
1778
|
|
|
|
|
|
|
// Condition |
1779
|
42609
|
|
|
|
|
|
SPVM_OP* op_condition = SPVM_OP_build_condition(compiler, op_condition_operand, 1); |
1780
|
42609
|
|
|
|
|
|
op_condition->flag |= SPVM_OP_C_FLAG_CONDITION_LOOP; |
1781
|
|
|
|
|
|
|
|
1782
|
|
|
|
|
|
|
// Set block flag |
1783
|
42609
|
|
|
|
|
|
op_block_statements->uv.block->id = SPVM_BLOCK_C_ID_LOOP_STATEMENTS; |
1784
|
|
|
|
|
|
|
|
1785
|
|
|
|
|
|
|
// Outer block for initialize loop variable |
1786
|
42609
|
|
|
|
|
|
SPVM_OP* op_block_init = SPVM_OP_new_op_block(compiler, op_for->file, op_for->line); |
1787
|
42609
|
|
|
|
|
|
op_block_init->uv.block->id = SPVM_BLOCK_C_ID_LOOP_INIT; |
1788
|
|
|
|
|
|
|
|
1789
|
|
|
|
|
|
|
// Block for increment |
1790
|
42609
|
|
|
|
|
|
SPVM_OP* op_loop_increment = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_LOOP_INCREMENT, op_for->file, op_for->line); |
1791
|
|
|
|
|
|
|
|
1792
|
42609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_loop_increment, op_loop_increment->last, op_increment); |
1793
|
|
|
|
|
|
|
|
1794
|
42609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_init); |
1795
|
42609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_condition); |
1796
|
42609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_block_statements); |
1797
|
42609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_loop_increment); |
1798
|
|
|
|
|
|
|
|
1799
|
42609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_loop, op_loop->last, op_block_init); |
1800
|
|
|
|
|
|
|
|
1801
|
42609
|
|
|
|
|
|
return op_loop; |
1802
|
|
|
|
|
|
|
} |
1803
|
|
|
|
|
|
|
|
1804
|
536
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_foreach_statement(SPVM_COMPILER* compiler, SPVM_OP* op_for, SPVM_OP* op_var_element, SPVM_OP* op_array, SPVM_OP* op_block_statements) { |
1805
|
|
|
|
|
|
|
|
1806
|
|
|
|
|
|
|
/* |
1807
|
|
|
|
|
|
|
{ |
1808
|
|
|
|
|
|
|
|
1809
|
|
|
|
|
|
|
my $.array = $array; |
1810
|
|
|
|
|
|
|
my $.array_length = @$.array; |
1811
|
|
|
|
|
|
|
for (my $.i = 0; $.i < $.array_length; $.i++) { |
1812
|
|
|
|
|
|
|
my $element = $.array->[$.i]; |
1813
|
|
|
|
|
|
|
|
1814
|
|
|
|
|
|
|
# ... |
1815
|
|
|
|
|
|
|
} |
1816
|
|
|
|
|
|
|
} |
1817
|
|
|
|
|
|
|
*/ |
1818
|
|
|
|
|
|
|
|
1819
|
536
|
|
|
|
|
|
SPVM_OP* op_var_init_name = SPVM_OP_new_op_name_tmp_var(compiler, op_for->file, op_for->line); |
1820
|
536
|
|
|
|
|
|
SPVM_OP* op_var_init_orig = SPVM_OP_new_op_var(compiler, op_var_init_name); |
1821
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_name = SPVM_OP_new_op_name(compiler, "$.array", op_for->file, op_for->line); |
1822
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_orig = SPVM_OP_new_op_var(compiler, op_var_array_name); |
1823
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_length_name = SPVM_OP_new_op_name(compiler, "$.array_length", op_for->file, op_for->line); |
1824
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_length_orig = SPVM_OP_new_op_var(compiler, op_var_array_length_name); |
1825
|
|
|
|
|
|
|
|
1826
|
|
|
|
|
|
|
// my $.i |
1827
|
536
|
|
|
|
|
|
SPVM_OP* op_var_init_for_decl = SPVM_OP_clone_op_var(compiler, op_var_init_orig); |
1828
|
536
|
|
|
|
|
|
SPVM_OP* op_var_decl_init = SPVM_OP_new_op_var_decl(compiler, op_for->file, op_for->line); |
1829
|
536
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_decl_init, op_var_init_for_decl, NULL, NULL); |
1830
|
|
|
|
|
|
|
|
1831
|
|
|
|
|
|
|
// 0 |
1832
|
536
|
|
|
|
|
|
SPVM_OP* op_constant_zero = SPVM_OP_new_op_constant_int(compiler, 0, op_for->file, op_for->line); |
1833
|
|
|
|
|
|
|
|
1834
|
|
|
|
|
|
|
// my $.i = 0 |
1835
|
536
|
|
|
|
|
|
SPVM_OP* op_assign_init = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_for->file, op_for->line); |
1836
|
536
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_init, op_var_init_for_decl, op_constant_zero); |
1837
|
|
|
|
|
|
|
|
1838
|
|
|
|
|
|
|
// my $.array |
1839
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_for_assign = SPVM_OP_clone_op_var(compiler, op_var_array_orig); |
1840
|
536
|
|
|
|
|
|
SPVM_OP* op_var_decl_array = SPVM_OP_new_op_var_decl(compiler, op_for->file, op_for->line); |
1841
|
536
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_decl_array, op_var_array_for_assign, NULL, NULL); |
1842
|
|
|
|
|
|
|
|
1843
|
|
|
|
|
|
|
// my $.array = $array |
1844
|
536
|
|
|
|
|
|
SPVM_OP* op_assign_array = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_for->file, op_for->line); |
1845
|
536
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_array, op_var_array_for_assign, op_array); |
1846
|
|
|
|
|
|
|
|
1847
|
|
|
|
|
|
|
// @$.array |
1848
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_for_length = SPVM_OP_clone_op_var(compiler, op_var_array_orig); |
1849
|
536
|
|
|
|
|
|
SPVM_OP* op_array_length = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ARRAY_LENGTH, compiler->current_file, compiler->current_line); |
1850
|
536
|
|
|
|
|
|
SPVM_OP_build_array_length(compiler, op_array_length, op_var_array_for_length); |
1851
|
|
|
|
|
|
|
|
1852
|
|
|
|
|
|
|
// my $.array_length |
1853
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_length_for_assign = SPVM_OP_clone_op_var(compiler, op_var_array_length_orig); |
1854
|
536
|
|
|
|
|
|
SPVM_OP* op_var_decl_array_length = SPVM_OP_new_op_var_decl(compiler, op_for->file, op_for->line); |
1855
|
536
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_decl_array_length, op_var_array_length_for_assign, NULL, NULL); |
1856
|
|
|
|
|
|
|
|
1857
|
|
|
|
|
|
|
// my $.array_length = @$.array |
1858
|
536
|
|
|
|
|
|
SPVM_OP* op_assign_array_length = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_for->file, op_for->line); |
1859
|
536
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_array_length, op_var_array_length_for_assign, op_array_length); |
1860
|
|
|
|
|
|
|
|
1861
|
|
|
|
|
|
|
// $.i < $array_length |
1862
|
536
|
|
|
|
|
|
SPVM_OP* op_var_init_for_condition = SPVM_OP_clone_op_var(compiler, op_var_init_orig); |
1863
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_length_for_condition = SPVM_OP_clone_op_var(compiler, op_var_array_length_orig); |
1864
|
536
|
|
|
|
|
|
SPVM_OP* op_numlt = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NUMERIC_LT, op_for->file, op_for->line); |
1865
|
536
|
|
|
|
|
|
SPVM_OP* op_numlt_comparison = SPVM_OP_build_comparison_op(compiler, op_numlt, op_var_init_for_condition, op_var_array_length_for_condition); |
1866
|
|
|
|
|
|
|
|
1867
|
|
|
|
|
|
|
// $.array->[$.i] |
1868
|
536
|
|
|
|
|
|
SPVM_OP* op_var_init_for_array_access = SPVM_OP_clone_op_var(compiler, op_var_init_orig); |
1869
|
536
|
|
|
|
|
|
SPVM_OP* op_var_array_for_array_access = SPVM_OP_clone_op_var(compiler, op_var_array_orig); |
1870
|
536
|
|
|
|
|
|
SPVM_OP* op_array_access = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ARRAY_ACCESS, compiler->current_file, compiler->current_line); |
1871
|
536
|
|
|
|
|
|
op_array_access = SPVM_OP_build_array_access(compiler, op_array_access, op_var_array_for_array_access, op_var_init_for_array_access); |
1872
|
|
|
|
|
|
|
|
1873
|
|
|
|
|
|
|
// my $element = $.array->[$.i] |
1874
|
536
|
|
|
|
|
|
SPVM_OP* op_assign_element = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_for->file, op_for->line); |
1875
|
536
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_element, op_var_element, op_array_access); |
1876
|
|
|
|
|
|
|
|
1877
|
|
|
|
|
|
|
// $.i |
1878
|
536
|
|
|
|
|
|
SPVM_OP* op_var_init_for_increament = SPVM_OP_clone_op_var(compiler, op_var_init_orig); |
1879
|
|
|
|
|
|
|
|
1880
|
|
|
|
|
|
|
// ++$.i; |
1881
|
536
|
|
|
|
|
|
SPVM_OP* op_inc_increament = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_PRE_INC, op_for->file, op_for->line); |
1882
|
536
|
|
|
|
|
|
op_inc_increament = SPVM_OP_build_inc(compiler, op_inc_increament, op_var_init_for_increament); |
1883
|
|
|
|
|
|
|
|
1884
|
536
|
|
|
|
|
|
SPVM_OP* op_statements = op_block_statements->first; |
1885
|
536
|
50
|
|
|
|
|
if (!op_statements) { |
1886
|
0
|
|
|
|
|
|
op_statements = SPVM_OP_new_op_list(compiler, op_for->file, op_for->line); |
1887
|
0
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_statements, op_block_statements->first, op_statements); |
1888
|
|
|
|
|
|
|
} |
1889
|
536
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements, op_statements->first, op_assign_element); |
1890
|
|
|
|
|
|
|
|
1891
|
536
|
|
|
|
|
|
op_for = SPVM_OP_build_for_statement(compiler, op_for, op_assign_init, op_numlt_comparison, op_inc_increament, op_block_statements); |
1892
|
|
|
|
|
|
|
|
1893
|
536
|
|
|
|
|
|
SPVM_OP* op_block_new = SPVM_OP_new_op_block(compiler, op_for->file, op_for->line); |
1894
|
536
|
|
|
|
|
|
SPVM_OP* op_statements_new = SPVM_OP_new_op_list(compiler, op_for->file, op_for->line); |
1895
|
536
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_new, op_block_new->last, op_statements_new); |
1896
|
|
|
|
|
|
|
|
1897
|
536
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements_new, op_statements_new->last, op_assign_array); |
1898
|
536
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements_new, op_statements_new->last, op_assign_array_length); |
1899
|
536
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_statements_new, op_statements_new->last, op_for); |
1900
|
|
|
|
|
|
|
|
1901
|
536
|
|
|
|
|
|
return op_block_new; |
1902
|
|
|
|
|
|
|
} |
1903
|
|
|
|
|
|
|
|
1904
|
26172
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_while_statement(SPVM_COMPILER* compiler, SPVM_OP* op_while, SPVM_OP* op_while_operand, SPVM_OP* op_block_statements) { |
1905
|
|
|
|
|
|
|
|
1906
|
|
|
|
|
|
|
// Loop |
1907
|
26172
|
|
|
|
|
|
SPVM_OP* op_loop = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_LOOP, op_while->file, op_while->line); |
1908
|
|
|
|
|
|
|
|
1909
|
|
|
|
|
|
|
// Init statement. This is null. |
1910
|
26172
|
|
|
|
|
|
SPVM_OP* op_init = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_DO_NOTHING, op_while->file, op_while->line); |
1911
|
|
|
|
|
|
|
|
1912
|
|
|
|
|
|
|
// Condition |
1913
|
26172
|
50
|
|
|
|
|
assert(op_while_operand->moresib == 0); |
1914
|
26172
|
|
|
|
|
|
SPVM_OP* op_condition = SPVM_OP_build_condition(compiler, op_while_operand, 1); |
1915
|
26172
|
|
|
|
|
|
op_condition->flag |= SPVM_OP_C_FLAG_CONDITION_LOOP; |
1916
|
|
|
|
|
|
|
|
1917
|
|
|
|
|
|
|
// Set block flag |
1918
|
26172
|
|
|
|
|
|
op_block_statements->uv.block->id = SPVM_BLOCK_C_ID_LOOP_STATEMENTS; |
1919
|
|
|
|
|
|
|
|
1920
|
|
|
|
|
|
|
// Next value. This is null. |
1921
|
26172
|
|
|
|
|
|
SPVM_OP* op_increment = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_DO_NOTHING, op_while->file, op_while->line); |
1922
|
|
|
|
|
|
|
|
1923
|
26172
|
|
|
|
|
|
SPVM_OP* op_block_init = SPVM_OP_new_op_block(compiler, op_while->file, op_while->line); |
1924
|
26172
|
|
|
|
|
|
op_block_init->uv.block->id = SPVM_BLOCK_C_ID_LOOP_INIT; |
1925
|
|
|
|
|
|
|
|
1926
|
|
|
|
|
|
|
// Block for increment |
1927
|
26172
|
|
|
|
|
|
SPVM_OP* op_loop_increment = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_LOOP_INCREMENT, op_while->file, op_while->line); |
1928
|
26172
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_loop_increment, op_loop_increment->last, op_increment); |
1929
|
|
|
|
|
|
|
|
1930
|
26172
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_init); |
1931
|
26172
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_condition); |
1932
|
26172
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_block_statements); |
1933
|
26172
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_init, op_block_init->last, op_loop_increment); |
1934
|
|
|
|
|
|
|
|
1935
|
26172
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_loop, op_loop->last, op_block_init); |
1936
|
|
|
|
|
|
|
|
1937
|
26172
|
|
|
|
|
|
return op_loop; |
1938
|
|
|
|
|
|
|
} |
1939
|
|
|
|
|
|
|
|
1940
|
12
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_if_require_statement(SPVM_COMPILER* compiler, SPVM_OP* op_if_require, SPVM_OP* op_use, SPVM_OP* op_block_true, SPVM_OP* op_block_false) { |
1941
|
|
|
|
|
|
|
|
1942
|
12
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_if_require, op_if_require->last, op_use); |
1943
|
12
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_if_require, op_if_require->last, op_block_true); |
1944
|
12
|
100
|
|
|
|
|
if (!op_block_false) { |
1945
|
8
|
|
|
|
|
|
op_block_false = SPVM_OP_new_op_block(compiler, op_block_true->file, op_block_true->line); |
1946
|
|
|
|
|
|
|
} |
1947
|
12
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_if_require, op_if_require->last, op_block_false); |
1948
|
|
|
|
|
|
|
|
1949
|
12
|
|
|
|
|
|
return op_if_require; |
1950
|
|
|
|
|
|
|
} |
1951
|
|
|
|
|
|
|
|
1952
|
437237
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_if_statement(SPVM_COMPILER* compiler, SPVM_OP* op_if, SPVM_OP* op_if_operand, SPVM_OP* op_block_true, SPVM_OP* op_block_false, int32_t no_scope) { |
1953
|
|
|
|
|
|
|
|
1954
|
|
|
|
|
|
|
// ELSIF is same as IF |
1955
|
437237
|
|
|
|
|
|
int32_t not_condition = 0; |
1956
|
|
|
|
|
|
|
|
1957
|
437237
|
100
|
|
|
|
|
if (op_if->id == SPVM_OP_C_ID_UNLESS) { |
1958
|
156994
|
|
|
|
|
|
op_if->id = SPVM_OP_C_ID_IF; |
1959
|
156994
|
|
|
|
|
|
not_condition = 1; |
1960
|
|
|
|
|
|
|
} |
1961
|
280243
|
100
|
|
|
|
|
else if (op_if->id == SPVM_OP_C_ID_ELSIF) { |
1962
|
25232
|
|
|
|
|
|
op_if->id = SPVM_OP_C_ID_IF; |
1963
|
|
|
|
|
|
|
} |
1964
|
|
|
|
|
|
|
|
1965
|
|
|
|
|
|
|
// Condition |
1966
|
437237
|
|
|
|
|
|
SPVM_OP* op_condition = SPVM_OP_build_condition(compiler, op_if_operand, not_condition); |
1967
|
437237
|
|
|
|
|
|
op_condition->flag |= SPVM_OP_C_FLAG_CONDITION_IF; |
1968
|
|
|
|
|
|
|
|
1969
|
|
|
|
|
|
|
// Create true block if needed |
1970
|
437237
|
100
|
|
|
|
|
if (op_block_true->id != SPVM_OP_C_ID_BLOCK) { |
1971
|
116183
|
|
|
|
|
|
SPVM_OP* op_not_block = op_block_true; |
1972
|
|
|
|
|
|
|
|
1973
|
116183
|
|
|
|
|
|
op_block_true = SPVM_OP_new_op_block(compiler, op_not_block->file, op_not_block->line); |
1974
|
116183
|
|
|
|
|
|
SPVM_OP* op_list = SPVM_OP_new_op_list(compiler, op_not_block->file, op_not_block->line); |
1975
|
116183
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list, op_list->last, op_not_block); |
1976
|
116183
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_true, op_block_true->last, op_list); |
1977
|
|
|
|
|
|
|
} |
1978
|
437237
|
|
|
|
|
|
op_block_true->uv.block->id = SPVM_BLOCK_C_ID_IF; |
1979
|
437237
|
|
|
|
|
|
op_block_true->uv.block->no_scope = no_scope; |
1980
|
|
|
|
|
|
|
|
1981
|
|
|
|
|
|
|
// Create false block if needed |
1982
|
437237
|
100
|
|
|
|
|
if (op_block_false->id != SPVM_OP_C_ID_BLOCK) { |
1983
|
390005
|
|
|
|
|
|
SPVM_OP* op_not_block = op_block_false; |
1984
|
|
|
|
|
|
|
|
1985
|
|
|
|
|
|
|
// Create block |
1986
|
390005
|
|
|
|
|
|
op_block_false = SPVM_OP_new_op_block(compiler, op_not_block->file, op_not_block->line); |
1987
|
390005
|
|
|
|
|
|
SPVM_OP* op_list = SPVM_OP_new_op_list(compiler, op_not_block->file, op_not_block->line); |
1988
|
390005
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list, op_list->last, op_not_block); |
1989
|
390005
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_block_false, op_block_false->last, op_list); |
1990
|
|
|
|
|
|
|
} |
1991
|
437237
|
|
|
|
|
|
op_block_false->uv.block->id = SPVM_BLOCK_C_ID_ELSE; |
1992
|
437237
|
|
|
|
|
|
op_block_false->uv.block->no_scope = no_scope; |
1993
|
|
|
|
|
|
|
|
1994
|
437237
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_if, op_if->last, op_condition); |
1995
|
437237
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_if, op_if->last, op_block_true); |
1996
|
437237
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_if, op_if->last, op_block_false); |
1997
|
|
|
|
|
|
|
|
1998
|
437237
|
|
|
|
|
|
return op_if; |
1999
|
|
|
|
|
|
|
} |
2000
|
|
|
|
|
|
|
|
2001
|
55846
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_array_length(SPVM_COMPILER* compiler, SPVM_OP* op_array_length, SPVM_OP* op_length) { |
2002
|
|
|
|
|
|
|
|
2003
|
55846
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_array_length, op_array_length->last, op_length); |
2004
|
|
|
|
|
|
|
|
2005
|
55846
|
|
|
|
|
|
return op_array_length; |
2006
|
|
|
|
|
|
|
} |
2007
|
|
|
|
|
|
|
|
2008
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_string_length(SPVM_COMPILER* compiler, SPVM_OP* op_string_length, SPVM_OP* op_length) { |
2009
|
|
|
|
|
|
|
|
2010
|
0
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_string_length, op_string_length->last, op_length); |
2011
|
|
|
|
|
|
|
|
2012
|
0
|
|
|
|
|
|
return op_string_length; |
2013
|
|
|
|
|
|
|
} |
2014
|
|
|
|
|
|
|
|
2015
|
56087
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_new(SPVM_COMPILER* compiler, SPVM_OP* op_new, SPVM_OP* op_type, SPVM_OP* op_length) { |
2016
|
|
|
|
|
|
|
|
2017
|
56087
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_new, op_new->last, op_type); |
2018
|
|
|
|
|
|
|
|
2019
|
56087
|
100
|
|
|
|
|
if (op_length) { |
2020
|
29920
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_new, op_new->last, op_length); |
2021
|
|
|
|
|
|
|
} |
2022
|
|
|
|
|
|
|
|
2023
|
56087
|
100
|
|
|
|
|
if (op_type->id == SPVM_OP_C_ID_TYPE) { |
2024
|
47548
|
|
|
|
|
|
op_type->uv.type->resolved_in_ast = 1; |
2025
|
|
|
|
|
|
|
} |
2026
|
|
|
|
|
|
|
|
2027
|
56087
|
100
|
|
|
|
|
if (op_type->id == SPVM_OP_C_ID_TYPE && strstr(op_type->uv.type->unresolved_basic_type_name, "::anon::")) { |
|
|
100
|
|
|
|
|
|
2028
|
|
|
|
|
|
|
|
2029
|
8093
|
|
|
|
|
|
const char* anon_basic_type_name = op_type->uv.type->unresolved_basic_type_name; |
2030
|
8093
|
|
|
|
|
|
SPVM_BASIC_TYPE* anon_basic_type = SPVM_HASH_get(compiler->basic_type_symtable, anon_basic_type_name, strlen(anon_basic_type_name)); |
2031
|
|
|
|
|
|
|
|
2032
|
|
|
|
|
|
|
// Anon method |
2033
|
8093
|
|
|
|
|
|
SPVM_METHOD* anon_method = SPVM_LIST_get(anon_basic_type->methods, 0); |
2034
|
8093
|
100
|
|
|
|
|
if (anon_method->anon_method_fields->length) { |
2035
|
|
|
|
|
|
|
// [Before] |
2036
|
|
|
|
|
|
|
// new Foo::anon::Line::Column |
2037
|
|
|
|
|
|
|
|
2038
|
|
|
|
|
|
|
// [After] |
2039
|
|
|
|
|
|
|
//( |
2040
|
|
|
|
|
|
|
// my $invocant = new Foo::anon::Line::Column, |
2041
|
|
|
|
|
|
|
// $invocant->{FIELD_NAME0} = DEFAULT0, |
2042
|
|
|
|
|
|
|
// $invocant->{FIELD_NAME1} = DEFAULT1, |
2043
|
|
|
|
|
|
|
// $invocant, |
2044
|
|
|
|
|
|
|
//) |
2045
|
|
|
|
|
|
|
|
2046
|
22
|
|
|
|
|
|
SPVM_OP* op_sequence = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_SEQUENCE, op_new->file, op_new->line); |
2047
|
|
|
|
|
|
|
|
2048
|
|
|
|
|
|
|
// my $invocant = new TYPE; |
2049
|
22
|
|
|
|
|
|
SPVM_OP* op_assign_new = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_new->file, op_new->line); |
2050
|
22
|
|
|
|
|
|
SPVM_OP* op_var_invocant_new_name = SPVM_OP_new_op_name_tmp_var(compiler, op_new->file, op_new->line); |
2051
|
22
|
|
|
|
|
|
SPVM_OP* op_var_invocant_new = SPVM_OP_new_op_var(compiler, op_var_invocant_new_name); |
2052
|
22
|
|
|
|
|
|
SPVM_OP* op_var_decl_invocant_new = SPVM_OP_new_op_var_decl_arg(compiler, op_new->file, op_new->line); |
2053
|
22
|
|
|
|
|
|
op_var_invocant_new = SPVM_OP_build_var_decl(compiler, op_var_decl_invocant_new, op_var_invocant_new, NULL, NULL); |
2054
|
22
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_new, op_var_invocant_new, op_new); |
2055
|
22
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_new); |
2056
|
|
|
|
|
|
|
|
2057
|
57
|
100
|
|
|
|
|
for (int32_t caputre_index = 0; caputre_index < anon_method->anon_method_fields->length; caputre_index++) { |
2058
|
35
|
|
|
|
|
|
SPVM_FIELD* anon_method_field = SPVM_LIST_get(anon_method->anon_method_fields, caputre_index); |
2059
|
35
|
|
|
|
|
|
const char* anon_method_field_name = anon_method_field->name; |
2060
|
35
|
|
|
|
|
|
SPVM_OP* op_anon_method_field_default = anon_method_field->op_anon_method_field_default; |
2061
|
|
|
|
|
|
|
|
2062
|
|
|
|
|
|
|
// $invocant->{FIELD_NAME} = DEFAULT |
2063
|
35
|
100
|
|
|
|
|
if (op_anon_method_field_default) { |
2064
|
|
|
|
|
|
|
// |
2065
|
27
|
|
|
|
|
|
SPVM_OP* op_invocant_set_field = SPVM_OP_clone_op_var(compiler, op_var_invocant_new); |
2066
|
27
|
|
|
|
|
|
SPVM_OP* op_name_field = SPVM_OP_new_op_name(compiler, anon_method_field->name, op_new->file, op_new->line); |
2067
|
27
|
|
|
|
|
|
SPVM_OP* op_field_access = SPVM_OP_new_op_field_access(compiler, op_new->file, op_new->line); |
2068
|
27
|
|
|
|
|
|
SPVM_OP_build_field_access(compiler, op_field_access, op_invocant_set_field, op_name_field); |
2069
|
27
|
|
|
|
|
|
SPVM_OP* op_assign_field_access = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_new->file, op_new->line); |
2070
|
27
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_field_access, op_field_access, op_anon_method_field_default); |
2071
|
27
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_field_access); |
2072
|
|
|
|
|
|
|
} |
2073
|
|
|
|
|
|
|
} |
2074
|
|
|
|
|
|
|
|
2075
|
|
|
|
|
|
|
// $invocant |
2076
|
22
|
|
|
|
|
|
SPVM_OP* op_var_invocant_ret = SPVM_OP_clone_op_var(compiler, op_var_invocant_new); |
2077
|
22
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_var_invocant_ret); |
2078
|
|
|
|
|
|
|
|
2079
|
22
|
|
|
|
|
|
op_new = op_sequence; |
2080
|
|
|
|
|
|
|
} |
2081
|
|
|
|
|
|
|
} |
2082
|
|
|
|
|
|
|
|
2083
|
56087
|
|
|
|
|
|
return op_new; |
2084
|
|
|
|
|
|
|
} |
2085
|
|
|
|
|
|
|
|
2086
|
8592
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_array_init(SPVM_COMPILER* compiler, SPVM_OP* op_array_init, SPVM_OP* op_list_elements, int32_t is_key_value_pairs) { |
2087
|
|
|
|
|
|
|
|
2088
|
|
|
|
|
|
|
// Array length |
2089
|
8592
|
|
|
|
|
|
int32_t length = 0; |
2090
|
|
|
|
|
|
|
{ |
2091
|
8592
|
|
|
|
|
|
SPVM_OP* op_element = op_list_elements->first; |
2092
|
8592
|
|
|
|
|
|
int32_t index = 0; |
2093
|
25629
|
100
|
|
|
|
|
while ((op_element = SPVM_OP_sibling(compiler, op_element))) { |
2094
|
17037
|
|
|
|
|
|
length++; |
2095
|
|
|
|
|
|
|
} |
2096
|
|
|
|
|
|
|
} |
2097
|
|
|
|
|
|
|
|
2098
|
8592
|
100
|
|
|
|
|
if (is_key_value_pairs && length % 2 != 0) { |
|
|
100
|
|
|
|
|
|
2099
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The lenght of the elements in {} of the array initialization must be an even number.\n at %s line %d", op_list_elements->file, op_list_elements->line); |
2100
|
1
|
|
|
|
|
|
return op_array_init; |
2101
|
|
|
|
|
|
|
} |
2102
|
|
|
|
|
|
|
|
2103
|
8591
|
|
|
|
|
|
SPVM_OP* op_constant_length = SPVM_OP_new_op_constant_int(compiler, length, op_array_init->file, op_array_init->line); |
2104
|
8591
|
|
|
|
|
|
SPVM_OP* op_new = NULL; |
2105
|
8591
|
100
|
|
|
|
|
if (length == 0) { |
2106
|
51
|
|
|
|
|
|
op_new = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NEW, op_array_init->file, op_array_init->line); |
2107
|
51
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_any_object_array_type(compiler, op_array_init->file, op_array_init->line); |
2108
|
51
|
|
|
|
|
|
SPVM_OP_build_new(compiler, op_new, op_type, op_constant_length); |
2109
|
51
|
|
|
|
|
|
op_array_init = op_new; |
2110
|
|
|
|
|
|
|
} |
2111
|
8540
|
50
|
|
|
|
|
else if (length > 0) { |
2112
|
|
|
|
|
|
|
{ |
2113
|
8540
|
|
|
|
|
|
SPVM_OP* op_pushmark = op_list_elements->first; |
2114
|
8540
|
|
|
|
|
|
SPVM_OP* op_first_element = SPVM_OP_sibling(compiler, op_pushmark); |
2115
|
8540
|
100
|
|
|
|
|
if (op_first_element->id == SPVM_OP_C_ID_UNDEF) { |
2116
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The first element in the array initialization must be defined.\n at %s line %d", op_array_init->file, op_array_init->line); |
2117
|
1
|
|
|
|
|
|
return op_array_init; |
2118
|
|
|
|
|
|
|
} |
2119
|
|
|
|
|
|
|
} |
2120
|
|
|
|
|
|
|
|
2121
|
8539
|
100
|
|
|
|
|
if (is_key_value_pairs) { |
2122
|
555
|
|
|
|
|
|
SPVM_OP* op_pushmark = op_list_elements->first; |
2123
|
555
|
|
|
|
|
|
SPVM_OP* op_first_element = SPVM_OP_sibling(compiler, op_pushmark); |
2124
|
555
|
50
|
|
|
|
|
if (is_key_value_pairs) { |
2125
|
555
|
|
|
|
|
|
SPVM_OP* op_type_cast = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_TYPE_CAST, op_array_init->file, op_array_init->line); |
2126
|
555
|
|
|
|
|
|
SPVM_OP* op_type_for_cast = SPVM_OP_new_op_any_object_type(compiler, op_array_init->file, op_array_init->line); |
2127
|
555
|
|
|
|
|
|
SPVM_OP* op_stab = SPVM_OP_cut_op(compiler, op_first_element); |
2128
|
555
|
|
|
|
|
|
SPVM_OP_build_type_cast(compiler, op_type_cast, op_type_for_cast, op_first_element, NULL); |
2129
|
555
|
|
|
|
|
|
SPVM_OP_replace_op(compiler, op_stab, op_type_cast); |
2130
|
|
|
|
|
|
|
} |
2131
|
|
|
|
|
|
|
} |
2132
|
|
|
|
|
|
|
|
2133
|
8539
|
|
|
|
|
|
SPVM_OP* op_pushmark = op_list_elements->first; |
2134
|
8539
|
|
|
|
|
|
SPVM_OP* op_first_element = SPVM_OP_sibling(compiler, op_pushmark); |
2135
|
|
|
|
|
|
|
|
2136
|
8539
|
|
|
|
|
|
SPVM_OP* op_sequence = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_SEQUENCE, op_array_init->file, op_array_init->line); |
2137
|
|
|
|
|
|
|
|
2138
|
|
|
|
|
|
|
// my $first_element = FIRST_ELEMENT; |
2139
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_first_element_name = SPVM_OP_new_op_name_tmp_var(compiler, op_array_init->file, op_array_init->line); |
2140
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_first_element = SPVM_OP_new_op_var(compiler, op_var_first_element_name); |
2141
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_decl_first_element = SPVM_OP_new_op_var_decl_arg(compiler, op_array_init->file, op_array_init->line); |
2142
|
8539
|
|
|
|
|
|
op_var_first_element = SPVM_OP_build_var_decl(compiler, op_var_decl_first_element, op_var_first_element, NULL, NULL); |
2143
|
8539
|
|
|
|
|
|
SPVM_OP* op_assign_first_element = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_array_init->file, op_array_init->line); |
2144
|
8539
|
|
|
|
|
|
SPVM_OP_cut_op(compiler, op_first_element); |
2145
|
8539
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_first_element, op_var_first_element, op_first_element); |
2146
|
8539
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_first_element); |
2147
|
|
|
|
|
|
|
|
2148
|
|
|
|
|
|
|
// my $array = new $first_element; |
2149
|
8539
|
|
|
|
|
|
op_new = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NEW, op_array_init->file, op_array_init->line); |
2150
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_first_element_new = SPVM_OP_clone_op_var(compiler, op_var_first_element); |
2151
|
8539
|
|
|
|
|
|
op_new = SPVM_OP_build_new(compiler, op_new, op_var_first_element_new, op_constant_length); |
2152
|
8539
|
|
|
|
|
|
SPVM_OP* op_assign_new = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_array_init->file, op_array_init->line); |
2153
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_array_new_name = SPVM_OP_new_op_name_tmp_var(compiler, op_array_init->file, op_array_init->line); |
2154
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_array_new = SPVM_OP_new_op_var(compiler, op_var_array_new_name); |
2155
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_decl_array_new = SPVM_OP_new_op_var_decl_arg(compiler, op_array_init->file, op_array_init->line); |
2156
|
8539
|
|
|
|
|
|
op_var_array_new = SPVM_OP_build_var_decl(compiler, op_var_decl_array_new, op_var_array_new, NULL, NULL); |
2157
|
8539
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_new, op_var_array_new, op_new); |
2158
|
8539
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_new); |
2159
|
|
|
|
|
|
|
|
2160
|
|
|
|
|
|
|
{ |
2161
|
8539
|
|
|
|
|
|
int32_t index = 0; |
2162
|
8539
|
|
|
|
|
|
SPVM_OP* op_element = op_list_elements->first; |
2163
|
25572
|
100
|
|
|
|
|
while ((op_element = SPVM_OP_sibling(compiler, op_element))) { |
2164
|
17033
|
|
|
|
|
|
SPVM_OP* op_assign_array_access = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_array_init->file, op_array_init->line); |
2165
|
17033
|
|
|
|
|
|
SPVM_OP* op_array_access = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ARRAY_ACCESS, op_array_init->file, op_array_init->line); |
2166
|
17033
|
|
|
|
|
|
SPVM_OP* op_var_array_set = SPVM_OP_clone_op_var(compiler, op_var_array_new); |
2167
|
17033
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_array_access, op_array_access->last, op_var_array_set); |
2168
|
17033
|
|
|
|
|
|
SPVM_OP* op_constant_index = SPVM_OP_new_op_constant_int(compiler, index, op_array_init->file, op_array_init->line); |
2169
|
17033
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_array_access, op_array_access->last, op_constant_index); |
2170
|
|
|
|
|
|
|
|
2171
|
17033
|
100
|
|
|
|
|
if (index == 0) { |
2172
|
|
|
|
|
|
|
// $array->[0] = $first_element; |
2173
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_first_element_array_set = SPVM_OP_clone_op_var(compiler, op_var_first_element); |
2174
|
8539
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_array_access, op_array_access, op_var_first_element_array_set); |
2175
|
|
|
|
|
|
|
} |
2176
|
|
|
|
|
|
|
else { |
2177
|
|
|
|
|
|
|
// $array->[$i] = ELEMENT |
2178
|
8494
|
|
|
|
|
|
SPVM_OP* op_stab = SPVM_OP_cut_op(compiler, op_element); |
2179
|
8494
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_array_access, op_array_access, op_element); |
2180
|
8494
|
|
|
|
|
|
op_element = op_stab; |
2181
|
|
|
|
|
|
|
} |
2182
|
|
|
|
|
|
|
|
2183
|
17033
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_array_access); |
2184
|
|
|
|
|
|
|
|
2185
|
17033
|
|
|
|
|
|
index++; |
2186
|
|
|
|
|
|
|
} |
2187
|
|
|
|
|
|
|
} |
2188
|
|
|
|
|
|
|
|
2189
|
|
|
|
|
|
|
// $array |
2190
|
8539
|
|
|
|
|
|
SPVM_OP* op_var_array_ret = SPVM_OP_clone_op_var(compiler, op_var_array_new); |
2191
|
8539
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_var_array_ret); |
2192
|
|
|
|
|
|
|
|
2193
|
8539
|
|
|
|
|
|
op_array_init = op_sequence; |
2194
|
|
|
|
|
|
|
} |
2195
|
|
|
|
|
|
|
|
2196
|
8590
|
|
|
|
|
|
return op_array_init; |
2197
|
|
|
|
|
|
|
} |
2198
|
|
|
|
|
|
|
|
2199
|
164058
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_array_access(SPVM_COMPILER* compiler, SPVM_OP* op_array_access, SPVM_OP* op_array, SPVM_OP* op_index) { |
2200
|
|
|
|
|
|
|
|
2201
|
164058
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_array_access, op_array_access->last, op_array); |
2202
|
164058
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_array_access, op_array_access->last, op_index); |
2203
|
|
|
|
|
|
|
|
2204
|
164058
|
|
|
|
|
|
return op_array_access; |
2205
|
|
|
|
|
|
|
} |
2206
|
|
|
|
|
|
|
|
2207
|
186836
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_field_access(SPVM_COMPILER* compiler, SPVM_OP* op_field_access, SPVM_OP* op_invocant, SPVM_OP* op_name_field) { |
2208
|
|
|
|
|
|
|
|
2209
|
186836
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_field_access, op_field_access->last, op_invocant); |
2210
|
|
|
|
|
|
|
|
2211
|
186836
|
|
|
|
|
|
SPVM_FIELD_ACCESS* field_access = op_field_access->uv.field_access; |
2212
|
|
|
|
|
|
|
|
2213
|
186836
|
|
|
|
|
|
field_access->op_name = op_name_field; |
2214
|
|
|
|
|
|
|
|
2215
|
186836
|
|
|
|
|
|
return op_field_access; |
2216
|
|
|
|
|
|
|
} |
2217
|
|
|
|
|
|
|
|
2218
|
19
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_can(SPVM_COMPILER* compiler, SPVM_OP* op_can, SPVM_OP* op_var, SPVM_OP* op_name) { |
2219
|
|
|
|
|
|
|
|
2220
|
19
|
100
|
|
|
|
|
if (op_name->id == SPVM_OP_C_ID_CONSTANT) { |
2221
|
4
|
|
|
|
|
|
SPVM_OP* op_constant = op_name; |
2222
|
4
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
2223
|
4
|
|
|
|
|
|
SPVM_TYPE* constant_type = constant->type; |
2224
|
4
|
|
|
|
|
|
const char* constant_chars = (const char*)constant->value.oval; |
2225
|
4
|
|
|
|
|
|
int32_t is_empty_string = 0; |
2226
|
4
|
50
|
|
|
|
|
if (SPVM_TYPE_is_string_type(compiler, constant_type->basic_type->id, constant_type->dimension, constant_type->flag)) { |
2227
|
4
|
100
|
|
|
|
|
if (strcmp(constant_chars, "") == 0) { |
2228
|
3
|
|
|
|
|
|
is_empty_string = 1; |
2229
|
|
|
|
|
|
|
} |
2230
|
|
|
|
|
|
|
} |
2231
|
|
|
|
|
|
|
|
2232
|
4
|
100
|
|
|
|
|
if (!is_empty_string) { |
2233
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "If the right operand of the can operator is a constant value, it must be an empty string \"\".\n at %s line %d", op_name->file, op_name->line); |
2234
|
|
|
|
|
|
|
} |
2235
|
|
|
|
|
|
|
|
2236
|
4
|
|
|
|
|
|
op_name = SPVM_OP_new_op_name(compiler, "", op_name->file, op_name->line); |
2237
|
|
|
|
|
|
|
} |
2238
|
|
|
|
|
|
|
|
2239
|
19
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_can, op_can->last, op_var); |
2240
|
19
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_can, op_can->last, op_name); |
2241
|
|
|
|
|
|
|
|
2242
|
19
|
|
|
|
|
|
SPVM_OP* op_name_var_condition = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_var->file, op_var->line); |
2243
|
19
|
|
|
|
|
|
SPVM_OP* op_var_condition = SPVM_OP_new_op_var(compiler, op_name_var_condition); |
2244
|
19
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_var->file, op_var->line); |
2245
|
19
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var_condition, op_can); |
2246
|
|
|
|
|
|
|
|
2247
|
19
|
|
|
|
|
|
return op_assign; |
2248
|
|
|
|
|
|
|
} |
2249
|
|
|
|
|
|
|
|
2250
|
1057
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_is_read_only(SPVM_COMPILER* compiler, SPVM_OP* op_is_read_only, SPVM_OP* op_operand) { |
2251
|
|
|
|
|
|
|
|
2252
|
1057
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_is_read_only, op_is_read_only->last, op_operand); |
2253
|
|
|
|
|
|
|
|
2254
|
1057
|
|
|
|
|
|
SPVM_OP* op_name_var_condition = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_operand->file, op_operand->line); |
2255
|
1057
|
|
|
|
|
|
SPVM_OP* op_var_condition = SPVM_OP_new_op_var(compiler, op_name_var_condition); |
2256
|
1057
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_operand->file, op_operand->line); |
2257
|
1057
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var_condition, op_is_read_only); |
2258
|
|
|
|
|
|
|
|
2259
|
1057
|
|
|
|
|
|
return op_assign; |
2260
|
|
|
|
|
|
|
} |
2261
|
|
|
|
|
|
|
|
2262
|
45
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_weaken_field(SPVM_COMPILER* compiler, SPVM_OP* op_weaken, SPVM_OP* op_field_access) { |
2263
|
|
|
|
|
|
|
|
2264
|
45
|
|
|
|
|
|
SPVM_OP* op_weaken_field = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_WEAKEN_FIELD, op_weaken->file, op_weaken->line); |
2265
|
45
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_weaken_field, op_weaken_field->last, op_field_access); |
2266
|
|
|
|
|
|
|
|
2267
|
45
|
|
|
|
|
|
op_field_access->flag |= SPVM_OP_C_FLAG_FIELD_ACCESS_WEAKEN; |
2268
|
|
|
|
|
|
|
|
2269
|
45
|
|
|
|
|
|
return op_weaken_field; |
2270
|
|
|
|
|
|
|
} |
2271
|
|
|
|
|
|
|
|
2272
|
4
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_unweaken_field(SPVM_COMPILER* compiler, SPVM_OP* op_unweaken, SPVM_OP* op_field_access) { |
2273
|
|
|
|
|
|
|
|
2274
|
4
|
|
|
|
|
|
SPVM_OP* op_unweaken_field = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_UNWEAKEN_FIELD, op_unweaken->file, op_unweaken->line); |
2275
|
4
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_unweaken_field, op_unweaken_field->last, op_field_access); |
2276
|
|
|
|
|
|
|
|
2277
|
4
|
|
|
|
|
|
op_field_access->flag |= SPVM_OP_C_FLAG_FIELD_ACCESS_UNWEAKEN; |
2278
|
|
|
|
|
|
|
|
2279
|
4
|
|
|
|
|
|
return op_unweaken_field; |
2280
|
|
|
|
|
|
|
} |
2281
|
|
|
|
|
|
|
|
2282
|
8
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_isweak_field(SPVM_COMPILER* compiler, SPVM_OP* op_isweak, SPVM_OP* op_field_access) { |
2283
|
|
|
|
|
|
|
|
2284
|
8
|
|
|
|
|
|
SPVM_OP* op_isweak_field = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ISWEAK_FIELD, op_isweak->file, op_isweak->line); |
2285
|
8
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_isweak_field, op_isweak_field->last, op_field_access); |
2286
|
8
|
|
|
|
|
|
op_field_access->flag |= SPVM_OP_C_FLAG_FIELD_ACCESS_ISWEAK; |
2287
|
|
|
|
|
|
|
|
2288
|
8
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_field_access->file, op_field_access->line); |
2289
|
8
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
2290
|
8
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_field_access->file, op_field_access->line); |
2291
|
8
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var, op_field_access); |
2292
|
|
|
|
|
|
|
|
2293
|
8
|
|
|
|
|
|
return op_assign; |
2294
|
|
|
|
|
|
|
} |
2295
|
|
|
|
|
|
|
|
2296
|
154837
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_type_cast(SPVM_COMPILER* compiler, SPVM_OP* op_type_cast, SPVM_OP* op_type, SPVM_OP* op_operand, SPVM_OP* op_attributes) { |
2297
|
|
|
|
|
|
|
|
2298
|
154837
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_type_cast, op_type_cast->last, op_operand); |
2299
|
154837
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_type_cast, op_type_cast->last, op_type); |
2300
|
|
|
|
|
|
|
|
2301
|
154837
|
|
|
|
|
|
op_type_cast->file = op_type->file; |
2302
|
154837
|
|
|
|
|
|
op_type_cast->line = op_type->line; |
2303
|
|
|
|
|
|
|
|
2304
|
154837
|
|
|
|
|
|
return op_type_cast; |
2305
|
|
|
|
|
|
|
} |
2306
|
|
|
|
|
|
|
|
2307
|
1394
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_implement(SPVM_COMPILER* compiler, SPVM_OP* op_interface, SPVM_OP* op_type) { |
2308
|
|
|
|
|
|
|
|
2309
|
1394
|
|
|
|
|
|
SPVM_INTERFACE* interface = SPVM_INTERFACE_new(compiler); |
2310
|
1394
|
|
|
|
|
|
op_interface->uv.interface = interface; |
2311
|
1394
|
|
|
|
|
|
interface->op_interface = op_interface; |
2312
|
1394
|
|
|
|
|
|
interface->op_type = op_type; |
2313
|
|
|
|
|
|
|
|
2314
|
|
|
|
|
|
|
// add use stack |
2315
|
1394
|
|
|
|
|
|
SPVM_OP* op_use = SPVM_OP_new_op_use(compiler, op_interface->file, op_interface->line); |
2316
|
1394
|
|
|
|
|
|
SPVM_OP* op_name_alias = NULL; |
2317
|
1394
|
|
|
|
|
|
int32_t is_require = 0; |
2318
|
1394
|
|
|
|
|
|
SPVM_OP_build_use(compiler, op_use, op_type, op_name_alias, is_require); |
2319
|
|
|
|
|
|
|
|
2320
|
1394
|
|
|
|
|
|
return op_interface; |
2321
|
|
|
|
|
|
|
} |
2322
|
|
|
|
|
|
|
|
2323
|
2834406
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_var_decl(SPVM_COMPILER* compiler, SPVM_OP* op_var_decl, SPVM_OP* op_var, SPVM_OP* op_type, SPVM_OP* op_attributes) { |
2324
|
|
|
|
|
|
|
|
2325
|
|
|
|
|
|
|
// Declaration |
2326
|
2834406
|
|
|
|
|
|
op_var->uv.var->is_declaration = 1; |
2327
|
|
|
|
|
|
|
|
2328
|
|
|
|
|
|
|
// Create var_decl var information |
2329
|
2834406
|
|
|
|
|
|
SPVM_VAR_DECL* var_decl = op_var_decl->uv.var_decl; |
2330
|
2834406
|
100
|
|
|
|
|
if (op_type) { |
2331
|
2353668
|
|
|
|
|
|
var_decl->type = op_type->uv.type; |
2332
|
2353668
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_var, op_var->last, op_type); |
2333
|
2353668
|
|
|
|
|
|
op_type->uv.type->resolved_in_ast = 1; |
2334
|
|
|
|
|
|
|
} |
2335
|
|
|
|
|
|
|
|
2336
|
|
|
|
|
|
|
// Name OP |
2337
|
2834406
|
|
|
|
|
|
SPVM_OP* op_name = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NAME, op_var->file, op_var->line); |
2338
|
2834406
|
|
|
|
|
|
op_name->uv.name = op_var->uv.var->name; |
2339
|
2834406
|
|
|
|
|
|
var_decl->var = op_var->uv.var; |
2340
|
|
|
|
|
|
|
|
2341
|
2834406
|
|
|
|
|
|
op_var->uv.var->var_decl = var_decl; |
2342
|
|
|
|
|
|
|
|
2343
|
2834406
|
100
|
|
|
|
|
if (strstr(op_var->uv.var->name, "::")) { |
2344
|
7
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The local variable \"%s\" cannnot contain \"::\".\n at %s line %d", op_var->uv.var->name, op_var->file, op_var->line); |
2345
|
|
|
|
|
|
|
} |
2346
|
|
|
|
|
|
|
|
2347
|
2834406
|
|
|
|
|
|
return op_var; |
2348
|
|
|
|
|
|
|
} |
2349
|
|
|
|
|
|
|
|
2350
|
252759
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_call_method(SPVM_COMPILER* compiler, SPVM_OP* op_call_method, SPVM_OP* op_invocant, SPVM_OP* op_name_method, SPVM_OP* op_list_operands) { |
2351
|
|
|
|
|
|
|
|
2352
|
252759
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_call_method, op_call_method->last, op_list_operands); |
2353
|
|
|
|
|
|
|
|
2354
|
252759
|
|
|
|
|
|
SPVM_CALL_METHOD* call_method = op_call_method->uv.call_method; |
2355
|
|
|
|
|
|
|
|
2356
|
252759
|
|
|
|
|
|
const char* method_name = op_name_method->uv.name; |
2357
|
|
|
|
|
|
|
|
2358
|
|
|
|
|
|
|
// Class method call |
2359
|
252759
|
50
|
|
|
|
|
assert(op_invocant->id != SPVM_OP_C_ID_NAME); |
2360
|
252759
|
100
|
|
|
|
|
if (op_invocant->id == SPVM_OP_C_ID_TYPE || op_invocant->id == SPVM_OP_C_ID_CURRENT_CLASS) { |
|
|
100
|
|
|
|
|
|
2361
|
165689
|
|
|
|
|
|
call_method->is_class_method = 1; |
2362
|
165689
|
|
|
|
|
|
call_method->op_name = op_name_method; |
2363
|
331378
|
100
|
|
|
|
|
if (op_invocant->id == SPVM_OP_C_ID_TYPE) { |
2364
|
115252
|
|
|
|
|
|
call_method->basic_type_name = op_invocant->uv.type->unresolved_basic_type_name; |
2365
|
115252
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_call_method, op_call_method->last, op_invocant); |
2366
|
|
|
|
|
|
|
|
2367
|
115252
|
|
|
|
|
|
op_invocant->uv.type->resolved_in_ast = 1; |
2368
|
|
|
|
|
|
|
} |
2369
|
50437
|
50
|
|
|
|
|
else if (op_invocant->id == SPVM_OP_C_ID_CURRENT_CLASS) { |
2370
|
50437
|
|
|
|
|
|
call_method->is_current = 1; |
2371
|
|
|
|
|
|
|
} |
2372
|
|
|
|
|
|
|
} |
2373
|
|
|
|
|
|
|
// Instance method call |
2374
|
|
|
|
|
|
|
else { |
2375
|
87070
|
|
|
|
|
|
call_method->op_name = op_name_method; |
2376
|
|
|
|
|
|
|
|
2377
|
87070
|
100
|
|
|
|
|
if (op_invocant->id == SPVM_OP_C_ID_VAR) { |
2378
|
83771
|
|
|
|
|
|
op_invocant->uv.var->call_method = call_method; |
2379
|
|
|
|
|
|
|
} |
2380
|
|
|
|
|
|
|
|
2381
|
87070
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list_operands, op_list_operands->first, op_invocant); |
2382
|
|
|
|
|
|
|
} |
2383
|
|
|
|
|
|
|
|
2384
|
252759
|
|
|
|
|
|
return op_call_method; |
2385
|
|
|
|
|
|
|
} |
2386
|
|
|
|
|
|
|
|
2387
|
31241
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_unary_op(SPVM_COMPILER* compiler, SPVM_OP* op_unary, SPVM_OP* op_first) { |
2388
|
|
|
|
|
|
|
|
2389
|
|
|
|
|
|
|
// Build op |
2390
|
31241
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_unary, op_unary->last, op_first); |
2391
|
|
|
|
|
|
|
|
2392
|
31241
|
|
|
|
|
|
return op_unary; |
2393
|
|
|
|
|
|
|
} |
2394
|
|
|
|
|
|
|
|
2395
|
7550
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_unary_op_var(SPVM_COMPILER* compiler, SPVM_OP* op_unary, SPVM_OP* op_first) { |
2396
|
|
|
|
|
|
|
|
2397
|
7550
|
|
|
|
|
|
const char* op_name = SPVM_OP_get_op_name(compiler, op_unary->id); |
2398
|
7550
|
|
|
|
|
|
char op_name_lc[16] = {0}; |
2399
|
7550
|
|
|
|
|
|
snprintf(op_name_lc, 16, "%s", op_name); |
2400
|
128350
|
100
|
|
|
|
|
for (int32_t i = 0; i < 16; i++) { |
2401
|
120800
|
100
|
|
|
|
|
if (op_name_lc[i] != '\0') { |
2402
|
57966
|
|
|
|
|
|
op_name_lc[i] += ('a' - 'A'); |
2403
|
|
|
|
|
|
|
} |
2404
|
|
|
|
|
|
|
} |
2405
|
|
|
|
|
|
|
|
2406
|
7550
|
100
|
|
|
|
|
if (op_first->id != SPVM_OP_C_ID_VAR) { |
2407
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The operand of the %s operator must be a variable.\n at %s line %d", op_name_lc, op_first->file, op_first->line); |
2408
|
|
|
|
|
|
|
} |
2409
|
|
|
|
|
|
|
|
2410
|
|
|
|
|
|
|
// Build op |
2411
|
7550
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_unary, op_unary->last, op_first); |
2412
|
|
|
|
|
|
|
|
2413
|
7550
|
|
|
|
|
|
return op_unary; |
2414
|
|
|
|
|
|
|
} |
2415
|
|
|
|
|
|
|
|
2416
|
352579
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_comparison_op(SPVM_COMPILER* compiler, SPVM_OP* op_comparison, SPVM_OP* op_first, SPVM_OP* op_last) { |
2417
|
|
|
|
|
|
|
|
2418
|
352579
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_comparison, op_comparison->last, op_first); |
2419
|
352579
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_comparison, op_comparison->last, op_last); |
2420
|
|
|
|
|
|
|
|
2421
|
352579
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_comparison->file, op_comparison->line); |
2422
|
352579
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
2423
|
352579
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_comparison->file, op_comparison->line); |
2424
|
352579
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var, op_comparison); |
2425
|
|
|
|
|
|
|
|
2426
|
352579
|
|
|
|
|
|
return op_assign; |
2427
|
|
|
|
|
|
|
} |
2428
|
|
|
|
|
|
|
|
2429
|
8406
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_binary_is(SPVM_COMPILER* compiler, SPVM_OP* op_is, SPVM_OP* op_first, SPVM_OP* op_last) { |
2430
|
|
|
|
|
|
|
|
2431
|
8406
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_is, op_is->last, op_first); |
2432
|
8406
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_is, op_is->last, op_last); |
2433
|
|
|
|
|
|
|
|
2434
|
8406
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_is->file, op_is->line); |
2435
|
8406
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
2436
|
8406
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_is->file, op_is->line); |
2437
|
8406
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var, op_is); |
2438
|
|
|
|
|
|
|
|
2439
|
8406
|
|
|
|
|
|
return op_assign; |
2440
|
|
|
|
|
|
|
} |
2441
|
|
|
|
|
|
|
|
2442
|
4599
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_isa(SPVM_COMPILER* compiler, SPVM_OP* op_isa, SPVM_OP* op_operand, SPVM_OP* op_type) { |
2443
|
|
|
|
|
|
|
|
2444
|
4599
|
|
|
|
|
|
return SPVM_OP_build_binary_is(compiler, op_isa, op_operand, op_type); |
2445
|
|
|
|
|
|
|
} |
2446
|
|
|
|
|
|
|
|
2447
|
20
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_isa_error(SPVM_COMPILER* compiler, SPVM_OP* op_isa_error, SPVM_OP* op_operand, SPVM_OP* op_type) { |
2448
|
|
|
|
|
|
|
|
2449
|
20
|
|
|
|
|
|
return SPVM_OP_build_binary_is(compiler, op_isa_error, op_operand, op_type); |
2450
|
|
|
|
|
|
|
} |
2451
|
|
|
|
|
|
|
|
2452
|
3753
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_is_type(SPVM_COMPILER* compiler, SPVM_OP* op_is_type, SPVM_OP* op_operand, SPVM_OP* op_type) { |
2453
|
|
|
|
|
|
|
|
2454
|
3753
|
|
|
|
|
|
return SPVM_OP_build_binary_is(compiler, op_is_type, op_operand, op_type); |
2455
|
|
|
|
|
|
|
} |
2456
|
|
|
|
|
|
|
|
2457
|
18
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_is_error(SPVM_COMPILER* compiler, SPVM_OP* op_is_error, SPVM_OP* op_operand, SPVM_OP* op_type) { |
2458
|
|
|
|
|
|
|
|
2459
|
18
|
|
|
|
|
|
return SPVM_OP_build_binary_is(compiler, op_is_error, op_operand, op_type); |
2460
|
|
|
|
|
|
|
} |
2461
|
|
|
|
|
|
|
|
2462
|
16
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_is_compile_type(SPVM_COMPILER* compiler, SPVM_OP* op_is_compile_type, SPVM_OP* op_operand, SPVM_OP* op_compile_type) { |
2463
|
|
|
|
|
|
|
|
2464
|
16
|
|
|
|
|
|
return SPVM_OP_build_binary_is(compiler, op_is_compile_type, op_operand, op_compile_type); |
2465
|
|
|
|
|
|
|
} |
2466
|
|
|
|
|
|
|
|
2467
|
311719
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_binary_op(SPVM_COMPILER* compiler, SPVM_OP* op_bin, SPVM_OP* op_first, SPVM_OP* op_last) { |
2468
|
|
|
|
|
|
|
|
2469
|
|
|
|
|
|
|
// Build op |
2470
|
311719
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_bin, op_bin->last, op_first); |
2471
|
311719
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_bin, op_bin->last, op_last); |
2472
|
|
|
|
|
|
|
|
2473
|
311719
|
|
|
|
|
|
return op_bin; |
2474
|
|
|
|
|
|
|
} |
2475
|
|
|
|
|
|
|
|
2476
|
106612
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_special_assign(SPVM_COMPILER* compiler, SPVM_OP* op_special_assign, SPVM_OP* op_dist, SPVM_OP* op_src) { |
2477
|
|
|
|
|
|
|
|
2478
|
|
|
|
|
|
|
/* |
2479
|
|
|
|
|
|
|
++$var, ++$VAR, ++$@ |
2480
|
|
|
|
|
|
|
( |
2481
|
|
|
|
|
|
|
my $old = $var, |
2482
|
|
|
|
|
|
|
$var = $old + 1, |
2483
|
|
|
|
|
|
|
) |
2484
|
|
|
|
|
|
|
|
2485
|
|
|
|
|
|
|
++$$var_ref |
2486
|
|
|
|
|
|
|
( |
2487
|
|
|
|
|
|
|
my $old = $$var_ref, |
2488
|
|
|
|
|
|
|
$$var_ref = $old + 1, |
2489
|
|
|
|
|
|
|
) |
2490
|
|
|
|
|
|
|
|
2491
|
|
|
|
|
|
|
++ARRAY->[INDEX] |
2492
|
|
|
|
|
|
|
( |
2493
|
|
|
|
|
|
|
my $array = ARRAY, |
2494
|
|
|
|
|
|
|
my $index = INDEX, |
2495
|
|
|
|
|
|
|
my $old = $array->[$index], |
2496
|
|
|
|
|
|
|
$array->[$index] = $old + 1, |
2497
|
|
|
|
|
|
|
) |
2498
|
|
|
|
|
|
|
|
2499
|
|
|
|
|
|
|
++OBJECT->{FIELD_NAME} |
2500
|
|
|
|
|
|
|
( |
2501
|
|
|
|
|
|
|
my $object = OBJECT, |
2502
|
|
|
|
|
|
|
my $old = $object->{FIELD_NAME}, |
2503
|
|
|
|
|
|
|
$object->{FIELD_NAME} = $old + 1, |
2504
|
|
|
|
|
|
|
) |
2505
|
|
|
|
|
|
|
|
2506
|
|
|
|
|
|
|
++ARRAY->[INDEX]{FIELD_NAME} |
2507
|
|
|
|
|
|
|
( |
2508
|
|
|
|
|
|
|
my $array = ARRAY, |
2509
|
|
|
|
|
|
|
my $index = INDEX, |
2510
|
|
|
|
|
|
|
my $old = $array->[$index]{FIELD_NAME}, |
2511
|
|
|
|
|
|
|
$array->[$index]{FIELD_NAME} = $old + 1, |
2512
|
|
|
|
|
|
|
) |
2513
|
|
|
|
|
|
|
|
2514
|
|
|
|
|
|
|
ACCESS++ |
2515
|
|
|
|
|
|
|
( |
2516
|
|
|
|
|
|
|
..., |
2517
|
|
|
|
|
|
|
..., |
2518
|
|
|
|
|
|
|
$old, |
2519
|
|
|
|
|
|
|
) |
2520
|
|
|
|
|
|
|
*/ |
2521
|
|
|
|
|
|
|
|
2522
|
106612
|
|
|
|
|
|
SPVM_OP* op_sequence = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_SEQUENCE, op_special_assign->file, op_special_assign->line); |
2523
|
|
|
|
|
|
|
|
2524
|
106612
|
|
|
|
|
|
SPVM_OP* op_assign_save_old = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_special_assign->file, op_special_assign->line); |
2525
|
|
|
|
|
|
|
|
2526
|
106612
|
|
|
|
|
|
SPVM_OP* op_name_var_old = SPVM_OP_new_op_name_tmp_var(compiler, op_special_assign->file, op_special_assign->line); |
2527
|
|
|
|
|
|
|
|
2528
|
106612
|
|
|
|
|
|
SPVM_OP* op_var_old = SPVM_OP_new_op_var(compiler, op_name_var_old); |
2529
|
|
|
|
|
|
|
|
2530
|
106612
|
|
|
|
|
|
SPVM_OP* op_var_old_decl = SPVM_OP_new_op_var_decl(compiler, op_special_assign->file, op_special_assign->line); |
2531
|
106612
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_old_decl, op_var_old, NULL, NULL); |
2532
|
|
|
|
|
|
|
|
2533
|
106612
|
|
|
|
|
|
SPVM_OP* op_assign_update = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_special_assign->file, op_special_assign->line); |
2534
|
106612
|
|
|
|
|
|
SPVM_OP* op_var_old_clone = SPVM_OP_clone_op_var(compiler, op_var_old); |
2535
|
|
|
|
|
|
|
|
2536
|
|
|
|
|
|
|
int32_t culc_op_id; |
2537
|
|
|
|
|
|
|
|
2538
|
106612
|
|
|
|
|
|
switch (op_special_assign->id) { |
2539
|
|
|
|
|
|
|
case SPVM_OP_C_ID_PRE_INC: |
2540
|
|
|
|
|
|
|
case SPVM_OP_C_ID_POST_INC: |
2541
|
|
|
|
|
|
|
{ |
2542
|
81530
|
100
|
|
|
|
|
if (!SPVM_OP_is_mutable(compiler, op_dist)) { |
2543
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The operand of ++ operator must be mutable.\n at %s line %d", op_dist->file, op_dist->line); |
2544
|
1
|
|
|
|
|
|
return op_special_assign; |
2545
|
|
|
|
|
|
|
} |
2546
|
|
|
|
|
|
|
|
2547
|
81529
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_ADD; |
2548
|
81529
|
|
|
|
|
|
break; |
2549
|
|
|
|
|
|
|
} |
2550
|
|
|
|
|
|
|
case SPVM_OP_C_ID_PRE_DEC: |
2551
|
|
|
|
|
|
|
case SPVM_OP_C_ID_POST_DEC: |
2552
|
|
|
|
|
|
|
{ |
2553
|
10201
|
100
|
|
|
|
|
if (!SPVM_OP_is_mutable(compiler, op_dist)) { |
2554
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The operand of -- operator must be mutable.\n at %s line %d", op_dist->file, op_dist->line); |
2555
|
1
|
|
|
|
|
|
return op_special_assign; |
2556
|
|
|
|
|
|
|
} |
2557
|
|
|
|
|
|
|
|
2558
|
10200
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_SUBTRACT; |
2559
|
10200
|
|
|
|
|
|
break; |
2560
|
|
|
|
|
|
|
} |
2561
|
|
|
|
|
|
|
case SPVM_OP_C_ID_SPECIAL_ASSIGN: { |
2562
|
14881
|
100
|
|
|
|
|
if (!SPVM_OP_is_mutable(compiler, op_dist)) { |
2563
|
1
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The left operand of the special assign operator must be mutable.\n at %s line %d", op_dist->file, op_dist->line); |
2564
|
1
|
|
|
|
|
|
return op_special_assign; |
2565
|
|
|
|
|
|
|
} |
2566
|
|
|
|
|
|
|
|
2567
|
14880
|
|
|
|
|
|
switch (op_special_assign->flag) { |
2568
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_ADD: { |
2569
|
5866
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_ADD; |
2570
|
5866
|
|
|
|
|
|
break; |
2571
|
|
|
|
|
|
|
} |
2572
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_SUBTRACT: { |
2573
|
14
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_SUBTRACT; |
2574
|
14
|
|
|
|
|
|
break; |
2575
|
|
|
|
|
|
|
} |
2576
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_MULTIPLY: { |
2577
|
537
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_MULTIPLY; |
2578
|
537
|
|
|
|
|
|
break; |
2579
|
|
|
|
|
|
|
} |
2580
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_DIVIDE: { |
2581
|
14
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_DIVIDE; |
2582
|
14
|
|
|
|
|
|
break; |
2583
|
|
|
|
|
|
|
} |
2584
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_REMAINDER: { |
2585
|
10
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_REMAINDER; |
2586
|
10
|
|
|
|
|
|
break; |
2587
|
|
|
|
|
|
|
} |
2588
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_LEFT_SHIFT: { |
2589
|
10
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_LEFT_SHIFT; |
2590
|
10
|
|
|
|
|
|
break; |
2591
|
|
|
|
|
|
|
} |
2592
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_RIGHT_ARITHMETIC_SHIFT: { |
2593
|
10
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_RIGHT_ARITHMETIC_SHIFT; |
2594
|
10
|
|
|
|
|
|
break; |
2595
|
|
|
|
|
|
|
} |
2596
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_RIGHT_LOGICAL_SHIFT: { |
2597
|
10
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_RIGHT_LOGICAL_SHIFT; |
2598
|
10
|
|
|
|
|
|
break; |
2599
|
|
|
|
|
|
|
} |
2600
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_BIT_XOR: { |
2601
|
10
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_BIT_XOR; |
2602
|
10
|
|
|
|
|
|
break; |
2603
|
|
|
|
|
|
|
} |
2604
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_BIT_OR: { |
2605
|
10
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_BIT_OR; |
2606
|
10
|
|
|
|
|
|
break; |
2607
|
|
|
|
|
|
|
} |
2608
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_BIT_AND: { |
2609
|
10
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_BIT_AND; |
2610
|
10
|
|
|
|
|
|
break; |
2611
|
|
|
|
|
|
|
} |
2612
|
|
|
|
|
|
|
case SPVM_OP_C_FLAG_SPECIAL_ASSIGN_CONCAT: { |
2613
|
8379
|
|
|
|
|
|
culc_op_id = SPVM_OP_C_ID_CONCAT; |
2614
|
8379
|
|
|
|
|
|
break; |
2615
|
|
|
|
|
|
|
} |
2616
|
|
|
|
|
|
|
default: { |
2617
|
0
|
|
|
|
|
|
assert(0); |
2618
|
|
|
|
|
|
|
break; |
2619
|
|
|
|
|
|
|
} |
2620
|
|
|
|
|
|
|
} |
2621
|
|
|
|
|
|
|
|
2622
|
14880
|
|
|
|
|
|
break; |
2623
|
|
|
|
|
|
|
} |
2624
|
|
|
|
|
|
|
} |
2625
|
|
|
|
|
|
|
|
2626
|
106609
|
|
|
|
|
|
SPVM_OP* op_culc = SPVM_OP_new_op(compiler, culc_op_id, op_special_assign->file, op_special_assign->line); |
2627
|
|
|
|
|
|
|
|
2628
|
106609
|
|
|
|
|
|
op_culc->allow_narrowing_conversion = 1; |
2629
|
106609
|
|
|
|
|
|
op_culc->original_id = op_special_assign->id; |
2630
|
|
|
|
|
|
|
|
2631
|
106609
|
|
|
|
|
|
SPVM_OP_build_binary_op(compiler, op_culc, op_var_old_clone, op_src); |
2632
|
|
|
|
|
|
|
|
2633
|
203930
|
100
|
|
|
|
|
if (op_dist->id == SPVM_OP_C_ID_VAR || op_dist->id == SPVM_OP_C_ID_EXCEPTION_VAR) { |
|
|
50
|
|
|
|
|
|
2634
|
97321
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_save_old, op_var_old, op_dist); |
2635
|
97321
|
|
|
|
|
|
SPVM_OP* op_var = op_dist; |
2636
|
97321
|
|
|
|
|
|
SPVM_OP* op_var_clone = SPVM_OP_clone_op_var(compiler, op_var); |
2637
|
97321
|
|
|
|
|
|
SPVM_OP* op_dist_clone = op_var_clone; |
2638
|
97321
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_update, op_dist_clone, op_culc); |
2639
|
|
|
|
|
|
|
} |
2640
|
9288
|
100
|
|
|
|
|
else if (op_dist->id == SPVM_OP_C_ID_DEREF) { |
2641
|
1106
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_save_old, op_var_old, op_dist); |
2642
|
1106
|
|
|
|
|
|
SPVM_OP* op_deref = op_dist; |
2643
|
1106
|
|
|
|
|
|
SPVM_OP* op_var_deref = op_deref->first; |
2644
|
1106
|
|
|
|
|
|
SPVM_OP* op_deref_clone = SPVM_OP_clone_op_deref(compiler, op_deref, op_var_deref); |
2645
|
1106
|
|
|
|
|
|
SPVM_OP* op_dist_clone = op_deref_clone; |
2646
|
1106
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_update, op_dist_clone, op_culc); |
2647
|
|
|
|
|
|
|
} |
2648
|
8182
|
100
|
|
|
|
|
else if (op_dist->id == SPVM_OP_C_ID_ARRAY_ACCESS) { |
2649
|
131
|
|
|
|
|
|
SPVM_OP* op_array_access = op_dist; |
2650
|
|
|
|
|
|
|
|
2651
|
131
|
|
|
|
|
|
SPVM_OP* op_array = op_array_access->first; |
2652
|
131
|
|
|
|
|
|
SPVM_OP* op_index = op_array_access->last; |
2653
|
|
|
|
|
|
|
|
2654
|
131
|
|
|
|
|
|
SPVM_OP_cut_op(compiler, op_array_access->first); |
2655
|
131
|
|
|
|
|
|
SPVM_OP_cut_op(compiler, op_array_access->last); |
2656
|
|
|
|
|
|
|
|
2657
|
131
|
|
|
|
|
|
SPVM_OP* op_assign_array_get = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_array->file, op_array->line); |
2658
|
131
|
|
|
|
|
|
SPVM_OP* op_name_var_array = SPVM_OP_new_op_name_tmp_var(compiler, op_array->file, op_array->line); |
2659
|
131
|
|
|
|
|
|
SPVM_OP* op_var_array_get = SPVM_OP_new_op_var(compiler, op_name_var_array); |
2660
|
131
|
|
|
|
|
|
SPVM_OP* op_var_array_get_decl = SPVM_OP_new_op_var_decl(compiler, op_array->file,op_array->line); |
2661
|
131
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_array_get_decl, op_var_array_get, NULL, NULL); |
2662
|
131
|
|
|
|
|
|
op_assign_array_get = SPVM_OP_build_assign(compiler, op_assign_array_get, op_var_array_get, op_array); |
2663
|
131
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_array_get); |
2664
|
|
|
|
|
|
|
|
2665
|
131
|
|
|
|
|
|
SPVM_OP* op_assign_index_get = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_index->file, op_index->line); |
2666
|
131
|
|
|
|
|
|
SPVM_OP* op_name_var_index = SPVM_OP_new_op_name_tmp_var(compiler, op_index->file, op_index->line); |
2667
|
131
|
|
|
|
|
|
SPVM_OP* op_var_index_get = SPVM_OP_new_op_var(compiler, op_name_var_index); |
2668
|
131
|
|
|
|
|
|
SPVM_OP* op_var_index_get_decl = SPVM_OP_new_op_var_decl(compiler, op_index->file,op_index->line); |
2669
|
131
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_index_get_decl, op_var_index_get, NULL, NULL); |
2670
|
131
|
|
|
|
|
|
op_assign_index_get = SPVM_OP_build_assign(compiler, op_assign_index_get, op_var_index_get, op_index); |
2671
|
131
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_index_get); |
2672
|
|
|
|
|
|
|
|
2673
|
131
|
|
|
|
|
|
SPVM_OP* op_array_access_clone_get = SPVM_OP_clone_op_array_access(compiler, op_array_access, op_var_array_get, op_var_index_get); |
2674
|
131
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_save_old, op_var_old, op_array_access_clone_get); |
2675
|
|
|
|
|
|
|
|
2676
|
131
|
|
|
|
|
|
SPVM_OP* op_assign_array_set = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_array->file, op_array->line); |
2677
|
131
|
|
|
|
|
|
SPVM_OP* op_var_array_set = SPVM_OP_new_op_var(compiler, op_name_var_array); |
2678
|
131
|
|
|
|
|
|
SPVM_OP* op_var_array_set_decl = SPVM_OP_new_op_var_decl(compiler, op_array->file,op_array->line); |
2679
|
|
|
|
|
|
|
|
2680
|
131
|
|
|
|
|
|
SPVM_OP* op_assign_index_set = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_index->file, op_index->line); |
2681
|
131
|
|
|
|
|
|
SPVM_OP* op_var_index_set = SPVM_OP_new_op_var(compiler, op_name_var_index); |
2682
|
131
|
|
|
|
|
|
SPVM_OP* op_var_index_set_decl = SPVM_OP_new_op_var_decl(compiler, op_index->file,op_index->line); |
2683
|
|
|
|
|
|
|
|
2684
|
131
|
|
|
|
|
|
SPVM_OP* op_array_access_clone_set = SPVM_OP_clone_op_array_access(compiler, op_array_access, op_var_array_set, op_var_index_set); |
2685
|
131
|
|
|
|
|
|
SPVM_OP* op_dist_clone_set = op_array_access_clone_set; |
2686
|
131
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_update, op_dist_clone_set, op_culc); |
2687
|
|
|
|
|
|
|
} |
2688
|
8051
|
50
|
|
|
|
|
else if (op_dist->id == SPVM_OP_C_ID_FIELD_ACCESS) { |
2689
|
|
|
|
|
|
|
|
2690
|
8051
|
|
|
|
|
|
SPVM_OP* op_field_access = op_dist; |
2691
|
|
|
|
|
|
|
|
2692
|
8051
|
|
|
|
|
|
SPVM_OP* op_invocant = op_field_access->first; |
2693
|
8051
|
|
|
|
|
|
SPVM_OP* op_name_field = op_field_access->uv.field_access->op_name; |
2694
|
|
|
|
|
|
|
|
2695
|
8051
|
|
|
|
|
|
SPVM_OP_cut_op(compiler, op_field_access->first); |
2696
|
|
|
|
|
|
|
|
2697
|
8051
|
100
|
|
|
|
|
if (op_invocant->id == SPVM_OP_C_ID_ARRAY_ACCESS) { |
2698
|
86
|
|
|
|
|
|
SPVM_OP* op_array_access = op_invocant; |
2699
|
|
|
|
|
|
|
|
2700
|
86
|
|
|
|
|
|
SPVM_OP* op_array = op_array_access->first; |
2701
|
86
|
|
|
|
|
|
SPVM_OP* op_index = op_array_access->last; |
2702
|
|
|
|
|
|
|
|
2703
|
86
|
|
|
|
|
|
SPVM_OP_cut_op(compiler, op_array_access->first); |
2704
|
86
|
|
|
|
|
|
SPVM_OP_cut_op(compiler, op_array_access->last); |
2705
|
|
|
|
|
|
|
|
2706
|
86
|
|
|
|
|
|
SPVM_OP* op_assign_array_get = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_array->file, op_array->line); |
2707
|
86
|
|
|
|
|
|
SPVM_OP* op_name_var_array = SPVM_OP_new_op_name_tmp_var(compiler, op_array->file, op_array->line); |
2708
|
86
|
|
|
|
|
|
SPVM_OP* op_var_array_get = SPVM_OP_new_op_var(compiler, op_name_var_array); |
2709
|
86
|
|
|
|
|
|
SPVM_OP* op_var_array_get_decl = SPVM_OP_new_op_var_decl(compiler, op_array->file,op_array->line); |
2710
|
86
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_array_get_decl, op_var_array_get, NULL, NULL); |
2711
|
86
|
|
|
|
|
|
op_assign_array_get = SPVM_OP_build_assign(compiler, op_assign_array_get, op_var_array_get, op_array); |
2712
|
86
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_array_get); |
2713
|
|
|
|
|
|
|
|
2714
|
86
|
|
|
|
|
|
SPVM_OP* op_assign_index_get = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_index->file, op_index->line); |
2715
|
86
|
|
|
|
|
|
SPVM_OP* op_name_var_index = SPVM_OP_new_op_name_tmp_var(compiler, op_index->file, op_index->line); |
2716
|
86
|
|
|
|
|
|
SPVM_OP* op_var_index_get = SPVM_OP_new_op_var(compiler, op_name_var_index); |
2717
|
86
|
|
|
|
|
|
SPVM_OP* op_var_index_get_decl = SPVM_OP_new_op_var_decl(compiler, op_index->file,op_index->line); |
2718
|
86
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_index_get_decl, op_var_index_get, NULL, NULL); |
2719
|
86
|
|
|
|
|
|
op_assign_index_get = SPVM_OP_build_assign(compiler, op_assign_index_get, op_var_index_get, op_index); |
2720
|
86
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_index_get); |
2721
|
|
|
|
|
|
|
|
2722
|
86
|
|
|
|
|
|
SPVM_OP* op_array_field_access_clone_get = SPVM_OP_clone_op_array_field_access(compiler, op_field_access, op_name_field, op_array_access, op_var_array_get, op_var_index_get); |
2723
|
86
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_save_old, op_var_old, op_array_field_access_clone_get); |
2724
|
|
|
|
|
|
|
|
2725
|
86
|
|
|
|
|
|
SPVM_OP* op_assign_array_set = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_array->file, op_array->line); |
2726
|
86
|
|
|
|
|
|
SPVM_OP* op_var_array_set = SPVM_OP_new_op_var(compiler, op_name_var_array); |
2727
|
86
|
|
|
|
|
|
SPVM_OP* op_var_array_set_decl = SPVM_OP_new_op_var_decl(compiler, op_array->file,op_array->line); |
2728
|
86
|
|
|
|
|
|
SPVM_OP* op_assign_index_set = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_index->file, op_index->line); |
2729
|
86
|
|
|
|
|
|
SPVM_OP* op_var_index_set = SPVM_OP_new_op_var(compiler, op_name_var_index); |
2730
|
86
|
|
|
|
|
|
SPVM_OP* op_var_index_set_decl = SPVM_OP_new_op_var_decl(compiler, op_index->file,op_index->line); |
2731
|
86
|
|
|
|
|
|
SPVM_OP* op_array_field_access_clone_set = SPVM_OP_clone_op_array_field_access(compiler, op_array_access, op_name_field, op_array_access, op_var_array_set, op_var_index_set); |
2732
|
86
|
|
|
|
|
|
SPVM_OP* op_dist_clone_set = op_array_field_access_clone_set; |
2733
|
86
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_update, op_dist_clone_set, op_culc); |
2734
|
|
|
|
|
|
|
} |
2735
|
|
|
|
|
|
|
else { |
2736
|
7965
|
|
|
|
|
|
SPVM_OP* op_assign_invocant_get = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_invocant->file, op_invocant->line); |
2737
|
7965
|
|
|
|
|
|
SPVM_OP* op_name_var_invocant = SPVM_OP_new_op_name_tmp_var(compiler, op_invocant->file, op_invocant->line); |
2738
|
7965
|
|
|
|
|
|
SPVM_OP* op_var_invocant_get = SPVM_OP_new_op_var(compiler, op_name_var_invocant); |
2739
|
7965
|
|
|
|
|
|
SPVM_OP* op_var_invocant_get_decl = SPVM_OP_new_op_var_decl(compiler, op_invocant->file,op_invocant->line); |
2740
|
7965
|
|
|
|
|
|
SPVM_OP_build_var_decl(compiler, op_var_invocant_get_decl, op_var_invocant_get, NULL, NULL); |
2741
|
7965
|
|
|
|
|
|
op_assign_invocant_get = SPVM_OP_build_assign(compiler, op_assign_invocant_get, op_var_invocant_get, op_invocant); |
2742
|
7965
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_invocant_get); |
2743
|
|
|
|
|
|
|
|
2744
|
7965
|
|
|
|
|
|
SPVM_OP* op_name_field_get = SPVM_OP_new_op_name(compiler, op_name_field->uv.name, op_name_field->file, op_name_field->line); |
2745
|
7965
|
|
|
|
|
|
SPVM_OP* op_field_access_clone_get = SPVM_OP_clone_op_field_access(compiler, op_field_access, op_var_invocant_get, op_name_field_get); |
2746
|
7965
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_save_old, op_var_old, op_field_access_clone_get); |
2747
|
|
|
|
|
|
|
|
2748
|
7965
|
|
|
|
|
|
SPVM_OP* op_assign_invocant_set = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_invocant->file, op_invocant->line); |
2749
|
7965
|
|
|
|
|
|
SPVM_OP* op_var_invocant_set = SPVM_OP_new_op_var(compiler, op_name_var_invocant); |
2750
|
7965
|
|
|
|
|
|
SPVM_OP* op_var_invocant_set_decl = SPVM_OP_new_op_var_decl(compiler, op_invocant->file,op_invocant->line); |
2751
|
7965
|
|
|
|
|
|
SPVM_OP* op_name_field_set = SPVM_OP_new_op_name(compiler, op_name_field->uv.name, op_name_field->file, op_name_field->line); |
2752
|
7965
|
|
|
|
|
|
SPVM_OP* op_field_access_clone_set = SPVM_OP_clone_op_field_access(compiler, op_field_access, op_var_invocant_set, op_name_field_set); |
2753
|
7965
|
|
|
|
|
|
SPVM_OP* op_dist_clone_set = op_field_access_clone_set; |
2754
|
8051
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign_update, op_dist_clone_set, op_culc); |
2755
|
|
|
|
|
|
|
} |
2756
|
|
|
|
|
|
|
} |
2757
|
|
|
|
|
|
|
else { |
2758
|
0
|
|
|
|
|
|
assert(0); |
2759
|
|
|
|
|
|
|
} |
2760
|
|
|
|
|
|
|
|
2761
|
106609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_save_old); |
2762
|
106609
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_assign_update); |
2763
|
|
|
|
|
|
|
|
2764
|
|
|
|
|
|
|
// Return the old value |
2765
|
106609
|
100
|
|
|
|
|
if (op_special_assign->id == SPVM_OP_C_ID_POST_INC || op_special_assign->id == SPVM_OP_C_ID_POST_DEC) { |
|
|
100
|
|
|
|
|
|
2766
|
79468
|
|
|
|
|
|
SPVM_OP* op_var_old_clone_ret = SPVM_OP_clone_op_var(compiler, op_var_old_clone); |
2767
|
79468
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_sequence, op_sequence->last, op_var_old_clone_ret); |
2768
|
|
|
|
|
|
|
} |
2769
|
|
|
|
|
|
|
|
2770
|
106609
|
|
|
|
|
|
return op_sequence; |
2771
|
|
|
|
|
|
|
} |
2772
|
|
|
|
|
|
|
|
2773
|
81530
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_inc(SPVM_COMPILER* compiler, SPVM_OP* op_inc, SPVM_OP* op_first) { |
2774
|
|
|
|
|
|
|
|
2775
|
81530
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_inc, op_inc->last, op_first); |
2776
|
|
|
|
|
|
|
|
2777
|
81530
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant_int(compiler, 1, op_first->file, op_first->line); |
2778
|
81530
|
|
|
|
|
|
op_inc = SPVM_OP_build_special_assign(compiler, op_inc, op_first, op_constant); |
2779
|
|
|
|
|
|
|
|
2780
|
81530
|
|
|
|
|
|
return op_inc; |
2781
|
|
|
|
|
|
|
} |
2782
|
|
|
|
|
|
|
|
2783
|
10201
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_dec(SPVM_COMPILER* compiler, SPVM_OP* op_dec, SPVM_OP* op_first) { |
2784
|
|
|
|
|
|
|
|
2785
|
10201
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_dec, op_dec->last, op_first); |
2786
|
|
|
|
|
|
|
|
2787
|
10201
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant_int(compiler, 1, op_first->file, op_first->line); |
2788
|
10201
|
|
|
|
|
|
op_dec = SPVM_OP_build_special_assign(compiler, op_dec, op_first, op_constant); |
2789
|
|
|
|
|
|
|
|
2790
|
10201
|
|
|
|
|
|
return op_dec; |
2791
|
|
|
|
|
|
|
} |
2792
|
|
|
|
|
|
|
|
2793
|
48421
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_logical_and(SPVM_COMPILER* compiler, SPVM_OP* op_logical_and, SPVM_OP* op_first, SPVM_OP* op_last) { |
2794
|
|
|
|
|
|
|
|
2795
|
|
|
|
|
|
|
// Convert && to if statement |
2796
|
|
|
|
|
|
|
/* before |
2797
|
|
|
|
|
|
|
AND |
2798
|
|
|
|
|
|
|
first |
2799
|
|
|
|
|
|
|
last |
2800
|
|
|
|
|
|
|
*/ |
2801
|
|
|
|
|
|
|
|
2802
|
|
|
|
|
|
|
/* after |
2803
|
|
|
|
|
|
|
IF if1 |
2804
|
|
|
|
|
|
|
CONDITION |
2805
|
|
|
|
|
|
|
first |
2806
|
|
|
|
|
|
|
IF if2 |
2807
|
|
|
|
|
|
|
CONDITION |
2808
|
|
|
|
|
|
|
last |
2809
|
|
|
|
|
|
|
TYPE_CONVERTION_BOOL |
2810
|
|
|
|
|
|
|
condition_flag true |
2811
|
|
|
|
|
|
|
TYPE_CONVERTION_BOOL |
2812
|
|
|
|
|
|
|
0 false1 |
2813
|
|
|
|
|
|
|
TYPE_CONVERTION_BOOL |
2814
|
|
|
|
|
|
|
0 false2 |
2815
|
|
|
|
|
|
|
*/ |
2816
|
|
|
|
|
|
|
|
2817
|
48421
|
|
|
|
|
|
SPVM_OP* op_if1 = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_IF, op_logical_and->file, op_logical_and->line); |
2818
|
|
|
|
|
|
|
|
2819
|
|
|
|
|
|
|
// Constant true |
2820
|
48421
|
|
|
|
|
|
SPVM_OP* op_name_var_true = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_logical_and->file, op_logical_and->line); |
2821
|
48421
|
|
|
|
|
|
SPVM_OP* op_var_true = SPVM_OP_new_op_var(compiler, op_name_var_true); |
2822
|
48421
|
|
|
|
|
|
SPVM_OP* op_assign_bool_true = SPVM_OP_new_op_assign_bool(compiler, op_var_true, op_if1->file, op_if1->line); |
2823
|
|
|
|
|
|
|
|
2824
|
|
|
|
|
|
|
// Constant false 1 |
2825
|
48421
|
|
|
|
|
|
SPVM_OP* op_constant_false1 = SPVM_OP_new_op_constant_int(compiler, 0, op_if1->file, op_if1->line); |
2826
|
48421
|
|
|
|
|
|
SPVM_OP* op_assign_bool_false1 = SPVM_OP_new_op_assign_bool(compiler, op_constant_false1, op_if1->file, op_if1->line); |
2827
|
|
|
|
|
|
|
|
2828
|
|
|
|
|
|
|
// Constant false 2 |
2829
|
48421
|
|
|
|
|
|
SPVM_OP* op_constant_false2 = SPVM_OP_new_op_constant_int(compiler, 0, op_if1->file, op_if1->line); |
2830
|
48421
|
|
|
|
|
|
SPVM_OP* op_assign_bool_false2 = SPVM_OP_new_op_assign_bool(compiler, op_constant_false2, op_if1->file, op_if1->line); |
2831
|
|
|
|
|
|
|
|
2832
|
|
|
|
|
|
|
// if2 |
2833
|
48421
|
|
|
|
|
|
SPVM_OP* op_if2 = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_IF, op_if1->file, op_if1->line); |
2834
|
|
|
|
|
|
|
|
2835
|
|
|
|
|
|
|
// Build if tree |
2836
|
48421
|
|
|
|
|
|
int32_t no_scope = 1; |
2837
|
48421
|
|
|
|
|
|
SPVM_OP_build_if_statement(compiler, op_if2, op_last, op_assign_bool_true, op_assign_bool_false1, no_scope); |
2838
|
48421
|
|
|
|
|
|
SPVM_OP_build_if_statement(compiler, op_if1, op_first, op_if2, op_assign_bool_false2, no_scope); |
2839
|
|
|
|
|
|
|
|
2840
|
48421
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_logical_and->file, op_logical_and->line); |
2841
|
48421
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
2842
|
48421
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_logical_and->file, op_logical_and->line); |
2843
|
48421
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var, op_if1); |
2844
|
|
|
|
|
|
|
|
2845
|
48421
|
|
|
|
|
|
return op_assign; |
2846
|
|
|
|
|
|
|
} |
2847
|
|
|
|
|
|
|
|
2848
|
8092
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_logical_or(SPVM_COMPILER* compiler, SPVM_OP* op_logical_or, SPVM_OP* op_first, SPVM_OP* op_last) { |
2849
|
|
|
|
|
|
|
|
2850
|
|
|
|
|
|
|
// Convert || to if statement |
2851
|
|
|
|
|
|
|
// before |
2852
|
|
|
|
|
|
|
// OR |
2853
|
|
|
|
|
|
|
// first |
2854
|
|
|
|
|
|
|
// last |
2855
|
|
|
|
|
|
|
|
2856
|
|
|
|
|
|
|
// after |
2857
|
|
|
|
|
|
|
// IF if1 |
2858
|
|
|
|
|
|
|
// first |
2859
|
|
|
|
|
|
|
// TYPE_CONVERTION_BOOL |
2860
|
|
|
|
|
|
|
// condition_flag true1 |
2861
|
|
|
|
|
|
|
// IF if2 |
2862
|
|
|
|
|
|
|
// last |
2863
|
|
|
|
|
|
|
// TYPE_CONVERTION_BOOL |
2864
|
|
|
|
|
|
|
// condition_flag true2 |
2865
|
|
|
|
|
|
|
// TYPE_CONVERTION_BOOL |
2866
|
|
|
|
|
|
|
// 0 false |
2867
|
|
|
|
|
|
|
|
2868
|
8092
|
|
|
|
|
|
SPVM_OP* op_if1 = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_IF, op_logical_or->file, op_logical_or->line); |
2869
|
|
|
|
|
|
|
|
2870
|
|
|
|
|
|
|
// Constant true 1 |
2871
|
8092
|
|
|
|
|
|
SPVM_OP* op_name_var_true1 = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_logical_or->file, op_logical_or->line); |
2872
|
8092
|
|
|
|
|
|
SPVM_OP* op_var_true1 = SPVM_OP_new_op_var(compiler, op_name_var_true1); |
2873
|
8092
|
|
|
|
|
|
SPVM_OP* op_bool_true1 = SPVM_OP_new_op_assign_bool(compiler, op_var_true1, op_if1->file, op_if1->line); |
2874
|
|
|
|
|
|
|
|
2875
|
|
|
|
|
|
|
// Constant true 2 |
2876
|
8092
|
|
|
|
|
|
SPVM_OP* op_name_var_true2 = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_logical_or->file, op_logical_or->line); |
2877
|
8092
|
|
|
|
|
|
SPVM_OP* op_var_true2 = SPVM_OP_new_op_var(compiler, op_name_var_true2); |
2878
|
8092
|
|
|
|
|
|
SPVM_OP* op_bool_true2 = SPVM_OP_new_op_assign_bool(compiler, op_var_true2, op_if1->file, op_if1->line); |
2879
|
|
|
|
|
|
|
|
2880
|
|
|
|
|
|
|
// Constant false |
2881
|
8092
|
|
|
|
|
|
SPVM_OP* op_constant_false = SPVM_OP_new_op_constant_int(compiler, 0, op_if1->file, op_if1->line); |
2882
|
8092
|
|
|
|
|
|
SPVM_OP* op_bool_false = SPVM_OP_new_op_assign_bool(compiler, op_constant_false, op_if1->file, op_if1->line); |
2883
|
|
|
|
|
|
|
|
2884
|
|
|
|
|
|
|
// if2 |
2885
|
8092
|
|
|
|
|
|
SPVM_OP* op_if2 = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_IF, op_if1->file, op_if1->line); |
2886
|
|
|
|
|
|
|
|
2887
|
|
|
|
|
|
|
// Build if tree |
2888
|
8092
|
|
|
|
|
|
int32_t no_scope = 1; |
2889
|
8092
|
|
|
|
|
|
SPVM_OP_build_if_statement(compiler, op_if2, op_last, op_bool_true2, op_bool_false, no_scope); |
2890
|
8092
|
|
|
|
|
|
SPVM_OP_build_if_statement(compiler, op_if1, op_first, op_bool_true1, op_if2, no_scope); |
2891
|
|
|
|
|
|
|
|
2892
|
8092
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_logical_or->file, op_logical_or->line); |
2893
|
8092
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
2894
|
8092
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_logical_or->file, op_logical_or->line); |
2895
|
8092
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var, op_if1); |
2896
|
|
|
|
|
|
|
|
2897
|
8092
|
|
|
|
|
|
return op_assign; |
2898
|
|
|
|
|
|
|
} |
2899
|
|
|
|
|
|
|
|
2900
|
3157
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_logical_not(SPVM_COMPILER* compiler, SPVM_OP* op_not, SPVM_OP* op_first) { |
2901
|
|
|
|
|
|
|
|
2902
|
|
|
|
|
|
|
// Convert ! to if statement |
2903
|
|
|
|
|
|
|
// before |
2904
|
|
|
|
|
|
|
// LOGICAL_NOT |
2905
|
|
|
|
|
|
|
// first |
2906
|
|
|
|
|
|
|
|
2907
|
|
|
|
|
|
|
// after |
2908
|
|
|
|
|
|
|
// IF |
2909
|
|
|
|
|
|
|
// first |
2910
|
|
|
|
|
|
|
// TYPE_CONVERTION_BOOL |
2911
|
|
|
|
|
|
|
// 0 |
2912
|
|
|
|
|
|
|
// TYPE_CONVERTION_BOOL |
2913
|
|
|
|
|
|
|
// 1 |
2914
|
|
|
|
|
|
|
|
2915
|
3157
|
|
|
|
|
|
SPVM_OP* op_if = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_IF, op_not->file, op_not->line); |
2916
|
|
|
|
|
|
|
|
2917
|
|
|
|
|
|
|
// Constant false |
2918
|
3157
|
|
|
|
|
|
SPVM_OP* op_constant_false = SPVM_OP_new_op_constant_int(compiler, 0, op_if->file, op_if->line); |
2919
|
3157
|
|
|
|
|
|
SPVM_OP* op_assign_bool_false = SPVM_OP_new_op_assign_bool(compiler, op_constant_false, op_if->file, op_if->line); |
2920
|
|
|
|
|
|
|
|
2921
|
|
|
|
|
|
|
// Constant true |
2922
|
3157
|
|
|
|
|
|
SPVM_OP* op_constant_true = SPVM_OP_new_op_constant_int(compiler, 1, op_if->file, op_if->line); |
2923
|
3157
|
|
|
|
|
|
SPVM_OP* op_assign_bool_true = SPVM_OP_new_op_assign_bool(compiler, op_constant_true, op_if->file, op_if->line); |
2924
|
|
|
|
|
|
|
|
2925
|
|
|
|
|
|
|
// Build if tree |
2926
|
3157
|
|
|
|
|
|
int32_t no_scope = 1; |
2927
|
3157
|
|
|
|
|
|
SPVM_OP_build_if_statement(compiler, op_if, op_first, op_assign_bool_false, op_assign_bool_true, no_scope); |
2928
|
|
|
|
|
|
|
|
2929
|
3157
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, "$.condition_flag", op_not->file, op_not->line); |
2930
|
3157
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
2931
|
3157
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_not->file, op_not->line); |
2932
|
3157
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var, op_if); |
2933
|
|
|
|
|
|
|
|
2934
|
3157
|
|
|
|
|
|
return op_assign; |
2935
|
|
|
|
|
|
|
} |
2936
|
|
|
|
|
|
|
|
2937
|
3530586
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_assign(SPVM_COMPILER* compiler, SPVM_OP* op_assign, SPVM_OP* op_dist, SPVM_OP* op_src) { |
2938
|
|
|
|
|
|
|
|
2939
|
|
|
|
|
|
|
// Build op |
2940
|
|
|
|
|
|
|
// Exchange left and right for excecution order |
2941
|
|
|
|
|
|
|
|
2942
|
3530586
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_assign, op_assign->last, op_src); |
2943
|
3530586
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_assign, op_assign->last, op_dist); |
2944
|
|
|
|
|
|
|
|
2945
|
3530586
|
|
|
|
|
|
op_dist->is_dist = 1; |
2946
|
|
|
|
|
|
|
|
2947
|
3530586
|
100
|
|
|
|
|
if (!SPVM_OP_is_mutable(compiler, op_dist)) { |
2948
|
3
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "The left operand of the assign operator must be mutable.\n at %s line %d", op_dist->file, op_dist->line); |
2949
|
|
|
|
|
|
|
} |
2950
|
|
|
|
|
|
|
|
2951
|
3530586
|
|
|
|
|
|
return op_assign; |
2952
|
|
|
|
|
|
|
} |
2953
|
|
|
|
|
|
|
|
2954
|
170154
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_return(SPVM_COMPILER* compiler, SPVM_OP* op_return, SPVM_OP* op_operand) { |
2955
|
|
|
|
|
|
|
|
2956
|
170154
|
100
|
|
|
|
|
if (op_operand) { |
2957
|
158100
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_return, op_return->last, op_operand); |
2958
|
|
|
|
|
|
|
} |
2959
|
|
|
|
|
|
|
|
2960
|
170154
|
|
|
|
|
|
return op_return; |
2961
|
|
|
|
|
|
|
} |
2962
|
|
|
|
|
|
|
|
2963
|
700486
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_operator_statement(SPVM_COMPILER* compiler, SPVM_OP* op_operator) { |
2964
|
|
|
|
|
|
|
|
2965
|
700486
|
|
|
|
|
|
return op_operator; |
2966
|
|
|
|
|
|
|
} |
2967
|
|
|
|
|
|
|
|
2968
|
140561
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_die(SPVM_COMPILER* compiler, SPVM_OP* op_die, SPVM_OP* op_operand, SPVM_OP* op_type) { |
2969
|
|
|
|
|
|
|
|
2970
|
140561
|
100
|
|
|
|
|
if (!op_operand || op_operand->id == SPVM_OP_C_ID_UNDEF) { |
|
|
100
|
|
|
|
|
|
2971
|
|
|
|
|
|
|
// Default error message |
2972
|
13
|
|
|
|
|
|
op_operand = SPVM_OP_new_op_constant_string(compiler, "Error", strlen("Error"), op_die->file, op_die->line); |
2973
|
|
|
|
|
|
|
} |
2974
|
|
|
|
|
|
|
|
2975
|
|
|
|
|
|
|
// Exception variable |
2976
|
140561
|
|
|
|
|
|
SPVM_OP* op_exception_var = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_EXCEPTION_VAR, op_operand->file, op_operand->line); |
2977
|
|
|
|
|
|
|
|
2978
|
|
|
|
|
|
|
// Assign |
2979
|
140561
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, op_operand->file, op_operand->line); |
2980
|
140561
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_exception_var, op_operand); |
2981
|
|
|
|
|
|
|
|
2982
|
140561
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_die, op_die->last, op_assign); |
2983
|
|
|
|
|
|
|
|
2984
|
140561
|
100
|
|
|
|
|
if (!op_type) { |
2985
|
140552
|
|
|
|
|
|
op_type = SPVM_OP_new_op_unresolved_type(compiler, "Error", 0, 0, op_die->file, op_die->line); |
2986
|
|
|
|
|
|
|
} |
2987
|
|
|
|
|
|
|
|
2988
|
140561
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_die, op_die->last, op_type); |
2989
|
|
|
|
|
|
|
|
2990
|
140561
|
|
|
|
|
|
return op_die; |
2991
|
|
|
|
|
|
|
} |
2992
|
|
|
|
|
|
|
|
2993
|
264
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_warn(SPVM_COMPILER* compiler, SPVM_OP* op_warn, SPVM_OP* op_operand) { |
2994
|
|
|
|
|
|
|
|
2995
|
264
|
100
|
|
|
|
|
if (!op_operand || op_operand->id == SPVM_OP_C_ID_UNDEF) { |
|
|
100
|
|
|
|
|
|
2996
|
|
|
|
|
|
|
// Default warn message |
2997
|
34
|
|
|
|
|
|
op_operand = SPVM_OP_new_op_constant_string(compiler, "Warning", strlen("Warning"), op_warn->file, op_warn->line); |
2998
|
|
|
|
|
|
|
} |
2999
|
|
|
|
|
|
|
|
3000
|
264
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_warn, op_warn->last, op_operand); |
3001
|
|
|
|
|
|
|
|
3002
|
264
|
|
|
|
|
|
return op_warn; |
3003
|
|
|
|
|
|
|
} |
3004
|
|
|
|
|
|
|
|
3005
|
64
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_basic_type_id(SPVM_COMPILER* compiler, SPVM_OP* op_basic_type_id, SPVM_OP* op_type) { |
3006
|
|
|
|
|
|
|
|
3007
|
64
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_basic_type_id, op_basic_type_id->last, op_type); |
3008
|
|
|
|
|
|
|
|
3009
|
64
|
|
|
|
|
|
return op_basic_type_id; |
3010
|
|
|
|
|
|
|
} |
3011
|
|
|
|
|
|
|
|
3012
|
263
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_print(SPVM_COMPILER* compiler, SPVM_OP* op_print, SPVM_OP* op_operand) { |
3013
|
|
|
|
|
|
|
|
3014
|
263
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_print, op_print->last, op_operand); |
3015
|
|
|
|
|
|
|
|
3016
|
263
|
|
|
|
|
|
return op_print; |
3017
|
|
|
|
|
|
|
} |
3018
|
|
|
|
|
|
|
|
3019
|
1052
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_make_read_only(SPVM_COMPILER* compiler, SPVM_OP* op_make_read_only, SPVM_OP* op_operand) { |
3020
|
|
|
|
|
|
|
|
3021
|
1052
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_make_read_only, op_make_read_only->last, op_operand); |
3022
|
|
|
|
|
|
|
|
3023
|
1052
|
|
|
|
|
|
return op_make_read_only; |
3024
|
|
|
|
|
|
|
} |
3025
|
|
|
|
|
|
|
|
3026
|
335389
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_basic_type(SPVM_COMPILER* compiler, SPVM_OP* op_name) { |
3027
|
|
|
|
|
|
|
|
3028
|
335389
|
|
|
|
|
|
const char* name = op_name->uv.name; |
3029
|
|
|
|
|
|
|
|
3030
|
|
|
|
|
|
|
SPVM_OP* op_type; |
3031
|
|
|
|
|
|
|
|
3032
|
|
|
|
|
|
|
// Add basic type |
3033
|
335389
|
|
|
|
|
|
SPVM_BASIC_TYPE* found_basic_type = SPVM_HASH_get(compiler->basic_type_symtable, name, strlen(name)); |
3034
|
335389
|
100
|
|
|
|
|
if (found_basic_type) { |
3035
|
128545
|
|
|
|
|
|
op_type = SPVM_OP_new_op_type(compiler, name, found_basic_type, 0, 0, op_name->file, op_name->line); |
3036
|
|
|
|
|
|
|
} |
3037
|
|
|
|
|
|
|
else { |
3038
|
206844
|
|
|
|
|
|
SPVM_BASIC_TYPE* new_basic_type = SPVM_LIST_get(compiler->basic_types, 0); |
3039
|
206844
|
|
|
|
|
|
op_type = SPVM_OP_new_op_type(compiler, name, new_basic_type, 0, 0, op_name->file, op_name->line); |
3040
|
|
|
|
|
|
|
} |
3041
|
|
|
|
|
|
|
|
3042
|
335389
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_type, op_type->last, op_name); |
3043
|
|
|
|
|
|
|
|
3044
|
335389
|
|
|
|
|
|
return op_type; |
3045
|
|
|
|
|
|
|
} |
3046
|
|
|
|
|
|
|
|
3047
|
2912
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_ref_type(SPVM_COMPILER* compiler, SPVM_OP* op_type_original) { |
3048
|
|
|
|
|
|
|
|
3049
|
|
|
|
|
|
|
// Type |
3050
|
2912
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new(compiler, op_type_original->uv.type->basic_type->id, op_type_original->uv.type->dimension, SPVM_NATIVE_C_TYPE_FLAG_REF); |
3051
|
2912
|
|
|
|
|
|
type->unresolved_basic_type_name = op_type_original->uv.type->unresolved_basic_type_name; |
3052
|
|
|
|
|
|
|
|
3053
|
|
|
|
|
|
|
// Type OP |
3054
|
2912
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, op_type_original->file, op_type_original->line); |
3055
|
2912
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_type, op_type->last, op_type_original); |
3056
|
|
|
|
|
|
|
|
3057
|
2912
|
|
|
|
|
|
return op_type; |
3058
|
|
|
|
|
|
|
} |
3059
|
|
|
|
|
|
|
|
3060
|
9517
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_mutable_type(SPVM_COMPILER* compiler, SPVM_OP* op_type_elem) { |
3061
|
|
|
|
|
|
|
|
3062
|
|
|
|
|
|
|
// Type |
3063
|
9517
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new(compiler, op_type_elem->uv.type->basic_type->id, op_type_elem->uv.type->dimension, op_type_elem->uv.type->flag | SPVM_NATIVE_C_TYPE_FLAG_MUTABLE); |
3064
|
9517
|
|
|
|
|
|
type->unresolved_basic_type_name = op_type_elem->uv.type->unresolved_basic_type_name; |
3065
|
|
|
|
|
|
|
|
3066
|
|
|
|
|
|
|
// Type OP |
3067
|
9517
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, op_type_elem->file, op_type_elem->line); |
3068
|
|
|
|
|
|
|
|
3069
|
9517
|
|
|
|
|
|
return op_type; |
3070
|
|
|
|
|
|
|
} |
3071
|
|
|
|
|
|
|
|
3072
|
132801
|
|
|
|
|
|
SPVM_OP* SPVM_OP_build_array_type(SPVM_COMPILER* compiler, SPVM_OP* op_type_elem, SPVM_OP* op_length) { |
3073
|
|
|
|
|
|
|
|
3074
|
|
|
|
|
|
|
// Type |
3075
|
132801
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new(compiler, op_type_elem->uv.type->basic_type->id, op_type_elem->uv.type->dimension + 1, 0); |
3076
|
132801
|
|
|
|
|
|
type->unresolved_basic_type_name = op_type_elem->uv.type->unresolved_basic_type_name; |
3077
|
|
|
|
|
|
|
|
3078
|
|
|
|
|
|
|
// Type OP |
3079
|
132801
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, op_type_elem->file, op_type_elem->line); |
3080
|
132801
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_type, op_type->last, op_type_elem); |
3081
|
|
|
|
|
|
|
|
3082
|
132801
|
100
|
|
|
|
|
if (op_length) { |
3083
|
21330
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_type, op_type->last, op_length); |
3084
|
|
|
|
|
|
|
} |
3085
|
|
|
|
|
|
|
else { |
3086
|
111471
|
|
|
|
|
|
SPVM_OP* op_do_nothing = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_DO_NOTHING, op_type_elem->file, op_type_elem->line); |
3087
|
111471
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_type, op_type->last, op_do_nothing); |
3088
|
|
|
|
|
|
|
} |
3089
|
|
|
|
|
|
|
|
3090
|
132801
|
|
|
|
|
|
return op_type; |
3091
|
|
|
|
|
|
|
} |
3092
|
|
|
|
|
|
|
|
3093
|
681871
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_assign_bool(SPVM_COMPILER* compiler, SPVM_OP* op_operand, const char* file, int32_t line) { |
3094
|
681871
|
|
|
|
|
|
SPVM_OP* op_bool = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_BOOL, file, line); |
3095
|
681871
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_bool, op_bool->last, op_operand); |
3096
|
|
|
|
|
|
|
|
3097
|
681871
|
|
|
|
|
|
SPVM_OP* op_name_var = SPVM_OP_new_op_name(compiler, "$.condition_flag", file, line); |
3098
|
681871
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op_var(compiler, op_name_var); |
3099
|
681871
|
|
|
|
|
|
SPVM_OP* op_assign = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ASSIGN, file, line); |
3100
|
681871
|
|
|
|
|
|
SPVM_OP_build_assign(compiler, op_assign, op_var, op_bool); |
3101
|
|
|
|
|
|
|
|
3102
|
681871
|
|
|
|
|
|
return op_assign; |
3103
|
|
|
|
|
|
|
} |
3104
|
|
|
|
|
|
|
|
3105
|
2322339
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_var_decl(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3106
|
2322339
|
|
|
|
|
|
SPVM_OP* op_var_decl = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_VAR_DECL, file, line); |
3107
|
2322339
|
|
|
|
|
|
SPVM_VAR_DECL* var_decl = SPVM_VAR_DECL_new(compiler); |
3108
|
|
|
|
|
|
|
|
3109
|
2322339
|
|
|
|
|
|
op_var_decl->uv.var_decl = var_decl; |
3110
|
2322339
|
|
|
|
|
|
var_decl->op_var_decl = op_var_decl; |
3111
|
|
|
|
|
|
|
|
3112
|
2322339
|
|
|
|
|
|
return op_var_decl; |
3113
|
|
|
|
|
|
|
} |
3114
|
|
|
|
|
|
|
|
3115
|
520466
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_var_decl_arg(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3116
|
520466
|
|
|
|
|
|
SPVM_OP* op_var_decl = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_VAR_DECL, file, line); |
3117
|
520466
|
|
|
|
|
|
SPVM_VAR_DECL* var_decl = SPVM_VAR_DECL_new_arg(compiler); |
3118
|
|
|
|
|
|
|
|
3119
|
520466
|
|
|
|
|
|
op_var_decl->uv.var_decl = var_decl; |
3120
|
520466
|
|
|
|
|
|
var_decl->op_var_decl = op_var_decl; |
3121
|
|
|
|
|
|
|
|
3122
|
520466
|
|
|
|
|
|
return op_var_decl; |
3123
|
|
|
|
|
|
|
} |
3124
|
|
|
|
|
|
|
|
3125
|
353589
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_attribute(SPVM_COMPILER* compiler, int32_t id, const char* file, int32_t line) { |
3126
|
353589
|
|
|
|
|
|
SPVM_OP* op_attribute = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ATTRIBUTE, file, line); |
3127
|
|
|
|
|
|
|
|
3128
|
353589
|
|
|
|
|
|
SPVM_ATTRIBUTE* attribute = SPVM_ATTRIBUTE_new(compiler); |
3129
|
353589
|
|
|
|
|
|
attribute->id = id; |
3130
|
353589
|
|
|
|
|
|
op_attribute->uv.attribute = attribute; |
3131
|
|
|
|
|
|
|
|
3132
|
353589
|
|
|
|
|
|
return op_attribute; |
3133
|
|
|
|
|
|
|
} |
3134
|
|
|
|
|
|
|
|
3135
|
41405
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_undef(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3136
|
41405
|
|
|
|
|
|
SPVM_OP* op_undef = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_UNDEF, file, line); |
3137
|
|
|
|
|
|
|
|
3138
|
41405
|
|
|
|
|
|
return op_undef; |
3139
|
|
|
|
|
|
|
} |
3140
|
|
|
|
|
|
|
|
3141
|
1562778
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_block(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3142
|
1562778
|
|
|
|
|
|
SPVM_OP* op_block = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_BLOCK, file, line); |
3143
|
|
|
|
|
|
|
|
3144
|
1562778
|
|
|
|
|
|
SPVM_BLOCK* block = SPVM_BLOCK_new(compiler); |
3145
|
1562778
|
|
|
|
|
|
op_block->uv.block = block; |
3146
|
|
|
|
|
|
|
|
3147
|
1562778
|
|
|
|
|
|
return op_block; |
3148
|
|
|
|
|
|
|
} |
3149
|
|
|
|
|
|
|
|
3150
|
80311
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_use(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3151
|
80311
|
|
|
|
|
|
SPVM_OP* op_use = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_USE, file, line); |
3152
|
|
|
|
|
|
|
|
3153
|
80311
|
|
|
|
|
|
SPVM_USE* use = SPVM_USE_new(compiler); |
3154
|
80311
|
|
|
|
|
|
op_use->uv.use = use; |
3155
|
|
|
|
|
|
|
|
3156
|
80311
|
|
|
|
|
|
return op_use; |
3157
|
|
|
|
|
|
|
} |
3158
|
|
|
|
|
|
|
|
3159
|
6027406
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_name(SPVM_COMPILER* compiler, const char* name, const char* file, int32_t line) { |
3160
|
|
|
|
|
|
|
|
3161
|
6027406
|
|
|
|
|
|
SPVM_OP* op_name = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NAME, file, line); |
3162
|
|
|
|
|
|
|
|
3163
|
6027406
|
|
|
|
|
|
SPVM_STRING* name_string = SPVM_STRING_new(compiler, name, strlen(name)); |
3164
|
|
|
|
|
|
|
|
3165
|
6027406
|
|
|
|
|
|
name = name_string->value; |
3166
|
|
|
|
|
|
|
|
3167
|
6027406
|
|
|
|
|
|
op_name->uv.name = name; |
3168
|
|
|
|
|
|
|
|
3169
|
6027406
|
|
|
|
|
|
return op_name; |
3170
|
|
|
|
|
|
|
} |
3171
|
|
|
|
|
|
|
|
3172
|
6858912
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_var(SPVM_COMPILER* compiler, SPVM_OP* op_name) { |
3173
|
|
|
|
|
|
|
|
3174
|
6858912
|
|
|
|
|
|
SPVM_OP* op_var = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_VAR, op_name->file, op_name->line); |
3175
|
|
|
|
|
|
|
|
3176
|
6858912
|
|
|
|
|
|
SPVM_VAR* var = SPVM_VAR_new(compiler); |
3177
|
6858912
|
|
|
|
|
|
var->op_name = op_name; |
3178
|
6858912
|
|
|
|
|
|
var->name = op_name->uv.name; |
3179
|
6858912
|
|
|
|
|
|
op_var->uv.var = var; |
3180
|
|
|
|
|
|
|
|
3181
|
6858912
|
|
|
|
|
|
return op_var; |
3182
|
|
|
|
|
|
|
} |
3183
|
|
|
|
|
|
|
|
3184
|
12964
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_class_var_access(SPVM_COMPILER* compiler, SPVM_OP* op_class_var_name) { |
3185
|
|
|
|
|
|
|
|
3186
|
12964
|
|
|
|
|
|
const char* class_var_name = op_class_var_name->uv.name; |
3187
|
|
|
|
|
|
|
|
3188
|
12964
|
|
|
|
|
|
SPVM_OP* op_class_var_access = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_CLASS_VAR_ACCESS, op_class_var_name->file, op_class_var_name->line); |
3189
|
|
|
|
|
|
|
|
3190
|
12964
|
|
|
|
|
|
SPVM_CLASS_VAR_ACCESS* class_var_access = SPVM_CLASS_VAR_ACCESS_new(compiler); |
3191
|
12964
|
|
|
|
|
|
class_var_access->op_name = op_class_var_name; |
3192
|
12964
|
|
|
|
|
|
op_class_var_access->uv.class_var_access = class_var_access; |
3193
|
|
|
|
|
|
|
|
3194
|
12964
|
|
|
|
|
|
return op_class_var_access; |
3195
|
|
|
|
|
|
|
} |
3196
|
|
|
|
|
|
|
|
3197
|
2283
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_array_field_access(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3198
|
|
|
|
|
|
|
|
3199
|
2283
|
|
|
|
|
|
SPVM_OP* op_array_field_access = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ARRAY_FIELD_ACCESS, file, line); |
3200
|
|
|
|
|
|
|
|
3201
|
2283
|
|
|
|
|
|
SPVM_ARRAY_FIELD_ACCESS* array_field_access = SPVM_ARRAY_FIELD_ACCESS_new(compiler); |
3202
|
|
|
|
|
|
|
|
3203
|
2283
|
|
|
|
|
|
op_array_field_access->uv.array_field_access = array_field_access; |
3204
|
|
|
|
|
|
|
|
3205
|
2283
|
|
|
|
|
|
return op_array_field_access; |
3206
|
|
|
|
|
|
|
} |
3207
|
|
|
|
|
|
|
|
3208
|
348828
|
|
|
|
|
|
SPVM_OP* SPVM_OP_clone_op_var(SPVM_COMPILER* compiler, SPVM_OP* op_var) { |
3209
|
|
|
|
|
|
|
|
3210
|
348828
|
|
|
|
|
|
SPVM_OP* op_name = SPVM_OP_new_op_name(compiler, op_var->uv.var->name, op_var->file, op_var->line); |
3211
|
348828
|
|
|
|
|
|
SPVM_OP* op_var_clone = SPVM_OP_new_op_var(compiler, op_name); |
3212
|
348828
|
|
|
|
|
|
SPVM_VAR* var_clone = op_var_clone->uv.var; |
3213
|
|
|
|
|
|
|
|
3214
|
348828
|
|
|
|
|
|
var_clone->var_decl = op_var->uv.var->var_decl; |
3215
|
|
|
|
|
|
|
|
3216
|
348828
|
|
|
|
|
|
return op_var_clone; |
3217
|
|
|
|
|
|
|
} |
3218
|
|
|
|
|
|
|
|
3219
|
15930
|
|
|
|
|
|
SPVM_OP* SPVM_OP_clone_op_field_access(SPVM_COMPILER* compiler, SPVM_OP* op_field_access, SPVM_OP* op_var_invocant, SPVM_OP* op_name_field) { |
3220
|
|
|
|
|
|
|
|
3221
|
15930
|
|
|
|
|
|
SPVM_OP* op_var_invocant_clone = SPVM_OP_clone_op_var(compiler, op_var_invocant); |
3222
|
|
|
|
|
|
|
|
3223
|
15930
|
|
|
|
|
|
SPVM_OP* op_field_access_clone = SPVM_OP_new_op_field_access(compiler, op_field_access->file, op_field_access->line); |
3224
|
|
|
|
|
|
|
|
3225
|
15930
|
|
|
|
|
|
SPVM_OP* op_name_field_clone = SPVM_OP_new_op_name(compiler,op_name_field->uv.name, op_name_field->file, op_name_field->line); |
3226
|
|
|
|
|
|
|
|
3227
|
15930
|
|
|
|
|
|
op_field_access_clone = SPVM_OP_build_field_access(compiler, op_field_access_clone, op_var_invocant_clone, op_name_field_clone); |
3228
|
|
|
|
|
|
|
|
3229
|
15930
|
|
|
|
|
|
return op_field_access_clone; |
3230
|
|
|
|
|
|
|
} |
3231
|
|
|
|
|
|
|
|
3232
|
262
|
|
|
|
|
|
SPVM_OP* SPVM_OP_clone_op_array_access(SPVM_COMPILER* compiler, SPVM_OP* op_array_access, SPVM_OP* op_var_array, SPVM_OP* op_var_index) { |
3233
|
262
|
|
|
|
|
|
SPVM_OP* op_var_array_clone = SPVM_OP_clone_op_var(compiler, op_var_array); |
3234
|
262
|
|
|
|
|
|
SPVM_OP* op_var_index_clone = SPVM_OP_clone_op_var(compiler, op_var_index); |
3235
|
262
|
|
|
|
|
|
SPVM_OP* op_array_access_clone = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ARRAY_ACCESS, op_array_access->file, op_array_access->line); |
3236
|
|
|
|
|
|
|
|
3237
|
262
|
|
|
|
|
|
op_array_access_clone = SPVM_OP_build_array_access(compiler, op_array_access_clone, op_var_array_clone, op_var_index_clone); |
3238
|
|
|
|
|
|
|
|
3239
|
262
|
|
|
|
|
|
op_array_access_clone->flag = op_array_access->flag; |
3240
|
|
|
|
|
|
|
|
3241
|
262
|
|
|
|
|
|
return op_array_access_clone; |
3242
|
|
|
|
|
|
|
} |
3243
|
|
|
|
|
|
|
|
3244
|
172
|
|
|
|
|
|
SPVM_OP* SPVM_OP_clone_op_array_field_access(SPVM_COMPILER* compiler, SPVM_OP* op_field_access, SPVM_OP* op_name_field, SPVM_OP* op_array_access, SPVM_OP* op_var_array, SPVM_OP* op_var_index) { |
3245
|
|
|
|
|
|
|
|
3246
|
172
|
|
|
|
|
|
SPVM_OP* op_field_access_clone = SPVM_OP_new_op_field_access(compiler, op_field_access->file, op_field_access->line); |
3247
|
|
|
|
|
|
|
|
3248
|
172
|
|
|
|
|
|
SPVM_OP* op_var_array_clone = SPVM_OP_clone_op_var(compiler, op_var_array); |
3249
|
172
|
|
|
|
|
|
SPVM_OP* op_var_index_clone = SPVM_OP_clone_op_var(compiler, op_var_index); |
3250
|
|
|
|
|
|
|
|
3251
|
172
|
|
|
|
|
|
SPVM_OP* op_array_access_clone = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_ARRAY_ACCESS, op_array_access->file, op_array_access->line); |
3252
|
172
|
|
|
|
|
|
op_array_access_clone = SPVM_OP_build_array_access(compiler, op_array_access_clone, op_var_array_clone, op_var_index_clone); |
3253
|
|
|
|
|
|
|
|
3254
|
172
|
|
|
|
|
|
op_array_access_clone->flag = op_array_access->flag; |
3255
|
|
|
|
|
|
|
|
3256
|
172
|
|
|
|
|
|
SPVM_OP* op_name_field_clone = SPVM_OP_new_op_name(compiler, op_name_field->uv.name, op_name_field->file, op_name_field->line); |
3257
|
|
|
|
|
|
|
|
3258
|
172
|
|
|
|
|
|
op_field_access_clone = SPVM_OP_build_field_access(compiler, op_field_access_clone, op_array_access_clone, op_name_field_clone); |
3259
|
|
|
|
|
|
|
|
3260
|
172
|
|
|
|
|
|
return op_field_access_clone; |
3261
|
|
|
|
|
|
|
} |
3262
|
|
|
|
|
|
|
|
3263
|
1106
|
|
|
|
|
|
SPVM_OP* SPVM_OP_clone_op_deref(SPVM_COMPILER* compiler, SPVM_OP* op_deref, SPVM_OP* op_var) { |
3264
|
|
|
|
|
|
|
|
3265
|
1106
|
|
|
|
|
|
SPVM_OP* op_deref_clone = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_DEREF, op_deref->file, op_deref->line); |
3266
|
|
|
|
|
|
|
|
3267
|
1106
|
|
|
|
|
|
SPVM_OP* op_var_clone = SPVM_OP_clone_op_var(compiler, op_var); |
3268
|
|
|
|
|
|
|
|
3269
|
1106
|
|
|
|
|
|
SPVM_OP_build_unary_op(compiler, op_deref_clone, op_var_clone); |
3270
|
|
|
|
|
|
|
|
3271
|
1106
|
|
|
|
|
|
return op_deref_clone; |
3272
|
|
|
|
|
|
|
} |
3273
|
|
|
|
|
|
|
|
3274
|
1002055
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3275
|
1002055
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_CONSTANT, file, line); |
3276
|
1002055
|
|
|
|
|
|
SPVM_CONSTANT* constant = SPVM_CONSTANT_new(compiler); |
3277
|
1002055
|
50
|
|
|
|
|
assert(constant); |
3278
|
1002055
|
|
|
|
|
|
op_constant->uv.constant = constant; |
3279
|
1002055
|
|
|
|
|
|
constant->op_constant = op_constant; |
3280
|
|
|
|
|
|
|
|
3281
|
1002055
|
|
|
|
|
|
return op_constant; |
3282
|
|
|
|
|
|
|
} |
3283
|
|
|
|
|
|
|
|
3284
|
49656
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant_byte(SPVM_COMPILER* compiler, int8_t value, const char* file, int32_t line) { |
3285
|
49656
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant(compiler, file, line); |
3286
|
49656
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
3287
|
|
|
|
|
|
|
|
3288
|
49656
|
|
|
|
|
|
constant->value.bval = value; |
3289
|
49656
|
|
|
|
|
|
SPVM_OP* op_constant_type = SPVM_OP_new_op_byte_type(compiler, file, line); |
3290
|
49656
|
|
|
|
|
|
constant->type = op_constant_type->uv.type; |
3291
|
|
|
|
|
|
|
|
3292
|
49656
|
|
|
|
|
|
return op_constant; |
3293
|
|
|
|
|
|
|
} |
3294
|
|
|
|
|
|
|
|
3295
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant_short(SPVM_COMPILER* compiler, int16_t value, const char* file, int32_t line) { |
3296
|
0
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant(compiler, file, line); |
3297
|
0
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
3298
|
|
|
|
|
|
|
|
3299
|
0
|
|
|
|
|
|
constant->value.sval = value; |
3300
|
0
|
|
|
|
|
|
SPVM_OP* op_constant_type = SPVM_OP_new_op_short_type(compiler, file, line); |
3301
|
0
|
|
|
|
|
|
constant->type = op_constant_type->uv.type; |
3302
|
|
|
|
|
|
|
|
3303
|
0
|
|
|
|
|
|
return op_constant; |
3304
|
|
|
|
|
|
|
} |
3305
|
|
|
|
|
|
|
|
3306
|
747358
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant_int(SPVM_COMPILER* compiler, int32_t value, const char* file, int32_t line) { |
3307
|
747358
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant(compiler, file, line); |
3308
|
747358
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
3309
|
|
|
|
|
|
|
|
3310
|
747358
|
50
|
|
|
|
|
assert(op_constant->uv.constant); |
3311
|
|
|
|
|
|
|
|
3312
|
747358
|
|
|
|
|
|
constant->value.ival = value; |
3313
|
747358
|
|
|
|
|
|
SPVM_OP* op_constant_type = SPVM_OP_new_op_int_type(compiler, file, line); |
3314
|
747358
|
|
|
|
|
|
constant->type = op_constant_type->uv.type; |
3315
|
|
|
|
|
|
|
|
3316
|
747358
|
|
|
|
|
|
return op_constant; |
3317
|
|
|
|
|
|
|
} |
3318
|
|
|
|
|
|
|
|
3319
|
5494
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant_long(SPVM_COMPILER* compiler, int64_t value, const char* file, int32_t line) { |
3320
|
5494
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant(compiler, file, line); |
3321
|
5494
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
3322
|
|
|
|
|
|
|
|
3323
|
5494
|
|
|
|
|
|
constant->value.lval = value; |
3324
|
5494
|
|
|
|
|
|
SPVM_OP* op_constant_type = SPVM_OP_new_op_long_type(compiler, file, line); |
3325
|
5494
|
|
|
|
|
|
constant->type = op_constant_type->uv.type; |
3326
|
|
|
|
|
|
|
|
3327
|
5494
|
|
|
|
|
|
return op_constant; |
3328
|
|
|
|
|
|
|
} |
3329
|
|
|
|
|
|
|
|
3330
|
1367
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant_float(SPVM_COMPILER* compiler, float value, const char* file, int32_t line) { |
3331
|
1367
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant(compiler, file, line); |
3332
|
1367
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
3333
|
|
|
|
|
|
|
|
3334
|
1367
|
|
|
|
|
|
constant->value.fval = value; |
3335
|
1367
|
|
|
|
|
|
SPVM_OP* op_constant_type = SPVM_OP_new_op_float_type(compiler, file, line); |
3336
|
1367
|
|
|
|
|
|
constant->type = op_constant_type->uv.type; |
3337
|
|
|
|
|
|
|
|
3338
|
1367
|
|
|
|
|
|
return op_constant; |
3339
|
|
|
|
|
|
|
} |
3340
|
|
|
|
|
|
|
|
3341
|
2138
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant_double(SPVM_COMPILER* compiler, double value, const char* file, int32_t line) { |
3342
|
2138
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant(compiler, file, line); |
3343
|
2138
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
3344
|
|
|
|
|
|
|
|
3345
|
2138
|
|
|
|
|
|
constant->value.dval = value; |
3346
|
2138
|
|
|
|
|
|
SPVM_OP* op_constant_type = SPVM_OP_new_op_double_type(compiler, file, line); |
3347
|
2138
|
|
|
|
|
|
constant->type = op_constant_type->uv.type; |
3348
|
|
|
|
|
|
|
|
3349
|
2138
|
|
|
|
|
|
return op_constant; |
3350
|
|
|
|
|
|
|
} |
3351
|
|
|
|
|
|
|
|
3352
|
196042
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_constant_string(SPVM_COMPILER* compiler, const char* string, int32_t length, const char* file, int32_t line) { |
3353
|
|
|
|
|
|
|
|
3354
|
196042
|
|
|
|
|
|
SPVM_OP* op_constant = SPVM_OP_new_op_constant(compiler, file, line); |
3355
|
196042
|
|
|
|
|
|
SPVM_CONSTANT* constant = op_constant->uv.constant; |
3356
|
|
|
|
|
|
|
|
3357
|
196042
|
|
|
|
|
|
SPVM_STRING* cached_string_string = SPVM_STRING_new(compiler, string, length); |
3358
|
196042
|
|
|
|
|
|
const char* cached_string = cached_string_string->value; |
3359
|
|
|
|
|
|
|
|
3360
|
196042
|
|
|
|
|
|
constant->value.oval = (void*)cached_string; |
3361
|
196042
|
|
|
|
|
|
SPVM_OP* op_constant_type = SPVM_OP_new_op_string_type(compiler, file, line); |
3362
|
196042
|
|
|
|
|
|
constant->type = op_constant_type->uv.type; |
3363
|
196042
|
|
|
|
|
|
constant->string_length = length; |
3364
|
|
|
|
|
|
|
|
3365
|
196042
|
|
|
|
|
|
return op_constant; |
3366
|
|
|
|
|
|
|
} |
3367
|
|
|
|
|
|
|
|
3368
|
106234
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_void_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3369
|
106234
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_void_type(compiler); |
3370
|
106234
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3371
|
106234
|
|
|
|
|
|
return op_type; |
3372
|
|
|
|
|
|
|
} |
3373
|
|
|
|
|
|
|
|
3374
|
74896
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_byte_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3375
|
74896
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_byte_type(compiler); |
3376
|
74896
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3377
|
74896
|
|
|
|
|
|
return op_type; |
3378
|
|
|
|
|
|
|
} |
3379
|
|
|
|
|
|
|
|
3380
|
19552
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_short_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3381
|
19552
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_short_type(compiler); |
3382
|
19552
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3383
|
19552
|
|
|
|
|
|
return op_type; |
3384
|
|
|
|
|
|
|
} |
3385
|
|
|
|
|
|
|
|
3386
|
2660571
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_int_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3387
|
2660571
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_int_type(compiler); |
3388
|
2660571
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3389
|
2660571
|
|
|
|
|
|
return op_type; |
3390
|
|
|
|
|
|
|
} |
3391
|
|
|
|
|
|
|
|
3392
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_bool_object_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3393
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_bool_object_type(compiler); |
3394
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3395
|
0
|
|
|
|
|
|
return op_type; |
3396
|
|
|
|
|
|
|
} |
3397
|
|
|
|
|
|
|
|
3398
|
47483
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_long_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3399
|
47483
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_long_type(compiler); |
3400
|
47483
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3401
|
47483
|
|
|
|
|
|
return op_type; |
3402
|
|
|
|
|
|
|
} |
3403
|
|
|
|
|
|
|
|
3404
|
29645
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_float_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3405
|
29645
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_float_type(compiler); |
3406
|
29645
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3407
|
29645
|
|
|
|
|
|
return op_type; |
3408
|
|
|
|
|
|
|
} |
3409
|
|
|
|
|
|
|
|
3410
|
39191
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_double_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3411
|
39191
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_double_type(compiler); |
3412
|
39191
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3413
|
39191
|
|
|
|
|
|
return op_type; |
3414
|
|
|
|
|
|
|
} |
3415
|
|
|
|
|
|
|
|
3416
|
326754
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_string_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3417
|
326754
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_string_type(compiler); |
3418
|
326754
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3419
|
326754
|
|
|
|
|
|
return op_type; |
3420
|
|
|
|
|
|
|
} |
3421
|
|
|
|
|
|
|
|
3422
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_undef_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3423
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_undef_type(compiler); |
3424
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3425
|
0
|
|
|
|
|
|
return op_type; |
3426
|
|
|
|
|
|
|
} |
3427
|
|
|
|
|
|
|
|
3428
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_byte_ref_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3429
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_byte_ref_type(compiler); |
3430
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3431
|
0
|
|
|
|
|
|
return op_type; |
3432
|
|
|
|
|
|
|
} |
3433
|
|
|
|
|
|
|
|
3434
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_short_ref_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3435
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_short_ref_type(compiler); |
3436
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3437
|
0
|
|
|
|
|
|
return op_type; |
3438
|
|
|
|
|
|
|
} |
3439
|
|
|
|
|
|
|
|
3440
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_int_ref_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3441
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_int_ref_type(compiler); |
3442
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3443
|
0
|
|
|
|
|
|
return op_type; |
3444
|
|
|
|
|
|
|
} |
3445
|
|
|
|
|
|
|
|
3446
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_long_ref_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3447
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_long_ref_type(compiler); |
3448
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3449
|
0
|
|
|
|
|
|
return op_type; |
3450
|
|
|
|
|
|
|
} |
3451
|
|
|
|
|
|
|
|
3452
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_float_ref_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3453
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_float_ref_type(compiler); |
3454
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3455
|
0
|
|
|
|
|
|
return op_type; |
3456
|
|
|
|
|
|
|
} |
3457
|
|
|
|
|
|
|
|
3458
|
0
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_double_ref_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3459
|
0
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_double_ref_type(compiler); |
3460
|
0
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3461
|
0
|
|
|
|
|
|
return op_type; |
3462
|
|
|
|
|
|
|
} |
3463
|
|
|
|
|
|
|
|
3464
|
51492
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_any_object_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3465
|
51492
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_any_object_type(compiler); |
3466
|
51492
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3467
|
51492
|
|
|
|
|
|
return op_type; |
3468
|
|
|
|
|
|
|
} |
3469
|
|
|
|
|
|
|
|
3470
|
254823
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_unresolved_type(SPVM_COMPILER* compiler, const char* name, int32_t type_dimension, int32_t type_flag, const char* file, int32_t line) { |
3471
|
254823
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_unresolved_type(compiler, name, type_dimension, type_flag); |
3472
|
254823
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3473
|
254823
|
|
|
|
|
|
return op_type; |
3474
|
|
|
|
|
|
|
} |
3475
|
|
|
|
|
|
|
|
3476
|
51
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_any_object_array_type(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3477
|
51
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_any_object_array_type(compiler); |
3478
|
51
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op_type(compiler, type->unresolved_basic_type_name, type->basic_type, type->dimension, type->flag, file, line); |
3479
|
|
|
|
|
|
|
|
3480
|
51
|
|
|
|
|
|
return op_type; |
3481
|
|
|
|
|
|
|
} |
3482
|
|
|
|
|
|
|
|
3483
|
4496355
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_type(SPVM_COMPILER* compiler, const char* unresolved_basic_type_name, SPVM_BASIC_TYPE* basic_type, int32_t type_dimension, int32_t type_flag, const char* file, int32_t line) { |
3484
|
|
|
|
|
|
|
|
3485
|
4496355
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_TYPE, file, line); |
3486
|
4496355
|
|
|
|
|
|
SPVM_TYPE* type = SPVM_TYPE_new_uninitialized(compiler); |
3487
|
|
|
|
|
|
|
|
3488
|
4496355
|
|
|
|
|
|
type->unresolved_basic_type_name = unresolved_basic_type_name; |
3489
|
4496355
|
|
|
|
|
|
type->basic_type = basic_type; |
3490
|
4496355
|
|
|
|
|
|
type->dimension = type_dimension; |
3491
|
4496355
|
|
|
|
|
|
type->flag = type_flag; |
3492
|
|
|
|
|
|
|
|
3493
|
4496355
|
|
|
|
|
|
op_type->uv.type = type; |
3494
|
|
|
|
|
|
|
|
3495
|
4496355
|
|
|
|
|
|
SPVM_LIST_push(compiler->op_types, op_type); |
3496
|
|
|
|
|
|
|
|
3497
|
4496355
|
|
|
|
|
|
return op_type; |
3498
|
|
|
|
|
|
|
} |
3499
|
|
|
|
|
|
|
|
3500
|
32
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_true(SPVM_COMPILER* compiler, SPVM_OP* op) { |
3501
|
|
|
|
|
|
|
|
3502
|
32
|
|
|
|
|
|
SPVM_OP* op_call_method = SPVM_OP_new_op_call_method(compiler, op->file, op->line); |
3503
|
32
|
|
|
|
|
|
SPVM_OP* op_name_basic_type = SPVM_OP_new_op_name(compiler, "Bool", op->file, op->line); |
3504
|
32
|
|
|
|
|
|
SPVM_OP* op_name_method = SPVM_OP_new_op_name(compiler, "TRUE", op->file, op->line); |
3505
|
32
|
|
|
|
|
|
SPVM_OP* op_operators = SPVM_OP_new_op_list(compiler, op->file, op->line); |
3506
|
32
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_build_basic_type(compiler, op_name_basic_type); |
3507
|
|
|
|
|
|
|
|
3508
|
32
|
|
|
|
|
|
op_call_method = SPVM_OP_build_call_method(compiler, op_call_method, op_type, op_name_method, op_operators); |
3509
|
|
|
|
|
|
|
|
3510
|
32
|
|
|
|
|
|
return op_call_method; |
3511
|
|
|
|
|
|
|
} |
3512
|
|
|
|
|
|
|
|
3513
|
30
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_false(SPVM_COMPILER* compiler, SPVM_OP* op) { |
3514
|
|
|
|
|
|
|
|
3515
|
30
|
|
|
|
|
|
SPVM_OP* op_call_method = SPVM_OP_new_op_call_method(compiler, op->file, op->line); |
3516
|
30
|
|
|
|
|
|
SPVM_OP* op_name_basic_type = SPVM_OP_new_op_name(compiler, "Bool", op->file, op->line); |
3517
|
30
|
|
|
|
|
|
SPVM_OP* op_name_method = SPVM_OP_new_op_name(compiler, "FALSE", op->file, op->line); |
3518
|
30
|
|
|
|
|
|
SPVM_OP* op_operators = SPVM_OP_new_op_list(compiler, op->file, op->line); |
3519
|
30
|
|
|
|
|
|
SPVM_OP* op_type = SPVM_OP_build_basic_type(compiler, op_name_basic_type); |
3520
|
|
|
|
|
|
|
|
3521
|
30
|
|
|
|
|
|
op_call_method = SPVM_OP_build_call_method(compiler, op_call_method, op_type, op_name_method, op_operators); |
3522
|
|
|
|
|
|
|
|
3523
|
30
|
|
|
|
|
|
return op_call_method; |
3524
|
|
|
|
|
|
|
} |
3525
|
|
|
|
|
|
|
|
3526
|
186836
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_field_access(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3527
|
186836
|
|
|
|
|
|
SPVM_OP* op_field_access = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_FIELD_ACCESS, file, line); |
3528
|
|
|
|
|
|
|
|
3529
|
186836
|
|
|
|
|
|
SPVM_FIELD_ACCESS* field_access = SPVM_FIELD_ACCESS_new(compiler); |
3530
|
|
|
|
|
|
|
|
3531
|
186836
|
|
|
|
|
|
op_field_access->uv.field_access = field_access; |
3532
|
|
|
|
|
|
|
|
3533
|
186836
|
|
|
|
|
|
return op_field_access; |
3534
|
|
|
|
|
|
|
} |
3535
|
|
|
|
|
|
|
|
3536
|
252759
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_call_method(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3537
|
|
|
|
|
|
|
|
3538
|
252759
|
|
|
|
|
|
SPVM_OP* op_call_method = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_CALL_METHOD, file, line); |
3539
|
|
|
|
|
|
|
|
3540
|
252759
|
|
|
|
|
|
SPVM_CALL_METHOD* call_method = SPVM_CALL_METHOD_new(compiler); |
3541
|
|
|
|
|
|
|
|
3542
|
252759
|
|
|
|
|
|
op_call_method->uv.call_method = call_method; |
3543
|
|
|
|
|
|
|
|
3544
|
252759
|
|
|
|
|
|
return op_call_method; |
3545
|
|
|
|
|
|
|
} |
3546
|
|
|
|
|
|
|
|
3547
|
2146627
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_list(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3548
|
|
|
|
|
|
|
|
3549
|
2146627
|
|
|
|
|
|
SPVM_OP* op_pushmark = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_PUSHMARK, file, line); |
3550
|
|
|
|
|
|
|
|
3551
|
2146627
|
|
|
|
|
|
SPVM_OP* op_list = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_LIST, file, line); |
3552
|
2146627
|
|
|
|
|
|
SPVM_OP_insert_child(compiler, op_list, op_list->last, op_pushmark); |
3553
|
|
|
|
|
|
|
|
3554
|
2146627
|
|
|
|
|
|
return op_list; |
3555
|
|
|
|
|
|
|
} |
3556
|
|
|
|
|
|
|
|
3557
|
132647
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op_name_tmp_var(SPVM_COMPILER* compiler, const char* file, int32_t line) { |
3558
|
|
|
|
|
|
|
|
3559
|
|
|
|
|
|
|
// Temparary variable name |
3560
|
132647
|
|
|
|
|
|
char* name = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, strlen("$.tmp_in_op2147483647") + 1); |
3561
|
132647
|
|
|
|
|
|
sprintf(name, "$.tmp_in_op%d", compiler->current_tmp_vars_length); |
3562
|
132647
|
|
|
|
|
|
compiler->current_tmp_vars_length++; |
3563
|
132647
|
|
|
|
|
|
SPVM_OP* op_name = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_NAME, file, line); |
3564
|
132647
|
|
|
|
|
|
op_name->uv.name = name; |
3565
|
|
|
|
|
|
|
|
3566
|
132647
|
|
|
|
|
|
return op_name; |
3567
|
|
|
|
|
|
|
} |
3568
|
|
|
|
|
|
|
|
3569
|
53326358
|
|
|
|
|
|
SPVM_OP* SPVM_OP_new_op(SPVM_COMPILER* compiler, int32_t id, const char* file, int32_t line) { |
3570
|
|
|
|
|
|
|
|
3571
|
53326358
|
|
|
|
|
|
SPVM_OP *op = SPVM_ALLOCATOR_alloc_memory_block_tmp(compiler->current_each_compile_allocator, sizeof(SPVM_OP)); |
3572
|
|
|
|
|
|
|
|
3573
|
53326358
|
|
|
|
|
|
memset(op, 0, sizeof(SPVM_OP)); |
3574
|
|
|
|
|
|
|
|
3575
|
53326358
|
|
|
|
|
|
op->id = id; |
3576
|
|
|
|
|
|
|
|
3577
|
53326358
|
50
|
|
|
|
|
assert(!op->file); |
3578
|
53326358
|
50
|
|
|
|
|
assert(!op->line); |
3579
|
|
|
|
|
|
|
|
3580
|
53326358
|
|
|
|
|
|
op->file = file; |
3581
|
53326358
|
|
|
|
|
|
op->line = line; |
3582
|
|
|
|
|
|
|
|
3583
|
53326358
|
|
|
|
|
|
SPVM_LIST_push(compiler->ops, op); |
3584
|
|
|
|
|
|
|
|
3585
|
53326358
|
|
|
|
|
|
return op; |
3586
|
|
|
|
|
|
|
} |
3587
|
|
|
|
|
|
|
|
3588
|
19037
|
|
|
|
|
|
int32_t SPVM_OP_is_allowed(SPVM_COMPILER* compiler, SPVM_BASIC_TYPE* basic_type_current, SPVM_BASIC_TYPE* basic_type_dist) { |
3589
|
|
|
|
|
|
|
|
3590
|
19037
|
|
|
|
|
|
SPVM_LIST* allows = basic_type_dist->allows; |
3591
|
|
|
|
|
|
|
|
3592
|
19037
|
|
|
|
|
|
const char* current_basic_type_name = basic_type_current->name; |
3593
|
19037
|
|
|
|
|
|
const char* dist_basic_type_name = basic_type_dist->name; |
3594
|
|
|
|
|
|
|
|
3595
|
19037
|
|
|
|
|
|
int32_t is_allowed = 0; |
3596
|
19037
|
50
|
|
|
|
|
if (strcmp(current_basic_type_name, dist_basic_type_name) == 0) { |
3597
|
0
|
|
|
|
|
|
is_allowed = 1; |
3598
|
|
|
|
|
|
|
} |
3599
|
|
|
|
|
|
|
else { |
3600
|
19037
|
100
|
|
|
|
|
for (int32_t i = 0; i < allows->length; i++) { |
3601
|
19028
|
|
|
|
|
|
SPVM_ALLOW* allow = SPVM_LIST_get(allows, i); |
3602
|
19028
|
|
|
|
|
|
const char* allow_basic_type_name = allow->basic_type_name; |
3603
|
19028
|
50
|
|
|
|
|
if (strcmp(current_basic_type_name, allow_basic_type_name) == 0) { |
3604
|
19028
|
|
|
|
|
|
is_allowed = 1; |
3605
|
19028
|
|
|
|
|
|
break; |
3606
|
|
|
|
|
|
|
} |
3607
|
|
|
|
|
|
|
} |
3608
|
|
|
|
|
|
|
} |
3609
|
|
|
|
|
|
|
|
3610
|
19037
|
|
|
|
|
|
return is_allowed; |
3611
|
|
|
|
|
|
|
} |
3612
|
|
|
|
|
|
|
|
3613
|
3637198
|
|
|
|
|
|
int32_t SPVM_OP_is_mutable(SPVM_COMPILER* compiler, SPVM_OP* op) { |
3614
|
|
|
|
|
|
|
|
3615
|
3637198
|
100
|
|
|
|
|
switch (op->id) { |
3616
|
|
|
|
|
|
|
case SPVM_OP_C_ID_VAR: |
3617
|
|
|
|
|
|
|
case SPVM_OP_C_ID_CLASS_VAR_ACCESS: |
3618
|
|
|
|
|
|
|
case SPVM_OP_C_ID_ARRAY_ACCESS: |
3619
|
|
|
|
|
|
|
case SPVM_OP_C_ID_FIELD_ACCESS: |
3620
|
|
|
|
|
|
|
case SPVM_OP_C_ID_DEREF: |
3621
|
|
|
|
|
|
|
case SPVM_OP_C_ID_EXCEPTION_VAR: |
3622
|
|
|
|
|
|
|
case SPVM_OP_C_ID_ARRAY_FIELD_ACCESS: |
3623
|
3637192
|
|
|
|
|
|
return 1; |
3624
|
|
|
|
|
|
|
} |
3625
|
|
|
|
|
|
|
|
3626
|
6
|
|
|
|
|
|
return 0; |
3627
|
|
|
|
|
|
|
} |
3628
|
|
|
|
|
|
|
|
3629
|
506018
|
|
|
|
|
|
int32_t SPVM_OP_is_comparison_op(SPVM_COMPILER* compiler, SPVM_OP* op) { |
3630
|
|
|
|
|
|
|
|
3631
|
506018
|
50
|
|
|
|
|
switch (op->id) { |
3632
|
|
|
|
|
|
|
case SPVM_OP_C_ID_NUMERIC_EQ: |
3633
|
|
|
|
|
|
|
case SPVM_OP_C_ID_NUMERIC_NE: |
3634
|
|
|
|
|
|
|
case SPVM_OP_C_ID_NUMERIC_GT: |
3635
|
|
|
|
|
|
|
case SPVM_OP_C_ID_NUMERIC_GE: |
3636
|
|
|
|
|
|
|
case SPVM_OP_C_ID_NUMERIC_LT: |
3637
|
|
|
|
|
|
|
case SPVM_OP_C_ID_NUMERIC_LE: |
3638
|
|
|
|
|
|
|
case SPVM_OP_C_ID_NUMERIC_CMP: |
3639
|
|
|
|
|
|
|
case SPVM_OP_C_ID_STRING_EQ: |
3640
|
|
|
|
|
|
|
case SPVM_OP_C_ID_STRING_NE: |
3641
|
|
|
|
|
|
|
case SPVM_OP_C_ID_STRING_GT: |
3642
|
|
|
|
|
|
|
case SPVM_OP_C_ID_STRING_GE: |
3643
|
|
|
|
|
|
|
case SPVM_OP_C_ID_STRING_LT: |
3644
|
|
|
|
|
|
|
case SPVM_OP_C_ID_STRING_LE: |
3645
|
|
|
|
|
|
|
case SPVM_OP_C_ID_STRING_CMP: |
3646
|
|
|
|
|
|
|
case SPVM_OP_C_ID_ISA: |
3647
|
|
|
|
|
|
|
case SPVM_OP_C_ID_ISA_ERROR: |
3648
|
|
|
|
|
|
|
case SPVM_OP_C_ID_IS_TYPE: |
3649
|
|
|
|
|
|
|
case SPVM_OP_C_ID_IS_ERROR: |
3650
|
|
|
|
|
|
|
{ |
3651
|
0
|
|
|
|
|
|
return 1; |
3652
|
|
|
|
|
|
|
} |
3653
|
|
|
|
|
|
|
} |
3654
|
|
|
|
|
|
|
|
3655
|
506018
|
|
|
|
|
|
return 0; |
3656
|
|
|
|
|
|
|
} |
3657
|
|
|
|
|
|
|
|
3658
|
6488448
|
|
|
|
|
|
SPVM_OP* SPVM_OP_get_parent(SPVM_COMPILER* compiler, SPVM_OP* op_target) { |
3659
|
|
|
|
|
|
|
|
3660
|
|
|
|
|
|
|
SPVM_OP* op_parent; |
3661
|
6488448
|
|
|
|
|
|
SPVM_OP* op_cur = op_target; |
3662
|
|
|
|
|
|
|
while (1) { |
3663
|
10425338
|
100
|
|
|
|
|
if (op_cur->moresib) { |
3664
|
3936890
|
|
|
|
|
|
op_cur = op_cur->sibparent; |
3665
|
|
|
|
|
|
|
} |
3666
|
|
|
|
|
|
|
else { |
3667
|
6488448
|
|
|
|
|
|
op_parent = op_cur->sibparent; |
3668
|
6488448
|
|
|
|
|
|
break; |
3669
|
|
|
|
|
|
|
} |
3670
|
3936890
|
|
|
|
|
|
} |
3671
|
|
|
|
|
|
|
|
3672
|
6488448
|
|
|
|
|
|
return op_parent; |
3673
|
|
|
|
|
|
|
} |
3674
|
|
|
|
|
|
|
|
3675
|
3244224
|
|
|
|
|
|
void SPVM_OP_get_before(SPVM_COMPILER* compiler, SPVM_OP* op_target, SPVM_OP** op_before_ptr, int32_t* next_is_child_ptr) { |
3676
|
|
|
|
|
|
|
|
3677
|
|
|
|
|
|
|
// Get parent |
3678
|
3244224
|
|
|
|
|
|
SPVM_OP* op_parent = SPVM_OP_get_parent(compiler, op_target); |
3679
|
|
|
|
|
|
|
|
3680
|
|
|
|
|
|
|
SPVM_OP* op_before; |
3681
|
3244224
|
|
|
|
|
|
int32_t next_is_child = 0; |
3682
|
3244224
|
100
|
|
|
|
|
if (op_parent->first == op_target) { |
3683
|
1562204
|
|
|
|
|
|
op_before = op_parent; |
3684
|
1562204
|
|
|
|
|
|
next_is_child = 1; |
3685
|
|
|
|
|
|
|
} |
3686
|
|
|
|
|
|
|
else { |
3687
|
1682020
|
|
|
|
|
|
op_before = op_parent->first; |
3688
|
|
|
|
|
|
|
while (1) { |
3689
|
3327054
|
100
|
|
|
|
|
if (op_before->sibparent == op_target) { |
3690
|
1682020
|
|
|
|
|
|
break; |
3691
|
|
|
|
|
|
|
} |
3692
|
|
|
|
|
|
|
else { |
3693
|
1645034
|
|
|
|
|
|
op_before = op_before->sibparent; |
3694
|
|
|
|
|
|
|
} |
3695
|
1645034
|
|
|
|
|
|
} |
3696
|
|
|
|
|
|
|
} |
3697
|
|
|
|
|
|
|
|
3698
|
3244224
|
|
|
|
|
|
*op_before_ptr = op_before; |
3699
|
3244224
|
|
|
|
|
|
*next_is_child_ptr = next_is_child; |
3700
|
3244224
|
|
|
|
|
|
} |
3701
|
|
|
|
|
|
|
|
3702
|
|
|
|
|
|
|
// Replace target op with replace op |
3703
|
1595074
|
|
|
|
|
|
void SPVM_OP_replace_op(SPVM_COMPILER* compiler, SPVM_OP* op_target, SPVM_OP* op_replace) { |
3704
|
|
|
|
|
|
|
|
3705
|
|
|
|
|
|
|
// Get parent op |
3706
|
1595074
|
|
|
|
|
|
SPVM_OP* op_parent = SPVM_OP_get_parent(compiler, op_target); |
3707
|
|
|
|
|
|
|
|
3708
|
1595074
|
|
|
|
|
|
int32_t op_target_is_last_child = op_parent->last == op_target; |
3709
|
|
|
|
|
|
|
|
3710
|
|
|
|
|
|
|
// Get before op |
3711
|
|
|
|
|
|
|
int32_t next_is_child; |
3712
|
|
|
|
|
|
|
SPVM_OP* op_before; |
3713
|
1595074
|
|
|
|
|
|
SPVM_OP_get_before(compiler, op_target, &op_before, &next_is_child); |
3714
|
|
|
|
|
|
|
|
3715
|
|
|
|
|
|
|
// Stab |
3716
|
1595074
|
100
|
|
|
|
|
if (next_is_child) { |
3717
|
|
|
|
|
|
|
// One child |
3718
|
774509
|
100
|
|
|
|
|
if (op_before->first == op_before->last) { |
3719
|
257843
|
|
|
|
|
|
op_before->first = op_replace; |
3720
|
257843
|
|
|
|
|
|
op_before->last = op_replace; |
3721
|
|
|
|
|
|
|
} |
3722
|
|
|
|
|
|
|
// More |
3723
|
|
|
|
|
|
|
else { |
3724
|
774509
|
|
|
|
|
|
op_before->first = op_replace; |
3725
|
|
|
|
|
|
|
} |
3726
|
|
|
|
|
|
|
} |
3727
|
|
|
|
|
|
|
else { |
3728
|
820565
|
|
|
|
|
|
op_before->sibparent = op_replace; |
3729
|
|
|
|
|
|
|
} |
3730
|
1595074
|
|
|
|
|
|
op_replace->moresib = op_target->moresib; |
3731
|
1595074
|
|
|
|
|
|
op_replace->sibparent = op_target->sibparent; |
3732
|
|
|
|
|
|
|
|
3733
|
1595074
|
100
|
|
|
|
|
if (op_target_is_last_child) { |
3734
|
888635
|
|
|
|
|
|
op_parent->last = op_replace; |
3735
|
|
|
|
|
|
|
} |
3736
|
1595074
|
|
|
|
|
|
} |
3737
|
|
|
|
|
|
|
|
3738
|
|
|
|
|
|
|
// Cut op and insert stab into original position and return stab |
3739
|
1649150
|
|
|
|
|
|
SPVM_OP* SPVM_OP_cut_op(SPVM_COMPILER* compiler, SPVM_OP* op_target) { |
3740
|
|
|
|
|
|
|
// Get parent op |
3741
|
1649150
|
|
|
|
|
|
SPVM_OP* op_parent = SPVM_OP_get_parent(compiler, op_target); |
3742
|
|
|
|
|
|
|
|
3743
|
1649150
|
|
|
|
|
|
int32_t op_target_is_last_child = op_parent->last == op_target; |
3744
|
|
|
|
|
|
|
|
3745
|
|
|
|
|
|
|
// Get before op |
3746
|
|
|
|
|
|
|
int32_t next_is_child; |
3747
|
|
|
|
|
|
|
SPVM_OP* op_before; |
3748
|
1649150
|
|
|
|
|
|
SPVM_OP_get_before(compiler, op_target, &op_before, &next_is_child); |
3749
|
|
|
|
|
|
|
|
3750
|
|
|
|
|
|
|
// Stab |
3751
|
1649150
|
|
|
|
|
|
SPVM_OP* op_stab = SPVM_OP_new_op(compiler, SPVM_OP_C_ID_DO_NOTHING, op_target->file, op_target->line); |
3752
|
1649150
|
100
|
|
|
|
|
if (next_is_child) { |
3753
|
|
|
|
|
|
|
|
3754
|
|
|
|
|
|
|
// One child |
3755
|
787695
|
100
|
|
|
|
|
if (op_before->first == op_before->last) { |
3756
|
265894
|
|
|
|
|
|
op_before->first = op_stab; |
3757
|
265894
|
|
|
|
|
|
op_before->last = op_stab; |
3758
|
|
|
|
|
|
|
} |
3759
|
|
|
|
|
|
|
// More |
3760
|
|
|
|
|
|
|
else { |
3761
|
787695
|
|
|
|
|
|
op_before->first = op_stab; |
3762
|
|
|
|
|
|
|
} |
3763
|
|
|
|
|
|
|
} |
3764
|
|
|
|
|
|
|
else { |
3765
|
861455
|
|
|
|
|
|
op_before->sibparent = op_stab; |
3766
|
|
|
|
|
|
|
} |
3767
|
1649150
|
|
|
|
|
|
op_stab->moresib = op_target->moresib; |
3768
|
1649150
|
|
|
|
|
|
op_stab->sibparent = op_target->sibparent; |
3769
|
|
|
|
|
|
|
|
3770
|
|
|
|
|
|
|
// Clear target |
3771
|
1649150
|
|
|
|
|
|
op_target->moresib = 0; |
3772
|
1649150
|
|
|
|
|
|
op_target->sibparent = NULL; |
3773
|
|
|
|
|
|
|
|
3774
|
1649150
|
100
|
|
|
|
|
if (op_target_is_last_child) { |
3775
|
929065
|
|
|
|
|
|
op_parent->last = op_stab; |
3776
|
|
|
|
|
|
|
} |
3777
|
|
|
|
|
|
|
|
3778
|
1649150
|
|
|
|
|
|
return op_stab; |
3779
|
|
|
|
|
|
|
} |
3780
|
|
|
|
|
|
|
|
3781
|
|
|
|
|
|
|
// Insert child. Child must not have sibling. |
3782
|
25109895
|
|
|
|
|
|
void SPVM_OP_insert_child(SPVM_COMPILER* compiler, SPVM_OP* parent, SPVM_OP* start, SPVM_OP* insert) { |
3783
|
|
|
|
|
|
|
|
3784
|
|
|
|
|
|
|
// del_count not used |
3785
|
25109895
|
50
|
|
|
|
|
assert(parent); |
3786
|
25109895
|
50
|
|
|
|
|
assert(insert); |
3787
|
25109895
|
50
|
|
|
|
|
assert(insert->moresib == 0); |
3788
|
|
|
|
|
|
|
|
3789
|
25109895
|
100
|
|
|
|
|
if (start) { |
3790
|
10934221
|
100
|
|
|
|
|
if (start->moresib) { |
3791
|
733276
|
|
|
|
|
|
insert->moresib = 1; |
3792
|
733276
|
|
|
|
|
|
insert->sibparent = start->sibparent; |
3793
|
|
|
|
|
|
|
|
3794
|
733276
|
|
|
|
|
|
start->sibparent = insert; |
3795
|
|
|
|
|
|
|
} |
3796
|
|
|
|
|
|
|
else { |
3797
|
10200945
|
|
|
|
|
|
parent->last = insert; |
3798
|
|
|
|
|
|
|
|
3799
|
10200945
|
|
|
|
|
|
insert->moresib = 0; |
3800
|
10200945
|
|
|
|
|
|
insert->sibparent = parent; |
3801
|
|
|
|
|
|
|
|
3802
|
10200945
|
|
|
|
|
|
start->moresib = 1; |
3803
|
10934221
|
|
|
|
|
|
start->sibparent = insert; |
3804
|
|
|
|
|
|
|
} |
3805
|
|
|
|
|
|
|
} |
3806
|
|
|
|
|
|
|
else { |
3807
|
14175674
|
50
|
|
|
|
|
if (parent->first) { |
3808
|
0
|
|
|
|
|
|
insert->moresib = 1; |
3809
|
0
|
|
|
|
|
|
insert->sibparent = parent->first; |
3810
|
|
|
|
|
|
|
|
3811
|
0
|
|
|
|
|
|
parent->first = insert; |
3812
|
|
|
|
|
|
|
} |
3813
|
|
|
|
|
|
|
else { |
3814
|
14175674
|
|
|
|
|
|
insert->moresib = 0; |
3815
|
14175674
|
|
|
|
|
|
insert->sibparent = parent; |
3816
|
|
|
|
|
|
|
|
3817
|
14175674
|
|
|
|
|
|
parent->first = insert; |
3818
|
14175674
|
|
|
|
|
|
parent->last = insert; |
3819
|
|
|
|
|
|
|
} |
3820
|
|
|
|
|
|
|
} |
3821
|
25109895
|
|
|
|
|
|
} |
3822
|
|
|
|
|
|
|
|
3823
|
57677109
|
|
|
|
|
|
SPVM_OP* SPVM_OP_sibling(SPVM_COMPILER* compiler, SPVM_OP* op) { |
3824
|
|
|
|
|
|
|
|
3825
|
57677109
|
100
|
|
|
|
|
return op->moresib ? op->sibparent : NULL; |
3826
|
|
|
|
|
|
|
} |
3827
|
|
|
|
|
|
|
|
3828
|
7550
|
|
|
|
|
|
const char* SPVM_OP_get_op_name(SPVM_COMPILER* compiler, int32_t op_id) { |
3829
|
7550
|
|
|
|
|
|
const char* op_name = (SPVM_OP_C_ID_NAMES())[op_id]; |
3830
|
|
|
|
|
|
|
|
3831
|
7550
|
|
|
|
|
|
return op_name; |
3832
|
|
|
|
|
|
|
} |
3833
|
|
|
|
|
|
|
|
3834
|
|
|
|
|
|
|
|