Ejemplo n.º 1
0
# Below are opcode changes since Python 2.6
rm_op(l, "BUILD_MAP", 104)
rm_op(l, "LOAD_ATTR", 105)
rm_op(l, "COMPARE_OP", 106)
rm_op(l, "IMPORT_NAME", 107)
rm_op(l, "IMPORT_FROM", 108)
rm_op(l, "JUMP_IF_FALSE", 111)
rm_op(l, "EXTENDED_ARG", 143)
rm_op(l, "JUMP_IF_TRUE", 112)

def_op(l, "LIST_APPEND", 94, 2, 1)  # Calls list.append(TOS[-i], TOS).
# Used to implement list comprehensions.
def_op(l, "BUILD_SET", 104)  # Number of set items
def_op(l, "BUILD_MAP", 105)
name_op(l, "LOAD_ATTR", 106)
compare_op(l, "COMPARE_OP", 107)

name_op(l, "IMPORT_NAME", 108, 2, 1)  # Index in name list
name_op(l, "IMPORT_FROM", 109, 0, 1)

jabs_op(l, "JUMP_IF_FALSE_OR_POP", 111)  # Target byte offset from beginning of code
jabs_op(l, "JUMP_IF_TRUE_OR_POP", 112)  # ""
jabs_op(l, "POP_JUMP_IF_FALSE", 114)  # ""
jabs_op(l, "POP_JUMP_IF_TRUE", 115)  # ""
jrel_op(l, "SETUP_WITH", 143, 0, 2)

def_op(l, "EXTENDED_ARG", 145)
def_op(l, "SET_ADD", 146, 1, 0)  # Calls set.add(TOS1[-i], TOS).
# Used to implement set comprehensions.
def_op(l, "MAP_ADD", 147, 2, 1)  # Calls dict.setitem(TOS1[-i], TOS, TOS1)
Ejemplo n.º 2
0
def_op(l, "BREAK_LOOP",           80,  0,  0, fallthrough=False)

def_op(l, "LOAD_LOCALS",          82,  0,  1)
def_op(l, "RETURN_VALUE",         83,  1,  0, fallthrough=False)
def_op(l, "IMPORT_STAR",          84,  1,  0)
def_op(l, "EXEC_STMT",            85,  3,  0)
def_op(l, "YIELD_VALUE",          86,  1,  1)

def_op(l, "POP_BLOCK",            87,  0,  0)
def_op(l, "END_FINALLY",          88,  1,  0)
def_op(l, "BUILD_CLASS",          89,  2,  0)

HAVE_ARGUMENT = 90              # Opcodes from here have an argument:

store_op(l, "STORE_NAME",          90,  1,  0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_NAME",          91,  0,  0)  # ""
varargs_op(l, "UNPACK_SEQUENCE",   92, -1,  1)  # TOS is number of tuple items
jrel_op(l, "FOR_ITER",             93,  0,  1)  # TOS is read

store_op(l, "STORE_ATTR",          95,  2,  0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_ATTR",          96,  1,  0)  # ""
store_op(l, "STORE_GLOBAL",        97,  1,  0, is_type="name")  # ""
name_op(l, "DELETE_GLOBAL",        98,  0,  0)  # ""
nargs_op(l, "DUP_TOPX",            99, -1,  2)  # number of items to duplicate
const_op(l, "LOAD_CONST",         100,  0,  1)  # Operand is in const list
name_op(l, "LOAD_NAME",           101,  0,  1)  # Operand is in name list
varargs_op(l, "BUILD_TUPLE",      102, -1,  1)  # TOS is number of tuple items
varargs_op(l, "BUILD_LIST",       103, -1,  1)  # TOS is number of list items
varargs_op(l, "BUILD_MAP",        104,  0,  1)  # TOS is number of kwarg items. Always zero for now
name_op(l, "LOAD_ATTR",           105,  1,  1)  # Operand is in name list
compare_op(l, "COMPARE_OP",       106,  2,  1)  # Comparison operator
Ejemplo n.º 3
0
    varargs_op,
)

version = 2.6
version_tuple = (2, 6)
python_implementation = "PyPy"

l = locals()
init_opdata(l, opcode_26, version_tuple, is_pypy=True)

# FIXME: DRY common PYPY opcode additions

# fmt: off
# PyPy only
# ----------
name_op(l, 'LOOKUP_METHOD', 201, 1, 2)
nargs_op(l, 'CALL_METHOD', 202, -1, 1)
# fmt: on

l["hasnargs"].append(202)

# Used only in single-mode compilation list-comprehension generators
varargs_op(l, "BUILD_LIST_FROM_ARG", 203)

# Used only in assert statements
jrel_op(l, "JUMP_IF_NOT_DEBUG", 204, conditional=True)

# FIXME remove (fix uncompyle6)
update_pj2(globals(), l)

finalize_opcodes(l)
Ejemplo n.º 4
0
# Below are opcode changes since Python 2.6
rm_op(l, 'BUILD_MAP', 104)
rm_op(l, 'LOAD_ATTR', 105)
rm_op(l, 'COMPARE_OP', 106)
rm_op(l, 'IMPORT_NAME', 107)
rm_op(l, 'IMPORT_FROM', 108)
rm_op(l, 'JUMP_IF_FALSE', 111)
rm_op(l, 'EXTENDED_ARG', 143)
rm_op(l, 'JUMP_IF_TRUE', 112)

def_op(l, 'LIST_APPEND', 94, 2, 1)  # Calls list.append(TOS[-i], TOS).
# Used to implement list comprehensions.
def_op(l, 'BUILD_SET', 104)  # Number of set items
def_op(l, 'BUILD_MAP', 105)
name_op(l, 'LOAD_ATTR', 106)
compare_op(l, 'COMPARE_OP', 107)

name_op(l, 'IMPORT_NAME', 108, 2, 1)  # Index in name list
name_op(l, 'IMPORT_FROM', 109, 0, 1)

jabs_op(l, 'JUMP_IF_FALSE_OR_POP',
        111)  # Target byte offset from beginning of code
jabs_op(l, 'JUMP_IF_TRUE_OR_POP', 112)  # ""
jabs_op(l, 'POP_JUMP_IF_FALSE', 114)  # ""
jabs_op(l, 'POP_JUMP_IF_TRUE', 115)  # ""
jrel_op(l, 'SETUP_WITH', 143, 0, 2)

def_op(l, 'EXTENDED_ARG', 145)
def_op(l, 'SET_ADD', 146, 1, 0)  # Calls set.add(TOS1[-i], TOS).
# Used to implement set comprehensions.
def_op(l, "BREAK_LOOP", 80, 0, 0, fallthrough=False)

def_op(l, "LOAD_LOCALS", 82, 0, 1)
def_op(l, "RETURN_VALUE", 83, 1, 0, fallthrough=False)

def_op(l, "EXEC_STMT", 85, 3, 0)

def_op(l, "POP_BLOCK", 87, 0, 0)
def_op(l, "END_FINALLY", 88, 1, 0)
def_op(l, "BUILD_CLASS", 89, 3, 0)

# HAVE_ARGUMENT = 90               # Opcodes from here have an argument:

store_op(l, "STORE_NAME", 90, 1, 0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_NAME", 91, 0, 0)  # ""
varargs_op(l, "UNPACK_TUPLE", 92)  # Number of tuple items
def_op(l, "UNPACK_LIST", 93)  # Number of list items
store_op(l, "STORE_ATTR", 95, 2, 0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_ATTR", 96, 1, 0)  # ""
store_op(l, "STORE_GLOBAL", 97, 1, 0, is_type="name")  # ""
name_op(l, "DELETE_GLOBAL", 98, 0, 0)  # ""

const_op(l, "LOAD_CONST", 100, 0, 1)  # Operand is in const list
name_op(l, "LOAD_NAME", 101, 0, 1)  # Operand is in name list
varargs_op(l, "BUILD_TUPLE", 102, -1, 1)  # Number of tuple items
varargs_op(l, "BUILD_LIST", 103, -1, 1)  # Number of list items
varargs_op(l, "BUILD_MAP", 104, -1, 1)  # Always zero for now
name_op(l, "LOAD_ATTR", 105, 1, 1)  # Operand is in name list
compare_op(l, "COMPARE_OP", 106, 2, 1)  # Comparison operator
Ejemplo n.º 6
0
# These are removed since 3.6...
# and STORE_ANNOTATION introduced in 3.6!
rm_op(l, "STORE_ANNOTATION", 127)

# These have a changed stack effect since 3.6
#          OP NAME            OPCODE POP PUSH
#---------------------------------------------------------------
def_op(l, "WITH_CLEANUP_START",   81,  0,  2)
def_op(l, "WITH_CLEANUP_FINISH",  82,  3,  0)
def_op(l, "END_FINALLY",          88,  6,  0)
def_op(l, "POP_EXCEPT",           89,  3,  0) # Pops last 3 values
jrel_op(l, "SETUP_WITH",         143,  0,  6)
jrel_op(l, "SETUP_ASYNC_WITH",   154,  0,  5)

# These are new since Python 3.7
name_op(l, "LOAD_METHOD", 160, 0, 1)
nargs_op(l, "CALL_METHOD", 161, -2, 1)

format_MAKE_FUNCTION_flags = opcode_36.format_MAKE_FUNCTION_flags
format_value_flags = opcode_36.format_value_flags

def extended_format_RAISE_VARARGS(opc, instructions):
    raise_inst = instructions[0]
    assert raise_inst.opname == "RAISE_VARARGS"
    argc = raise_inst.argval
    if argc == 0:
        return "reraise"
    elif argc == 1:
        instance_arg = resolved_attrs(instructions[1:])
        if instance_arg:
            return "instance_arg"
Ejemplo n.º 7
0
# fmt: off
rm_op(l, "BUILD_TUPLE_UNPACK_WITH_CALL", 158)
rm_op(l, "LOAD_METHOD",                  160)

nargs_op(l, "CALL_FUNCTION_KW",          141, 9, 1)  # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION_EX",          142, -2, 1)

# The following were removed from 3.7 but still in Pypy 3.7

store_op(l,   'STORE_ANNOTATION',        127, 1, 0, is_type="name")

# PyPy only
# ----------

name_op(l, "LOOKUP_METHOD",              201, 1, 2)
l["hasvargs"].append(202)
nargs_op(l, "CALL_METHOD_KW",            204, -1, 1)


# Used only in single-mode compilation list-comprehension generators
varargs_op(l, "BUILD_LIST_FROM_ARG",     203)

# PyPy 3.6.1 (and 2.7.13) start to introduce LOAD_REVDB_VAR
import sys

if sys.version_info[:3] >= (3, 6, 1):
    def_op(l, "LOAD_REVDB_VAR",          205)

# FIXME remove (fix uncompyle6)
update_pj3(globals(), l)
Ejemplo n.º 8
0
def_op(l, 'INPLACE_OR',           79,  2,  1)
def_op(l, 'BREAK_LOOP',           80,  0,  0)

def_op(l, 'LOAD_LOCALS',          82,  0,  1)
def_op(l, 'RETURN_VALUE',         83,  1,  0, fallthrough=False)
def_op(l, 'IMPORT_STAR',          84,  1,  0)
def_op(l, 'EXEC_STMT',            85,  3,  0)
def_op(l, 'YIELD_VALUE',          86,  1,  1)

def_op(l, 'POP_BLOCK',            87,  0,  0)
def_op(l, 'END_FINALLY',          88,  1,  0)
def_op(l, 'BUILD_CLASS',          89,  3,  0)

HAVE_ARGUMENT = 90              # Opcodes from here have an argument:

name_op(l, 'STORE_NAME',           90,  1,  0)  # Operand is in name list
name_op(l, 'DELETE_NAME',          91,  0,  0)  # ""
varargs_op(l, 'UNPACK_SEQUENCE',   92,  9,  1)  # TOS is number of tuple items
jrel_op(l, 'FOR_ITER',             93,  9,  1)  # TOS is read

name_op(l, 'STORE_ATTR',           95,  2,  0)  # Operand is in name list
name_op(l, 'DELETE_ATTR',          96,  1,  0)  # ""
name_op(l, 'STORE_GLOBAL',         97,  1,  0)  # ""
name_op(l, 'DELETE_GLOBAL',        98,  0,  0)  # ""
def_op(l, 'DUP_TOPX',              99,  1, -1)  # number of items to duplicate
const_op(l, 'LOAD_CONST',         100,  0,  1)  # Operand is in const list
name_op(l, 'LOAD_NAME',           101,  0,  1)  # Operand is in name list
varargs_op(l, 'BUILD_TUPLE',      102,  9,  1)  # TOS is number of tuple items
varargs_op(l, 'BUILD_LIST',       103,  9,  1)  # TOS is number of list items
varargs_op(l, 'BUILD_MAP',        104,  0,  1)  # TOS is number of kwark items. Always zero for now
name_op(l, 'LOAD_ATTR',           105,  1,  1)  # Operand is in name list
Ejemplo n.º 9
0
def_op(l, 'INPLACE_OR', 79, 2, 1)
def_op(l, 'BREAK_LOOP', 80, 0, 0)

def_op(l, 'LOAD_LOCALS', 82, 0, 1)
def_op(l, 'RETURN_VALUE', 83, 1, 0)
def_op(l, 'IMPORT_STAR', 84, 1, 0)
def_op(l, 'EXEC_STMT', 85, 3, 0)
def_op(l, 'YIELD_VALUE', 86, 1, 1)

def_op(l, 'POP_BLOCK', 87, 0, 0)
def_op(l, 'END_FINALLY', 88, 1, 0)
def_op(l, 'BUILD_CLASS', 89, 3, 0)

HAVE_ARGUMENT = 90  # Opcodes from here have an argument:

name_op(l, 'STORE_NAME', 90, 1, 0)  # Operand is in name list
name_op(l, 'DELETE_NAME', 91, 0, 0)  # ""
varargs_op(l, 'UNPACK_SEQUENCE', 92, -1, 1)  # Number of tuple items
jrel_op(l, 'FOR_ITER', 93, -1, -1)

name_op(l, 'STORE_ATTR', 95, 2, 0)  # Operand is in name list
name_op(l, 'DELETE_ATTR', 96, 1, 0)  # ""
name_op(l, 'STORE_GLOBAL', 97, 1, 0)  # ""
name_op(l, 'DELETE_GLOBAL', 98, 0, 0)  # ""
def_op(l, 'DUP_TOPX', 99, 1, -1)  # number of items to duplicate
const_op(l, 'LOAD_CONST', 100, 0, 1)  # Operand is in const list
name_op(l, 'LOAD_NAME', 101, 0, 1)  # Operand is in name list
varargs_op(l, 'BUILD_TUPLE', 102, -1, 1)  # Number of tuple items
varargs_op(l, 'BUILD_LIST', 103, -1, 1)  # Number of list items
varargs_op(l, 'BUILD_MAP', 104, -1, 1)  # Always zero for now
name_op(l, 'LOAD_ATTR', 105, 1, 1)  # Operand is in name list
Ejemplo n.º 10
0
def_op(l, 'WITH_CLEANUP', 81, 1,
       0)  # Cleans up the stack when a with statement
# block exits.  Handle stack special

def_op(l, 'RETURN_VALUE', 83, 1, 0, fallthrough=False)
def_op(l, 'IMPORT_STAR', 84, 1, 0)

def_op(l, 'YIELD_VALUE', 86, 1, 1)
def_op(l, 'POP_BLOCK', 87, 0, 0)
def_op(l, 'END_FINALLY', 88, 1, 0)
def_op(l, 'POP_EXCEPT', 89, 1, -1)

HAVE_ARGUMENT = 90  # Opcodes from here have an argument:

store_op(l, 'STORE_NAME', 90, 1, 0, is_type="name")  # Operand is in name list
name_op(l, 'DELETE_NAME', 91, 0, 0)  # ""
varargs_op(l, 'UNPACK_SEQUENCE', 92, 9, 1)  # TOS is number of tuple items
jrel_op(l, 'FOR_ITER', 93, 9, 1)

def_op(l, 'UNPACK_EX', 94, 9,
       1)  # assignment with a starred target; TOS is #entries
# argument has a count
store_op(l, 'STORE_ATTR', 95, 2, 0, is_type="name")  # Operand is in name list
name_op(l, 'DELETE_ATTR', 96, 1, 0)  # ""
store_op(l, 'STORE_GLOBAL', 97, 1, 0, is_type="name")  # ""
name_op(l, 'DELETE_GLOBAL', 98, 0, 0)  # ""

# Python 2's DUP_TOPX is gone starting in Python 3.2

const_op(l, 'LOAD_CONST', 100, 0, 1)  # Operand is in const list
name_op(l, 'LOAD_NAME', 101, 0, 1)  # Operand is in name list
Ejemplo n.º 11
0
def_op(l, 'WITH_CLEANUP', 81, 1,
       0)  # Cleans up the stack when a with statement
# block exits.  Handle stack special

def_op(l, 'RETURN_VALUE', 83, 1, 0, fallthrough=False)
def_op(l, 'IMPORT_STAR', 84, 1, 0)

def_op(l, 'YIELD_VALUE', 86, 1, 1)
def_op(l, 'POP_BLOCK', 87, 0, 0)
def_op(l, 'END_FINALLY', 88, 1, 0)
def_op(l, 'POP_EXCEPT', 89, 0, 0)

HAVE_ARGUMENT = 90  # Opcodes from here have an argument:

store_op(l, 'STORE_NAME', 90, 1, 0, is_type="name")  # Operand is in name list
name_op(l, 'DELETE_NAME', 91, 0, 0)  # ""
varargs_op(l, 'UNPACK_SEQUENCE', 92, 0, -1)  # unpacks TOS, arg is the count
jrel_op(l, 'FOR_ITER', 93, 0, 1)

varargs_op(l, 'UNPACK_EX', 94, 0,
           0)  # assignment with a starred target; arg is count
store_op(l, 'STORE_ATTR', 95, 2, 0, is_type="name")  # Operand is in name list
name_op(l, 'DELETE_ATTR', 96, 1, 0)  # ""
store_op(l, 'STORE_GLOBAL', 97, 1, 0, is_type="name")  # ""
name_op(l, 'DELETE_GLOBAL', 98, 0, 0)  # ""

# Python 2's DUP_TOPX is gone starting in Python 3.2

const_op(l, 'LOAD_CONST', 100, 0, 1)  # Operand is in const list
name_op(l, 'LOAD_NAME', 101, 0, 1)  # Operand is in name list
varargs_op(l, 'BUILD_TUPLE', 102, -1, 1)  # TOS is count of tuple items
Ejemplo n.º 12
0
)

version = 1.4
python_implementation = "CPython"

l = locals()
init_opdata(l, opcode_15, version)

# 1.4 Bytecodes not in 1.5
def_op(l, "UNARY_CALL", 14)
def_op(l, "BINARY_CALL", 26)
def_op(l, "RAISE_EXCEPTION", 81)
def_op(l, "BUILD_FUNCTION", 86)
varargs_op(l, "UNPACK_ARG", 94)  # Number of arguments expected
varargs_op(l, "UNPACK_VARARG", 99)  # Minimal number of arguments
name_op(l, "LOAD_LOCAL", 115)
varargs_op(l, "SET_FUNC_ARGS", 117)  # Argcount
varargs_op(l, "RESERVE_FAST", 123)  # Number of local variables

update_pj2(globals(), l)

opcode_arg_fmt = {"EXTENDED_ARG": format_extended_arg}

finalize_opcodes(l)


def findlinestarts(co, dup_lines=False):
    code = co.co_code
    n = len(code)
    offset = 0
    while offset < n:
Ejemplo n.º 13
0
# Below are opcode changes since Python 2.6
rm_op(l, 'BUILD_MAP',     104)
rm_op(l, 'LOAD_ATTR',     105)
rm_op(l, 'COMPARE_OP',    106)
rm_op(l, 'IMPORT_NAME',   107)
rm_op(l, 'IMPORT_FROM',   108)
rm_op(l, 'JUMP_IF_FALSE', 111)
rm_op(l, 'EXTENDED_ARG',  143)
rm_op(l, 'JUMP_IF_TRUE',  112)

def_op(l, 'LIST_APPEND',            94, 2, 1) # Calls list.append(TOS[-i], TOS).
                                              # Used to implement list comprehensions.
def_op(l, 'BUILD_SET',             104)       # Number of set items
def_op(l, 'BUILD_MAP',             105)
name_op(l, 'LOAD_ATTR',            106)
compare_op(l, 'COMPARE_OP',        107)

name_op(l, 'IMPORT_NAME',          108,  2,  1)  # Index in name list
name_op(l, 'IMPORT_FROM',          109,  0,  1)

jabs_op(l, 'JUMP_IF_FALSE_OR_POP', 111) # Target byte offset from beginning of code
jabs_op(l, 'JUMP_IF_TRUE_OR_POP',  112)  # ""
jabs_op(l, 'POP_JUMP_IF_FALSE',    114)  # ""
jabs_op(l, 'POP_JUMP_IF_TRUE',     115)  # ""
jrel_op(l, 'SETUP_WITH',           143,  0,  2)

def_op(l, 'EXTENDED_ARG',          145)
def_op(l, 'SET_ADD',               146,  1,  0)  # Calls set.add(TOS1[-i], TOS).
                                                 # Used to implement set comprehensions.
def_op(l, 'MAP_ADD',               147,  2,  1)  # Calls dict.setitem(TOS1[-i], TOS, TOS1)
Ejemplo n.º 14
0
# of keyword arguments if bit 0 of *oparg* is 1.


# MAKE_FUNCTION oparg

# This is a different opcode from before.

# The tuple of default values for positional-or-keyword parameters,
# the dict of default values for keyword-only parameters, the dict of
# annotations and the closure are pushed on the stack if corresponding
# bit (0-3) is set. They are followed by the code object and the
# qualified name of the function.


# These are new since Python 3.6
name_op(l,  'STORE_ANNOTATION', 127) # Index in name list
jrel_op(l,  'SETUP_ASYNC_WITH', 154)
def_op(l,   'FORMAT_VALUE',     155)
varargs_op(l, 'BUILD_CONST_KEY_MAP', 156, -1, 1) # TOS is count of kwargs
nargs_op(l, 'CALL_FUNCTION_EX', 142, -1, 1)
def_op(l,   'SETUP_ANNOTATIONS', 85)
def_op(l,   'BUILD_STRING',     157)
def_op(l,   'BUILD_TUPLE_UNPACK_WITH_CALL', 158)

MAKE_FUNCTION_FLAGS = tuple("default keyword-only annotation closure".split())

def format_MAKE_FUNCTION_arg(flags):
    pattr = ''
    for flag in MAKE_FUNCTION_FLAGS:
        bit = flags & 1
        if bit:
Ejemplo n.º 15
0
# MAKE_FUNCTION oparg

# This is a different opcode from before.

# The tuple of default values for positional-or-keyword parameters,
# the dict of default values for keyword-only parameters, the dict of
# annotations and the closure are pushed on the stack if corresponding
# bit (0-3) is set. They are followed by the code object and the
# qualified name of the function.

# These are removed since 3.6...
# and STORE_ANNOTATION introduced in 3.6!
rm_op(l, 'STORE_ANNOTATION', 127)

# These are new since Python 3.7
name_op(l, 'LOAD_METHOD', 160)
nargs_op(l, 'CALL_METHOD', 161)

MAKE_FUNCTION_FLAGS = tuple("default keyword-only annotation closure".split())


def format_MAKE_FUNCTION_arg(flags):
    pattr = ''
    for flag in MAKE_FUNCTION_FLAGS:
        bit = flags & 1
        if bit:
            if pattr:
                pattr += ", " + flag
            else:
                pattr = flag
                pass
Ejemplo n.º 16
0
    # Although these aren't used here, they are exported
    update_pj2)

version = 1.4

l = locals()
init_opdata(l, opcode_15, version)

# 1.4 Bytecodes not in 1.5
def_op(l, 'UNARY_CALL', 14)
def_op(l, 'BINARY_CALL', 26)
def_op(l, 'RAISE_EXCEPTION', 81)
def_op(l, 'BUILD_FUNCTION', 86)
varargs_op(l, 'UNPACK_ARG', 94)  # Number of arguments expected
varargs_op(l, 'UNPACK_VARARG', 99)  # Minimal number of arguments
name_op(l, 'LOAD_LOCAL', 115)
varargs_op(l, 'SET_FUNC_ARGS', 117)  # Argcount
varargs_op(l, 'RESERVE_FAST', 123)  # Number of local variables

update_pj2(globals(), l)

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)


def findlinestarts(co, dup_lines=False):
    code = co.co_code
    n = len(code)
Ejemplo n.º 17
0
# These are removed since 3.6...
# and STORE_ANNOTATION introduced in 3.6!
rm_op(l, 'STORE_ANNOTATION', 127)

# These have a changed stack effect since 3.6
#          OP NAME            OPCODE POP PUSH
#---------------------------------------------------------------
def_op(l, 'WITH_CLEANUP_START', 81, 0, 2)
def_op(l, 'WITH_CLEANUP_FINISH', 82, 3, 0)
def_op(l, 'END_FINALLY', 88, 6, 0)
def_op(l, 'POP_EXCEPT', 89, 3, 0)  # Pops last 3 values
jrel_op(l, 'SETUP_WITH', 143, 0, 6)
jrel_op(l, 'SETUP_ASYNC_WITH', 154, 0, 5)

# These are new since Python 3.7
name_op(l, 'LOAD_METHOD', 160, 0, 1)
nargs_op(l, 'CALL_METHOD', 161, -2, 1)

format_MAKE_FUNCTION_arg = opcode_36.format_MAKE_FUNCTION_arg
format_value_flags = opcode_36.format_value_flags

opcode_arg_fmt = {
    'CALL_FUNCTION': opcode_36.format_CALL_FUNCTION,
    'CALL_FUNCTION_KW': opcode_36.format_CALL_FUNCTION_KW,
    'CALL_FUNCTION_EX': opcode_36.format_CALL_FUNCTION_EX,
    'CALL_METHOD': opcode_36.format_CALL_FUNCTION,
    'MAKE_FUNCTION': format_MAKE_FUNCTION_arg,
    'FORMAT_VALUE': format_value_flags,
    'EXTENDED_ARG': opcode_36.format_extended_arg36
}
Ejemplo n.º 18
0
import xdis.opcodes.opcode_32 as opcode_32

l = locals()

version = 3.1
python_implementation = "CPython"

init_opdata(l, opcode_32, version)

# These are in Python 3.2 but not in Python 3.1
rm_op(l, "DUP_TOP_TWO", 5)
rm_op(l, "DELETE_DEREF", 138)
rm_op(l, "SETUP_WITH", 143)

# These are in Python 3.1 but not Python 3.2
name_op(l, "IMPORT_NAME", 108,  1, 1)  # Imports TOS and TOS1; module pushed
def_op(l, "ROT_FOUR",       5,  4, 4)
def_op(l, "DUP_TOPX",      99, -1, 2)  # number of items to duplicate

# This op is in 3.2 but its opcode is a 144 instead
def_op(l, "EXTENDED_ARG", 143)

update_pj3(globals(), l)

opcode_arg_fmt = {
    "MAKE_FUNCTION": format_MAKE_FUNCTION_default_argc,
    "EXTENDED_ARG": format_extended_arg,
}

opcode_extended_fmt = {
    "LOAD_ATTR": extended_format_ATTR,
Ejemplo n.º 19
0
# CALL_FUNCTION_EX** takes 2 to 3 arguments on the stack: the
# function, the tuple of positional arguments, and optionally the dict
# of keyword arguments if bit 0 of *oparg* is 1.

# MAKE_FUNCTION oparg

# This is a different opcode from before.

# The tuple of default values for positional-or-keyword parameters,
# the dict of default values for keyword-only parameters, the dict of
# annotations and the closure are pushed on the stack if corresponding
# bit (0-3) is set. They are followed by the code object and the
# qualified name of the function.

# These are new since Python 3.6
name_op(l, 'STORE_ANNOTATION', 127)  # Index in name list
jrel_op(l, 'SETUP_ASYNC_WITH', 154)
def_op(l, 'FORMAT_VALUE', 155)
varargs_op(l, 'BUILD_CONST_KEY_MAP', 156, -1, 1)  # TOS is count of kwargs
nargs_op(l, 'CALL_FUNCTION_EX', 142, -1, 1)
def_op(l, 'SETUP_ANNOTATIONS', 85)
def_op(l, 'BUILD_STRING', 157)
varargs_op(l, 'BUILD_TUPLE_UNPACK_WITH_CALL', 158)

MAKE_FUNCTION_FLAGS = tuple("default keyword-only annotation closure".split())


def format_MAKE_FUNCTION_arg(flags):
    pattr = ''
    for flag in MAKE_FUNCTION_FLAGS:
        bit = flags & 1
Ejemplo n.º 20
0
python_implementation = "CPython"

version = 2.6
version_tuple = (2, 6)

l = locals()
init_opdata(l, opcode_25, version_tuple)

# Below are opcode changes since Python 2.5

# fmt: off
#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
store_op(l, "STORE_MAP",          54,  3,  1)
rm_op(l,    "IMPORT_NAME",       107)
name_op(l,  "IMPORT_NAME",       107,  2,  1)  # Imports namei; TOS and TOS1 provide fromlist and level. Module pushed.
# fmt: on

# FIXME remove (fix uncompyle6)
update_pj2(globals(), l)

opcode_arg_fmt = {
    "CALL_FUNCTION": format_CALL_FUNCTION_pos_name_encoded,
    "CALL_FUNCTION_KW": format_CALL_FUNCTION_pos_name_encoded,
    "CALL_FUNCTION_VAR_KW": format_CALL_FUNCTION_pos_name_encoded,
    "EXTENDED_ARG": format_extended_arg,
    "MAKE_FUNCTION": format_MAKE_FUNCTION_default_argc,
    "RAISE_VARARGS": format_RAISE_VARARGS_older,
}

opcode_extended_fmt = {
Ejemplo n.º 21
0
    varargs_op, update_pj3)

version = 3.5

import xdis.opcodes.opcode_35 as opcode_35

l = locals()
init_opdata(l, opcode_35, version, is_pypy=True)

## FIXME: DRY common PYPY opcode additions

# PyPy only
# ----------
def_op(l, 'FORMAT_VALUE',   155)
def_op(l, 'BUILD_STRING',   157)
name_op(l, 'LOOKUP_METHOD',  201,  1, 2)
nargs_op(l, 'CALL_METHOD', 202, -1, 1)
l['hasvargs'].append(202)

# Used only in single-mode compilation list-comprehension generators
varargs_op(l, 'BUILD_LIST_FROM_ARG', 203)

# Used only in assert statements
jrel_op(l, 'JUMP_IF_NOT_DEBUG',      204, conditional=True)

# There are no opcodes to remove or change.
# If there were, they'd be listed below.

# FIXME remove (fix uncompyle6)
update_pj3(globals(), l)
Ejemplo n.º 22
0
    update_pj2
    )

version = 1.4

l = locals()
init_opdata(l, opcode_15, version)

# 1.4 Bytecodes not in 1.5
def_op(l, 'UNARY_CALL',         14)
def_op(l, 'BINARY_CALL',        26)
def_op(l, 'RAISE_EXCEPTION',    81)
def_op(l, 'BUILD_FUNCTION',     86)
varargs_op(l, 'UNPACK_ARG',     94)   # Number of arguments expected
varargs_op(l, 'UNPACK_VARARG',  99)  # Minimal number of arguments
name_op(l, 'LOAD_LOCAL',       115)
varargs_op(l, 'SET_FUNC_ARGS', 117)  # Argcount
varargs_op(l, 'RESERVE_FAST',  123)  # Number of local variables

update_pj2(globals(), l)

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)

def findlinestarts(co, dup_lines=False):
    code = co.co_code
    n = len(code)
    offset = 0