1# (C) Copyright 2017, 2020-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"""
17CPython 2.6 bytecode opcodes
18
19This is a like Python 2.6's opcode.py with some additional classification
20of stack usage, and opererand formatting functions.
21"""
22
23from xdis.opcodes.base import (
24    extended_format_ATTR,
25    extended_format_CALL_FUNCTION,
26    extended_format_MAKE_FUNCTION_older,
27    extended_format_RAISE_VARARGS_older,
28    extended_format_RETURN_VALUE,
29    finalize_opcodes,
30    format_CALL_FUNCTION_pos_name_encoded,
31    format_MAKE_FUNCTION_default_argc,
32    format_RAISE_VARARGS_older,
33    format_extended_arg,
34    init_opdata,
35    name_op,
36    rm_op,
37    store_op,
38    update_pj2,
39)
40import xdis.opcodes.opcode_25 as opcode_25
41
42python_implementation = "CPython"
43
44version = 2.6
45
46l = locals()
47init_opdata(l, opcode_25, version)
48
49# Below are opcode changes since Python 2.5
50
51# fmt: off
52#          OP NAME            OPCODE POP PUSH
53#--------------------------------------------
54store_op(l, "STORE_MAP",          54,  3,  1)
55rm_op(l,    "IMPORT_NAME",       107)
56name_op(l,  "IMPORT_NAME",       107,  2,  1)  # Imports namei; TOS and TOS1 provide fromlist and level. Module pushed.
57# fmt: on
58
59# FIXME remove (fix uncompyle6)
60update_pj2(globals(), l)
61
62opcode_arg_fmt = {
63    "CALL_FUNCTION": format_CALL_FUNCTION_pos_name_encoded,
64    "CALL_FUNCTION_KW": format_CALL_FUNCTION_pos_name_encoded,
65    "CALL_FUNCTION_VAR_KW": format_CALL_FUNCTION_pos_name_encoded,
66    "EXTENDED_ARG": format_extended_arg,
67    "MAKE_FUNCTION": format_MAKE_FUNCTION_default_argc,
68    "RAISE_VARARGS": format_RAISE_VARARGS_older,
69}
70
71opcode_extended_fmt = {
72    "CALL_FUNCTION": extended_format_CALL_FUNCTION,
73    "LOAD_ATTR": extended_format_ATTR,
74    "MAKE_FUNCTION": extended_format_MAKE_FUNCTION_older,
75    "RAISE_VARARGS": extended_format_RAISE_VARARGS_older,
76    "RETURN_VALUE": extended_format_RETURN_VALUE,
77    "STORE_ATTR": extended_format_ATTR,
78}
79finalize_opcodes(l)
80