summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2024-01-26 19:14:54 +0100
committerHenry Gressmann <mail@henrygressmann.de>2024-01-26 19:14:54 +0100
commit1f6ac248e106f77dee20af26567c61b2a35b75ba (patch)
treeb1bb054432d236311c50bce1f6be5b9c6bf1d754
parent8adce672578683dcc7ab62e5492e0f5dbc07a0b4 (diff)
fix: import param order
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
-rw-r--r--crates/tinywasm/src/runtime/stack/value_stack.rs10
-rw-r--r--examples/rust/src/hello.rs4
-rw-r--r--examples/wasm-rust.rs6
3 files changed, 6 insertions, 14 deletions
diff --git a/crates/tinywasm/src/runtime/stack/value_stack.rs b/crates/tinywasm/src/runtime/stack/value_stack.rs
index bb4e398..f8f0951 100644
--- a/crates/tinywasm/src/runtime/stack/value_stack.rs
+++ b/crates/tinywasm/src/runtime/stack/value_stack.rs
@@ -1,6 +1,5 @@
use core::ops::Range;
-use crate::log;
use crate::{runtime::RawWasmValue, Error, Result};
use alloc::vec::Vec;
use tinywasm_types::{ValType, WasmValue};
@@ -85,14 +84,7 @@ impl ValueStack {
#[inline]
pub(crate) fn pop_params(&mut self, types: &[ValType]) -> Result<Vec<WasmValue>> {
- log::info!("pop_params: types={:?}", types);
- log::info!("stack={:?}", self.stack);
-
- let mut res = Vec::with_capacity(types.len());
- for ty in types.iter() {
- res.push(self.pop()?.attach_type(*ty));
- }
-
+ let res = self.pop_n_rev(types.len())?.iter().zip(types.iter()).map(|(v, ty)| v.attach_type(*ty)).collect();
Ok(res)
}
diff --git a/examples/rust/src/hello.rs b/examples/rust/src/hello.rs
index 6bb6d97..c8e2ac3 100644
--- a/examples/rust/src/hello.rs
+++ b/examples/rust/src/hello.rs
@@ -2,7 +2,7 @@
#[link(wasm_import_module = "env")]
extern "C" {
- fn print_utf8(location: i32, len: i32);
+ fn print_utf8(location: i64, len: i32);
}
const ARG: &[u8] = &[0u8; 100];
@@ -23,6 +23,6 @@ pub unsafe extern "C" fn hello(len: i32) {
let res = format!("Hello, {}!", arg).as_bytes().to_vec();
let len = res.len() as i32;
- let ptr = res.leak().as_ptr() as i32;
+ let ptr = res.leak().as_ptr() as i64;
print_utf8(ptr, len);
}
diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs
index 6580bd5..468ab2e 100644
--- a/examples/wasm-rust.rs
+++ b/examples/wasm-rust.rs
@@ -55,10 +55,10 @@ fn hello() -> Result<()> {
imports.define(
"env",
"print_utf8",
- Extern::typed_func(|mut ctx: FuncContext<'_>, args: (i32, i32)| {
+ Extern::typed_func(|mut ctx: FuncContext<'_>, args: (i64, i32)| {
let mem = ctx.memory("memory")?;
- let ptr = args.1 as usize;
- let len = args.0 as usize;
+ let ptr = args.0 as usize;
+ let len = args.1 as usize;
let string = mem.load_string(ptr, len)?;
println!("{}", string);
Ok(())