diff options
| author | Henry <mail@henrygressmann.de> | 2026-08-11 17:25:32 +0200 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2026-08-11 17:25:32 +0200 |
| commit | 64cf33ced2db2135dd355a1c6e049bf51c93d956 (patch) | |
| tree | d75977f68718fcb5270f12a10a17bf2d56be85d3 /examples/wasm-rust.rs | |
| parent | be3c350746e3dc6284b40349a8ac4a170d807c58 (diff) | |
chore: more superinstructions, cleanup
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'examples/wasm-rust.rs')
| -rw-r--r-- | examples/wasm-rust.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs index 672b290..b3398f8 100644 --- a/examples/wasm-rust.rs +++ b/examples/wasm-rust.rs @@ -35,6 +35,8 @@ fn main() -> Result<()> { println!(" host_fn"); println!(" fibonacci - calculate fibonacci(30)"); println!(" tinywasm - run printi32 inside of tinywasm inside of itself"); + println!(" tinywasm_precompiled - run a precompiled module inside of tinywasm"); + println!(" tinywasm_no_std - run a precompiled module inside of no_std tinywasm"); println!(" argon2id - run argon2id(1000, 2, 1)"); return Ok(()); } @@ -44,6 +46,7 @@ fn main() -> Result<()> { "printi32" => printi32()?, "fibonacci" => fibonacci()?, "tinywasm" => tinywasm()?, + "tinywasm_precompiled" => tinywasm_precompiled()?, "tinywasm_no_std" => tinywasm_no_std()?, "argon2id" => argon2id()?, "host_fn" => host_fn()?, @@ -57,6 +60,8 @@ fn main() -> Result<()> { fibonacci()?; println!("\ntinywasm.wasm:"); tinywasm()?; + println!("\ntinywasm_precompiled.wasm:"); + tinywasm_precompiled()?; println!("\ntinywasm_no_std.wasm:"); tinywasm_no_std()?; println!("argon2id.wasm:"); @@ -100,6 +105,21 @@ fn tinywasm_no_std() -> Result<()> { Ok(()) } +fn tinywasm_precompiled() -> Result<()> { + let module = tinywasm::parse_file("./examples/rust/out/tinywasm_precompiled.opt.wasm")?; + let mut store = Store::default(); + + let mut imports = Imports::new(); + imports.define("env", "printi32", HostFunction::from(|_: FuncContext<'_>, _x: i32| Ok(()))); + let instance = ModuleInstance::instantiate(&mut store, &module, Some(black_box(&imports)))?; + + let hello = instance.func::<(), ()>(&store, "hello")?; + hello.call(&mut store, black_box(()))?; + hello.call(&mut store, black_box(()))?; + hello.call(&mut store, black_box(()))?; + Ok(()) +} + fn hello() -> Result<()> { let module = tinywasm::parse_file("./examples/rust/out/hello.opt.wasm")?; let mut store = Store::default(); @@ -212,6 +232,11 @@ mod tests { } #[test] + fn test_tinywasm_precompiled() { + tinywasm_precompiled().unwrap(); + } + + #[test] fn test_tinywasm_no_std() { tinywasm_no_std().unwrap(); } |
