From 032d2cdd590c1cdd30490384742a90dc0c759176 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sat, 20 Jan 2024 17:53:59 +0100 Subject: chore: progress towards host functions Signed-off-by: Henry Gressmann --- crates/types/src/lib.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'crates/types/src') diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 1eef0a5..5b290ca 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -339,12 +339,33 @@ impl FuncType { } } -/// A WebAssembly Function +// A WebAssembly Function #[derive(Debug, Clone)] -pub struct Function { +pub enum Function { + WasmFunction(WasmFunction), + HostFunction(HostFunction), +} + +impl Function { + pub fn ty(&self) -> TypeAddr { + match self { + Self::WasmFunction(f) => f.ty, + Self::HostFunction(f) => f.ty, + } + } +} + +#[derive(Debug, Clone)] +pub struct WasmFunction { pub ty: TypeAddr, - pub locals: Box<[ValType]>, pub instructions: Box<[Instruction]>, + pub locals: Box<[ValType]>, +} + +#[derive(Debug, Clone)] +pub struct HostFunction { + pub ty: TypeAddr, + pub func: fn(&mut [WasmValue]) -> Result<(), ()>, } /// A WebAssembly Module Export -- cgit v1.3.1