@@ -1840,7 +1840,7 @@ impl Compiler {
1840
1840
fn jump_to_fail_pop ( & mut self , pattern_context : & mut PatternContext ) -> CompileResult < ( ) > {
1841
1841
let pops = pattern_context. on_top + pattern_context. stores . len ( ) ;
1842
1842
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]);
1844
1844
Ok ( ( ) )
1845
1845
}
1846
1846
// static int
@@ -2054,7 +2054,11 @@ impl Compiler {
2054
2054
) -> CompileResult < ( ) > {
2055
2055
self . compile_expression ( subject) ?;
2056
2056
// 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 ( ) ;
2058
2062
2059
2063
let match_case_type = cases. last ( ) . expect ( "cases is not empty" ) ;
2060
2064
let has_default = match_case_type. pattern . is_match_star ( ) && 1 < cases. len ( ) ;
@@ -2088,7 +2092,7 @@ impl Compiler {
2088
2092
// }
2089
2093
if let Some ( guard) = & m. guard {
2090
2094
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 ] ) ?;
2092
2096
}
2093
2097
if i != cases. len ( ) - ( has_default as usize ) - 1 {
2094
2098
// ADDOP(c, LOC(m->pattern), POP_TOP);
@@ -2103,6 +2107,7 @@ impl Compiler {
2103
2107
// A trailing "case _" is common, and lets us save a bit of redundant
2104
2108
// pushing and popping in the loop above:
2105
2109
let m = & cases. last ( ) . unwrap ( ) ;
2110
+ self . switch_to_block ( * pattern_blocks. last ( ) . unwrap ( ) ) ;
2106
2111
if cases. len ( ) == 1 {
2107
2112
// No matches. Done with the subject:
2108
2113
// ADDOP(c, LOC(m->pattern), POP_TOP);
@@ -3419,6 +3424,7 @@ impl Compiler {
3419
3424
u32 :: MAX ,
3420
3425
"switching {prev:?} -> {block:?} from block that's already got a next"
3421
3426
) ;
3427
+ eprintln ! ( "switch_to_block {prev:?} -> {block:?}" ) ;
3422
3428
prev_block. next = block;
3423
3429
code. current_block = block;
3424
3430
}
0 commit comments