Duplicate the effect of Python 3.10's ROT_* instructions using SWAPs.
(&mut self, mut count: usize)
| 5968 | |
| 5969 | /// Duplicate the effect of Python 3.10's ROT_* instructions using SWAPs. |
| 5970 | fn pattern_helper_rotate(&mut self, mut count: usize) -> CompileResult<()> { |
| 5971 | // Rotate TOS (top of stack) to position `count` down |
| 5972 | // This is done by a series of swaps |
| 5973 | // For count=1, no rotation needed (already at top) |
| 5974 | // For count=2, swap TOS with item 1 position down |
| 5975 | // For count=3, swap TOS with item 2 positions down, then with item 1 position down |
| 5976 | while count > 1 { |
| 5977 | // Emit a SWAP instruction with the current count. |
| 5978 | emit!( |
| 5979 | self, |
| 5980 | Instruction::Swap { |
| 5981 | i: u32::try_from(count).unwrap() |
| 5982 | } |
| 5983 | ); |
| 5984 | count -= 1; |
| 5985 | } |
| 5986 | Ok(()) |
| 5987 | } |
| 5988 | |
| 5989 | /// Helper to store a captured name for a star pattern. |
| 5990 | /// |
no outgoing calls
no test coverage detected