opcode_37pypy.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # (C) Copyright 2021-2024 by Rocky Bernstein
  2. """
  3. PYPY 3.7 opcodes
  4. This is a like PyPy 3.7's opcode.py with some classification
  5. of stack usage and information for formatting instructions.
  6. """
  7. import sys
  8. from typing import List
  9. import xdis.opcodes.opcode_37 as opcode_37
  10. from xdis.opcodes.base import (
  11. call_op,
  12. def_op,
  13. finalize_opcodes,
  14. init_opdata,
  15. name_op,
  16. rm_op,
  17. store_op,
  18. update_pj3,
  19. varargs_op,
  20. )
  21. from xdis.opcodes.opcode_36pypy import opcode_arg_fmt36pypy, opcode_extended_fmt36pypy
  22. from xdis.opcodes.opcode_37 import opcode_arg_fmt37, opcode_extended_fmt37
  23. version_tuple = (3, 7)
  24. python_implementation = "PyPy"
  25. # oppush[op] => number of stack entries pushed
  26. oppush: List[int] = [0] * 256
  27. # oppop[op] => number of stack entries popped
  28. oppop: List[int] = [0] * 256
  29. loc = locals()
  30. init_opdata(loc, opcode_37, version_tuple, is_pypy=True)
  31. # FIXME: DRY common PYPY opcode additions
  32. # fmt: off
  33. rm_op(loc, "BUILD_TUPLE_UNPACK_WITH_CALL", 158)
  34. rm_op(loc, "LOAD_METHOD", 160)
  35. call_op(loc, "CALL_FUNCTION_KW", 141, 9, 1) # #args + (#kwargs << 8)
  36. call_op(loc, "CALL_FUNCTION_EX", 142, -2, 1)
  37. # The following were removed from 3.7 but still in some versions Pypy 3.7
  38. store_op(loc, 'STORE_ANNOTATION', 127, 1, 0, is_type="name")
  39. # PyPy only
  40. # ----------
  41. name_op(loc, "LOOKUP_METHOD", 201, 1, 2)
  42. loc["hasvargs"].append(202)
  43. call_op(loc, "CALL_METHOD_KW", 204, -1, 1)
  44. # Used only in single-mode compilation list-comprehension generators
  45. varargs_op(loc, "BUILD_LIST_FROM_ARG", 203)
  46. # PyPy 3.6.1 (and 2.7.13) start to introduce LOAD_REVDB_VAR
  47. if sys.version_info[:3] >= (3, 6, 1):
  48. def_op(loc, "LOAD_REVDB_VAR", 205)
  49. # fmt: on
  50. opcode_arg_fmt = opcode_arg_fmt37pypy = {**opcode_arg_fmt37, **opcode_arg_fmt36pypy}
  51. opcode_extended_fmt = opcode_extended_fmt37pypy = {
  52. **opcode_extended_fmt37,
  53. **opcode_extended_fmt36pypy,
  54. }
  55. update_pj3(globals(), loc)
  56. finalize_opcodes(loc)