1# (C) Copyright 2017, 2021 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"""
17PYPY 2.6 opcodes
18
19This is a like Python 2.6's opcode.py with some classification
20of stack usage.
21"""
22
23import xdis.opcodes.opcode_26 as opcode_26
24from xdis.opcodes.base import (
25    extended_format_ATTR,
26    extended_format_RETURN_VALUE,
27    finalize_opcodes,
28    init_opdata,
29    jrel_op,
30    name_op,
31    nargs_op,
32    update_pj2,
33    varargs_op,
34)
35
36version = 2.6
37python_implementation = "PyPy"
38
39l = locals()
40init_opdata(l, opcode_26, version, is_pypy=True)
41
42# FIXME: DRY common PYPY opcode additions
43
44# fmt: off
45# PyPy only
46# ----------
47name_op(l,   'LOOKUP_METHOD',   201,  1, 2)
48nargs_op(l,  'CALL_METHOD',     202, -1, 1)
49# fmt: on
50
51l["hasnargs"].append(202)
52
53# Used only in single-mode compilation list-comprehension generators
54varargs_op(l, "BUILD_LIST_FROM_ARG", 203)
55
56# Used only in assert statements
57jrel_op(l, "JUMP_IF_NOT_DEBUG", 204, conditional=True)
58
59# FIXME remove (fix uncompyle6)
60update_pj2(globals(), l)
61
62finalize_opcodes(l)
63
64opcode_extended_fmt = {
65    "LOAD_ATTR": extended_format_ATTR,
66    "RETURN_VALUE": extended_format_RETURN_VALUE,
67    "STORE_ATTR": extended_format_ATTR,
68}
69