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

@ -32,12 +32,6 @@ void print_valtype(const wasm_valtype_t* type) {
void print_valtypes(const wasm_valtype_vec_t* types) {
bool first = true;
if (!types) {
printf("> Error print a NULL valtype\n");
return;
}
for (size_t i = 0; i < types->size; ++i) {
if (first) {
first = false;
@ -49,11 +43,6 @@ void print_valtypes(const wasm_valtype_vec_t* types) {
}
void print_externtype(const wasm_externtype_t* type) {
if (!type) {
printf("> Error print a NULL externtype\n");
return;
}
switch (wasm_externtype_kind(type)) {
case WASM_EXTERN_FUNC: {
const wasm_functype_t* functype =
@ -89,11 +78,6 @@ void print_externtype(const wasm_externtype_t* type) {
}
void print_name(const wasm_name_t* name) {
if (!name) {
printf("> Error print a NULL name\n");
return;
}
printf("\"%.*s\"", (int)name->size, name->data);
}
@ -139,8 +123,9 @@ int main(int argc, const char* argv[]) {
// Instantiate.
printf("Instantiating module...\n");
wasm_extern_vec_t imports = WASM_EMPTY_VEC;
own wasm_instance_t* instance =
wasm_instance_new(store, module, NULL, NULL);
wasm_instance_new(store, module, &imports, NULL);
if (!instance) {
printf("> Error instantiating module!\n");
return 1;