Skip to content

Commit 4ef2a50

Browse files
youknowonearihant2math
authored andcommitted
applied fix
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent 223fbe4 commit 4ef2a50

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

compiler/codegen/src/compile.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ impl Compiler {
18401840
fn jump_to_fail_pop(&mut self, pattern_context: &mut PatternContext) -> CompileResult<()> {
18411841
let pops = pattern_context.on_top + pattern_context.stores.len();
18421842
self.ensure_fail_pop(pattern_context, pops)?;
1843-
self.switch_to_block(pattern_context.fail_pop[pops]);
1843+
// self.switch_to_block(pattern_context.fail_pop[pops]);
18441844
Ok(())
18451845
}
18461846
// static int
@@ -2054,7 +2054,11 @@ impl Compiler {
20542054
) -> CompileResult<()> {
20552055
self.compile_expression(subject)?;
20562056
// Block at the end of the switch statement that we jump to after finishing a branch
2057-
let end_block = self.new_block();
2057+
let pattern_blocks = std::iter::repeat_with(|| self.new_block())
2058+
.take(cases.len() + 1)
2059+
.collect::<Vec<_>>();
2060+
eprintln!("created pattern_blocks: {:?} - {:?}(end block)", pattern_blocks.first().unwrap(), pattern_blocks.last().unwrap());
2061+
let end_block = *pattern_blocks.last().unwrap();
20582062

20592063
let match_case_type = cases.last().expect("cases is not empty");
20602064
let has_default = match_case_type.pattern.is_match_star() && 1 < cases.len();
@@ -2088,7 +2092,7 @@ impl Compiler {
20882092
// }
20892093
if let Some(guard) = &m.guard {
20902094
self.ensure_fail_pop(pattern_context, 0)?;
2091-
self.compile_jump_if(guard, false, pattern_context.fail_pop[0])?;
2095+
self.compile_jump_if(guard, false, pattern_blocks[i + 1])?;
20922096
}
20932097
if i != cases.len() - (has_default as usize) - 1 {
20942098
// ADDOP(c, LOC(m->pattern), POP_TOP);
@@ -2103,6 +2107,7 @@ impl Compiler {
21032107
// A trailing "case _" is common, and lets us save a bit of redundant
21042108
// pushing and popping in the loop above:
21052109
let m = &cases.last().unwrap();
2110+
self.switch_to_block(*pattern_blocks.last().unwrap());
21062111
if cases.len() == 1 {
21072112
// No matches. Done with the subject:
21082113
// ADDOP(c, LOC(m->pattern), POP_TOP);
@@ -3419,6 +3424,7 @@ impl Compiler {
34193424
u32::MAX,
34203425
"switching {prev:?} -> {block:?} from block that's already got a next"
34213426
);
3427+
eprintln!("switch_to_block {prev:?} -> {block:?}");
34223428
prev_block.next = block;
34233429
code.current_block = block;
34243430
}

0 commit comments

Comments
 (0)