opcode_31.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # (C) Copyright 2017, 2020-2021, 2023-2024 by Rocky Bernstein
  2. """
  3. CPython 3.1 bytecode opcodes
  4. This is a like Python 3.1's opcode.py with some classification
  5. of stack usage and information for formatting instructions.
  6. """
  7. import xdis.opcodes.opcode_32 as opcode_32
  8. from xdis.opcodes.base import (
  9. def_op,
  10. finalize_opcodes,
  11. init_opdata,
  12. name_op,
  13. rm_op,
  14. update_pj3,
  15. )
  16. from xdis.opcodes.opcode_33 import opcode_arg_fmt33, opcode_extended_fmt33
  17. loc = locals()
  18. version_tuple = (3, 1)
  19. python_implementation = "CPython"
  20. init_opdata(loc, opcode_32, version_tuple)
  21. # fmt: off
  22. # These are in Python 3.2 but not in Python 3.1
  23. rm_op(loc, "DUP_TOP_TWO", 5)
  24. rm_op(loc, "DELETE_DEREF", 138)
  25. rm_op(loc, "SETUP_WITH", 143)
  26. rm_op(loc, "EXTENDED_ARG", 144)
  27. # These are in Python 3.1 but not Python 3.2
  28. name_op(loc, "IMPORT_NAME", 108, 1, 1) # Imports TOS and TOS1; module pushed
  29. loc["nullaryloadop"].add(108)
  30. def_op(loc, "ROT_FOUR", 5, 4, 4)
  31. def_op(loc, "DUP_TOPX", 99, -1, 2) # number of items to duplicate
  32. # This op is in 3.2 but its opcode is a 144 instead
  33. def_op(loc, "EXTENDED_ARG", 143)
  34. # fmt: on
  35. opcode_arg_fmt = opcode_arg_fmt31 = opcode_arg_fmt33.copy()
  36. opcode_extended_fmt = opcode_extended_fmt31 = opcode_extended_fmt33.copy()
  37. update_pj3(globals(), loc)
  38. finalize_opcodes(loc)