Fix bad local variable generation

This commit is contained in:
Rerumu 2022-04-25 18:29:06 -04:00
parent 5e955efcbd
commit b6664aacfd
2 changed files with 14 additions and 4 deletions

View File

@ -125,13 +125,18 @@ fn write_call_store(result: Range<usize>, w: Writer) -> Result<()> {
} }
fn write_variable_list(func: &Function, w: Writer) -> Result<()> { fn write_variable_list(func: &Function, w: Writer) -> Result<()> {
let mut total = 0;
for data in &func.local_data { for data in &func.local_data {
let range = 0..data.count().try_into().unwrap(); let range = total..total + usize::try_from(data.count()).unwrap();
let typed = data.value_type();
total = range.end;
write!(w, "local ")?; write!(w, "local ")?;
write_ascending("loc", range.clone(), w)?; write_ascending("loc", range.clone(), w)?;
write!(w, " = ")?; write!(w, " = ")?;
write_separated(range, |_, w| write!(w, "ZERO_{} ", data.value_type()), w)?; write_separated(range, |_, w| write!(w, "ZERO_{} ", typed), w)?;
} }
if func.num_stack != 0 { if func.num_stack != 0 {

View File

@ -124,13 +124,18 @@ fn write_call_store(result: Range<usize>, w: Writer) -> Result<()> {
} }
fn write_variable_list(func: &Function, w: Writer) -> Result<()> { fn write_variable_list(func: &Function, w: Writer) -> Result<()> {
let mut total = 0;
for data in &func.local_data { for data in &func.local_data {
let range = 0..data.count().try_into().unwrap(); let range = total..total + usize::try_from(data.count()).unwrap();
let typed = data.value_type();
total = range.end;
write!(w, "local ")?; write!(w, "local ")?;
write_ascending("loc", range.clone(), w)?; write_ascending("loc", range.clone(), w)?;
write!(w, " = ")?; write!(w, " = ")?;
write_separated(range, |_, w| write!(w, "ZERO_{} ", data.value_type()), w)?; write_separated(range, |_, w| write!(w, "ZERO_{} ", typed), w)?;
} }
if func.num_stack != 0 { if func.num_stack != 0 {