From b0b4eba3b7ff5bfbcb8835c473ac3945c5160332 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Mon, 29 Jan 2024 17:31:01 +0100 Subject: feat: Bulk Memory Operations Proposal Signed-off-by: Henry Gressmann --- examples/rust/build.sh | 2 +- examples/wasm-rust.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/rust/build.sh b/examples/rust/build.sh index a13357d..5450345 100755 --- a/examples/rust/build.sh +++ b/examples/rust/build.sh @@ -10,7 +10,7 @@ dest_dir="out" mkdir -p "$dest_dir" for bin in "${bins[@]}"; do - RUSTFLAGS="-C target-feature=+reference-types -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin" + RUSTFLAGS="-C target-feature=+reference-types,+bulk-memory -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin" cp "$out_dir/$bin.wasm" "$dest_dir/" wasm-opt "$dest_dir/$bin.wasm" -o "$dest_dir/$bin.wasm" -O --intrinsic-lowering -O diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs index 468ab2e..96e3419 100644 --- a/examples/wasm-rust.rs +++ b/examples/wasm-rust.rs @@ -1,5 +1,5 @@ use color_eyre::eyre::Result; -use tinywasm::{Extern, FuncContext, Imports, Module, Store}; +use tinywasm::{Extern, FuncContext, Imports, MemoryStringExt, Module, Store}; fn main() -> Result<()> { let args = std::env::args().collect::>(); @@ -56,7 +56,7 @@ fn hello() -> Result<()> { "env", "print_utf8", Extern::typed_func(|mut ctx: FuncContext<'_>, args: (i64, i32)| { - let mem = ctx.memory("memory")?; + let mem = ctx.exported_memory("memory")?; let ptr = args.0 as usize; let len = args.1 as usize; let string = mem.load_string(ptr, len)?; @@ -69,7 +69,7 @@ fn hello() -> Result<()> { let arg_ptr = instance.exported_func::<(), i32>(&mut store, "arg_ptr")?.call(&mut store, ())?; let arg = b"world"; - instance.exported_memory(&mut store, "memory")?.store(arg_ptr as usize, arg.len(), arg)?; + instance.exported_memory_mut(&mut store, "memory")?.store(arg_ptr as usize, arg.len(), arg)?; let hello = instance.exported_func::(&mut store, "hello")?; hello.call(&mut store, arg.len() as i32)?; -- cgit v1.3.1