()
| 18 | "#; |
| 19 | |
| 20 | fn main() -> Result<()> { |
| 21 | let wasm = wat::parse_str(WASM)?; |
| 22 | let module = tinywasm::parse_bytes(&wasm)?; |
| 23 | let mut store = Store::default(); |
| 24 | |
| 25 | let call_add_twice = HostFunction::from(&mut store, |mut ctx: FuncContext<'_>, value: i32| { |
| 26 | let add_one = ctx.module().func::<i32, i32>(ctx.store(), "add_one")?; |
| 27 | |
| 28 | // Use ctx.call for reentrant calls from host functions. Function::call |
| 29 | // starts a root invocation and cannot preserve the active call stacks. |
| 30 | let value = ctx.call(&add_one, value)?; |
| 31 | ctx.call(&add_one, value) |
| 32 | }); |
| 33 | |
| 34 | let mut imports = Imports::new(); |
| 35 | imports.define("host", "call_add_twice", call_add_twice); |
| 36 | |
| 37 | let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?; |
| 38 | let run = instance.func::<i32, i32>(&store, "run")?; |
| 39 | |
| 40 | assert_eq!(run.call(&mut store, 40)?, 52); |
| 41 | |
| 42 | Ok(()) |
| 43 | } |
nothing calls this directly
no test coverage detected