summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-08-02 17:16:57 (GMT)
committerGitHub <noreply@github.com>2023-08-02 17:16:57 (GMT)
commitdd693d6320feeca887174fa592537669d017ca9b (patch)
tree488cbb4232bf30180f2a6bf316c15356ada77935 /Lib
parentb9c9a36c2f2edc11b9c27eb7c5810919d9da9767 (diff)
downloadcpython-dd693d6320feeca887174fa592537669d017ca9b.zip
cpython-dd693d6320feeca887174fa592537669d017ca9b.tar.gz
cpython-dd693d6320feeca887174fa592537669d017ca9b.tar.bz2
gh-105481: simplify definition of pseudo ops in Lib/opcode.py (#107561)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/opcode.py44
1 files changed, 15 insertions, 29 deletions
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 51432ab..5a9f8dd 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -19,23 +19,11 @@ if sys.version_info[:2] >= (3, 13):
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
-def is_pseudo(op):
- return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE
-
opmap = {}
-# pseudo opcodes (used in the compiler) mapped to the values
-# they can become in the actual code.
-_pseudo_ops = {}
-
def def_op(name, op):
opmap[name] = op
-def pseudo_op(name, op, real_ops):
- def_op(name, op)
- _pseudo_ops[name] = real_ops
-
-
# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes
@@ -212,29 +200,27 @@ def_op('INSTRUMENTED_LINE', 254)
# 255 is reserved
-MIN_PSEUDO_OPCODE = 256
-
-pseudo_op('SETUP_FINALLY', 256, ['NOP'])
-pseudo_op('SETUP_CLEANUP', 257, ['NOP'])
-pseudo_op('SETUP_WITH', 258, ['NOP'])
-pseudo_op('POP_BLOCK', 259, ['NOP'])
+# Pseudo ops are above 255:
-pseudo_op('JUMP', 260, ['JUMP_FORWARD', 'JUMP_BACKWARD'])
-pseudo_op('JUMP_NO_INTERRUPT', 261, ['JUMP_FORWARD', 'JUMP_BACKWARD_NO_INTERRUPT'])
+def_op('SETUP_FINALLY', 256)
+def_op('SETUP_CLEANUP', 257)
+def_op('SETUP_WITH', 258)
+def_op('POP_BLOCK', 259)
-pseudo_op('LOAD_METHOD', 262, ['LOAD_ATTR'])
-pseudo_op('LOAD_SUPER_METHOD', 263, ['LOAD_SUPER_ATTR'])
-pseudo_op('LOAD_ZERO_SUPER_METHOD', 264, ['LOAD_SUPER_ATTR'])
-pseudo_op('LOAD_ZERO_SUPER_ATTR', 265, ['LOAD_SUPER_ATTR'])
+def_op('JUMP', 260)
+def_op('JUMP_NO_INTERRUPT', 261)
-pseudo_op('STORE_FAST_MAYBE_NULL', 266, ['STORE_FAST'])
-pseudo_op('LOAD_CLOSURE', 267, ['LOAD_FAST'])
+def_op('LOAD_METHOD', 262)
+def_op('LOAD_SUPER_METHOD', 263)
+def_op('LOAD_ZERO_SUPER_METHOD', 264)
+def_op('LOAD_ZERO_SUPER_ATTR', 265)
-MAX_PSEUDO_OPCODE = MIN_PSEUDO_OPCODE + len(_pseudo_ops) - 1
+def_op('STORE_FAST_MAYBE_NULL', 266)
+def_op('LOAD_CLOSURE', 267)
-del def_op, pseudo_op
+del def_op
-opname = ['<%r>' % (op,) for op in range(MAX_PSEUDO_OPCODE + 1)]
+opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
for op, i in opmap.items():
opname[i] = op