| Bound | Native (WAMR) | js (WebAssembly) |
|---|---|---|
| Memory ceiling | Enforced: the maximum pages of the instantiation | Enforced: a rewrite of the memory maximum |
| Refused memory.grow | MemoryLimit (enlarge-memory callback) | MemoryLimit (an appended grow function) |
| Instruction budget | Enforced: WAMR metering, 1 to 9223372036854775807 instructions | Not enforced |
| Deadline | Enforced: a watchdog thread calls wasm_runtime_terminate; it is always joined | Not enforced: end the worker |
| Host work | Not metered: a host function and the kernel's forwarded calls count no instructions; the deadline bounds them | Not metered |
| Features beyond the core set | simd (SIMDe headers) | simd |
///|
test "add two i64 values" {
let engine = @engine.Engine::default()
let instance = engine
.compile(@fixtures.add())
.instantiate(@engine.Imports::new())
assert_eq(instance.call("add", [I64(2), I64(40)]), [I64(42)])
}
///|
test "a host function for an import" {
let signature = @engine.Signature::new([I64, I64], [I64])
let imports = @engine.Imports::new().host("env", "add", signature, (_, args) => {
guard args is [I64(a), I64(b)] else {
raise @engine.HostError("bad arguments")
}
[I64(a + b)]
})
let instance = @engine.Engine::default()
.compile(@fixtures.host())
.instantiate(imports)
assert_eq(instance.call("call_add", [I64(1), I64(2)]), [I64(3)])
}
///|
test "a memory ceiling" {
let instance = @engine.Engine::default()
.compile(@fixtures.grow())
.instantiate(
@engine.Imports::new(),
memory_ceiling=@engine.PageCount::parse(2),
)
assert_eq(instance.call("grow", [I32(1)]), [I32(1)])
assert_eq(instance.call("grow", [I32(1)]), [I32(-1)])
}pub suberror LimitError {
LimitError(String, Int64, String)
}pub struct Caller {
// private fields
}pub struct Engine {
// private fields
}pub struct Function {
// private fields
}pub(all) struct ImportDescriptor {
module_ : String
name : String
kind : ExternKind
} derive(Eq, Debug)pub struct Imports {
// private fields
}pub struct Instance {
// private fields
}pub struct Memory {
// private fields
}impl GuestMemory for Memorypub struct Module {
// private fields
}fn host_entry_count() -> Intfn live_watchdogs() -> IntInstall
Download zipAn Extism host for MoonBit: a WASM engine layer, the Extism kernel and a plugin API