1# (C) Copyright 2017, 2020 by Rocky Bernstein
2"""
3CPython 2.4 bytecode opcodes
4
5This is a like Python 2.3's opcode.py with some additional classification
6of stack usage, and opererand formatting functions.
7"""
8
9import xdis.opcodes.opcode_2x as opcode_2x
10from xdis.opcodes.base import (
11    def_op,
12    extended_format_ATTR,
13    extended_format_CALL_FUNCTION,
14    extended_format_MAKE_FUNCTION_older,
15    extended_format_RAISE_VARARGS_older,
16    extended_format_RETURN_VALUE,
17    init_opdata,
18    finalize_opcodes,
19    format_CALL_FUNCTION_pos_name_encoded,
20    format_MAKE_FUNCTION_default_argc,
21    format_RAISE_VARARGS_older,
22    format_extended_arg,
23    update_pj2
24)
25
26version = 2.4
27python_implementation = "CPython"
28
29l = locals()
30init_opdata(l, opcode_2x, version)
31
32# Bytecodes added since 2.3
33#          OP NAME            OPCODE POP PUSH
34#--------------------------------------------
35def_op(l, 'NOP',                   9,  0,  0)
36def_op(l, 'LIST_APPEND',          18,  2,  0)  # Calls list.append(TOS[-i], TOS).
37                                               # Used to implement list comprehensions.
38def_op(l, 'YIELD_VALUE',          86,  1,  1)
39
40# FIXME remove (fix uncompyle6)
41update_pj2(globals(), l)
42
43finalize_opcodes(l)
44
45opcode_arg_fmt = {
46    "CALL_FUNCTION": format_CALL_FUNCTION_pos_name_encoded,
47    "CALL_FUNCTION_KW": format_CALL_FUNCTION_pos_name_encoded,
48    "CALL_FUNCTION_VAR_KW": format_CALL_FUNCTION_pos_name_encoded,
49    "EXTENDED_ARG": format_extended_arg,
50    "MAKE_FUNCTION": format_MAKE_FUNCTION_default_argc,
51    "RAISE_VARARGS": format_RAISE_VARARGS_older,
52}
53
54opcode_extended_fmt = {
55    "CALL_FUNCTION": extended_format_CALL_FUNCTION,
56    "LOAD_ATTR": extended_format_ATTR,
57    "MAKE_FUNCTION": extended_format_MAKE_FUNCTION_older,
58    "RAISE_VARARGS": extended_format_RAISE_VARARGS_older,
59    "RETURN_VALUE": extended_format_RETURN_VALUE,
60    "STORE_ATTR": extended_format_ATTR,
61}
62