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/rust/src/tinywasm_precompiled.rs | |
| parent | be3c350746e3dc6284b40349a8ac4a170d807c58 (diff) | |
chore: more superinstructions, cleanup
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'examples/rust/src/tinywasm_precompiled.rs')
| -rw-r--r-- | examples/rust/src/tinywasm_precompiled.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/rust/src/tinywasm_precompiled.rs b/examples/rust/src/tinywasm_precompiled.rs new file mode 100644 index 0000000..bc0e0c1 --- /dev/null +++ b/examples/rust/src/tinywasm_precompiled.rs @@ -0,0 +1,30 @@ +#![no_main] +use tinywasm::{FuncContext, HostFunction, Module, ModuleInstance}; + +#[link(wasm_import_module = "env")] +unsafe extern "C" { + fn printi32(x: i32); +} + +#[unsafe(no_mangle)] +pub extern "C" fn hello() { + let _ = run(); +} + +fn run() -> tinywasm::Result<()> { + let module = Module::try_from_twasm(include_bytes!("./print.twasm"))?; + let mut store = tinywasm::Store::default(); + + let printi32 = HostFunction::from(|_: FuncContext<'_>, v: i32| { + unsafe { printi32(v) } + Ok(()) + }); + + let mut imports = tinywasm::Imports::new(); + imports.define("env", "printi32", printi32); + + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports))?; + let add_and_print = instance.func::<(i32, i32), ()>(&store, "add_and_print")?; + add_and_print.call(&mut store, (1, 2))?; + Ok(()) +} |
