Call a function and return a resumable execution handle. The returned handle keeps a mutable borrow of the [`Store`] until it completes. Use [`FuncExecution::resume_with_fuel`] (or [`FuncExecution::resume_with_time_budget`] with `std`) to continue.
(
&self,
store: &'store mut Store,
params: &[WasmValue],
)
| 48 | /// completes. Use [`FuncExecution::resume_with_fuel`] (or |
| 49 | /// [`FuncExecution::resume_with_time_budget`] with `std`) to continue. |
| 50 | pub fn call_resumable<'store>( |
| 51 | &self, |
| 52 | store: &'store mut Store, |
| 53 | params: &[WasmValue], |
| 54 | ) -> Result<FuncExecution<'store>> { |
| 55 | #[inline] |
| 56 | fn call_resumable_inner( |
| 57 | func: &Function, |
| 58 | store: &mut Store, |
| 59 | params: &[WasmValue], |
| 60 | ) -> Result<FuncExecutionState> { |
| 61 | let func_instance = store.state.get_func(func.addr); |
| 62 | match func_instance { |
| 63 | FunctionInstance::Host(host_func) => host_func |
| 64 | .clone() |
| 65 | .call(FuncContext { store, module_addr: func.module_addr }, params) |
| 66 | .map(|result| FuncExecutionState::Completed { result: Some(result) }), |
| 67 | FunctionInstance::Wasm(wasm_func) => { |
| 68 | store.call_stack.clear(); |
| 69 | store.value_stack.clear(); |
| 70 | store.value_stack.extend_from_wasmvalues(params)?; |
| 71 | let locals_base = store.value_stack.enter_locals(&wasm_func.func.params, &wasm_func.func.locals)?; |
| 72 | let callframe = CallFrame::new(func.addr, locals_base, wasm_func.func.locals); |
| 73 | |
| 74 | Ok(FuncExecutionState::Running { |
| 75 | exec_state: ExecutionState { callframe }, |
| 76 | root_func_addr: func.addr, |
| 77 | }) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | self.item.validate_store(store)?; |
| 83 | validate_call_params(&self.ty, params)?; |
| 84 | |
| 85 | store.enter_execution()?; |
| 86 | let result = call_resumable_inner(self, store, params); |
| 87 | store.exit_execution(); |
| 88 | |
| 89 | Ok(FuncExecution { store, state: result? }) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | #[derive(Clone, PartialEq, Eq)] |