bpo-41463: Generate information about jumps from 'opcode.py' rather than duplicating it in 'compile.c'#21714
Merged
markshannon merged 3 commits intopython:masterfrom Aug 4, 2020
Merged
Conversation
…te it in 'compile.c'
pablogsal
reviewed
Aug 4, 2020
Python/compile.c
Outdated
| int i_lineno; | ||
| }; | ||
|
|
||
| static int |
Member
There was a problem hiding this comment.
Suggested change
| static int | |
| static inline int |
pablogsal
reviewed
Aug 4, 2020
Python/compile.c
Outdated
| return (_PyOpcode_RelativeJump[opcode>>5]>>(opcode&31))&1; | ||
| } | ||
|
|
||
| static int |
Member
There was a problem hiding this comment.
Suggested change
| static int | |
| static inline int |
pablogsal
reviewed
Aug 4, 2020
Python/compile.c
Outdated
| is_relative_jump(struct instr *i) | ||
| { | ||
| int opcode = i->i_opcode; | ||
| return (_PyOpcode_RelativeJump[opcode>>5]>>(opcode&31))&1; |
Member
There was a problem hiding this comment.
Can you define 5 and 31 as globals with a name (using #define or with static variables). That way this will read a bit better
pablogsal
reviewed
Aug 4, 2020
Member
pablogsal
left a comment
There was a problem hiding this comment.
Look great, I left some minor comments
pablogsal
reviewed
Aug 4, 2020
| int oparg = inst->i_oparg; | ||
| int nextop = i+1 < bb->b_iused ? bb->b_instr[i+1].i_opcode : 0; | ||
| if (inst->i_jabs || inst->i_jrel) { | ||
| if (is_jump(inst)) { |
pablogsal
reviewed
Aug 4, 2020
Python/compile.c
Outdated
| static inline int | ||
| is_relative_jump(struct instr *i) | ||
| { | ||
| int opcode = i->i_opcode; |
Member
There was a problem hiding this comment.
Apologies for insisting a bit but it still took me a minute to parse the expression to follow how the function is determining if is a relative jump. I would suggest to maybe add a comment here briefly explaining the process as someone with less context will certainly struggle
pablogsal
approved these changes
Aug 4, 2020
Member
pablogsal
left a comment
There was a problem hiding this comment.
LGTM
I left a comment, feel free to address it before landing
shihai1991
pushed a commit
to shihai1991/cpython
that referenced
this pull request
Aug 20, 2020
…han duplicating it in 'compile.c' (pythonGH-21714) Generate information about jumps from 'opcode.py' rather than duplicate it in 'compile.c'
xzy3
pushed a commit
to xzy3/cpython
that referenced
this pull request
Oct 18, 2020
…han duplicating it in 'compile.c' (pythonGH-21714) Generate information about jumps from 'opcode.py' rather than duplicate it in 'compile.c'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The motivation for this PR is to avoid errors when modifying compile.c.
Setting the
i_jabsandi_jrelfields of every instruction is error prone and unnecessary.https://bugs.python.org/issue41463