Esempio n. 1
0
    init_opdata,
    jabs_op,
    jrel_op,
    name_op,
    rm_op,
    update_pj3,
)
import xdis.opcodes.opcode_26 as opcode_26

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)
Esempio n. 2
0
# This is used from outside this module
from xdis.cross_dis import findlabels

import xdis.opcodes.opcode_11 as opcode_11
from xdis.opcodes.base import (
    init_opdata,
    rm_op,
    finalize_opcodes,
    format_extended_arg,
    # Although these aren't used here, they are exported
    update_pj2,
)

version = 1.0
python_implementation = "CPython"

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

# 1.0 - 1.1 bytecodes differences
rm_op(l, "LOAD_GLOBALS", 84)
rm_op(l, "EXEC_STMT", 85)

update_pj2(globals(), l)

opcode_arg_fmt = {"EXTENDED_ARG": format_extended_arg}

finalize_opcodes(l)

findlinestarts = opcode_11.findlinestarts
Esempio n. 3
0
    name_op,
    rm_op,
    update_pj3,
)

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,
Esempio n. 4
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,
}
Esempio n. 5
0
    format_BUILD_MAP_UNPACK_WITH_CALL,
    format_CALL_FUNCTION_EX,
    format_CALL_FUNCTION_KW,
    format_MAKE_FUNCTION_flags,
    format_extended_arg36,
)

version = 3.8
python_implementation = "CPython"

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/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
Esempio n. 6
0
    rm_op,
    update_pj2,
)

import xdis.opcodes.opcode_31 as opcode_31

version = 3.0
python_implementation = "CPython"

l = locals()

init_opdata(l, opcode_31, version)

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

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

def_op(l, 'SET_ADD', 17, 2, 0)  # Calls set.add(TOS1[-i], TOS).
Esempio n. 7
0
    def_op, finalize_opcodes, init_opdata,
    jrel_op, name_op, nargs_op, rm_op,
    varargs_op, update_pj3)

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)
Esempio n. 8
0
    format_extended_arg36,
)

from xdis.opcodes.opcode_36 import format_MAKE_FUNCTION_flags
from xdis.opcodes.opcode_37 import extended_format_RAISE_VARARGS, format_RAISE_VARARGS
import xdis.opcodes.opcode_38 as opcode_38

version = 3.9
python_implementation = "CPython"

l = locals()

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_value_flags = opcode_38.format_value_flags
Esempio n. 9
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)
Esempio n. 10
0
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""
CPython 2.0 bytecode opcodes

This is similar to the opcode portion in Python 2.0's dis.py library.
"""

import xdis.opcodes.opcode_21 as opcode_21
from xdis.opcodes.base import (
    init_opdata, finalize_opcodes, format_extended_arg, rm_op, update_pj2)

version = 2.0

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

# 2.1 Bytecodes not in 2.0
rm_op(l, 'CONTINUE_LOOP', 119)
rm_op(l, 'MAKE_CLOSURE',  134)
rm_op(l, 'LOAD_CLOSURE',  135)
rm_op(l, 'LOAD_DEREF',    136)
rm_op(l, 'STORE_DEREF',   137)

update_pj2(globals(), l)

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Esempio n. 11
0
from xdis.opcodes.opcode_33 import (
    extended_format_MAKE_FUNCTION,
    format_MAKE_FUNCTION_default_pos_arg,
)

version = 3.5
python_implementation = "CPython"

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)

# 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)
Esempio n. 12
0
from xdis.opcodes.opcode_36 import format_MAKE_FUNCTION_flags
from xdis.opcodes.opcode_37 import extended_format_RAISE_VARARGS, format_RAISE_VARARGS
import xdis.opcodes.opcode_39 as opcode_39

version = 3.10
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
Esempio n. 13
0
import xdis.opcodes.opcode_35 as opcode_35

# When we use EXTENDED_ARG, by how much do we
# shift (or what power of two do we multiply) the operand value?
# Note: this changes in Python 3.6
EXTENDED_ARG_SHIFT = 8

version = 3.6

l = locals()

init_opdata(l, opcode_35, version)

# These are removed since Python 3.6
rm_op(l, 'MAKE_CLOSURE',         134)
rm_op(l, 'CALL_FUNCTION_VAR',    140)
rm_op(l, 'CALL_FUNCTION_VAR_KW', 142)

### Opcodes that have changed drastically ####


# BUILD_MAP_UNPACK_WITH_CALL oparg

# oparg is the number of unpacked mappings which no longer limited by
# 255. As in BUILD_MAP_UNPACK.The location of the function is `oparg +
# 2`.


# CALL_FUNCTION oparg
Esempio 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 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)
Esempio n. 15
0
This is a like Python 2.7's opcode.py with some classification
of stack usage.
"""

from xdis.opcodes.base import (
    def_op, compare_op, finalize_opcodes, format_extended_arg,
    init_opdata, jabs_op, jrel_op, name_op, rm_op, update_pj3)
import xdis.opcodes.opcode_26 as opcode_26

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)
Esempio n. 16
0
# This is used from outside this module
from xdis.bytecode import findlabels

import xdis.opcodes.opcode_14 as opcode_14
from xdis.opcodes.base import (
    init_opdata,
    def_op,
    rm_op,
    finalize_opcodes,
    format_extended_arg,
    # Although these aren't used here, they are exported
    update_pj2,
)

version = 1.3

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}

finalize_opcodes(l)

findlinestarts = opcode_14.findlinestarts
Esempio n. 17
0
from xdis.opcodes.base import (def_op, format_extended_arg, finalize_opcodes,
                               init_opdata, rm_op, update_pj3)

from xdis.opcodes.opcode_3x import format_MAKE_FUNCTION_arg

import xdis.opcodes.opcode_32 as opcode_32

l = locals()

version = 3.1

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
def_op(l, 'ROT_FOUR', 5)
def_op(l, 'DUP_TOPX', 99)

# 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_arg,
    'EXTENDED_ARG': format_extended_arg,
Esempio n. 18
0
This is a like Python 2.7's opcode.py with some classification
of stack usage.
"""

from xdis.opcodes.base import (def_op, compare_op, finalize_opcodes,
                               format_extended_arg, init_opdata, jabs_op,
                               jrel_op, name_op, rm_op, update_pj3)
import xdis.opcodes.opcode_26 as opcode_26

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)
Esempio n. 19
0
    format_extended_arg36,
    init_opdata, nargs_op,
    def_op, jrel_op, rm_op,
    update_pj3
    )

import xdis.opcodes.opcode_37 as opcode_37

version = 3.8

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
Esempio n. 20
0
"""

from xdis.opcodes.base import (finalize_opcodes, format_extended_arg36,
                               init_opdata, nargs_op, def_op, jrel_op, rm_op,
                               update_pj3)

import xdis.opcodes.opcode_37 as opcode_37

version = 3.8

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
Esempio n. 21
0
    update_pj3,
)

version = 3.6

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

name_op(l, "LOOKUP_METHOD", 201, 1, 2)
nargs_op(l, "CALL_METHOD", 202, -1, 1)
l["hasvargs"].append(202)
Esempio n. 22
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)
Esempio n. 23
0
    update_pj3,
)

import xdis.opcodes.opcode_3x as opcode_3x

version = 3.3
version_tuple = (3, 3)
python_implementation = "CPython"

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

# Below are opcode changes since Python 3.2

# fmt: off
rm_op(l, "STOP_CODE", 0)
def_op(l, "YIELD_FROM", 72, 1, 0)
# fmt: on

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",
Esempio n. 24
0
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""
CPython 2.0 bytecode opcodes

This is similar to the opcode portion in Python 2.0's dis.py library.
"""

import xdis.opcodes.opcode_21 as opcode_21
from xdis.opcodes.base import (init_opdata, finalize_opcodes,
                               format_extended_arg, rm_op, update_pj2)

version = 2.0

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

# 2.1 Bytecodes not in 2.0
rm_op(l, 'CONTINUE_LOOP', 119)
rm_op(l, 'MAKE_CLOSURE', 134)
rm_op(l, 'LOAD_CLOSURE', 135)
rm_op(l, 'LOAD_DEREF', 136)
rm_op(l, 'STORE_DEREF', 137)

update_pj2(globals(), l)

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Esempio n. 25
0
                               update_pj3)

from xdis.opcodes.opcode_3x import format_MAKE_FUNCTION_arg

import xdis.opcodes.opcode_34 as opcode_34

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)
Esempio n. 26
0
    extended_format_MAKE_FUNCTION_older,
    extended_format_RETURN_VALUE,
    finalize_opcodes,
    format_extended_arg,
    rm_op,
    update_pj2,
)

version = 2.1
python_implementation = "CPython"

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

# 2.1 bytecodes changes from 2.2
rm_op(l, "BINARY_FLOOR_DIVIDE", 26)
rm_op(l, "BINARY_TRUE_DIVIDE", 27)
rm_op(l, "INPLACE_FLOOR_DIVIDE", 28)
rm_op(l, "INPLACE_TRUE_DIVIDE", 29)
rm_op(l, "GET_ITER", 68)
rm_op(l, "YIELD_VALUE", 86)
rm_op(l, "FOR_ITER", 93)

update_pj2(globals(), l)

finalize_opcodes(l)

opcode_arg_fmt = {"EXTENDED_ARG": format_extended_arg}

opcode_extended_fmt = {
    "MAKE_FUNCTION": extended_format_MAKE_FUNCTION_older,
Esempio n. 27
0
    def_op, finalize_opcodes, format_extended_arg, init_opdata,
    jrel_op, rm_op, update_pj2)

from xdis.opcodes.opcode_3x import format_MAKE_FUNCTION_arg

import xdis.opcodes.opcode_31 as opcode_31

version = 3.0

l = locals()

init_opdata(l, opcode_31, version)

# 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)
Esempio n. 28
0
CPython 2.1 bytecode opcodes

This is similar to the opcode portion in Python 2.1's dis.py library.
"""

import xdis.opcodes.opcode_22 as opcode_22
from xdis.opcodes.base import (
    init_opdata, finalize_opcodes, format_extended_arg, rm_op, update_pj2)

version = 2.1

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

# 2.1 bytecodes changes from 2.2
rm_op(l, 'BINARY_FLOOR_DIVIDE',  26)
rm_op(l, 'BINARY_TRUE_DIVIDE',   27)
rm_op(l, 'INPLACE_FLOOR_DIVIDE', 28)
rm_op(l, 'INPLACE_TRUE_DIVIDE',  29)
rm_op(l, 'GET_ITER',             68)
rm_op(l, 'YIELD_VALUE',          86)
rm_op(l, 'FOR_ITER',             93)

update_pj2(globals(), l)

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg,
}

finalize_opcodes(l)
Esempio n. 29
0
    format_extended_arg36,
)

from xdis.opcodes.opcode_36 import format_MAKE_FUNCTION_flags
from xdis.opcodes.opcode_37 import extended_format_RAISE_VARARGS, format_RAISE_VARARGS
import xdis.opcodes.opcode_38 as opcode_38

version = 3.9
python_implementation = "CPython"

l = locals()

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, "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
Esempio n. 30
0
# 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 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)
Esempio n. 31
0
    format_CALL_FUNCTION_pos_name_encoded,
    format_MAKE_FUNCTION_default_argc,
    format_extended_arg,
    init_opdata,
    rm_op,
    update_pj2,
)

version = 2.0
python_implementation = "CPython"

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

# 2.1 Bytecodes not in 2.0
rm_op(l, "CONTINUE_LOOP", 119)
rm_op(l, "MAKE_CLOSURE", 134)
rm_op(l, "LOAD_CLOSURE", 135)
rm_op(l, "LOAD_DEREF", 136)
rm_op(l, "STORE_DEREF", 137)

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,
Esempio n. 32
0
import xdis.opcodes.opcode_35 as opcode_35

# When we use EXTENDED_ARG, by how much do we
# shift (or what power of two do we multiply) the operand value?
# Note: this changes in Python 3.6
EXTENDED_ARG_SHIFT = 8

version = 3.6

l = locals()

init_opdata(l, opcode_35, version)

# These are removed since Python 3.6
rm_op(l, 'MAKE_CLOSURE', 134)
rm_op(l, 'CALL_FUNCTION_VAR', 140)
rm_op(l, 'CALL_FUNCTION_VAR_KW', 142)

### Opcodes that have changed drastically ####

# BUILD_MAP_UNPACK_WITH_CALL oparg

# oparg is the number of unpacked mappings which no longer limited by
# 255. As in BUILD_MAP_UNPACK.The location of the function is `oparg +
# 2`.

# CALL_FUNCTION oparg

# oparg is the number of positional arguments on the stack which no
# longer limited by 255.
Esempio n. 33
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)
Esempio n. 34
0
python_implementation = "PyPy"

from xdis.opcodes.opcode_33 import extended_format_MAKE_FUNCTION
import xdis.opcodes.opcode_37 as opcode_37
from xdis.opcodes.opcode_37 import (
    format_MAKE_FUNCTION_flags,
)

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


# FIXME: DRY common PYPY opcode additions

# 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)
Esempio n. 35
0
    format_extended_arg, jrel_op, rm_op, update_pj3)

from xdis.opcodes.opcode_3x import format_MAKE_FUNCTION_arg

import xdis.opcodes.opcode_34 as opcode_34

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)
Esempio n. 36
0
    init_opdata,
    rm_op,
    update_pj3,
)

import xdis.opcodes.opcode_33 as opcode_33

version = 3.4
python_implementation = "CPython"

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
free_op(l, "LOAD_CLASSDEREF", 148)

update_pj3(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,
    "MAKE_FUNCTION": opcode_33.format_MAKE_FUNCTION_default_pos_arg,
    "EXTENDED_ARG": format_extended_arg,
    "RAISE_VARARGS": format_RAISE_VARARGS_older
}
Esempio n. 37
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, 1, 0)

update_pj3(globals(), l)

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

finalize_opcodes(l)