@@ -401,7 +401,7 @@ impl Compiler {
401401
402402 /// Compile a slice expression
403403 // = compiler_slice
404- fn compile_slice ( & mut self , s : & ExprSlice ) -> CompileResult < u32 > {
404+ fn compile_slice ( & mut self , s : & ExprSlice ) -> CompileResult < BuildSliceArgCount > {
405405 // Compile lower
406406 if let Some ( lower) = & s. lower {
407407 self . compile_expression ( lower) ?;
@@ -416,13 +416,14 @@ impl Compiler {
416416 self . emit_load_const ( ConstantData :: None ) ;
417417 }
418418
419- // Compile step if present
420- if let Some ( step) = & s. step {
421- self . compile_expression ( step) ?;
422- Ok ( 3 ) // Three values on stack
423- } else {
424- Ok ( 2 ) // Two values on stack
425- }
419+ Ok ( match & s. step {
420+ Some ( step) => {
421+ // Compile step if present
422+ self . compile_expression ( step) ?;
423+ BuildSliceArgCount :: Three
424+ }
425+ None => BuildSliceArgCount :: Two ,
426+ } )
426427 }
427428
428429 /// Compile a subscript expression
@@ -449,29 +450,19 @@ impl Compiler {
449450
450451 // Handle two-element slice (for Load/Store, not Del)
451452 if Self :: is_two_element_slice ( slice) && !matches ! ( ctx, ExprContext :: Del ) {
452- let n = match slice {
453+ let argc = match slice {
453454 Expr :: Slice ( s) => self . compile_slice ( s) ?,
454455 _ => unreachable ! ( "is_two_element_slice should only return true for Expr::Slice" ) ,
455456 } ;
456457 match ctx {
457458 ExprContext :: Load => {
458459 // CPython uses BINARY_SLICE
459- emit ! (
460- self ,
461- Instruction :: BuildSlice {
462- argc: BuildSliceArgCount :: from_op_arg( n) . unwrap( )
463- }
464- ) ;
460+ emit ! ( self , Instruction :: BuildSlice { argc } ) ;
465461 emit ! ( self , Instruction :: Subscript ) ;
466462 }
467463 ExprContext :: Store => {
468464 // CPython uses STORE_SLICE
469- emit ! (
470- self ,
471- Instruction :: BuildSlice {
472- argc: BuildSliceArgCount :: from_op_arg( n) . unwrap( )
473- }
474- ) ;
465+ emit ! ( self , Instruction :: BuildSlice { argc } ) ;
475466 emit ! ( self , Instruction :: StoreSubscript ) ;
476467 }
477468 _ => unreachable ! ( ) ,
0 commit comments