diff options
Diffstat (limited to 'examples/rust/src')
| -rw-r--r-- | examples/rust/src/tinywasm.rs | 2 | ||||
| -rw-r--r-- | examples/rust/src/tinywasm_no_std.rs | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/examples/rust/src/tinywasm.rs b/examples/rust/src/tinywasm.rs index 08c8135..68e6375 100644 --- a/examples/rust/src/tinywasm.rs +++ b/examples/rust/src/tinywasm.rs @@ -12,7 +12,7 @@ pub extern "C" fn hello() { } fn run() -> tinywasm::Result<()> { - let module = tinywasm::Module::parse_bytes(include_bytes!("../out/print.wasm"))?; + let module = tinywasm::Module::parse_stream(&include_bytes!("../out/print.wasm")[..])?; let mut store = tinywasm::Store::default(); let mut imports = tinywasm::Imports::new(); diff --git a/examples/rust/src/tinywasm_no_std.rs b/examples/rust/src/tinywasm_no_std.rs index 9f2b28c..c20e243 100644 --- a/examples/rust/src/tinywasm_no_std.rs +++ b/examples/rust/src/tinywasm_no_std.rs @@ -1,7 +1,19 @@ #![no_main] #![no_std] +use lol_alloc::{AssumeSingleThreaded, FreeListAllocator}; use tinywasm::{Extern, FuncContext}; +extern crate alloc; + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} + +#[global_allocator] +static ALLOCATOR: AssumeSingleThreaded<FreeListAllocator> = + unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) }; + #[link(wasm_import_module = "env")] extern "C" { fn printi32(x: i32); @@ -13,10 +25,13 @@ pub extern "C" fn hello() { } fn run() -> tinywasm::Result<()> { - let module = tinywasm::Module::parse_bytes(include_bytes!("../out/print.wasm"))?; let mut store = tinywasm::Store::default(); let mut imports = tinywasm::Imports::new(); + let res = tinywasm::parser::Parser::new().parse_module_bytes(include_bytes!("../out/print.wasm"))?; + let twasm = res.serialize_twasm(); + let module = tinywasm::Module::parse_bytes(&twasm)?; + imports.define( "env", "printi32", |
