opcode_38.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # (C) Copyright 2019-2021, 2023 by Rocky Bernstein
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. """
  17. CPython 3.8 bytecode opcodes
  18. This is like Python 3.8's opcode.py with some classification
  19. of stack usage and information for formatting instructions.
  20. """
  21. import xdis.opcodes.opcode_37 as opcode_37
  22. from xdis.opcodes.base import (
  23. def_op,
  24. finalize_opcodes,
  25. init_opdata,
  26. jrel_op,
  27. nargs_op,
  28. rm_op,
  29. update_pj3,
  30. )
  31. from xdis.opcodes.opcode_37 import opcode_arg_fmt37, opcode_extended_fmt37
  32. version_tuple = (3, 8)
  33. python_implementation = "CPython"
  34. loc = l = locals()
  35. init_opdata(l, opcode_37, version_tuple)
  36. # fmt: off
  37. # These are removed since 3.7...
  38. rm_op(l, "BREAK_LOOP", 80)
  39. rm_op(l, "CONTINUE_LOOP", 119)
  40. rm_op(l, "SETUP_LOOP", 120)
  41. rm_op(l, "SETUP_EXCEPT", 121)
  42. # These are new/changed since Python 3.7
  43. # OP NAME OPCODE POP PUSH
  44. # --------------------------------------------
  45. def_op(l, "ROT_FOUR", 6, 4, 4) # Opcode number changed from 5 to 6. Why?
  46. def_op(l, "BEGIN_FINALLY", 53, 0, 6)
  47. def_op(l, "END_ASYNC_FOR", 54, 7, 0) # POP is 0, when not 7
  48. def_op(l, "END_FINALLY", 88, 6, 0) # POP is 6, when not 1
  49. jrel_op(l, "CALL_FINALLY", 162, 0, 1)
  50. nargs_op(l, "POP_FINALLY", 163, 6, 0) # PUSH/POP vary
  51. # fmt: on
  52. opcode_arg_fmt = opcode_arg_fmt38 = opcode_arg_fmt37.copy()
  53. opcode_extended_fmt = opcode_extended_fmt38 = opcode_extended_fmt37.copy()
  54. update_pj3(globals(), loc)
  55. finalize_opcodes(l)