@@ -370,6 +370,10 @@ pub type NameIdx = u32;
370370#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
371371#[ repr( u8 ) ]
372372pub enum Instruction {
373+ /// No-op, don't do anything at all
374+ ///
375+ /// Equivalent to `NOP` in cpython bytecode
376+ Nop ,
373377 /// Importing by name
374378 ImportName {
375379 idx : Arg < NameIdx > ,
@@ -428,6 +432,9 @@ pub enum Instruction {
428432 op : Arg < ComparisonOperator > ,
429433 } ,
430434 Pop ,
435+ Swap {
436+ index : Arg < u32 > ,
437+ } ,
431438 Rotate2 ,
432439 Rotate3 ,
433440 Duplicate ,
@@ -1177,6 +1184,7 @@ impl Instruction {
11771184 ///
11781185 pub fn stack_effect ( & self , arg : OpArg , jump : bool ) -> i32 {
11791186 match self {
1187+ Nop => 0 ,
11801188 ImportName { .. } | ImportNameless => -1 ,
11811189 ImportStar => -1 ,
11821190 ImportFrom { .. } => 1 ,
@@ -1197,6 +1205,7 @@ impl Instruction {
11971205 | TestOperation { .. }
11981206 | CompareOperation { .. } => -1 ,
11991207 Pop => -1 ,
1208+ Swap { .. } => 0 ,
12001209 Rotate2 | Rotate3 => 0 ,
12011210 Duplicate => 1 ,
12021211 Duplicate2 => 2 ,
@@ -1361,6 +1370,7 @@ impl Instruction {
13611370 } ;
13621371
13631372 match self {
1373+ Nop => w ! ( Nop ) ,
13641374 ImportName { idx } => w ! ( ImportName , name = idx) ,
13651375 ImportNameless => w ! ( ImportNameless ) ,
13661376 ImportStar => w ! ( ImportStar ) ,
@@ -1392,6 +1402,7 @@ impl Instruction {
13921402 TestOperation { op } => w ! ( TestOperation , ?op) ,
13931403 CompareOperation { op } => w ! ( CompareOperation , ?op) ,
13941404 Pop => w ! ( Pop ) ,
1405+ Swap { index } => w ! ( Swap , index) ,
13951406 Rotate2 => w ! ( Rotate2 ) ,
13961407 Rotate3 => w ! ( Rotate3 ) ,
13971408 Duplicate => w ! ( Duplicate ) ,
0 commit comments