Skip to content

Conversation

@markshannon
Copy link
Member

@markshannonmarkshannon commented Aug 3, 2020

The motivation for this PR is to avoid errors when modifying compile.c.
Setting the i_jabs and i_jrel fields of every instruction is error prone and unnecessary.

https://bugs.python.org/issue41463

inti_lineno;
};

staticint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
staticint
staticinlineint

return (_PyOpcode_RelativeJump[opcode>>5]>>(opcode&31))&1;
}

staticint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
staticint
staticinlineint

is_relative_jump(structinstr*i)
{
intopcode=i->i_opcode;
return (_PyOpcode_RelativeJump[opcode>>5]>>(opcode&31))&1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@pablogsalpablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look great, I left some minor comments

intoparg=inst->i_oparg;
intnextop=i+1<bb->b_iused ? bb->b_instr[i+1].i_opcode : 0;
if (inst->i_jabs||inst->i_jrel){
if (is_jump(inst)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

staticinlineint
is_relative_jump(structinstr*i)
{
intopcode=i->i_opcode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@pablogsalpablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I left a comment, feel free to address it before landing

Copy link
Member

@pablogsalpablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@markshannonmarkshannon merged commit 582aaf1 into python:masterAug 4, 2020
@markshannonmarkshannon deleted the remove-i-fields branch August 4, 2020 22:05
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'
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@markshannon@pablogsal@the-knights-who-say-ni@bedevere-bot