@@ -217,31 +217,29 @@ macro_rules! emit {
217
217
}
218
218
219
219
struct PatternContext {
220
- // // A list of strings corresponding to name captures. It is used to track:
221
- // // - Repeated name assignments in the same pattern.
222
- // // - Different name assignments in alternatives.
223
- // // - The order of name assignments in alternatives.
224
- // PyObject *stores;
225
- // // If 0, any name captures against our subject will raise.
226
- // int allow_irrefutable;
227
- // // An array of blocks to jump to on failure. Jumping to fail_pop[i] will pop
228
- // // i items off of the stack. The end result looks like this (with each block
229
- // // falling through to the next):
230
- // // fail_pop[4]: POP_TOP
231
- // // fail_pop[3]: POP_TOP
232
- // // fail_pop[2]: POP_TOP
233
- // // fail_pop[1]: POP_TOP
234
- // // fail_pop[0]: NOP
235
- // jump_target_label *fail_pop;
236
220
// // The current length of fail_pop.
237
221
// Py_ssize_t fail_pop_size;
238
- // // The number of items on top of the stack that need to *stay* on top of the
239
- // // stack. Variable captures go beneath these. All of them will be popped on
240
- // // failure.
241
- // Py_ssize_t on_top;
222
+
223
+ /// Py_ssize_t on_top;
224
+ /// A list of strings corresponding to name captures. It is used to track:
225
+ /// - Repeated name assignments in the same pattern.
226
+ /// - Different name assignments in alternatives.
227
+ /// - The order of name assignments in alternatives.
242
228
pub stores : Vec < String > ,
229
+ /// If 0, any name captures against our subject will raise.
243
230
pub allow_irrefutable : bool ,
231
+ /// An array of blocks to jump to on failure. Jumping to fail_pop[i] will pop
232
+ /// i items off of the stack. The end result looks like this (with each block
233
+ /// falling through to the next):
234
+ /// fail_pop[4]: POP_TOP
235
+ /// fail_pop[3]: POP_TOP
236
+ /// fail_pop[2]: POP_TOP
237
+ /// fail_pop[1]: POP_TOP
238
+ /// fail_pop[0]: NOP
244
239
pub fail_pop : Vec < BlockIdx > ,
240
+ /// The number of items on top of the stack that need to *stay* on top of the
241
+ /// stack. Variable captures go beneath these. All of them will be popped on
242
+ /// failure.
245
243
pub on_top : usize ,
246
244
}
247
245
@@ -2055,9 +2053,8 @@ impl Compiler {
2055
2053
pattern_context : & mut PatternContext ,
2056
2054
) -> CompileResult < ( ) > {
2057
2055
self . compile_expression ( subject) ?;
2058
- // Blocks at the end of the switch statement that we jump to after finishing a branch
2059
- // TODO: optimize, we can reuse the same block for all cases
2060
- let mut end_block = self . new_block ( ) ;
2056
+ // Block at the end of the switch statement that we jump to after finishing a branch
2057
+ let end_block = self . new_block ( ) ;
2061
2058
2062
2059
let match_case_type = cases. last ( ) . expect ( "cases is not empty" ) ;
2063
2060
let has_default = match_case_type. pattern . is_match_star ( ) && 1 < cases. len ( ) ;
@@ -2117,7 +2114,6 @@ impl Compiler {
2117
2114
self . compile_statements ( & m. body ) ?;
2118
2115
}
2119
2116
2120
- self . switch_to_block ( end_block) ;
2121
2117
Ok ( ( ) )
2122
2118
}
2123
2119
0 commit comments