New Instruction ToBool,PopJumpIfFalse by youknowone · Pull Request #6112 · RustPython/RustPython
Walkthrough
Renames conditional-jump variants to PopJumpIfTrue/PopJumpIfFalse, adds a unit ToBool instruction, updates label extraction, stack effects, and disassembly, and implements runtime handling plus a pop-and-jump helper. Codegen and JIT emission were updated to emit the PopJump variants.
Changes
| Cohort / File(s) | Summary |
|---|---|
Bytecode definition & formattingcompiler/core/src/bytecode.rs |
Renames JumpIfTrue → PopJumpIfTrue and JumpIfFalse → PopJumpIfFalse; adds ToBool unit variant; includes PopJump variants in label extraction; updates stack effects (PopJumpIfTrue/PopJumpIfFalse: -1, ToBool: 0); extends disassembly/printing and adds doc comment for PopJump behavior. |
VM execution & control flowvm/src/frame.rs |
Adds ToBool runtime handling (pop, convert via try_to_bool, push PyBool); implements PopJumpIfTrue/PopJumpIfFalse via new pop_jump_if helper (pop, boolize, conditional jump); integrates these into main instruction dispatch. |
Code generation updatescompiler/codegen/src/compile.rs |
Emits PopJumpIfTrue/PopJumpIfFalse in places that previously emitted JumpIfTrue/JumpIfFalse, changing stack discipline so the test value is popped as part of the jump. |
JIT emissionjit/src/instructions.rs |
Match arms updated to handle PopJumpIfTrue/PopJumpIfFalse (renamed variants); codegen logic for popping, boolean conversion, and conditional branching preserved. |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant BC as Bytecode
participant Frame as ExecutingFrame
participant Stack
participant VM as VM/Runtime
rect rgba(230,240,255,0.6)
note over BC,Frame: ToBool execution
Frame->>Stack: pop value
Frame->>VM: try_to_bool(value)
VM-->>Frame: bool_obj
Frame->>Stack: push bool_obj
end
rect rgba(240,230,255,0.6)
note over BC,Frame: PopJumpIfTrue / PopJumpIfFalse execution
Frame->>Stack: pop value
Frame->>VM: try_to_bool(value)
VM-->>Frame: bool_result
alt pop result matches jump condition
Frame->>Frame: jump to target label
else
Frame->>Frame: continue (value discarded)
end
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~30 minutes
Poem
A rabbit peeks at bytecode trees,
PopJumpIfTrue and PopJumpIfFalse with ease,
ToBool nibbles values, turns them right,
One pop, one hop, then off in flight. 🥕
✨ Finishing Touches
- 📝 Generate Docstrings
🧪 Generate unit tests
- Create PR with unit tests
- Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.