summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-06-11 21:31:59 (GMT)
committerGitHub <noreply@github.com>2023-06-11 21:31:59 (GMT)
commit58f5227d7cdff803609a0bda6882997b3a5ec4bf (patch)
tree59cedf6d505015a2876a13da499894bcb8969f93 /Python/compile.c
parent20a56d8becba1a5a958b167fdb43b1a1b9228095 (diff)
downloadcpython-58f5227d7cdff803609a0bda6882997b3a5ec4bf.zip
cpython-58f5227d7cdff803609a0bda6882997b3a5ec4bf.tar.gz
cpython-58f5227d7cdff803609a0bda6882997b3a5ec4bf.tar.bz2
gh-105481: add pseudo-instructions to the bytecodes DSL (#105506)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index e3a7623..68b0466 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -134,7 +134,8 @@ enum {
int
_PyCompile_InstrSize(int opcode, int oparg)
{
- assert(!IS_PSEUDO_OPCODE(opcode));
+ assert(IS_PSEUDO_OPCODE(opcode) == IS_PSEUDO_INSTR(opcode));
+ assert(!IS_PSEUDO_INSTR(opcode));
assert(HAS_ARG(opcode) || oparg == 0);
int extended_args = (0xFFFFFF < oparg) + (0xFFFF < oparg) + (0xFF < oparg);
int caches = _PyOpcode_Caches[opcode];
@@ -241,9 +242,14 @@ instr_sequence_use_label(instr_sequence *seq, int lbl) {
return SUCCESS;
}
+
+#define MAX_OPCODE 511
+
static int
instr_sequence_addop(instr_sequence *seq, int opcode, int oparg, location loc)
{
+ assert(0 <= opcode && opcode <= MAX_OPCODE);
+ assert(IS_PSEUDO_OPCODE(opcode) == IS_PSEUDO_INSTR(opcode));
assert(IS_WITHIN_OPCODE_RANGE(opcode));
assert(HAS_ARG(opcode) || HAS_TARGET(opcode) || oparg == 0);
assert(0 <= oparg && oparg < (1 << 30));
@@ -1055,6 +1061,7 @@ compiler_addop_name(struct compiler_unit *u, location loc,
arg <<= 1;
}
if (opcode == LOAD_METHOD) {
+ assert(SAME_OPCODE_METADATA(LOAD_METHOD, LOAD_ATTR));
opcode = LOAD_ATTR;
arg <<= 1;
arg |= 1;
@@ -1064,15 +1071,18 @@ compiler_addop_name(struct compiler_unit *u, location loc,
arg |= 2;
}
if (opcode == LOAD_SUPER_METHOD) {
+ assert(SAME_OPCODE_METADATA(LOAD_SUPER_METHOD, LOAD_SUPER_ATTR));
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 3;
}
if (opcode == LOAD_ZERO_SUPER_ATTR) {
+ assert(SAME_OPCODE_METADATA(LOAD_ZERO_SUPER_ATTR, LOAD_SUPER_ATTR));
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
}
if (opcode == LOAD_ZERO_SUPER_METHOD) {
+ assert(SAME_OPCODE_METADATA(LOAD_ZERO_SUPER_METHOD, LOAD_SUPER_ATTR));
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 1;