EXTENDED_ARG = opmap['EXTENDED_ARG']
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
-for op, i in opmap.items():
- opname[i] = op
+for m in (opmap, _specialized_opmap):
+ for op, i in m.items():
+ opname[i] = op
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
opcodes = [dis.opmap[opname] for opname in names]
self.check_bool_function_result(_opcode.is_valid, opcodes, True)
+ def test_opmaps(self):
+ def check_roundtrip(name, map):
+ return self.assertEqual(opcode.opname[map[name]], name)
+
+ check_roundtrip('BINARY_OP', opcode.opmap)
+ check_roundtrip('BINARY_OP_ADD_INT', opcode._specialized_opmap)
+
def test_oplists(self):
def check_function(self, func, expected):
for op in [-10, 520]:
def test_widths(self):
long_opcodes = set(['JUMP_BACKWARD_NO_INTERRUPT',
'INSTRUMENTED_CALL_FUNCTION_EX'])
- for opcode, opname in enumerate(dis.opname):
+ for op, opname in enumerate(dis.opname):
if opname in long_opcodes or opname.startswith("INSTRUMENTED"):
continue
+ if opname in opcode._specialized_opmap:
+ continue
with self.subTest(opname=opname):
width = dis._OPNAME_WIDTH
- if opcode in dis.hasarg:
+ if op in dis.hasarg:
width += 1 + dis._OPARG_WIDTH
self.assertLessEqual(len(opname), width)
--- /dev/null
+Add specialized opcodes to ``opcode.opname``.