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 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#include "spvm_native.h" |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#include "spvm_type.h" |
16
|
|
|
|
|
|
|
#include "spvm_method.h" |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#include "spvm_list.h" |
19
|
|
|
|
|
|
|
#include "spvm_hash.h" |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#include "spvm_object.h" |
22
|
|
|
|
|
|
|
#include "spvm_opcode.h" |
23
|
|
|
|
|
|
|
#include "spvm_runtime_basic_type.h" |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#include "spvm_runtime_class_var.h" |
26
|
|
|
|
|
|
|
#include "spvm_runtime_field.h" |
27
|
|
|
|
|
|
|
#include "spvm_runtime.h" |
28
|
|
|
|
|
|
|
#include "spvm_runtime_method.h" |
29
|
|
|
|
|
|
|
#include "spvm_runtime_string.h" |
30
|
|
|
|
|
|
|
#include "spvm_api_runtime.h" |
31
|
|
|
|
|
|
|
#include "spvm_runtime_arg.h" |
32
|
|
|
|
|
|
|
#include "spvm_precompile.h" |
33
|
|
|
|
|
|
|
#include "spvm_api.h" |
34
|
|
|
|
|
|
|
#include "spvm_api_type.h" |
35
|
|
|
|
|
|
|
#include "spvm_runtime_basic_type.h" |
36
|
|
|
|
|
|
|
#include "spvm_api_basic_type.h" |
37
|
|
|
|
|
|
|
#include "spvm_mutex.h"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
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
119195
|
|
|
|
|
|
SPVM_API_RUNTIME* SPVM_API_RUNTIME_new_api() { |
98
|
|
|
|
|
|
|
|
99
|
119195
|
|
|
|
|
|
void* env_runtime_init[] = { |
100
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_object_data_offset, |
101
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_object_ref_count_offset, |
102
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_object_length_offset, |
103
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_basic_type_by_id, |
104
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_basic_type_by_name, |
105
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_basic_types_length, |
106
|
|
|
|
|
|
|
SPVM_API_RUNTIME_build_precompile_module_source, |
107
|
|
|
|
|
|
|
SPVM_API_RUNTIME_build_precompile_method_source, |
108
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_compiler, |
109
|
|
|
|
|
|
|
SPVM_API_RUNTIME_set_compiler, |
110
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_spvm_stdin, |
111
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_spvm_stdout, |
112
|
|
|
|
|
|
|
SPVM_API_RUNTIME_get_spvm_stderr, |
113
|
|
|
|
|
|
|
}; |
114
|
119195
|
|
|
|
|
|
SPVM_API_RUNTIME* env_runtime = calloc(1, sizeof(env_runtime_init)); |
115
|
119195
|
|
|
|
|
|
memcpy(env_runtime, env_runtime_init, sizeof(env_runtime_init)); |
116
|
|
|
|
|
|
|
|
117
|
119195
|
|
|
|
|
|
return env_runtime; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
119195
|
|
|
|
|
|
void SPVM_API_RUNTIME_free_api(SPVM_API_RUNTIME* api) { |
121
|
119195
|
|
|
|
|
|
free(api); |
122
|
119195
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_mutex_offset(SPVM_RUNTIME* runtime) { |
125
|
0
|
|
|
|
|
|
int32_t object_mutex_offset = sizeof(SPVM_OBJECT); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return object_mutex_offset; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
5665817
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_data_offset(SPVM_RUNTIME* runtime) { |
131
|
5665817
|
|
|
|
|
|
int32_t object_data_offset = sizeof(SPVM_OBJECT) + SPVM_MUTEX_size(); |
132
|
|
|
|
|
|
|
|
133
|
5665817
|
|
|
|
|
|
return object_data_offset; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
1457635
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_ref_count_offset(SPVM_RUNTIME* runtime) { |
137
|
|
|
|
|
|
|
|
138
|
1457635
|
|
|
|
|
|
return offsetof(SPVM_OBJECT, ref_count); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
1468372
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_length_offset(SPVM_RUNTIME* runtime) { |
142
|
|
|
|
|
|
|
|
143
|
1468372
|
|
|
|
|
|
return offsetof(SPVM_OBJECT, length); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
4037937
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* SPVM_API_RUNTIME_get_basic_type_by_id(SPVM_RUNTIME* runtime, int32_t basic_type_id) { |
147
|
|
|
|
|
|
|
|
148
|
4037937
|
50
|
|
|
|
|
if (basic_type_id < 0) { |
149
|
0
|
|
|
|
|
|
return NULL; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
4037937
|
50
|
|
|
|
|
if (basic_type_id >= runtime->basic_types_length) { |
153
|
0
|
|
|
|
|
|
return NULL; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
4037937
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* basic_type = runtime->basic_types[basic_type_id]; |
157
|
|
|
|
|
|
|
|
158
|
4037937
|
50
|
|
|
|
|
assert(basic_type); |
159
|
|
|
|
|
|
|
|
160
|
4037937
|
|
|
|
|
|
return basic_type; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
408438
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* SPVM_API_RUNTIME_get_basic_type_by_name(SPVM_RUNTIME* runtime, const char* basic_type_name) { |
164
|
|
|
|
|
|
|
|
165
|
408438
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* basic_type = (SPVM_RUNTIME_BASIC_TYPE*)SPVM_HASH_get(runtime->basic_type_symtable, basic_type_name, strlen(basic_type_name)); |
166
|
|
|
|
|
|
|
|
167
|
408438
|
|
|
|
|
|
return basic_type; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
1016
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_basic_types_length(SPVM_RUNTIME* runtime) { |
171
|
|
|
|
|
|
|
|
172
|
1016
|
|
|
|
|
|
return runtime->basic_types_length; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
182
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_is_any_object_type(SPVM_RUNTIME* runtime, SPVM_RUNTIME_BASIC_TYPE* basic_type, int32_t type_dimension, int32_t flag) { |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
int32_t is_any_object_type; |
178
|
182
|
50
|
|
|
|
|
if (type_dimension == 0) { |
179
|
182
|
|
|
|
|
|
int32_t basic_type_category = basic_type->category; |
180
|
|
|
|
|
|
|
|
181
|
182
|
100
|
|
|
|
|
switch (basic_type_category) { |
182
|
|
|
|
|
|
|
case SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_ANY_OBJECT: |
183
|
|
|
|
|
|
|
{ |
184
|
50
|
|
|
|
|
|
is_any_object_type = 1; |
185
|
50
|
|
|
|
|
|
break; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
default: { |
188
|
182
|
|
|
|
|
|
is_any_object_type = 0; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
0
|
0
|
|
|
|
|
else if (type_dimension >= 1) { |
193
|
0
|
|
|
|
|
|
is_any_object_type = 1; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
else { |
196
|
0
|
|
|
|
|
|
assert(0); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
182
|
|
|
|
|
|
return is_any_object_type; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_is_object_array_type(SPVM_RUNTIME* runtime, SPVM_RUNTIME_BASIC_TYPE* basic_type, int32_t dimension, int32_t flag) { |
203
|
|
|
|
|
|
|
|
204
|
0
|
0
|
|
|
|
|
if (dimension > 0) { |
205
|
0
|
0
|
|
|
|
|
if (SPVM_API_TYPE_is_object_type(runtime, basic_type, dimension - 1, flag)) { |
206
|
0
|
|
|
|
|
|
return 1; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
else { |
209
|
0
|
|
|
|
|
|
return 0; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
else { |
213
|
0
|
|
|
|
|
|
return 0; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
132
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_is_any_object_array_type(SPVM_RUNTIME* runtime, SPVM_RUNTIME_BASIC_TYPE* basic_type, int32_t type_dimension, int32_t flag) { |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
int32_t is_any_object_array_type; |
220
|
132
|
50
|
|
|
|
|
if (type_dimension == 1) { |
221
|
0
|
|
|
|
|
|
int32_t basic_type_category = basic_type->category; |
222
|
|
|
|
|
|
|
|
223
|
0
|
0
|
|
|
|
|
switch (basic_type_category) { |
224
|
|
|
|
|
|
|
case SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_ANY_OBJECT: |
225
|
|
|
|
|
|
|
{ |
226
|
0
|
|
|
|
|
|
is_any_object_array_type = 1; |
227
|
0
|
|
|
|
|
|
break; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
default: { |
230
|
0
|
|
|
|
|
|
is_any_object_array_type = 0; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
else { |
235
|
132
|
|
|
|
|
|
is_any_object_array_type = 0; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
132
|
|
|
|
|
|
return is_any_object_array_type; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
513
|
|
|
|
|
|
void SPVM_API_RUNTIME_build_precompile_module_source(SPVM_RUNTIME* runtime, SPVM_STRING_BUFFER* string_buffer, SPVM_RUNTIME_BASIC_TYPE* module_basic_type) { |
242
|
513
|
|
|
|
|
|
SPVM_PRECOMPILE* precompile = SPVM_PRECOMPILE_new(precompile); |
243
|
513
|
|
|
|
|
|
SPVM_PRECOMPILE_set_runtime(precompile, runtime); |
244
|
513
|
|
|
|
|
|
SPVM_PRECOMPILE_build_module_source(precompile, string_buffer, module_basic_type); |
245
|
513
|
|
|
|
|
|
SPVM_PRECOMPILE_free(precompile); |
246
|
513
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
2
|
|
|
|
|
|
void SPVM_API_RUNTIME_build_precompile_method_source(SPVM_RUNTIME* runtime, SPVM_STRING_BUFFER* string_buffer, SPVM_RUNTIME_METHOD* method) { |
249
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE* precompile = SPVM_PRECOMPILE_new(precompile); |
250
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE_set_runtime(precompile, runtime); |
251
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE_build_method_source(precompile, string_buffer, method->current_basic_type, method); |
252
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE_free(precompile); |
253
|
2
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
SPVM_COMPILER* SPVM_API_RUNTIME_get_compiler(SPVM_RUNTIME* runtime) { |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
return runtime->compiler; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
672
|
|
|
|
|
|
void SPVM_API_RUNTIME_set_compiler(SPVM_RUNTIME* runtime, SPVM_COMPILER* compiler) { |
261
|
|
|
|
|
|
|
|
262
|
672
|
|
|
|
|
|
runtime->compiler = compiler; |
263
|
672
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
2
|
|
|
|
|
|
FILE* SPVM_API_RUNTIME_get_spvm_stdin(SPVM_RUNTIME* runtime) { |
266
|
|
|
|
|
|
|
|
267
|
2
|
|
|
|
|
|
return runtime->spvm_stdin; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
22
|
|
|
|
|
|
FILE* SPVM_API_RUNTIME_get_spvm_stdout(SPVM_RUNTIME* runtime) { |
271
|
|
|
|
|
|
|
|
272
|
22
|
|
|
|
|
|
return runtime->spvm_stdout; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
22
|
|
|
|
|
|
FILE* SPVM_API_RUNTIME_get_spvm_stderr(SPVM_RUNTIME* runtime) { |
276
|
|
|
|
|
|
|
|
277
|
22
|
|
|
|
|
|
return runtime->spvm_stderr; |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|