opcode_27.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # (C) Copyright 2017, 2019-2021, 2023-2024 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 2.7 bytecode opcodes
  18. This is a like Python 2.7's opcode.py with some classification
  19. of stack usage.
  20. """
  21. import xdis.opcodes.opcode_26 as opcode_26
  22. from xdis.opcodes.base import (
  23. compare_op,
  24. def_op,
  25. finalize_opcodes,
  26. init_opdata,
  27. jabs_op,
  28. jrel_op,
  29. name_op,
  30. rm_op,
  31. update_pj3,
  32. varargs_op,
  33. )
  34. from xdis.opcodes.opcode_2x import opcode_extended_fmt_base2x, update_arg_fmt_base2x
  35. version_tuple = (2, 7)
  36. python_implementation = "CPython"
  37. loc = l = locals()
  38. init_opdata(l, opcode_26, version_tuple)
  39. # fmt: off
  40. # Below are opcode changes since Python 2.6
  41. rm_op(l, "LIST_APPEND", 18)
  42. rm_op(l, "BUILD_MAP", 104)
  43. rm_op(l, "LOAD_ATTR", 105)
  44. rm_op(l, "COMPARE_OP", 106)
  45. rm_op(l, "IMPORT_NAME", 107)
  46. rm_op(l, "IMPORT_FROM", 108)
  47. rm_op(l, "JUMP_IF_FALSE", 111)
  48. rm_op(l, "EXTENDED_ARG", 143)
  49. rm_op(l, "JUMP_IF_TRUE", 112)
  50. rm_op(l, "SETUP_EXCEPT", 121)
  51. rm_op(l, "SETUP_FINALLY", 122)
  52. # These have changed since 2.6 in stack effects.
  53. # OP NAME OPCODE POP PUSH
  54. #-----------------------------------------------
  55. def_op(l, "END_FINALLY", 88, 3, 0)
  56. jrel_op(l, "SETUP_EXCEPT", 121, 0, 0, conditional=True) # ""
  57. jrel_op(l, "SETUP_FINALLY" , 122, 0, 0, conditional=True) # ""
  58. def_op(l, "LIST_APPEND", 94, 2, 1) # Calls list.append(TOS[-i], TOS).
  59. # Used to implement list comprehensions.
  60. varargs_op(l, 'BUILD_SET', 104, -1, 1) # TOS is count of set items
  61. varargs_op(l, "BUILD_MAP", 105, 0, 1) # count is in argument
  62. name_op(l, "LOAD_ATTR", 106, 1, 1) # Operand is in name list
  63. compare_op(l, "COMPARE_OP", 107)
  64. name_op(l, "IMPORT_NAME", 108, 2, 1) # Index in name list
  65. name_op(l, "IMPORT_FROM", 109, 0, 1)
  66. jabs_op(l, "JUMP_IF_FALSE_OR_POP", 111) # Target byte offset from beginning of code
  67. jabs_op(l, "JUMP_IF_TRUE_OR_POP", 112) # ""
  68. jabs_op(l, "POP_JUMP_IF_FALSE", 114, 2, 1, conditional=True) # ""
  69. jabs_op(l, "POP_JUMP_IF_TRUE", 115, 2, 1, conditional=True) # ""
  70. jrel_op(l, "SETUP_WITH", 143, 0, 4)
  71. def_op(l, "EXTENDED_ARG", 145)
  72. def_op(l, "SET_ADD", 146, 1, 0) # Calls set.add(TOS1[-i], TOS).
  73. # Used to implement set comprehensions.
  74. def_op(l, "MAP_ADD", 147, 3, 1) # Calls dict.setitem(TOS1[-i], TOS, TOS1)
  75. # Used to implement dict comprehensions.
  76. # fmt: on
  77. opcode_arg_fmt = opcode_arg_fmt27 = update_arg_fmt_base2x.copy()
  78. opcode_extended_fmt = opcode_extended_fmt27 = opcode_extended_fmt_base2x.copy()
  79. update_pj3(globals(), l)
  80. finalize_opcodes(l)