File tree Expand file tree Collapse file tree 3 files changed +6
-14
lines changed
crates/tinywasm/src/runtime/stack Expand file tree Collapse file tree 3 files changed +6
-14
lines changed Original file line number Diff line number Diff line change 1
1
use core:: ops:: Range ;
2
2
3
- use crate :: log;
4
3
use crate :: { runtime:: RawWasmValue , Error , Result } ;
5
4
use alloc:: vec:: Vec ;
6
5
use tinywasm_types:: { ValType , WasmValue } ;
@@ -85,14 +84,7 @@ impl ValueStack {
85
84
86
85
#[ inline]
87
86
pub ( crate ) fn pop_params ( & mut self , types : & [ ValType ] ) -> Result < Vec < WasmValue > > {
88
- log:: info!( "pop_params: types={:?}" , types) ;
89
- log:: info!( "stack={:?}" , self . stack) ;
90
-
91
- let mut res = Vec :: with_capacity ( types. len ( ) ) ;
92
- for ty in types. iter ( ) {
93
- res. push ( self . pop ( ) ?. attach_type ( * ty) ) ;
94
- }
95
-
87
+ let res = self . pop_n_rev ( types. len ( ) ) ?. iter ( ) . zip ( types. iter ( ) ) . map ( |( v, ty) | v. attach_type ( * ty) ) . collect ( ) ;
96
88
Ok ( res)
97
89
}
98
90
Original file line number Diff line number Diff line change 2
2
3
3
#[ link( wasm_import_module = "env" ) ]
4
4
extern "C" {
5
- fn print_utf8 ( location : i32 , len : i32 ) ;
5
+ fn print_utf8 ( location : i64 , len : i32 ) ;
6
6
}
7
7
8
8
const ARG : & [ u8 ] = & [ 0u8 ; 100 ] ;
@@ -23,6 +23,6 @@ pub unsafe extern "C" fn hello(len: i32) {
23
23
let res = format ! ( "Hello, {}!" , arg) . as_bytes ( ) . to_vec ( ) ;
24
24
25
25
let len = res. len ( ) as i32 ;
26
- let ptr = res. leak ( ) . as_ptr ( ) as i32 ;
26
+ let ptr = res. leak ( ) . as_ptr ( ) as i64 ;
27
27
print_utf8 ( ptr, len) ;
28
28
}
Original file line number Diff line number Diff line change @@ -55,10 +55,10 @@ fn hello() -> Result<()> {
55
55
imports. define (
56
56
"env" ,
57
57
"print_utf8" ,
58
- Extern :: typed_func ( |mut ctx : FuncContext < ' _ > , args : ( i32 , i32 ) | {
58
+ Extern :: typed_func ( |mut ctx : FuncContext < ' _ > , args : ( i64 , i32 ) | {
59
59
let mem = ctx. memory ( "memory" ) ?;
60
- let ptr = args. 1 as usize ;
61
- let len = args. 0 as usize ;
60
+ let ptr = args. 0 as usize ;
61
+ let len = args. 1 as usize ;
62
62
let string = mem. load_string ( ptr, len) ?;
63
63
println ! ( "{}" , string) ;
64
64
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments