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
|
119269
|
|
|
|
|
|
SPVM_API_RUNTIME* SPVM_API_RUNTIME_new_api() { |
98
|
|
|
|
|
|
|
|
99
|
119269
|
|
|
|
|
|
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
|
|
|
|
|
|
|
}; |
111
|
119269
|
|
|
|
|
|
SPVM_API_RUNTIME* env_runtime = calloc(1, sizeof(env_runtime_init)); |
112
|
119269
|
|
|
|
|
|
memcpy(env_runtime, env_runtime_init, sizeof(env_runtime_init)); |
113
|
|
|
|
|
|
|
|
114
|
119269
|
|
|
|
|
|
return env_runtime; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
119269
|
|
|
|
|
|
void SPVM_API_RUNTIME_free_api(SPVM_API_RUNTIME* api) { |
118
|
119269
|
|
|
|
|
|
free(api); |
119
|
119269
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_mutex_offset(SPVM_RUNTIME* runtime) { |
122
|
0
|
|
|
|
|
|
int32_t object_mutex_offset = sizeof(SPVM_OBJECT); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return object_mutex_offset; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
5706659
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_data_offset(SPVM_RUNTIME* runtime) { |
128
|
5706659
|
|
|
|
|
|
int32_t object_data_offset = sizeof(SPVM_OBJECT) + SPVM_MUTEX_size(); |
129
|
|
|
|
|
|
|
|
130
|
5706659
|
|
|
|
|
|
return object_data_offset; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
1460468
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_ref_count_offset(SPVM_RUNTIME* runtime) { |
134
|
|
|
|
|
|
|
|
135
|
1460468
|
|
|
|
|
|
return offsetof(SPVM_OBJECT, ref_count); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
1471205
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_object_length_offset(SPVM_RUNTIME* runtime) { |
139
|
|
|
|
|
|
|
|
140
|
1471205
|
|
|
|
|
|
return offsetof(SPVM_OBJECT, length); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
4039046
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* SPVM_API_RUNTIME_get_basic_type_by_id(SPVM_RUNTIME* runtime, int32_t basic_type_id) { |
144
|
|
|
|
|
|
|
|
145
|
4039046
|
50
|
|
|
|
|
if (basic_type_id < 0) { |
146
|
0
|
|
|
|
|
|
return NULL; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
4039046
|
50
|
|
|
|
|
if (basic_type_id >= runtime->basic_types_length) { |
150
|
0
|
|
|
|
|
|
return NULL; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
4039046
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* basic_type = runtime->basic_types[basic_type_id]; |
154
|
|
|
|
|
|
|
|
155
|
4039046
|
50
|
|
|
|
|
assert(basic_type); |
156
|
|
|
|
|
|
|
|
157
|
4039046
|
|
|
|
|
|
return basic_type; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
413229
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* SPVM_API_RUNTIME_get_basic_type_by_name(SPVM_RUNTIME* runtime, const char* basic_type_name) { |
161
|
|
|
|
|
|
|
|
162
|
413229
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* basic_type = (SPVM_RUNTIME_BASIC_TYPE*)SPVM_HASH_get(runtime->basic_type_symtable, basic_type_name, strlen(basic_type_name)); |
163
|
|
|
|
|
|
|
|
164
|
413229
|
|
|
|
|
|
return basic_type; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
1000
|
|
|
|
|
|
int32_t SPVM_API_RUNTIME_get_basic_types_length(SPVM_RUNTIME* runtime) { |
168
|
|
|
|
|
|
|
|
169
|
1000
|
|
|
|
|
|
return runtime->basic_types_length; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
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) { |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
int32_t is_any_object_type; |
175
|
182
|
50
|
|
|
|
|
if (type_dimension == 0) { |
176
|
182
|
|
|
|
|
|
int32_t basic_type_category = basic_type->category; |
177
|
|
|
|
|
|
|
|
178
|
182
|
100
|
|
|
|
|
switch (basic_type_category) { |
179
|
|
|
|
|
|
|
case SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_ANY_OBJECT: |
180
|
|
|
|
|
|
|
{ |
181
|
50
|
|
|
|
|
|
is_any_object_type = 1; |
182
|
50
|
|
|
|
|
|
break; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
default: { |
185
|
182
|
|
|
|
|
|
is_any_object_type = 0; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
0
|
0
|
|
|
|
|
else if (type_dimension >= 1) { |
190
|
0
|
|
|
|
|
|
is_any_object_type = 1; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
else { |
193
|
0
|
|
|
|
|
|
assert(0); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
182
|
|
|
|
|
|
return is_any_object_type; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
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) { |
200
|
|
|
|
|
|
|
|
201
|
0
|
0
|
|
|
|
|
if (dimension > 0) { |
202
|
0
|
0
|
|
|
|
|
if (SPVM_API_TYPE_is_object_type(runtime, basic_type, dimension - 1, flag)) { |
203
|
0
|
|
|
|
|
|
return 1; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
else { |
206
|
0
|
|
|
|
|
|
return 0; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
else { |
210
|
0
|
|
|
|
|
|
return 0; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
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) { |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
int32_t is_any_object_array_type; |
217
|
132
|
50
|
|
|
|
|
if (type_dimension == 1) { |
218
|
0
|
|
|
|
|
|
int32_t basic_type_category = basic_type->category; |
219
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
switch (basic_type_category) { |
221
|
|
|
|
|
|
|
case SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_ANY_OBJECT: |
222
|
|
|
|
|
|
|
{ |
223
|
0
|
|
|
|
|
|
is_any_object_array_type = 1; |
224
|
0
|
|
|
|
|
|
break; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
default: { |
227
|
0
|
|
|
|
|
|
is_any_object_array_type = 0; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
else { |
232
|
132
|
|
|
|
|
|
is_any_object_array_type = 0; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
132
|
|
|
|
|
|
return is_any_object_array_type; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
520
|
|
|
|
|
|
void SPVM_API_RUNTIME_build_precompile_module_source(SPVM_RUNTIME* runtime, SPVM_STRING_BUFFER* string_buffer, SPVM_RUNTIME_BASIC_TYPE* module_basic_type) { |
239
|
520
|
|
|
|
|
|
SPVM_PRECOMPILE* precompile = SPVM_PRECOMPILE_new(precompile); |
240
|
520
|
|
|
|
|
|
SPVM_PRECOMPILE_set_runtime(precompile, runtime); |
241
|
520
|
|
|
|
|
|
SPVM_PRECOMPILE_build_module_source(precompile, string_buffer, module_basic_type); |
242
|
520
|
|
|
|
|
|
SPVM_PRECOMPILE_free(precompile); |
243
|
520
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
2
|
|
|
|
|
|
void SPVM_API_RUNTIME_build_precompile_method_source(SPVM_RUNTIME* runtime, SPVM_STRING_BUFFER* string_buffer, SPVM_RUNTIME_METHOD* method) { |
246
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE* precompile = SPVM_PRECOMPILE_new(precompile); |
247
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE_set_runtime(precompile, runtime); |
248
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE_build_method_source(precompile, string_buffer, method->current_basic_type, method); |
249
|
2
|
|
|
|
|
|
SPVM_PRECOMPILE_free(precompile); |
250
|
2
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
|
SPVM_COMPILER* SPVM_API_RUNTIME_get_compiler(SPVM_RUNTIME* runtime) { |
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
return runtime->compiler; |
255
|
|
|
|
|
|
|
} |
256
|
652
|
|
|
|
|
|
void SPVM_API_RUNTIME_set_compiler(SPVM_RUNTIME* runtime, SPVM_COMPILER* compiler) { |
257
|
|
|
|
|
|
|
|
258
|
652
|
|
|
|
|
|
runtime->compiler = compiler; |
259
|
652
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|