()
| 23 | "#; |
| 24 | |
| 25 | fn main() -> Result<()> { |
| 26 | let wasm = wat::parse_str(WASM)?; |
| 27 | let module = tinywasm::parse_bytes(&wasm)?; |
| 28 | let mut store = Store::default(); |
| 29 | let instance = ModuleInstance::instantiate(&mut store, &module, None)?; |
| 30 | let count_down = instance.func::<i32, i32>(&store, "count_down")?; |
| 31 | |
| 32 | let mut execution = count_down.call_resumable(&mut store, 10_000)?; |
| 33 | let fuel_per_round = 128; |
| 34 | let mut fuel_rounds = 0; |
| 35 | |
| 36 | let result = loop { |
| 37 | fuel_rounds += 1; |
| 38 | match execution.resume_with_fuel(fuel_per_round)? { |
| 39 | ExecProgress::Completed(value) => break value, |
| 40 | ExecProgress::Suspended => {} |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | println!("completed in {fuel_rounds} rounds of {fuel_per_round} fuel, result={result}"); |
| 45 | Ok(()) |
| 46 | } |
nothing calls this directly
no test coverage detected