1# (C) Copyright 2017, 2020 by Rocky Bernstein
2"""
3CPython 3.1 bytecode opcodes
4
5This is a like Python 3.1's opcode.py with some classification
6of stack usage.
7"""
8
9from xdis.opcodes.base import (
10    def_op,
11    extended_format_ATTR,
12    extended_format_CALL_FUNCTION,
13    finalize_opcodes,
14    format_MAKE_FUNCTION_default_argc,
15    format_extended_arg,
16    init_opdata,
17    name_op,
18    rm_op,
19    update_pj3,
20)
21
22import xdis.opcodes.opcode_32 as opcode_32
23
24l = locals()
25
26version = 3.1
27python_implementation = "CPython"
28
29init_opdata(l, opcode_32, version)
30
31# These are in Python 3.2 but not in Python 3.1
32rm_op(l, "DUP_TOP_TWO", 5)
33rm_op(l, "DELETE_DEREF", 138)
34rm_op(l, "SETUP_WITH", 143)
35
36# These are in Python 3.1 but not Python 3.2
37name_op(l, "IMPORT_NAME", 108,  1, 1)  # Imports TOS and TOS1; module pushed
38def_op(l, "ROT_FOUR",       5,  4, 4)
39def_op(l, "DUP_TOPX",      99, -1, 2)  # number of items to duplicate
40
41# This op is in 3.2 but its opcode is a 144 instead
42def_op(l, "EXTENDED_ARG", 143)
43
44update_pj3(globals(), l)
45
46opcode_arg_fmt = {
47    "MAKE_FUNCTION": format_MAKE_FUNCTION_default_argc,
48    "EXTENDED_ARG": format_extended_arg,
49}
50
51opcode_extended_fmt = {
52    "LOAD_ATTR": extended_format_ATTR,
53    "CALL_FUNCTION": extended_format_CALL_FUNCTION,
54    "STORE_ATTR": extended_format_ATTR,
55}
56finalize_opcodes(l)
57