1# (C) Copyright 2019-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 1.6 bytecode opcodes
18
19This is used in bytecode disassembly. This is similar to the
20opcodes in Python's dis.py library.
21"""
22
23# This is used from outside this module
24from xdis.cross_dis import findlabels, findlinestarts  # noqa
25
26import xdis.opcodes.opcode_15 as opcode_15
27from xdis.opcodes.base import (
28    extended_format_ATTR,
29    extended_format_MAKE_FUNCTION_older,
30    extended_format_RETURN_VALUE,
31    init_opdata,
32    nargs_op,
33    finalize_opcodes,
34    format_CALL_FUNCTION_pos_name_encoded,
35    format_MAKE_FUNCTION_default_argc,
36    format_extended_arg,
37    update_pj2,
38)
39
40version = 1.6
41python_implementation = "CPython"
42
43l = locals()
44init_opdata(l, opcode_15, version)
45
46# fmt: off
47# 1.6 Bytecodes not in 1.5
48nargs_op(l, "CALL_FUNCTION_VAR",    140, -1, 1)  # #args + (#kwargs << 8)
49nargs_op(l, "CALL_FUNCTION_KW",     141, -1, 1)  # #args + (#kwargs << 8)
50nargs_op(l, "CALL_FUNCTION_VAR_KW", 142, -1, 1)  # #args + (#kwargs << 8)
51
52update_pj2(globals(), l)
53
54opcode_arg_fmt = {"EXTENDED_ARG": format_extended_arg}
55
56opcode_arg_fmt = {
57    "EXTENDED_ARG":         format_extended_arg,
58    "CALL_FUNCTION":        format_CALL_FUNCTION_pos_name_encoded,
59    "CALL_FUNCTION_KW":     format_CALL_FUNCTION_pos_name_encoded,
60    "CALL_FUNCTION_VAR_KW": format_CALL_FUNCTION_pos_name_encoded,
61    "MAKE_FUNCTION":        format_MAKE_FUNCTION_default_argc,
62}
63
64opcode_extended_fmt = {
65    "LOAD_ATTR":     extended_format_ATTR,
66    "MAKE_FUNCTION": extended_format_MAKE_FUNCTION_older,
67    "RETURN_VALUE":  extended_format_RETURN_VALUE,
68    "STORE_ATTR":    extended_format_ATTR,
69}
70# fmt: on
71
72finalize_opcodes(l)
73