Is the current C API complete enough for porting this Rust code? #2465
Answered
by
lucianoiam
lucianoiam
asked this question in
Q&A
-
Background: trying to embed Wasmer in a C++ environment for running compiled AssemblyScript. AS requires let env = Env {
memory: Default::default(),
};
let abort_signature =
FunctionType::new(vec![Type::I32, Type::I32, Type::I32, Type::I32], vec![]);
let abort = Function::new(&store, &abort_signature, |_args| {
...
});
let import_object = imports! {
"env" => {
"abort" => abort
},
};
let instance = Instance::new(&module, &import_object)?; |
Beta Was this translation helpful? Give feedback.
Answered by
lucianoiam
Jul 17, 2021
Replies: 1 comment
-
For anyone interested, this is not an exact translation of the code above but enough for allowing unmodified AssemblyScript compiled modules to run: #define own
static inline own wasm_functype_t* wasm_functype_new_4_0(
own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3, own wasm_valtype_t* p4
) {
wasm_valtype_t* ps[4] = {p1, p2, p3, p4};
wasm_valtype_vec_t params, results;
wasm_valtype_vec_new(¶ms, 4, ps);
wasm_valtype_vec_new_empty(&results);
return wasm_functype_new(¶ms, &results);
}
own wasm_trap_t* abort(const wasm_val_vec_t* args, wasm_val_vec_t* results) {
return NULL;
}
...
wasm_functype_t *abortFuncType = wasm_functype_new_4_0(wasm_valtype_new_i32(),
wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32());
wasm_func_t *abortFunc = wasm_func_new(fWasmStore, abortFuncType, abort);
wasm_functype_delete(abortFuncType);
wasm_extern_vec_t imports;
wasm_extern_vec_new_uninitialized(&imports, 1);
imports.data[0] = wasm_func_as_extern(abortFunc);
instance = wasm_instance_new(store, module, &imports, &traps);
... |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lucianoiam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone interested, this is not an exact translation of the code above but enough for allowing unmodified AssemblyScript compiled modules to run: