1# (C) Copyright 2017, 2020 by Rocky Bernstein 2""" 3PYPY 2.7 opcodes 4 5This is a like Python 2.7's opcode.py with some classification 6of stack usage. 7""" 8 9import xdis.opcodes.opcode_27 as opcode_27 10from xdis.opcodes.base import ( 11 def_op, 12 extended_format_ATTR, 13 extended_format_CALL_FUNCTION, 14 extended_format_MAKE_FUNCTION_older, 15 extended_format_RAISE_VARARGS_older, 16 extended_format_RETURN_VALUE, 17 finalize_opcodes, 18 format_CALL_FUNCTION_pos_name_encoded, 19 format_MAKE_FUNCTION_default_argc, 20 format_RAISE_VARARGS_older, 21 format_extended_arg, 22 init_opdata, 23 jrel_op, 24 name_op, 25 nargs_op, 26 update_pj3, 27) 28 29version = 2.7 30python_implementation = "PyPy" 31 32l = locals() 33 34init_opdata(l, opcode_27, version, is_pypy=True) 35 36# FIXME: DRY common PYPY opcode additions 37 38# PyPy only 39# ---------- 40name_op(l, "LOOKUP_METHOD", 201, 1, 2) 41nargs_op(l, "CALL_METHOD", 202, -1, 1) 42l["hasnargs"].append(202) 43 44# Used only in single-mode compilation list-comprehension generators 45def_op(l, "BUILD_LIST_FROM_ARG", 203) 46 47# Used only in assert statements 48jrel_op(l, "JUMP_IF_NOT_DEBUG", 204, conditional=True) 49 50 51# PyPy 2.7.13 (and 3.6.1) start to introduce LOAD_REVDB_VAR 52import sys 53 54if sys.version_info[:3] >= (2, 7, 13) and sys.version_info[4] >= 42: 55 def_op(l, "LOAD_REVDB_VAR", 205) 56 57# There are no opcodes to remove or change. 58# If there were, they'd be listed below. 59 60# FIXME remove (fix uncompyle6) 61update_pj3(globals(), l) 62 63opcode_arg_fmt = { 64 "MAKE_FUNCTION": format_MAKE_FUNCTION_default_argc, 65 "EXTENDED_ARG": format_extended_arg, 66 "CALL_FUNCTION": format_CALL_FUNCTION_pos_name_encoded, 67 "RAISE_VARARGS": format_RAISE_VARARGS_older, 68} 69 70finalize_opcodes(l) 71 72opcode_extended_fmt = { 73 "CALL_FUNCTION": extended_format_CALL_FUNCTION, 74 "LOAD_ATTR": extended_format_ATTR, 75 "MAKE_FUNCTION": extended_format_MAKE_FUNCTION_older, 76 "RAISE_VARARGS": extended_format_RAISE_VARARGS_older, 77 "RETURN_VALUE": extended_format_RETURN_VALUE, 78 "STORE_ATTR": extended_format_ATTR, 79} 80