How to use the xdis.opcodes.base.nargs_op function in xdis

To help you get started, we’ve selected a few xdis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rocky / python-xdis / xdis / opcodes / opcode_2x.py View on Github external
store_op(l, "STORE_FAST",         125,  1,  0, is_type="local")  # Local variable number
local_op(l, "DELETE_FAST",        126,  0,  0) # Local variable number is in operand

nargs_op(l, "RAISE_VARARGS",      130, -1,  2, fallthrough=False)
                                                # Number of raise arguments (1, 2, or 3)
nargs_op(l, "CALL_FUNCTION",      131, -1,  2)  # TOS is #args + (#kwargs << 8)

nargs_op(l, "MAKE_FUNCTION",      132, -1,  2)  # TOS is number of args with default values
varargs_op(l, "BUILD_SLICE",      133,  2,  1)  # TOS is number of items

def_op(l, "MAKE_CLOSURE",         134, -3,  1)
free_op(l, "LOAD_CLOSURE",        135,  0,  1)
free_op(l, "LOAD_DEREF",          136,  0,  1)
store_op(l, "STORE_DEREF",        137,  1,  0, is_type="free")

nargs_op(l, "CALL_FUNCTION_VAR",  140, -2,  1)   # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION_KW",   141, -2,  1)   # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION_VAR_KW", 142, -3, 1)  # #args + (#kwargs << 8)

def_op(l, "EXTENDED_ARG", 143)
EXTENDED_ARG = 143
github rocky / python-xdis / xdis / opcodes / opcode_36pypy.py View on Github external
)

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
jrel_op(l, "JUMP_IF_NOT_DEBUG", 204, conditional=True)
github rocky / python-xdis / xdis / opcodes / opcode_32pypy.py View on Github external
)

version = 3.2
python_implementation = "PyPy"

import xdis.opcodes.opcode_32 as opcode_32

l = locals()
init_opdata(l, opcode_32, 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["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)

finalize_opcodes(l)
github rocky / python-xdis / xdis / opcodes / opcode_36pypy.py View on Github external
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
jrel_op(l, "JUMP_IF_NOT_DEBUG", 204, conditional=True)

# PyPy 3.6.1 (and 2.7.13) start to introduce LOAD_REVDB_VAR
github rocky / python-xdis / xdis / opcodes / opcode_3x.py View on Github external
nargs_op(l, 'RAISE_VARARGS',       130, -1,  1, fallthrough=False)
                                                 # Number of raise arguments (1, 2, or 3)
nargs_op(l, 'CALL_FUNCTION',       131, -1,  1)  # #args + (#kwargs << 8)

nargs_op(l, 'MAKE_FUNCTION',       132, -2,  1) # TOS is number of args if < 3.6
varargs_op(l, 'BUILD_SLICE',       133,  2,  1) # TOS is number of items to pop

nargs_op(l, 'MAKE_CLOSURE',        134, -3,  1) # TOS is number of items to pop
free_op(l, 'LOAD_CLOSURE',         135,  0,  1)
free_op(l, 'LOAD_DEREF',           136,  0,  1)
store_op(l, 'STORE_DEREF',         137,  1,  0, is_type="free")
free_op(l, 'DELETE_DEREF',         138,  0,  0)

nargs_op(l, 'CALL_FUNCTION_VAR',   140,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_KW',    141,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_VAR_KW',142,  -3,  1)   # #args + (#kwargs << 8)

jrel_op(l, 'SETUP_WITH',           143,  0,  7)

def_op(l, 'LIST_APPEND',           145,  2,  1)  # Calls list.append(TOS[-i], TOS).
                                                 # Used to implement list comprehensions.
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,  3,  1)  # Calls dict.setitem(TOS1[-i], TOS, TOS1)
                                                 # Used to implement dict comprehensions.

def_op(l, 'EXTENDED_ARG',          144,  0,   0)
EXTENDED_ARG = 144

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg
}
github rocky / python-xdis / xdis / opcodes / opcode_35pypy.py View on Github external
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)
update_pj3(globals(), l)

finalize_opcodes(l)
github rocky / python-xdis / xdis / opcodes / opcode_3x.py View on Github external
jabs_op(l, 'POP_JUMP_IF_TRUE',     115,  2,  1, conditional=True) # ""

name_op(l, 'LOAD_GLOBAL',          116,  0,  1)  # Operand is in name list

jabs_op(l, 'CONTINUE_LOOP',        119,  0,  0, fallthrough=False)  # Target address
jrel_op(l, 'SETUP_LOOP',           120,  0,  0, conditional=True) # Distance to target address
jrel_op(l, 'SETUP_EXCEPT',         121,  0,  6, conditional=True)  # ""
jrel_op(l, 'SETUP_FINALLY',        122,  0,  6, conditional=True)  # ""

local_op(l, 'LOAD_FAST',           124,  0,  1)  # Local variable number
store_op(l, 'STORE_FAST',          125,  1,  0, is_type="local")  # Local variable number
local_op(l, 'DELETE_FAST',         126,  0,  0)  # Local variable number

nargs_op(l, 'RAISE_VARARGS',       130, -1,  1, fallthrough=False)
                                                 # Number of raise arguments (1, 2, or 3)
nargs_op(l, 'CALL_FUNCTION',       131, -1,  1)  # #args + (#kwargs << 8)

nargs_op(l, 'MAKE_FUNCTION',       132, -2,  1) # TOS is number of args if < 3.6
varargs_op(l, 'BUILD_SLICE',       133,  2,  1) # TOS is number of items to pop

nargs_op(l, 'MAKE_CLOSURE',        134, -3,  1) # TOS is number of items to pop
free_op(l, 'LOAD_CLOSURE',         135,  0,  1)
free_op(l, 'LOAD_DEREF',           136,  0,  1)
store_op(l, 'STORE_DEREF',         137,  1,  0, is_type="free")
free_op(l, 'DELETE_DEREF',         138,  0,  0)

nargs_op(l, 'CALL_FUNCTION_VAR',   140,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_KW',    141,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_VAR_KW',142,  -3,  1)   # #args + (#kwargs << 8)

jrel_op(l, 'SETUP_WITH',           143,  0,  7)
github rocky / python-xdis / xdis / opcodes / opcode_3x.py View on Github external
nargs_op(l, 'RAISE_VARARGS',       130, -1,  1, fallthrough=False)
                                                 # Number of raise arguments (1, 2, or 3)
nargs_op(l, 'CALL_FUNCTION',       131, -1,  1)  # #args + (#kwargs << 8)

nargs_op(l, 'MAKE_FUNCTION',       132, -2,  1) # TOS is number of args if < 3.6
varargs_op(l, 'BUILD_SLICE',       133,  2,  1) # TOS is number of items to pop

nargs_op(l, 'MAKE_CLOSURE',        134, -3,  1) # TOS is number of items to pop
free_op(l, 'LOAD_CLOSURE',         135,  0,  1)
free_op(l, 'LOAD_DEREF',           136,  0,  1)
store_op(l, 'STORE_DEREF',         137,  1,  0, is_type="free")
free_op(l, 'DELETE_DEREF',         138,  0,  0)

nargs_op(l, 'CALL_FUNCTION_VAR',   140,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_KW',    141,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_VAR_KW',142,  -3,  1)   # #args + (#kwargs << 8)

jrel_op(l, 'SETUP_WITH',           143,  0,  7)

def_op(l, 'LIST_APPEND',           145,  2,  1)  # Calls list.append(TOS[-i], TOS).
                                                 # Used to implement list comprehensions.
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,  3,  1)  # Calls dict.setitem(TOS1[-i], TOS, TOS1)
                                                 # Used to implement dict comprehensions.

def_op(l, 'EXTENDED_ARG',          144,  0,   0)
EXTENDED_ARG = 144

opcode_arg_fmt = {
    'EXTENDED_ARG': format_extended_arg
github rocky / python-xdis / xdis / opcodes / opcode_3x.py View on Github external
name_op(l, 'LOAD_GLOBAL',          116,  0,  1)  # Operand is in name list

jabs_op(l, 'CONTINUE_LOOP',        119,  0,  0, fallthrough=False)  # Target address
jrel_op(l, 'SETUP_LOOP',           120,  0,  0, conditional=True) # Distance to target address
jrel_op(l, 'SETUP_EXCEPT',         121,  0,  6, conditional=True)  # ""
jrel_op(l, 'SETUP_FINALLY',        122,  0,  6, conditional=True)  # ""

local_op(l, 'LOAD_FAST',           124,  0,  1)  # Local variable number
store_op(l, 'STORE_FAST',          125,  1,  0, is_type="local")  # Local variable number
local_op(l, 'DELETE_FAST',         126,  0,  0)  # Local variable number

nargs_op(l, 'RAISE_VARARGS',       130, -1,  1, fallthrough=False)
                                                 # Number of raise arguments (1, 2, or 3)
nargs_op(l, 'CALL_FUNCTION',       131, -1,  1)  # #args + (#kwargs << 8)

nargs_op(l, 'MAKE_FUNCTION',       132, -2,  1) # TOS is number of args if < 3.6
varargs_op(l, 'BUILD_SLICE',       133,  2,  1) # TOS is number of items to pop

nargs_op(l, 'MAKE_CLOSURE',        134, -3,  1) # TOS is number of items to pop
free_op(l, 'LOAD_CLOSURE',         135,  0,  1)
free_op(l, 'LOAD_DEREF',           136,  0,  1)
store_op(l, 'STORE_DEREF',         137,  1,  0, is_type="free")
free_op(l, 'DELETE_DEREF',         138,  0,  0)

nargs_op(l, 'CALL_FUNCTION_VAR',   140,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_KW',    141,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_VAR_KW',142,  -3,  1)   # #args + (#kwargs << 8)

jrel_op(l, 'SETUP_WITH',           143,  0,  7)

def_op(l, 'LIST_APPEND',           145,  2,  1)  # Calls list.append(TOS[-i], TOS).
                                                 # Used to implement list comprehensions.
github rocky / python-xdis / xdis / opcodes / opcode_3x.py View on Github external
jabs_op(l, 'JUMP_ABSOLUTE',        113,  0,  0, fallthrough=False)  # Target byte offset from beginning of code
jabs_op(l, 'POP_JUMP_IF_FALSE',    114,  2,  1, conditional=True) # ""
jabs_op(l, 'POP_JUMP_IF_TRUE',     115,  2,  1, conditional=True) # ""

name_op(l, 'LOAD_GLOBAL',          116,  0,  1)  # Operand is in name list

jabs_op(l, 'CONTINUE_LOOP',        119,  0,  0, fallthrough=False)  # Target address
jrel_op(l, 'SETUP_LOOP',           120,  0,  0, conditional=True) # Distance to target address
jrel_op(l, 'SETUP_EXCEPT',         121,  0,  6, conditional=True)  # ""
jrel_op(l, 'SETUP_FINALLY',        122,  0,  6, conditional=True)  # ""

local_op(l, 'LOAD_FAST',           124,  0,  1)  # Local variable number
store_op(l, 'STORE_FAST',          125,  1,  0, is_type="local")  # Local variable number
local_op(l, 'DELETE_FAST',         126,  0,  0)  # Local variable number

nargs_op(l, 'RAISE_VARARGS',       130, -1,  1, fallthrough=False)
                                                 # Number of raise arguments (1, 2, or 3)
nargs_op(l, 'CALL_FUNCTION',       131, -1,  1)  # #args + (#kwargs << 8)

nargs_op(l, 'MAKE_FUNCTION',       132, -2,  1) # TOS is number of args if < 3.6
varargs_op(l, 'BUILD_SLICE',       133,  2,  1) # TOS is number of items to pop

nargs_op(l, 'MAKE_CLOSURE',        134, -3,  1) # TOS is number of items to pop
free_op(l, 'LOAD_CLOSURE',         135,  0,  1)
free_op(l, 'LOAD_DEREF',           136,  0,  1)
store_op(l, 'STORE_DEREF',         137,  1,  0, is_type="free")
free_op(l, 'DELETE_DEREF',         138,  0,  0)

nargs_op(l, 'CALL_FUNCTION_VAR',   140,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_KW',    141,  -2,  1)  # #args + (#kwargs << 8)
nargs_op(l, 'CALL_FUNCTION_VAR_KW',142,  -3,  1)   # #args + (#kwargs << 8)