Wasmtime C API bindings for MoonBit (native target)
Dependencies
cc-link-flags: -Ldeps/wasmtime/target/release -lwasmtimeimport {
"mizchi/wasmtime",
}
options(
"pre-build": [
{
"input": [
".mooncakes/mizchi/wasmtime/src/scripts/build-wasmtime.sh"
],
"output": [
"build-stamps/wasmtime_prebuild.stamp"
],
"command": "mkdir -p build-stamps && bash .mooncakes/mizchi/wasmtime/src/scripts/build-wasmtime.sh src/build-stamps/wasmtime_build.stamp && date -u +%Y-%m-%dT%H:%M:%SZ > $output"
}
],
)just # check + test (native target)
just fmt # format code
just check # type check
just test # run tests
just run # run main
just info # generate type definition files
just prebuild-log # show pre-build logfn main {
println(@wasmtime.version())
}let (engine, store, context) = @wasmtime.async_context_new(4 * 1024 * 1024)
let args = @wasmtime.make_val_buffer(0)
let results = @wasmtime.make_val_buffer(0)
let trap_ptr = @wasmtime.make_ptr_buffer()
let err_ptr = @wasmtime.make_ptr_buffer()
let params : Bytes = []
let results_sig : Bytes = []
let ty = @wasmtime.functype_new_from_valkinds_or_raise(params, results_sig)
let cb_ptr = @wasmtime.func_noop_callback_ptr()
let func_bytes = @wasmtime.func_buffer_new_with_ptr(context, ty, cb_ptr, 0, 0)
let future_result =
@wasmtime.func_call_async_result_autoclean(context, func_bytes, args, results, trap_ptr, err_ptr)
match future_result {
Ok(future) => {
while not(@wasmtime.call_future_poll(future)) { () }
@wasmtime.call_future_delete(future)
}
Err(_err) => {
// trap/error pointers are already deleted
}
}
// Error example: "func_call_async failed (error=true, trap=false)"
@wasmtime.functype_delete(ty)
@wasmtime.async_context_delete(engine, store)type OptLevel = Inttype ProfilingStrategy = Intfn config_cranelift_flag_set_bytes(config : Config, key : Bytes, key_len : Int, value : Bytes, value_len : Int) -> Unitfn context_epoch_deadline_async_yield_and_update(context : Context, delta : UInt64) -> WasmtimeErrorfn error_delete_ptr(bytes : Bytes) -> Unitfn error_delete_ptr_buffer(ptr_buf : Bytes) -> Unitfn func_call_async(context : Context, func_bytes : Bytes, args : Bytes, results : Bytes, trap_ptr : Bytes, err_ptr : Bytes) -> CallFuture raisefn func_call_async_bytes(context : Context, func : Bytes, args : Bytes, nargs : Int, results : Bytes, nresults : Int, trap_out : Bytes, error_out : Bytes) -> CallFuturefn func_call_async_result(context : Context, func_bytes : Bytes, args : Bytes, results : Bytes, trap_ptr : Bytes, err_ptr : Bytes) -> Result[CallFuture, Error]fn func_call_async_result_autoclean(context : Context, func_bytes : Bytes, args : Bytes, results : Bytes, trap_ptr : Bytes, err_ptr : Bytes) -> Result[CallFuture, Error]fn func_noop_callback_ptr() -> UInt64fn functype_new_from_kinds(params : Bytes, nparams : Int, results : Bytes, nresults : Int) -> FuncTypefn instance_pre_instantiate_async_bytes(instance_pre : InstancePre, context : Context, instance_out : Bytes, trap_out : Bytes, error_out : Bytes) -> CallFuturefn linker_define_async_func_ptr(linker : Linker, module_bytes : Bytes, module_len : Int, name : Bytes, name_len : Int, ty : FuncType, cb_ptr : UInt64, data_ptr : UInt64, finalizer_ptr : UInt64) -> WasmtimeErrorfn linker_instantiate_async_bytes(linker : Linker, context : Context, module_val : Module, instance_out : Bytes, trap_out : Bytes, error_out : Bytes) -> CallFuturefn make_instance_buffer() -> Bytesfn make_ptr_buffer() -> Bytesfn make_stack_creator_buffer() -> Bytesfn make_val_buffer(n : Int) -> Bytesfn noop_callback_ptr() -> UInt64fn ptr_buffer_is_null(ptr_buf : Bytes) -> Boolfn ptr_buffer_read_u64(ptr_buf : Bytes) -> UInt64fn ptr_is_null(bytes : Bytes) -> Boolfn ptr_read_u64(bytes : Bytes) -> UInt64fn stack_creator_sizeof() -> Intfn trap_delete_ptr(bytes : Bytes) -> Unitfn trap_delete_ptr_buffer(ptr_buf : Bytes) -> Unitfn val_buffer_count(buf : Bytes) -> Intfn val_buffer_count_or_raise(buf : Bytes) -> Int raisefn val_buffer_count_result(buf : Bytes) -> Result[Int, Error]fn val_buffer_get_f32(buf : Bytes, index : Int) -> Floatfn val_buffer_get_f64(buf : Bytes, index : Int) -> Doublefn val_buffer_get_i32(buf : Bytes, index : Int) -> Intfn val_buffer_get_i64(buf : Bytes, index : Int) -> Int64fn val_buffer_set_f32(buf : Bytes, index : Int, value : Float) -> Unitfn val_buffer_set_f64(buf : Bytes, index : Int, value : Double) -> Unitfn val_buffer_set_i32(buf : Bytes, index : Int, value : Int) -> Unitfn val_buffer_set_i64(buf : Bytes, index : Int, value : Int64) -> Unitfn val_buffer_unroot_at(buf : Bytes, index : Int) -> Unitfn val_get_f32_at(vals : Bytes, index : Int) -> Floatfn val_get_f64_at(vals : Bytes, index : Int) -> Doublefn val_get_i64_at(vals : Bytes, index : Int) -> Int64fn val_kind_at(vals : Bytes, index : Int) -> Intfn val_set_f32_at(vals : Bytes, index : Int, value : Float) -> Unitfn val_set_f64_at(vals : Bytes, index : Int, value : Double) -> Unitfn val_set_i32_at(vals : Bytes, index : Int, value : Int) -> Unitfn val_set_i64_at(vals : Bytes, index : Int, value : Int64) -> Unitfn val_unroot_at(vals : Bytes, index : Int) -> Unitfn version() -> StringWasmtime C API bindings for MoonBit (native target)
Dependencies