Skip to content

Commit

Permalink
fix!: ++delta_stp for if with else
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwfang committed Dec 5, 2024
1 parent 24781ed commit 8b645b4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/interpreter/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,10 @@ impl<'a, 'm> Expr<'a, 'm> {
Block(b) => self.push_label(self.blocktype(&b)?, LabelKind::Block)?,
Loop(b) => {
let type_ = self.blocktype(&b)?;
self.push_label(type_, LabelKind::Loop(self.branch_target(type_.params.len())))?
self.push_label(
type_,
LabelKind::Loop(self.branch_target(type_.params.len(), false)),
)?
}
If(b) => {
self.pop_check(ValType::I32)?;
Expand All @@ -596,7 +599,7 @@ impl<'a, 'm> Expr<'a, 'm> {
Else => {
match core::mem::replace(&mut self.label().kind, LabelKind::Block) {
LabelKind::If(source) => {
self.side_table.stitch(source, self.branch_target(source.result))?
self.side_table.stitch(source, self.branch_target(source.result, true))?
}
_ => Err(invalid())?,
}
Expand Down Expand Up @@ -849,7 +852,7 @@ impl<'a, 'm> Expr<'a, 'm> {

fn end_label(&mut self) -> CheckResult {
let results_len = self.label().type_.results.len();
let target = self.branch_target(results_len);
let target = self.branch_target(results_len, false);
for source in core::mem::take(&mut self.label().branches) {
self.side_table.stitch(source, target)?;
}
Expand Down Expand Up @@ -892,8 +895,11 @@ impl<'a, 'm> Expr<'a, 'm> {
branch
}

fn branch_target(&self, result: usize) -> SideTableBranch<'m> {
fn branch_target(&self, result: usize, is_if_with_else: bool) -> SideTableBranch<'m> {
let mut branch = self.branch();
if is_if_with_else {
branch.side_table += 1;
}
branch.result = result;
branch.stack += result;
branch
Expand Down

0 comments on commit 8b645b4

Please sign in to comment.