opcode_30.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # (C) Copyright 2017, 2019-2021, 2023-2024 by Rocky Bernstein
  2. """
  3. CPython 3.0 bytecode opcodes
  4. This is a like Python 3.0's opcode.py with some classification
  5. of stack usage and information for formatting instructions.
  6. """
  7. import xdis.opcodes.opcode_31 as opcode_31
  8. from xdis.opcodes.base import (
  9. def_op,
  10. finalize_opcodes,
  11. init_opdata,
  12. jrel_op,
  13. rm_op,
  14. update_pj2,
  15. )
  16. from xdis.opcodes.opcode_33 import opcode_arg_fmt33, opcode_extended_fmt33
  17. version_tuple = (3, 0)
  18. python_implementation = "CPython"
  19. loc = locals()
  20. init_opdata(loc, opcode_31, version_tuple)
  21. # These are in Python 3.x but not in Python 3.0
  22. # fmt: off
  23. rm_op(loc, "JUMP_IF_FALSE_OR_POP", 111)
  24. rm_op(loc, "JUMP_IF_TRUE_OR_POP", 112)
  25. rm_op(loc, "POP_JUMP_IF_FALSE", 114)
  26. rm_op(loc, "POP_JUMP_IF_TRUE", 115)
  27. rm_op(loc, "LIST_APPEND", 145)
  28. rm_op(loc, "SET_ADD", 146)
  29. rm_op(loc, "MAP_ADD", 147)
  30. # These are are in 3.0 but are not in 3.1 or they have
  31. # different opcode numbers. Note: As a result of opcode value
  32. # changes, these have to be applied *after* removing ops (with
  33. # the same name).
  34. # OP NAME OPCODE POP PUSH
  35. #--------------------------------------------
  36. def_op(loc, "SET_ADD", 17, 2, 0) # Calls set.add(TOS1[-i], TOS).
  37. # Used to implement set comprehensions.
  38. def_op(loc, "LIST_APPEND", 18, 2, 0) # Calls list.append(TOS1, TOS).
  39. # Used to implement list comprehensions.
  40. jrel_op(loc, "JUMP_IF_FALSE", 111, 1, 1)
  41. jrel_op(loc, "JUMP_IF_TRUE", 112, 1, 1)
  42. # fmt: on
  43. # Yes, pj2 not pj3 - Python 3.0 is more like 2.7 here with its
  44. # JUMP_IF rather than POP_JUMP_IF.
  45. opcode_arg_fmt = opcode_arg_fmt31 = opcode_arg_fmt33
  46. opcode_extended_fmt = opcode_extended_fmt31 = opcode_extended_fmt33
  47. update_pj2(globals(), loc)
  48. finalize_opcodes(loc)