diff --git a/src/backend/final.rs b/src/backend/final.rs index dd3849a..296d4a3 100644 --- a/src/backend/final.rs +++ b/src/backend/final.rs @@ -160,7 +160,7 @@ pub fn produce_func_wasm( locals: vec![], }; wasm.locals - .extend(f.locals.iter().map(|ty| ty_to_valty(*ty))); + .extend(f.locals.iter().skip(f.n_params).map(|ty| ty_to_valty(*ty))); wasm.locals .extend(locations.new_locals.iter().map(|ty| ty_to_valty(*ty))); diff --git a/src/frontend.rs b/src/frontend.rs index 12ce86a..68dd6b0 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -109,6 +109,7 @@ fn parse_body<'a>( for ¶m in &module.signatures[my_sig].params[..] { ret.locals.push(param); } + ret.n_params = module.signatures[my_sig].params.len(); for &r in &module.signatures[my_sig].returns[..] { ret.rets.push(r); } diff --git a/src/ir.rs b/src/ir.rs index c4d88ff..af68d1b 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -53,6 +53,7 @@ impl FuncDecl { #[derive(Clone, Debug, Default)] pub struct FunctionBody { + pub n_params: usize, pub rets: Vec, pub locals: Vec, pub blocks: Vec,