diff --git a/src/ir/module/mod.rs b/src/ir/module/mod.rs index fb01569..65c8032 100644 --- a/src/ir/module/mod.rs +++ b/src/ir/module/mod.rs @@ -243,13 +243,13 @@ impl<'a> Module<'a> { } Payload::CodeSectionEntry(body) => { let locals_reader = body.get_locals_reader()?; + let num_locals = locals_reader.get_count(); let locals = locals_reader.into_iter().collect::, _>>()?; let locals: Vec<(u32, DataType)> = locals .iter() .map(|(idx, val_type)| (*idx, DataType::from(*val_type))) .collect(); - // TODO: can I just iter locals once? - let num_locals = locals.iter().fold(0, |acc, x| acc + x.0) as usize; + let instructions = body .get_operators_reader()? .into_iter() diff --git a/src/ir/module/module_functions.rs b/src/ir/module/module_functions.rs index 5801884..0f89532 100644 --- a/src/ir/module/module_functions.rs +++ b/src/ir/module/module_functions.rs @@ -186,10 +186,10 @@ impl<'a> LocalFunction<'a> { pub(crate) fn add_local( ty: DataType, num_params: usize, - num_locals: &mut usize, + num_locals: &mut u32, locals: &mut Vec<(u32, DataType)>, ) -> LocalID { - let index = num_params + *num_locals; + let index = num_params + *num_locals as usize; let len = locals.len(); *num_locals += 1; diff --git a/src/ir/types.rs b/src/ir/types.rs index 6111dfd..f0419ba 100644 --- a/src/ir/types.rs +++ b/src/ir/types.rs @@ -832,7 +832,7 @@ pub struct Body<'a> { /// defined here then local indices 0 and 1 will refer to the parameters and /// index 2 will refer to the local here. pub locals: Vec<(u32, DataType)>, - pub num_locals: usize, + pub num_locals: u32, // accessing operators by .0 is not very clear pub instructions: Vec>, pub num_instructions: usize,