From 7b9b3ec681e68280399d9c67e01433c2d3acb6c2 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Mon, 24 Aug 2026 15:47:05 +0200 Subject: feat: add host typed reference / gc APIs (#54) - add Store-aware handles for references, GC objects, and exceptions - simplify host value conversion, rooting, and exception propagation - update examples, tests, and documentation - Remove deprecated APIs Signed-off-by: Henry --- examples/basic.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/basic.rs (limited to 'examples/basic.rs') diff --git a/examples/basic.rs b/examples/basic.rs new file mode 100644 index 0000000..1f717c5 --- /dev/null +++ b/examples/basic.rs @@ -0,0 +1,26 @@ +use anyhow::Result; +use tinywasm::{ModuleInstance, Store}; + +const WASM: &str = r#" +(module + (func $add (param $lhs i32) (param $rhs i32) (result i32) + local.get $lhs + local.get $rhs + i32.add) + (export "add" (func $add))) +"#; + +fn main() -> Result<()> { + let wasm = wat::parse_str(WASM)?; + let module = tinywasm::parse_bytes(&wasm)?; + + // Module is reusable, while Store owns the runtime state for this instance. + let mut store = Store::default(); + let instance = ModuleInstance::instantiate(&mut store, &module, None)?; + + // Typed handles validate parameters and results. Use func_untyped for dynamic values. + let add = instance.func::<(i32, i32), i32>(&store, "add")?; + + assert_eq!(add.call(&mut store, (1, 2))?, 3); + Ok(()) +} -- cgit v1.3.1