New submission from Irit Katriel <iritkatr...@gmail.com>:

There are a few "virtual opcodes" which are internal to the compiler. They can 
have values > 256. This way we don't waste any valid opcodes on them, and it is 
easier to detect when one of them escapes the compiler into the assemble stage.

In addition, there is an is_jump() function that treats the exception handling 
opcodes as jumps (and also assumes that any opcode >= SETUP_WITH is a jump):

static inline int
 is_jump(struct instr *i)
 {
    return i->i_opcode >= SETUP_WITH || is_bit_set_in_table(_PyOpcode_Jump, 
i->i_opcode);
 }

Then there is is_block_push just for the three virtual exception block opcodes:

static inline int
is_block_push(struct instr *instr)
{
    int opcode = instr->i_opcode;
    return opcode == SETUP_FINALLY || opcode == SETUP_WITH || opcode == 
SETUP_CLEANUP;
}

We can make is_jump return true just for jumps, and call is_block_push as well 
when it is needed (currently sometimes we call is_jump when there cannot be 
virtual opcodes anymore so we can assert that instead, and in one place we call 
is_jump and then exclude the virtual opcodes. Both of these will become clearer 
after we make this change).

----------
assignee: iritkatriel
components: Interpreter Core
messages: 416386
nosy: iritkatriel
priority: normal
severity: normal
status: open
title: Make virtual opcodes in the compiler > 256 and is_jump() identify only 
proper jumps
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue47172>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to