wasm/execution/runtime_structure/
function_instances.rs

1use alloc::vec::Vec;
2
3use crate::{
4    core::{decoding::reader::span::Span, structure::modules::indices::TypeIdx},
5    FuncType, Hostcode, ModuleAddr, ValType,
6};
7
8#[derive(Debug)]
9// TODO does not match the spec FuncInst
10pub enum FuncInst {
11    WasmFunc(WasmFuncInst),
12    HostFunc(HostFuncInst),
13}
14
15#[derive(Debug)]
16pub struct WasmFuncInst {
17    pub function_type: FuncType,
18    pub _ty: TypeIdx,
19    pub locals: Vec<ValType>,
20    pub code_expr: Span,
21    ///index of the sidetable corresponding to the beginning of this functions code
22    pub stp: usize,
23
24    // implicit back ref required for function invocation and is in the spec
25    // TODO module_addr or module ref?
26    pub module_addr: ModuleAddr,
27}
28
29#[derive(Debug)]
30pub struct HostFuncInst {
31    pub function_type: FuncType,
32    pub hostcode: Hostcode,
33}
34
35impl FuncInst {
36    pub fn ty(&self) -> &FuncType {
37        match self {
38            FuncInst::WasmFunc(wasm_func_inst) => &wasm_func_inst.function_type,
39            FuncInst::HostFunc(host_func_inst) => &host_func_inst.function_type,
40        }
41    }
42}