1# (C) Copyright 2017, 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 2.0 bytecode opcodes
18
19This is similar to (but better than) the opcode portion in Python 2.0's dis.py library.
20"""
21
22import xdis.opcodes.opcode_21 as opcode_21
23from xdis.opcodes.base import (
24    extended_format_ATTR,
25    extended_format_MAKE_FUNCTION_older,
26    extended_format_RETURN_VALUE,
27    finalize_opcodes,
28    format_CALL_FUNCTION_pos_name_encoded,
29    format_MAKE_FUNCTION_default_argc,
30    format_extended_arg,
31    init_opdata,
32    rm_op,
33    update_pj2,
34)
35
36version = 2.0
37python_implementation = "CPython"
38
39l = locals()
40init_opdata(l, opcode_21, version)
41
42# fmt: off
43# 2.1 Bytecodes not in 2.0
44rm_op(l, "CONTINUE_LOOP", 119)
45rm_op(l, "MAKE_CLOSURE",  134)
46rm_op(l, "LOAD_CLOSURE",  135)
47rm_op(l, "LOAD_DEREF",    136)
48rm_op(l, "STORE_DEREF",   137)
49
50update_pj2(globals(), l)
51
52finalize_opcodes(l)
53
54opcode_arg_fmt = {
55    "CALL_FUNCTION":        format_CALL_FUNCTION_pos_name_encoded,
56    "CALL_FUNCTION_KW":     format_CALL_FUNCTION_pos_name_encoded,
57    "CALL_FUNCTION_VAR_KW": format_CALL_FUNCTION_pos_name_encoded,
58    "EXTENDED_ARG":         format_extended_arg,
59    "MAKE_FUNCTION":        format_MAKE_FUNCTION_default_argc,
60}
61
62opcode_extended_fmt = {
63    "LOAD_ATTR": extended_format_ATTR,
64    "MAKE_FUNCTION":        extended_format_MAKE_FUNCTION_older,
65    "RETURN_VALUE":         extended_format_RETURN_VALUE,
66    "STORE_ATTR":           extended_format_ATTR,
67}
68# fmt: on
69