use alloc::{rc::Rc, sync::Arc};
use tinywasm_types::*;
use crate::func::HostFunction;
#[derive(Clone)]
#[cfg_attr(feature = "debug", derive(Debug))]
pub(crate) enum FunctionInstance {
Host(Rc<HostFunction>),
Wasm(WasmFunctionInstance),
}
impl FunctionInstance {
#[inline]
pub(crate) fn ty(&self) -> &Arc<FuncType> {
match self {
Self::Host(f) => &f.ty,
Self::Wasm(f) => f.ty(),
}
}
}
impl FunctionInstance {
pub(crate) fn new_wasm(func: Arc<WasmFunction>, owner: ModuleInstanceAddr) -> Self {
Self::Wasm(WasmFunctionInstance { func, owner })
}
}
#[derive(Clone)]
#[cfg_attr(feature = "debug", derive(Debug))]
pub(crate) struct WasmFunctionInstance {
pub(crate) func: Arc<WasmFunction>,
pub(crate) owner: ModuleInstanceAddr,
}
impl WasmFunctionInstance {
#[inline]
pub(crate) fn ty(&self) -> &Arc<FuncType> {
&self.func.ty
}
}