Exemple #1
0
# 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 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 = {
    "BUILD_MAP_UNPACK_WITH_CALL": opcode_36.format_BUILD_MAP_UNPACK_WITH_CALL,
from xdis.opcodes.opcode_3x import format_MAKE_FUNCTION_arg
import xdis.opcodes.opcode_36 as opcode_36

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

## FIXME: DRY common PYPY opcode additions

# Opcodes removed from 3.6.

rm_op(l, "CALL_FUNCTION_EX", 142)
rm_op(l, "BUILD_TUPLE_UNPACK_WITH_CALL", 158)

# The following were removed from 3.6 but still in Pypy 3.6
def_op(l, "MAKE_CLOSURE", 134, 9, 1)  # TOS is number of items to pop
nargs_op(l, "CALL_FUNCTION_VAR", 140, 9, 1)  # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION_KW", 141, 9, 1)  # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION_VAR_KW", 142, 9, 1)  # #args + (#kwargs << 8)

# 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)
Exemple #3
0
init_opdata(l, opcode_26, version)

# 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)

# These have changed since 2.6 in stack effects.
#          OP NAME            OPCODE   POP PUSH
#-----------------------------------------------
def_op(l, "END_FINALLY", 88, 3, 0)
jrel_op(l, "SETUP_EXCEPT", 121, 0, 0, conditional=True)  # ""
jrel_op(l, "SETUP_FINALLY", 122, 0, 0, conditional=True)  # ""

def_op(l, "LIST_APPEND", 94, 2, 1)  # Calls list.append(TOS[-i], TOS).

# Used to implement list comprehensions.
varargs_op(l, 'BUILD_SET', 104, -1, 1)  # TOS is count of set items
def_op(l, "BUILD_MAP", 105, 0, 1)  # count is in argument
name_op(l, "LOAD_ATTR", 106, 1, 1)  # Operand is in name list
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",
Exemple #4
0
# These are in Python 3.x but not in Python 3.0

rm_op(l, 'JUMP_IF_FALSE_OR_POP', 111)
rm_op(l, 'JUMP_IF_TRUE_OR_POP',  112)
rm_op(l, 'POP_JUMP_IF_FALSE',    114)
rm_op(l, 'POP_JUMP_IF_TRUE',     115)
rm_op(l, 'LIST_APPEND',          145)
rm_op(l, 'MAP_ADD',              147)

# These are are in 3.0 but are not in 3.1 or they have
# different opcode numbers. Note: As a result of opcode value
# changes, these have to be applied *after* removing ops (with
# the same name).

def_op(l, 'SET_ADD',        17,  1, 0)
def_op(l, 'LIST_APPEND',    18,  2, 1)

jrel_op(l, 'JUMP_IF_FALSE', 111, 1, 1)
jrel_op(l, 'JUMP_IF_TRUE',  112, 1, 1)

# This op is in 3.x but its opcode is a 144 instead
def_op(l, 'EXTENDED_ARG',  143)

update_pj2(globals(), l)

opcode_arg_fmt = {
    'MAKE_FUNCTION': format_MAKE_FUNCTION_arg,
    'EXTENDED_ARG': format_extended_arg,
}
Exemple #5
0
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""
CPython 2.6 bytecode opcodes

This is a like Python 2.6's opcode.py with some classification
of stack usage.
"""

from xdis.opcodes.base import (
    def_op, finalize_opcodes, format_extended_arg,
    init_opdata, update_pj2)
import xdis.opcodes.opcode_25 as opcode_25

version = 2.6

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

# Below are opcode changes since Python 2.5
def_op(l, 'STORE_MAP', 54, 3, 1)

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

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Exemple #6
0
from xdis.opcodes.base import (def_op, finalize_opcodes, init_opdata, jrel_op,
                               name_op, rm_op, varargs_op, update_pj3,
                               dump_opcodes)

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)
varargs_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)
Exemple #7
0
version = 3.6

import xdis.opcodes.opcode_36 as opcode_36

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

## FIXME: DRY common PYPY opcode additions

# Opcodes removed from 3.6.

rm_op(l, 'CALL_FUNCTION_EX',    142)
rm_op(l, 'BUILD_TUPLE_UNPACK_WITH_CALL', 158)

# The following were removed from 3.6 but still in Pypy 3.6
def_op(l, 'MAKE_CLOSURE',   134,  9,  1) # TOS is number of items to pop
nargs_op(l, 'CALL_FUNCTION_VAR',   140,  9,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_KW',    141,  9,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_VAR_KW',142,  9,  1)   # #args + (#kwargs << 8)

# 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
Exemple #8
0
    format_extended_arg,
    init_opdata,
    rm_op,
    # Although these aren't used here, they are exported
    update_pj2,
)

version = 1.3
python_implementation = "CPython"

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

# 1.3 - 1.4 bytecodes differences
rm_op(l, "BINARY_POWER", 19)
def_op(l, "LOAD_GLOBALS", 84)

update_pj2(globals(), l)

opcode_arg_fmt = {
    "EXTENDED_ARG": format_extended_arg,
    "RAISE_VARARGS": format_RAISE_VARARGS_older,
}

finalize_opcodes(l)

opcode_extended_fmt = {
    "RAISE_VARARGS": extended_format_RAISE_VARARGS_older,
    "RETURN_VALUE": extended_format_RETURN_VALUE,
}
Exemple #9
0
# These are in Python 3.x but not in Python 3.0

rm_op(l, 'JUMP_IF_FALSE_OR_POP', 111)
rm_op(l, 'JUMP_IF_TRUE_OR_POP', 112)
rm_op(l, 'POP_JUMP_IF_FALSE', 114)
rm_op(l, 'POP_JUMP_IF_TRUE', 115)
rm_op(l, 'LIST_APPEND', 145)
rm_op(l, 'MAP_ADD', 147)

# These are are in 3.0 but are not in 3.1 or they have
# different opcode numbers. Note: As a result of opcode value
# changes, these have to be applied *after* removing ops (with
# the same name).

def_op(l, 'SET_ADD', 17, 1, 0)
def_op(l, 'LIST_APPEND', 18, 2, 1)

jrel_op(l, 'JUMP_IF_FALSE', 111, 1, 1)
jrel_op(l, 'JUMP_IF_TRUE', 112, 1, 1)

# Yes, pj2 not pj3 - Python 3.0 is more like 2.7 here with its
# JUMP_IF rather than POP_JUMP_IF.
update_pj2(globals(), l)

opcode_arg_fmt = {
    'MAKE_FUNCTION': format_MAKE_FUNCTION_arg,
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Exemple #10
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:
            if pattr:
Exemple #11
0
# oppush[op] => number of stack entries pushed
oppush = [0] * 256

# oppop[op] => number of stack entries popped
oppop = [0] * 256

for op in range(256):
    opname[op] = '<%r>' % (op, )
del op

# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'STOP_CODE', 0, 0, 0)
def_op(l, 'POP_TOP', 1, 1, 0)
def_op(l, 'ROT_TWO', 2, 2, 2)
def_op(l, 'ROT_THREE', 3, 3, 3)
def_op(l, 'DUP_TOP', 4, 0, 1)

# Python 3.2+
def_op(l, 'DUP_TOP_TWO', 5, 0, 2)

def_op(l, 'NOP', 9)
def_op(l, 'UNARY_POSITIVE', 10, 1, 1)
def_op(l, 'UNARY_NEGATIVE', 11, 1, 1)
def_op(l, 'UNARY_NOT', 12, 1, 1)

def_op(l, 'UNARY_INVERT', 15, 1, 1)
Exemple #12
0
    rm_op,
    update_pj3,
)

import xdis.opcodes.opcode_3x as opcode_3x

version = 3.3
python_implementation = "CPython"

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

# Below are opcode changes since Python 3.2

rm_op(l, "STOP_CODE", 0)
def_op(l, "YIELD_FROM", 72, 1, 0)

update_pj3(globals(), l)

finalize_opcodes(l)


def format_MAKE_FUNCTION_default_pos_arg(argc):
    name_default, pos_args, = divmod(argc, 256)
    return ("%d positional, %d name and default" % (pos_args, name_default))


def extended_format_ATTR(opc, instructions):
    if instructions[1].opname in ("LOAD_CONST", "LOAD_GLOBAL", "LOAD_ATTR",
                                  "LOAD_NAME"):
        return "%s.%s " % (instructions[1].argrepr, instructions[0].argrepr)
Exemple #13
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
store_op(l, 'STORE_ANNOTATION', 127, is_type="name")  # 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
        if bit:
            if pattr:
Exemple #14
0
import xdis.opcodes.opcode_15 as opcode_15
from xdis.opcodes.base import (
    init_opdata,
    def_op, name_op, rm_op, varargs_op,
    finalize_opcodes, format_extended_arg,
    # 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,
}
Exemple #15
0
# oppush[op] => number of stack entries pushed
oppush = [0] * 256

# oppop[op] => number of stack entries popped
oppop  = [0] * 256

opmap = {}
opname = [''] * 256
for op in range(256): opname[op] = '<%r>' % (op,)
del op

# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

def_op(l, 'STOP_CODE', 0)
def_op(l, 'POP_TOP', 1)
def_op(l, 'ROT_TWO', 2)
def_op(l, 'ROT_THREE', 3)
def_op(l, 'DUP_TOP', 4)

def_op(l, 'UNARY_POSITIVE',  10, 1, 1)
def_op(l, 'UNARY_NEGATIVE',  11, 1, 1)
def_op(l, 'UNARY_NOT',       12, 1, 1)
def_op(l, 'UNARY_CONVERT',   13, 1, 1)

def_op(l, 'UNARY_INVERT',    15, 1, 1)

def_op(l, 'BINARY_POWER',    19, 1, 1)

def_op(l, 'BINARY_MULTIPLY', 20, 2, 1)
version = 2.7

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

# 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)
Exemple #17
0
# 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
#          OP NAME                OPCODE POP PUSH
#---------------------------------------------------
store_op(l,   'STORE_ANNOTATION', 127, 1, 0, is_type="name") # Stores TOS index in name list;
jrel_op(l,    'SETUP_ASYNC_WITH', 154, 2, 8)  # pops __aenter__ and __aexit__; pushed results on stack
def_op(l,     'FORMAT_VALUE',     155, 1, 1)
varargs_op(l, 'BUILD_CONST_KEY_MAP', 156, -2, 1) # TOS is count of kwargs
nargs_op(l,   'CALL_FUNCTION_EX', 142, -2, 1)
def_op(l,     'SETUP_ANNOTATIONS', 85, 1, 1)
varargs_op(l,  'BUILD_STRING',     157, -2, 2)
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):
    if flags == 0:
        return "Neither defaults, keyword-only args, annotations, nor closures"
    pattr = ''
    for flag in MAKE_FUNCTION_FLAGS:
        bit = flags & 1
        if bit:
Exemple #18
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 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:
            if pattr:
                pattr += ", " + flag
Exemple #19
0
version = 2.7

l = locals()

init_opdata(l, opcode_27, version, is_pypy=True)

# FIXME: DRY common PYPY opcode additions

# PyPy only
# ----------
name_op(l,    'LOOKUP_METHOD',   201,  1, 2)
nargs_op(l, 'CALL_METHOD',     202, -1, 1)
l['hasnargs'].append(202)

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

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


# PyPy 2.7.13 (and 3.6.1) start to introduce LOAD_REVDB_VAR
import sys
if sys.version_info[:3] >= (2, 7, 13) and sys.version_info[4] >= 42:
    def_op(l, 'LOAD_REVDB_VAR', 205)

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

# FIXME remove (fix uncompyle6)
update_pj3(globals(), l)
Exemple #20
0
from xdis.opcodes.base import (def_op, finalize_opcodes, init_opdata, jrel_op,
                               name_op, nargs_op, update_pj3)

version = 2.7

l = locals()

init_opdata(l, opcode_27, version, is_pypy=True)

# FIXME: DRY common PYPY opcode additions

# PyPy only
# ----------
name_op(l, 'LOOKUP_METHOD', 201, 1, 2)
nargs_op(l, 'CALL_METHOD', 202, -1, 1)
l['hasnargs'].append(202)

# Used only in single-mode compilation list-comprehension generators
def_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)

finalize_opcodes(l)
Exemple #21
0
l = locals()

init_opdata(l, opcode_37, version)

# These are removed since 3.7...
rm_op(l, 'BREAK_LOOP', 80)
rm_op(l, 'CONTINUE_LOOP', 119)
rm_op(l, 'SETUP_LOOP', 120)
rm_op(l, 'SETUP_EXCEPT', 121)

# These are new since Python 3.7

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'ROT_FOUR',           6,   4, 4)
def_op(l, 'BEGIN_FINALLY',     53,   0, 1)
def_op(l, 'END_ASYNC_FOR',     54,   7, 0)  # POP is 0, when not 7
def_op(l, 'END_FINALLY',       88,   1, 0)  # POP is 6, when not 1
jrel_op(l, 'CALL_FINALLY',    162,   0, 1)
nargs_op(l, 'POP_FINALLY',    163,   0, 0)  # PUSH/POP vary

format_MAKE_FUNCTION_arg = opcode_37.format_MAKE_FUNCTION_arg
format_value_flags = opcode_37.format_value_flags

opcode_arg_fmt = {
    'MAKE_FUNCTION': format_MAKE_FUNCTION_arg,
    'FORMAT_VALUE': format_value_flags,
    'EXTENDED_ARG': format_extended_arg36
}
Exemple #22
0
oppush = [0] * 256

# 9 means handle special. Note his forces oppush[i] - oppop[i] negative
# oppop[op] => number of stack entries popped
oppop = [0] * 256

for op in range(256):
    opname[op] = '<%r>' % (op, )
del op

# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'STOP_CODE', 0, 0, 0, fallthrough=False)
def_op(l, 'POP_TOP', 1, 1, 0)
def_op(l, 'ROT_TWO', 2, 2, 2)
def_op(l, 'ROT_THREE', 3, 3, 3)
def_op(l, 'DUP_TOP', 4, 0, 1)

# Python 3.2+
def_op(l, 'DUP_TOP_TWO', 5, 0, 2)

def_op(l, 'NOP', 9)
def_op(l, 'UNARY_POSITIVE', 10, 1, 1)
def_op(l, 'UNARY_NEGATIVE', 11, 1, 1)
def_op(l, 'UNARY_NOT', 12, 1, 1)

def_op(l, 'UNARY_INVERT', 15, 1, 1)
Exemple #23
0
of stack usage.
"""

from xdis.opcodes.base import (
    def_op, finalize_opcodes,
    format_extended_arg, init_opdata,
    rm_op, update_pj3)

from xdis.opcodes.opcode_3x import format_MAKE_FUNCTION_arg

import xdis.opcodes.opcode_3x as opcode_3x

version = 3.3

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

# Below are opcode changes since Python 3.2

rm_op(l,  'STOP_CODE',   0)
def_op(l, 'YIELD_FROM', 72)

update_pj3(globals(), l)

opcode_arg_fmt = {
    'MAKE_FUNCTION': format_MAKE_FUNCTION_arg,
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Exemple #24
0
version_tuple = (3, 10)
python_implementation = "CPython"

l = locals()

init_opdata(l, opcode_39, version_tuple)

# fmt: off
format_value_flags = opcode_39.format_value_flags
# These are removed since 3.9...
rm_op(l,  "RERAISE",                  48)

# These are added since 3.9...
#         OP NAME                 OPCODE  POP PUSH
#------------------------------------------------
def_op(l, "GET_LEN",                  30,   0, 1)
def_op(l, "MATCH_MAPPING",            31,   0, 1)
def_op(l, "MATCH_SEQUENCE",           32,   0, 1)
def_op(l, "MATCH_KEYS",               33,   0, 2)
def_op(l, "COPY_DICT_WITHOUT_KEYS",   34,   2, 2)
def_op(l, "ROT_N",                    99,   0, 0)
def_op(l, "RERAISE",                 119,   3, 0)
def_op(l, "GEN_START",               129,   1, 0)
def_op(l, "MATCH_CLASS",             152,   2, 1)
# fmt: on


def format_extended_is_op(arg):
    return "is" if arg == 0 else "is not"

Exemple #25
0
# oppush[op] => number of stack entries pushed
oppush = [0] * 256

# oppop[op] => number of stack entries popped
oppop  = [0] * 256

for op in range(256): opname[op] = '<%r>' % (op,)
del op

# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'STOP_CODE',             0,  0,  0)
def_op(l, 'POP_TOP',               1,  1,  0)
def_op(l, 'ROT_TWO',               2,  2,  2)
def_op(l, 'ROT_THREE',             3,  3,  3)
def_op(l, 'DUP_TOP',               4,  0,  1)

# Python 3.2+
def_op(l, 'DUP_TOP_TWO',           5,  0,  2)

def_op(l, 'NOP', 9)
def_op(l, 'UNARY_POSITIVE',       10,  1,  1)
def_op(l, 'UNARY_NEGATIVE',       11,  1,  1)
def_op(l, 'UNARY_NOT',            12,  1,  1)

def_op(l, 'UNARY_INVERT',         15,  1,  1)
Exemple #26
0
version = 3.5

l = locals()

init_opdata(l, opcode_34, version)

# These are removed since Python 3.5.
# Removals happen before adds since
# some opcodes are reused
rm_op(l, 'STORE_MAP',                    54)
rm_op(l, 'WITH_CLEANUP',                 81)

# These are new since Python 3.5
#          OP NAME                   OPCODE POP PUSH
#---------------------------------------------------
def_op(l, 'BINARY_MATRIX_MULTIPLY',      16,  2,  1)
def_op(l, 'INPLACE_MATRIX_MULTIPLY',     17,  2,  1)
def_op(l, 'GET_AITER',                   50,  1,  1)
def_op(l, 'GET_ANEXT',                   51,  0,  1)
def_op(l, 'BEFORE_ASYNC_WITH',           52)
def_op(l, 'GET_YIELD_FROM_ITER',         69,  0,  1)
def_op(l, 'GET_AWAITABLE',               73,  0,  0)
def_op(l, 'WITH_CLEANUP_START',          81,  0,  1)
def_op(l, 'WITH_CLEANUP_FINISH',         82, -1,  1)

varargs_op(l, 'BUILD_LIST_UNPACK',          149, -1,  1)
varargs_op(l, 'BUILD_MAP_UNPACK',           150, -1,  1)
varargs_op(l, 'BUILD_MAP_UNPACK_WITH_CALL', 151, -1,  1)
varargs_op(l, 'BUILD_TUPLE_UNPACK',         152, -1,  1)
varargs_op(l, 'BUILD_SET_UNPACK',           153, -1,  1)
Exemple #27
0
from xdis.opcodes.base import def_op, finalize_opcodes, init_opdata, update_pj3
import xdis.opcodes.opcode_27 as opcode_27

version = 2.7
python_implementation = "CPython"

l = locals()
init_opdata(l, opcode_27, 2.7)

def_op(l, "LOAD_VAR_ZERO_LOAD_CONST", 173, 0, 2)

update_pj3(globals(), l)

finalize_opcodes(l)
Exemple #28
0
# oppush[op] => number of stack entries pushed
oppush = [0] * 256

# 9 means handle special. Note his forces oppush[i] - oppop[i] negative
# oppop[op] => number of stack entries popped
oppop  = [0] * 256

for op in range(256): opname[op] = '<%r>' % (op,)
del op

# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'STOP_CODE',             0,  0,  0, fallthrough=False)
def_op(l, 'POP_TOP',               1,  1,  0)
def_op(l, 'ROT_TWO',               2,  2,  2)
def_op(l, 'ROT_THREE',             3,  3,  3)
def_op(l, 'DUP_TOP',               4,  0,  1)

# Python 3.2+
def_op(l, 'DUP_TOP_TWO',           5,  0,  2)

def_op(l, 'NOP', 9)
def_op(l, 'UNARY_POSITIVE',       10,  1,  1)
def_op(l, 'UNARY_NEGATIVE',       11,  1,  1)
def_op(l, 'UNARY_NOT',            12,  1,  1)

def_op(l, 'UNARY_INVERT',         15,  1,  1)
Exemple #29
0
    finalize_opcodes,
    format_extended_arg,
    # Although these aren't used here, they are exported
    update_pj2,
)

version = 1.4
version_tuple = (1, 4)
python_implementation = "CPython"

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

# fmt: off
# 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
# fmt: on

update_pj2(globals(), l)

opcode_arg_fmt = {"EXTENDED_ARG": format_extended_arg}

finalize_opcodes(l)
Exemple #30
0
    format_MAKE_FUNCTION_default_argc,
    format_RAISE_VARARGS_older,
    format_extended_arg,
    update_pj2,
)

version = 2.5
python_implementation = "CPython"

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

# Bytecodes added in 2.5 from 2.4
#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'WITH_CLEANUP', 81, 4, 3)

# 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 = {
    "CALL_FUNCTION": extended_format_CALL_FUNCTION,
Exemple #31
0
init_opdata(l, opcode_38, version)

# These are removed since 3.8...
rm_op(l, "BEGIN_FINALLY", 53)
rm_op(l, "WITH_CLEANUP_START", 81)
rm_op(l, "WITH_CLEANUP_FINISH", 82)
rm_op(l, "END_FINALLY", 88)
rm_op(l, "CALL_FINALLY", 162)
rm_op(l, "POP_FINALLY", 163)

# These are new since Python 3.9

#          OP NAME              OPCODE  POP PUSH
#-----------------------------------------------
def_op(l, 'RERAISE', 48, 3, 0)
def_op(l, 'WITH_EXCEPT_START', 49, 0, 1)
def_op(l, 'LOAD_ASSERTION_ERROR', 74, 0, 1)

format_MAKE_FUNCTION_arg = opcode_38.format_MAKE_FUNCTION_arg
format_value_flags = opcode_38.format_value_flags

opcode_arg_fmt = {
    "BUILD_MAP_UNPACK_WITH_CALL": format_BUILD_MAP_UNPACK_WITH_CALL,
    "CALL_FUNCTION_KW": format_CALL_FUNCTION_KW,
    "CALL_FUNCTION_EX": format_CALL_FUNCTION_EX,
    'MAKE_FUNCTION': format_MAKE_FUNCTION_arg,
    'FORMAT_VALUE': format_value_flags,
    'EXTENDED_ARG': format_extended_arg36
}
Exemple #32
0
rm_op(l, 'JUMP_IF_FALSE_OR_POP', 111)
rm_op(l, 'JUMP_IF_TRUE_OR_POP', 112)
rm_op(l, 'POP_JUMP_IF_FALSE', 114)
rm_op(l, 'POP_JUMP_IF_TRUE', 115)
rm_op(l, 'LIST_APPEND', 145)
rm_op(l, 'MAP_ADD', 147)

# These are are in 3.0 but are not in 3.1 or they have
# different opcode numbers. Note: As a result of opcode value
# changes, these have to be applied *after* removing ops (with
# the same name).

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------

def_op(l, 'SET_ADD', 17, 2, 0)  # Calls set.add(TOS1[-i], TOS).
# Used to implement set comprehensions.
def_op(l, 'LIST_APPEND', 18, 2, 0)  # Calls list.append(TOS1, TOS).
# Used to implement list comprehensions.
jrel_op(l, 'JUMP_IF_FALSE', 111, 1, 1)
jrel_op(l, 'JUMP_IF_TRUE', 112, 1, 1)

# Yes, pj2 not pj3 - Python 3.0 is more like 2.7 here with its
# JUMP_IF rather than POP_JUMP_IF.
update_pj2(globals(), l)

opcode_arg_fmt = {
    'MAKE_FUNCTION': format_MAKE_FUNCTION_default_argc,
    'EXTENDED_ARG': format_extended_arg,
}
Exemple #33
0
    jrel_op, name_op, varargs_op, update_pj3
    )

version = 2.7

l = locals()

init_opdata(l, opcode_27, version, is_pypy=True)

# FIXME: DRY common PYPY opcode additions

# PyPy only
# ----------
name_op(l,    'LOOKUP_METHOD',   201,  1, 2)
varargs_op(l, 'CALL_METHOD',     202, -1, 1)
l['hasnargs'].append(202)

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

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

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

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

finalize_opcodes(l)
Exemple #34
0
init_opdata(l, opcode_34, version)

# These are removed since Python 3.5.
# Removals happen before adds since
# some opcodes are reused
rm_op(l, "STORE_MAP",                    54)
rm_op(l, "WITH_CLEANUP",                 81)

# Stack effects are change from 3.4
varargs_op(l, "BUILD_MAP",              105, -1, -1)  # arg is count of kwarg items

# These are new since Python 3.5
#          OP NAME                   OPCODE POP PUSH
#---------------------------------------------------
def_op(l, "BINARY_MATRIX_MULTIPLY",      16,  2,  1)
def_op(l, "INPLACE_MATRIX_MULTIPLY",     17,  2,  1)
def_op(l, "GET_AITER",                   50,  1,  1)
def_op(l, "GET_ANEXT",                   51,  0,  1)
def_op(l, "BEFORE_ASYNC_WITH",           52,  0,  1)
def_op(l, "GET_YIELD_FROM_ITER",         69,  1,  1)
def_op(l, "GET_AWAITABLE",               73,  0,  0)
def_op(l, "WITH_CLEANUP_START",          81,  0,  1)
def_op(l, "WITH_CLEANUP_FINISH",         82,  1,  0)

varargs_op(l, "BUILD_LIST_UNPACK",          149, -1,  1)
varargs_op(l, "BUILD_MAP_UNPACK",           150, -1,  1)
varargs_op(l, "BUILD_MAP_UNPACK_WITH_CALL", 151, -1,  1)
varargs_op(l, "BUILD_TUPLE_UNPACK",         152, -1,  1)
varargs_op(l, "BUILD_SET_UNPACK",           153, -1,  1)
Exemple #35
0
l = locals()

init_opdata(l, opcode_37, version)

# These are removed since 3.7...
rm_op(l, "BREAK_LOOP", 80)
rm_op(l, "CONTINUE_LOOP", 119)
rm_op(l, "SETUP_LOOP", 120)
rm_op(l, "SETUP_EXCEPT", 121)

# These are new since Python 3.7

#          OP NAME            OPCODE POP PUSH
# --------------------------------------------
def_op(l, "ROT_FOUR", 6, 4, 4)
def_op(l, "BEGIN_FINALLY", 53, 0, 6)
def_op(l, "END_ASYNC_FOR", 54, 7, 0)  # POP is 0, when not 7
def_op(l, "END_FINALLY", 88, 6, 0)  # POP is 6, when not 1
jrel_op(l, "CALL_FINALLY", 162, 0, 1)
nargs_op(l, "POP_FINALLY", 163, 6, 0)  # PUSH/POP vary

format_value_flags = opcode_37.format_value_flags

opcode_arg_fmt = {
    "BUILD_MAP_UNPACK_WITH_CALL": format_BUILD_MAP_UNPACK_WITH_CALL,
    "CALL_FUNCTION_EX": format_CALL_FUNCTION_EX,
    "CALL_FUNCTION_KW": format_CALL_FUNCTION_KW,
    "EXTENDED_ARG": format_extended_arg36,
    "FORMAT_VALUE": format_value_flags,
    "MAKE_FUNCTION": format_MAKE_FUNCTION_flags,
Exemple #36
0
version = 3.1
version_tuple = (3, 1)
python_implementation = "CPython"

init_opdata(l, opcode_32, version_tuple)

# fmt: off
# 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)
# fmt: on

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,
Exemple #37
0
rm_op(l, "WITH_CLEANUP_FINISH", 82)
rm_op(l, "END_FINALLY", 88)
rm_op(l, "BUILD_LIST_UNPACK", 149)
rm_op(l, "BUILD_MAP_UNPACK", 150)
rm_op(l, "BUILD_MAP_UNPACK_WITH_CALL", 151)
rm_op(l, "BUILD_TUPLE_UNPACK", 152)
rm_op(l, "BUILD_SET_UNPACK", 153)
rm_op(l, "BUILD_TUPLE_UNPACK_WITH_CALL", 158)
rm_op(l, "CALL_FINALLY", 162)
rm_op(l, "POP_FINALLY", 163)

# These are new since Python 3.9

#          OP NAME               OPCODE  POP PUSH
#------------------------------------------------
def_op(l, 'RERAISE', 48, 3, 0)
def_op(l, 'WITH_EXCEPT_START', 49, 0, 1)
def_op(l, 'LOAD_ASSERTION_ERROR', 74, 0, 1)
def_op(l, 'LIST_TO_TUPLE', 82, 1, 1)

def_op(l, 'IS_OP', 117, 2, 1)
jabs_op(l, 'JUMP_IF_NOT_EXC_MATCH', 121, 2, 0)
def_op(l, 'CONTAINS_OP', 118, 2, 1)
def_op(l, 'LIST_EXTEND', 162, 2, 1)
def_op(l, 'SET_UPDATE', 163, 2, 1)
def_op(l, 'DICT_MERGE', 164, 2, 1)
def_op(l, 'DICT_UPDATE', 165, 2, 1)

format_value_flags = opcode_38.format_value_flags

Exemple #38
0
# oppush[op] => number of stack entries pushed
oppush = [0] * 256

# oppop[op] => number of stack entries popped
# 9 means handle special. Note his forces oppush[i] - oppop[i] negative
oppop  = [0] * 256

for op in range(256): opname[op] = '<%r>' % (op,)
del op

# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, "STOP_CODE",             0,  0,  0, fallthrough=False)
def_op(l, "POP_TOP",               1,  1,  0)
def_op(l, "ROT_TWO",               2,  2,  2)
def_op(l, "ROT_THREE",             3,  3,  3)
def_op(l, "DUP_TOP",               4,  0,  1)
def_op(l, "ROT_FOUR",              5,  4,  4)

def_op(l, "UNARY_POSITIVE",       10,  1,  1)
def_op(l, "UNARY_NEGATIVE",       11,  1,  1)
def_op(l, "UNARY_NOT",            12,  1,  1)
def_op(l, "UNARY_CONVERT",        13,  1,  1)

def_op(l, "UNARY_INVERT",         15,  1,  1)

def_op(l, "BINARY_POWER",         19,  2,  1)
Exemple #39
0
version = 2.7

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

# 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)
Exemple #40
0
    def_op, extended_format_ATTR, extended_format_CALL_FUNCTION,
    extended_format_MAKE_FUNCTION_older, extended_format_RAISE_VARARGS_older,
    extended_format_RETURN_VALUE, init_opdata, finalize_opcodes,
    format_CALL_FUNCTION_pos_name_encoded, format_MAKE_FUNCTION_default_argc,
    format_RAISE_VARARGS_older, format_extended_arg, update_pj2)

version = 2.4
python_implementation = "CPython"

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

# Bytecodes added since 2.3
#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'NOP', 9, 0, 0)
def_op(l, 'LIST_APPEND', 18, 2, 0)  # Calls list.append(TOS[-i], TOS).
# Used to implement list comprehensions.
def_op(l, 'YIELD_VALUE', 86, 1, 1)

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

finalize_opcodes(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,
Exemple #41
0
version = 2.7

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

# 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)
Exemple #42
0
"""

from xdis.opcodes.base import (def_op, finalize_opcodes, format_extended_arg,
                               free_op, init_opdata, rm_op, update_pj3)

from xdis.opcodes.opcode_3x import format_MAKE_FUNCTION_arg

import xdis.opcodes.opcode_33 as opcode_33

version = 3.4

l = locals()

init_opdata(l, opcode_33, version)

# These are removed since Python 3.3
rm_op(l, 'STORE_LOCALS', 69)

# These are new since Python 3.3
def_op(l, 'YIELD_FROM', 72)
free_op(l, 'LOAD_CLASSDEREF', 148)

update_pj3(globals(), l)

opcode_arg_fmt = {
    'MAKE_FUNCTION': format_MAKE_FUNCTION_arg,
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Exemple #43
0
CPython 2.4 bytecode opcodes

This is a like Python 2.3's opcode.py with some classification
of stack usage.
"""

import xdis.opcodes.opcode_2x as opcode_2x
from xdis.opcodes.base import (
    def_op, init_opdata,
    finalize_opcodes, format_extended_arg, update_pj2)

version = 2.4

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

# Bytecodes added since 2.3
def_op(l, 'NOP',           9,  0,  0)
def_op(l, 'LIST_APPEND',  18,  2,  1)  # Calls list.append(TOS[-i], TOS).
                                       # Used to implement list comprehensions.
def_op(l, 'YIELD_VALUE',  86,  1,  0)

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

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Exemple #44
0
    update_pj3,
)

version = 3.5
python_implementation = "PyPy"

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)
Exemple #45
0
version = 3.5

l = locals()

init_opdata(l, opcode_34, version)

# These are removed since Python 3.5.
# Removals happen before adds since
# some opcodes are reused
rm_op(l, 'STORE_MAP',                    54)
rm_op(l, 'WITH_CLEANUP',                 81)

# These are new since Python 3.5
#          OP NAME                   OPCODE POP PUSH
#---------------------------------------------------
def_op(l, 'BINARY_MATRIX_MULTIPLY',      16,  2,  1)
def_op(l, 'INPLACE_MATRIX_MULTIPLY',     17,  2,  1)
def_op(l, 'GET_AITER',                   50,  1,  1)
def_op(l, 'GET_ANEXT',                   51,  0,  1)
def_op(l, 'BEFORE_ASYNC_WITH',           52)
def_op(l, 'GET_YIELD_FROM_ITER',         69,  0,  1)
def_op(l, 'GET_AWAITABLE',               73,  0,  0)
def_op(l, 'WITH_CLEANUP_START',          81,  0,  1)
def_op(l, 'WITH_CLEANUP_FINISH',         82, -1,  1)
def_op(l, 'BUILD_LIST_UNPACK',          149, -1,  1)
def_op(l, 'BUILD_MAP_UNPACK',           150, -1,  1)
def_op(l, 'BUILD_MAP_UNPACK_WITH_CALL', 151, -1,  1)
def_op(l, 'BUILD_TUPLE_UNPACK',         152, -1,  1)
def_op(l, 'BUILD_SET_UNPACK',           153, -1,  1)
jrel_op(l, 'SETUP_ASYNC_WITH',          154,  0,  6)
Exemple #46
0
l = locals()

init_opdata(l, opcode_37, version_tuple)

# fmt: off
# These are removed since 3.7...
rm_op(l, "BREAK_LOOP",     80)
rm_op(l, "CONTINUE_LOOP", 119)
rm_op(l, "SETUP_LOOP",    120)
rm_op(l, "SETUP_EXCEPT",  121)

# These are new/changed since Python 3.7

#          OP NAME            OPCODE POP PUSH
# --------------------------------------------
def_op(l, "ROT_FOUR",          6,      4, 4)  # Opcode number changed from 5 to 6. Why?
def_op(l, "BEGIN_FINALLY",     53,     0, 6)
def_op(l, "END_ASYNC_FOR",     54,     7, 0)  # POP is 0, when not 7
def_op(l, "END_FINALLY",       88,     6, 0)  # POP is 6, when not 1
jrel_op(l, "CALL_FINALLY",    162,     0, 1)
nargs_op(l, "POP_FINALLY",    163,     6, 0)  # PUSH/POP vary


format_value_flags = opcode_37.format_value_flags

opcode_arg_fmt = {
    "BUILD_MAP_UNPACK_WITH_CALL": format_BUILD_MAP_UNPACK_WITH_CALL,
    "CALL_FUNCTION_EX":           format_CALL_FUNCTION_EX,
    "CALL_FUNCTION_KW":           format_CALL_FUNCTION_KW,
    "EXTENDED_ARG":               format_extended_arg36,
    "FORMAT_VALUE":               format_value_flags,
Exemple #47
0
# oppush[op] => number of stack entries pushed
oppush = [0] * 256

# oppop[op] => number of stack entries popped
# 9 means handle special. Note his forces oppush[i] - oppop[i] negative
oppop  = [0] * 256

for op in range(256): opname[op] = '<%r>' % (op,)
del op

# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

#          OP NAME            OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'STOP_CODE',             0,  0,  0, fallthrough=False)
def_op(l, 'POP_TOP',               1,  1,  0)
def_op(l, 'ROT_TWO',               2,  2,  2)
def_op(l, 'ROT_THREE',             3,  3,  3)
def_op(l, 'DUP_TOP',               4,  0,  1)
def_op(l, 'ROT_FOUR',              5,  4,  4)

def_op(l, 'UNARY_POSITIVE',       10,  1,  1)
def_op(l, 'UNARY_NEGATIVE',       11,  1,  1)
def_op(l, 'UNARY_NOT',            12,  1,  1)
def_op(l, 'UNARY_CONVERT',        13,  1,  1)

def_op(l, 'UNARY_INVERT',         15,  1,  1)

def_op(l, 'BINARY_POWER',         19,  2,  1)
Exemple #48
0
import xdis.opcodes.opcode_36 as opcode_36
from xdis.opcodes.opcode_36 import (
    format_MAKE_FUNCTION_flags, )

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

## FIXME: DRY common PYPY opcode additions

# Opcodes removed from 3.6.

rm_op(l, "CALL_FUNCTION_EX", 142)
rm_op(l, "BUILD_TUPLE_UNPACK_WITH_CALL", 158)

# The following were removed from 3.6 but still in Pypy 3.6
def_op(l, "MAKE_CLOSURE", 134, 9, 1)  # TOS is number of items to pop
nargs_op(l, "CALL_FUNCTION_VAR", 140, 9, 1)  # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION_KW", 141, 9, 1)  # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION_VAR_KW", 142, 9, 1)  # #args + (#kwargs << 8)

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

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
Exemple #49
0
    def_op, finalize_opcodes, init_opdata,
    jrel_op, name_op, nargs_op,
    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)
Exemple #50
0
# (C) Copyright 2017 by Rocky Bernstein
"""
CPython 2.5 bytecode opcodes

This is a like Python 2.5's opcode.py with some classification
of stack usage.
"""

import xdis.opcodes.opcode_24 as opcode_24
from xdis.opcodes.base import (
    def_op, init_opdata,
    finalize_opcodes, format_extended_arg,
    update_pj2)

version = 2.5

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

# Bytecodes added in 2.5 from 2.4
def_op(l, 'WITH_CLEANUP', 81)

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

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)