Refactor externref related APIs of reference types feature (#971)

Currently when calling wasm_runtime_call_wasm() to invoke wasm function
with externref type argument from runtime embedder, developer needs to
use wasm_externref_obj2ref() to convert externref obj into an internal ref
index firstly, which is not convenient to developer.
To align with GC feature in which all the references passed to
wasm_runtime_call_wasm() can be object pointers directly, we change the
interface of wasm_runtime_call_wasm() to allow to pass object pointer
directly for the externref argument, and refactor the related codes, update
the related samples and the document.
This commit is contained in:
Wenyong Huang
2022-01-19 11:25:08 +08:00
committed by GitHub
parent 2c743dbd51
commit 260d36a62d
30 changed files with 1148 additions and 595 deletions

View File

@ -39,10 +39,11 @@ wasm_func_t* get_export_func(const wasm_extern_vec_t* exports, size_t i) {
#define check_call(func, type, expected) \
{ \
wasm_val_vec_t results; \
wasm_val_vec_new_uninitialized(&results, 1); \
wasm_func_call(func, NULL, &results); \
check(results.data[0], type, expected); \
wasm_val_t vs[1]; \
wasm_val_vec_t args = WASM_EMPTY_VEC; \
wasm_val_vec_t results = WASM_ARRAY_VEC(vs); \
wasm_func_call(func, &args, &results); \
check(vs[0], type, expected); \
}
@ -116,19 +117,13 @@ int main(int argc, const char* argv[]) {
// Instantiate.
printf("Instantiating module...\n");
/*const wasm_extern_t* imports1[] = {
wasm_extern_t* externs[] = {
wasm_global_as_extern(const_f32_import),
wasm_global_as_extern(const_i64_import),
wasm_global_as_extern(var_f32_import),
wasm_global_as_extern(var_i64_import)
};*/
wasm_extern_vec_t imports;
wasm_extern_vec_new(&imports, 4, (wasm_extern_t* []) {
wasm_global_as_extern(const_f32_import),
wasm_global_as_extern(const_i64_import),
wasm_global_as_extern(var_f32_import),
wasm_global_as_extern(var_i64_import)
});
};
wasm_extern_vec_t imports = WASM_ARRAY_VEC(externs);
own wasm_instance_t* instance =
wasm_instance_new(store, module, &imports, NULL);
if (!instance) {
@ -208,18 +203,19 @@ int main(int argc, const char* argv[]) {
check_call(get_var_i64_export, i64, 38);
// Modify variables through calls and check again.
wasm_val_vec_t args73;
wasm_val_vec_new(&args73, 1, (wasm_val_t []){ WASM_F32_VAL(73) });
wasm_func_call(set_var_f32_import, &args73, NULL);
wasm_val_vec_t args74;
wasm_val_vec_new(&args74, 1, (wasm_val_t []){ WASM_I64_VAL(74) });
wasm_func_call(set_var_i64_import, &args74, NULL);
wasm_val_vec_t args77;
wasm_val_vec_new(&args77, 1, (wasm_val_t []){ WASM_F32_VAL(77) });
wasm_func_call(set_var_f32_export, &args77, NULL);
wasm_val_vec_t args78;
wasm_val_vec_new(&args78, 1, (wasm_val_t []){ WASM_I64_VAL(78) });
wasm_func_call(set_var_i64_export, &args78, NULL);
wasm_val_vec_t res = WASM_EMPTY_VEC;
wasm_val_t vs73[] = { WASM_F32_VAL(73) };
wasm_val_vec_t args73 = WASM_ARRAY_VEC(vs73);
wasm_func_call(set_var_f32_import, &args73, &res);
wasm_val_t vs74[] = { WASM_I64_VAL(74) };
wasm_val_vec_t args74 = WASM_ARRAY_VEC(vs74);
wasm_func_call(set_var_i64_import, &args74, &res);
wasm_val_t vs77[] = { WASM_F32_VAL(77) };
wasm_val_vec_t args77 = WASM_ARRAY_VEC(vs77);
wasm_func_call(set_var_f32_export, &args77, &res);
wasm_val_t vs78[] = { WASM_I64_VAL(78) };
wasm_val_vec_t args78 = WASM_ARRAY_VEC(vs78);
wasm_func_call(set_var_i64_export, &args78, &res);
check_global(var_f32_import, f32, 73);
check_global(var_i64_import, i64, 74);