The Python compiler currently generates the following byte code instructions.
Unary Operations take the top of the stack, apply the operation, and
push the result back on the stack.
Binary operations remove the top of the stack (TOS) and the second top-most
stack item (TOS1) from the stack. They perform the operation, and put the
result back on the stack.
In-place operations are like binary operations, in that they remove TOS and
TOS1, and push the result back on the stack, but the operation is done
in-place when TOS1 supports it, and the resulting TOS may be (but does not
have to be) the original TOS1.
The slice opcodes take up to three parameters.
Slice assignment needs even an additional parameter. As any statement,
they put nothing on the stack.
All of the following opcodes expect arguments. An argument is two
bytes, with the more significant byte last.
STOP_CODE
POP_TOP
ROT_TWO
ROT_THREE
ROT_FOUR
DUP_TOP
UNARY_POSITIVE
TOS = +TOS.
UNARY_NEGATIVE
TOS = -TOS.
UNARY_NOT
TOS = not TOS.
UNARY_CONVERT
TOS = `TOS`.
UNARY_INVERT
TOS = ~TOS.
BINARY_POWER
TOS = TOS1 ** TOS.
BINARY_MULTIPLY
TOS = TOS1 * TOS.
BINARY_DIVIDE
TOS = TOS1 / TOS.
BINARY_MODULO
TOS = TOS1 % TOS.
BINARY_ADD
TOS = TOS1 + TOS.
BINARY_SUBTRACT
TOS = TOS1 - TOS.
BINARY_SUBSCR
TOS = TOS1[TOS].
BINARY_LSHIFT
TOS = TOS1 <.
< TOSBINARY_RSHIFT
TOS = TOS1 >.
> TOSBINARY_AND
TOS = TOS1 & TOS.
BINARY_XOR
TOS = TOS1 ^ TOS.
BINARY_OR
TOS = TOS1 | TOS.
INPLACE_POWER
TOS = TOS1 ** TOS.
INPLACE_MULTIPLY
TOS = TOS1 * TOS.
INPLACE_DIVIDE
TOS = TOS1 / TOS.
INPLACE_MODULO
TOS = TOS1 % TOS.
INPLACE_ADD
TOS = TOS1 + TOS.
INPLACE_SUBTRACT
TOS = TOS1 - TOS.
INPLACE_LSHIFT
TOS = TOS1 <.
< TOSINPLACE_RSHIFT
TOS = TOS1 >.
> TOSINPLACE_AND
TOS = TOS1 & TOS.
INPLACE_XOR
TOS = TOS1 ^ TOS.
INPLACE_OR
TOS = TOS1 | TOS.
SLICE+0
TOS = TOS[:].
SLICE+1
TOS = TOS1[TOS:].
SLICE+2
TOS = TOS1[:TOS1].
SLICE+3
TOS = TOS2[TOS1:TOS].
STORE_SLICE+0
TOS[:] = TOS1.
STORE_SLICE+1
TOS1[TOS:] = TOS2.
STORE_SLICE+2
TOS1[:TOS] = TOS2.
STORE_SLICE+3
TOS2[TOS1:TOS] = TOS3.
DELETE_SLICE+0
del TOS[:].
DELETE_SLICE+1
del TOS1[TOS:].
DELETE_SLICE+2
del TOS1[:TOS].
DELETE_SLICE+3
del TOS2[TOS1:TOS].
STORE_SUBSCR
TOS1[TOS] = TOS2.
DELETE_SUBSCR
del TOS1[TOS].
PRINT_EXPR
POP_STACK.
PRINT_ITEM
sys.stdout. There
is one such instruction for each item in the print statement.
PRINT_ITEM_TO
PRINT_ITEM, but prints the item second from TOS to the
file-like object at TOS. This is used by the extended print statement.
PRINT_NEWLINE
sys.stdout. This is generated as the
last operation of a print statement, unless the statement
ends with a comma.
PRINT_NEWLINE_TO
PRINT_NEWLINE, but prints the new line on the file-like
object on the TOS. This is used by the extended print statement.
BREAK_LOOP
LOAD_LOCALS
RETURN_VALUE
IMPORT_STAR
from module import *.
EXEC_STMT
exec TOS2,TOS1,TOS. The compiler fills
missing optional parameters with None.
POP_BLOCK
END_FINALLY
BUILD_CLASS
STORE_NAME namei
name = TOS. namei is the index of name
in the attribute co_names of the code object.
The compiler tries to use STORE_LOCAL or STORE_GLOBAL
if possible.
DELETE_NAME namei
del name, where namei is the index into
co_names attribute of the code object.
UNPACK_SEQUENCE count
DUP_TOPX count
STORE_ATTR namei
TOS.name = TOS1, where namei is the index
of name in co_names.
DELETE_ATTR namei
del TOS.name, using namei as index into
co_names.
STORE_GLOBAL namei
STORE_NAME, but stores the name as a global.
DELETE_GLOBAL namei
DELETE_NAME, but deletes a global name.
LOAD_CONST consti
LOAD_NAME namei
BUILD_TUPLE count
BUILD_LIST count
BUILD_TUPLE, but creates a list.
BUILD_MAP zero
LOAD_ATTR namei
getattr(TOS, co_names[namei].
COMPARE_OP opname
cmp_op[opname].
IMPORT_NAME namei
co_names[namei]. The module object is
pushed onto the stack. The current namespace is not affected: for a
proper import statement, a subsequent STORE_FAST instruction
modifies the namespace.
IMPORT_FROM namei
co_names[namei] from the module found in
TOS. The resulting object is pushed onto the stack, to be subsequently
stored by a STORE_FAST instruction.
JUMP_FORWARD delta
JUMP_IF_TRUE delta
JUMP_IF_FALSE delta
JUMP_ABSOLUTE target
FOR_LOOP delta
LOAD_GLOBAL namei
co_names[namei] onto the stack.
SETUP_LOOP delta
SETUP_EXCEPT delta
SETUP_FINALLY delta
LOAD_FAST var_num
co_varnames[var_num] onto
the stack.
STORE_FAST var_num
co_varnames[var_num].
DELETE_FAST var_num
co_varnames[var_num].
SET_LINENO lineno
RAISE_VARARGS argc
CALL_FUNCTION argc
MAKE_FUNCTION argc
BUILD_SLICE argc
slice(TOS1, TOS) is pushed; if it is 3,
slice(TOS2, TOS1, TOS) is pushed.
See the slice() built-in function for more
information.
EXTENDED_ARG ext
CALL_FUNCTION_VAR argc
CALL_FUNCTION.
The top element on the stack contains the variable argument list, followed
by keyword and positional arguments.
CALL_FUNCTION_KW argc
CALL_FUNCTION.
The top element on the stack contains the keyword arguments dictionary,
followed by explicit keyword and positional arguments.
CALL_FUNCTION_VAR_KW argc
CALL_FUNCTION. The top element on the stack contains the
keyword arguments dictionary, followed by the variable-arguments
tuple, followed by explicit keyword and positional arguments.