blob: 5c98711b14dfd94ee6015888f41b6b986247452b [file] [log] [blame]
Fred Drake14f85211997-12-17 13:52:04 +00001\section{Standard Module \sectcode{dis}}
Guido van Rossumb62b6d11997-11-18 15:10:53 +00002\stmodindex{dis}
3
4\label{module-dis}
5
6The \code{dis} module supports the analysis of Python byte code by
7disassembling it. Since there is no Python assembler, this module
8defines the Python assembly language. The Python byte code which
9this module takes as an input is defined in the file
Fred Drake456035f1997-12-03 04:06:57 +000010\file{Include/opcode.h} and used by the compiler and the interpreter.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000011
12Example: Given the function myfunc
13
14\bcode\begin{verbatim}
15def myfunc(alist):
16 return len(alist)
17\end{verbatim}\ecode
18
Fred Drake456035f1997-12-03 04:06:57 +000019the following command can be used to get the disassembly of \code{myfunc()}:
Guido van Rossumb62b6d11997-11-18 15:10:53 +000020
21\begin{verbatim}
22>>> dis.dis(myfunc)
23 0 SET_LINENO 1
24
25 3 SET_LINENO 2
26 6 LOAD_GLOBAL 0 (len)
27 9 LOAD_FAST 0 (alist)
28 12 CALL_FUNCTION 1
29 15 RETURN_VALUE
30 16 LOAD_CONST 0 (None)
31 19 RETURN_VALUE
32\end{verbatim}
33
34The \code{dis} module defines the following functions:
35
36\renewcommand{\indexsubitem}{(in module dis)}
37
Guido van Rossumb62b6d11997-11-18 15:10:53 +000038\begin{funcdesc}{dis}{\optional{bytesource}}
39Disassemble the \var{bytesource} object. \var{bytesource} can denote
40either a class, a method, a function, or a code object. For a class,
41it disassembles all methods. For a single code sequence, it prints
42one line per byte code instruction. If no object is provided, it
43disassembles the last traceback.
44\end{funcdesc}
45
46\begin{funcdesc}{distb}{\optional{tb}}
47Disassembles the top-of-stack function of a traceback, using the last
48traceback if none was passed. The instruction causing the exception
49is indicated.
50\end{funcdesc}
51
52\begin{funcdesc}{disassemble}{code\optional{\, lasti}}
53Disassembles a code object, indicating the last instruction if \var{lasti}
54was provided. The output is divided in the following columns:
55\begin{itemize}
56\item the current instruction, indicated as \code{-->},
57\item a labelled instruction, indicated with \code{>>},
58\item the address of the instruction,
59\item the operation code name,
60\item operation parameters, and
61\item interpretation of the parameters in parentheses.
62\end{itemize}
63The parameter interpretation recognizes local and global
64variable names, constant values, branch targets, and compare
65operators.
66\end{funcdesc}
67
68\begin{funcdesc}{disco}{code\optional{\, lasti}}
69A synonym for disassemble. It is more convenient to type, and kept
70for compatibility with earlier Python releases.
71\end{funcdesc}
72
73\begin{datadesc}{opname}
74Sequence of a operation names, indexable using the byte code.
75\end{datadesc}
76
77\begin{datadesc}{cmp_op}
78Sequence of all compare operation names.
79\end{datadesc}
80
81\begin{datadesc}{hasconst}
82Sequence of byte codes that have a constant parameter.
83\end{datadesc}
84
85\begin{datadesc}{hasname}
86Sequence of byte codes that access a attribute by name.
87\end{datadesc}
88
89\begin{datadesc}{hasjrel}
90Sequence of byte codes that have a relative jump target.
91\end{datadesc}
92
93\begin{datadesc}{hasjabs}
94Sequence of byte codes that have an absolute jump target.
95\end{datadesc}
96
97\begin{datadesc}{haslocal}
98Sequence of byte codes that access a a local variable.
99\end{datadesc}
100
101\begin{datadesc}{hascompare}
102Sequence of byte codes of boolean operations.
103\end{datadesc}
104
105\subsection{Python Byte Code Instructions}
106
107The Python compiler currently generates the following byte code
108instructions.
109
110\renewcommand{\indexsubitem}{(byte code insns)}
111
Fred Drake456035f1997-12-03 04:06:57 +0000112\begin{opcodedesc}{STOP_CODE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000113Indicates end-of-code to the compiler, not used by the interpreter.
Fred Drake456035f1997-12-03 04:06:57 +0000114\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000115
Fred Drake456035f1997-12-03 04:06:57 +0000116\begin{opcodedesc}{POP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000117Removes the top-of-stack (TOS) item.
Fred Drake456035f1997-12-03 04:06:57 +0000118\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000119
Fred Drake456035f1997-12-03 04:06:57 +0000120\begin{opcodedesc}{ROT_TWO}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000121Swaps the two top-most stack items.
Fred Drake456035f1997-12-03 04:06:57 +0000122\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000123
Fred Drake456035f1997-12-03 04:06:57 +0000124\begin{opcodedesc}{ROT_THREE}{}
125Lifts second and third stack item one position up, moves top down
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000126to position three.
Fred Drake456035f1997-12-03 04:06:57 +0000127\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000128
Fred Drake456035f1997-12-03 04:06:57 +0000129\begin{opcodedesc}{DUP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000130Duplicates the reference on top of the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000131\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000132
133Unary Operations take the top of the stack, apply the operation, and
134push the result back on the stack.
135
Fred Drake456035f1997-12-03 04:06:57 +0000136\begin{opcodedesc}{UNARY_POSITIVE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000137Implements \code{TOS = +TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000138\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000139
Fred Drake456035f1997-12-03 04:06:57 +0000140\begin{opcodedesc}{UNARY_NEG}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000141Implements \code{TOS = -TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000142\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000143
Fred Drake456035f1997-12-03 04:06:57 +0000144\begin{opcodedesc}{UNARY_NOT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000145Implements \code{TOS = not TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000146\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000147
Fred Drake456035f1997-12-03 04:06:57 +0000148\begin{opcodedesc}{UNARY_CONVERT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000149Implements \code{TOS = `TOS`}.
Fred Drake456035f1997-12-03 04:06:57 +0000150\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000151
Fred Drake456035f1997-12-03 04:06:57 +0000152\begin{opcodedesc}{UNARY_INVERT}{}
Guido van Rossume903aab1997-12-18 16:28:56 +0000153Implements \code{TOS = \~TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000154\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000155
156Binary operations remove the top of the stack (TOS) and the second top-most
157stack item (TOS1) from the stack. They perform the operation, and put the
158result back on the stack.
159
Fred Drake456035f1997-12-03 04:06:57 +0000160\begin{opcodedesc}{BINARY_POWER}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000161Implements \code{TOS = TOS1 ** TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000162\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000163
Fred Drake456035f1997-12-03 04:06:57 +0000164\begin{opcodedesc}{BINARY_MULTIPLY}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000165Implements \code{TOS = TOS1 * TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000166\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000167
Fred Drake456035f1997-12-03 04:06:57 +0000168\begin{opcodedesc}{BINARY_DIVIDE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000169Implements \code{TOS = TOS1 / TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000170\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000171
Fred Drake456035f1997-12-03 04:06:57 +0000172\begin{opcodedesc}{BINARY_MODULO}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000173Implements \code{TOS = TOS1 \% TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000174\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000175
Fred Drake456035f1997-12-03 04:06:57 +0000176\begin{opcodedesc}{BINARY_ADD}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000177Implements \code{TOS = TOS1 + TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000178\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000179
Fred Drake456035f1997-12-03 04:06:57 +0000180\begin{opcodedesc}{BINARY_SUBTRACT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000181Implements \code{TOS = TOS1 - TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000182\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000183
Fred Drake456035f1997-12-03 04:06:57 +0000184\begin{opcodedesc}{BINARY_SUBSCR}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000185Implements \code{TOS = TOS1[TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000186\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000187
Fred Drake456035f1997-12-03 04:06:57 +0000188\begin{opcodedesc}{BINARY_LSHIFT}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000189Implements \code{TOS = TOS1 << TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000190\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000191
Fred Drake456035f1997-12-03 04:06:57 +0000192\begin{opcodedesc}{BINARY_RSHIFT}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000193Implements \code{TOS = TOS1 >> TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000194\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000195
Fred Drake456035f1997-12-03 04:06:57 +0000196\begin{opcodedesc}{BINARY_AND}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000197Implements \code{TOS = TOS1 and TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000198\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000199
Fred Drake456035f1997-12-03 04:06:57 +0000200\begin{opcodedesc}{BINARY_XOR}{}
Fred Draked7feffd1997-12-29 20:02:55 +0000201Implements \code{TOS = TOS1 \^\ TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000202\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000203
Fred Drake456035f1997-12-03 04:06:57 +0000204\begin{opcodedesc}{BINARY_OR}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000205Implements \code{TOS = TOS1 or TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000206\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000207
208The slice opcodes take up to three parameters.
209
Fred Drake456035f1997-12-03 04:06:57 +0000210\begin{opcodedesc}{SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000211Implements \code{TOS = TOS[:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000212\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000213
Fred Drake456035f1997-12-03 04:06:57 +0000214\begin{opcodedesc}{SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000215Implements \code{TOS = TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000216\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000217
Fred Drake456035f1997-12-03 04:06:57 +0000218\begin{opcodedesc}{SLICE+2}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000219Implements \code{TOS = TOS1[:TOS1]}.
Fred Drake456035f1997-12-03 04:06:57 +0000220\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000221
Fred Drake456035f1997-12-03 04:06:57 +0000222\begin{opcodedesc}{SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000223Implements \code{TOS = TOS2[TOS1:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000224\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000225
226Slice assignment needs even an additional parameter. As any statement,
227they put nothing on the stack.
228
Fred Drake456035f1997-12-03 04:06:57 +0000229\begin{opcodedesc}{STORE_SLICE+0}{}
Fred Drake7381e281997-12-04 04:51:12 +0000230Implements \code{TOS[:] = TOS1}.
Fred Drake456035f1997-12-03 04:06:57 +0000231\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000232
Fred Drake456035f1997-12-03 04:06:57 +0000233\begin{opcodedesc}{STORE_SLICE+1}{}
Fred Drake7381e281997-12-04 04:51:12 +0000234Implements \code{TOS1[TOS:] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000235\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000236
Fred Drake456035f1997-12-03 04:06:57 +0000237\begin{opcodedesc}{STORE_SLICE+2}{}
Fred Drake7381e281997-12-04 04:51:12 +0000238Implements \code{TOS1[:TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000239\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000240
Fred Drake456035f1997-12-03 04:06:57 +0000241\begin{opcodedesc}{STORE_SLICE+3}{}
Fred Drake7381e281997-12-04 04:51:12 +0000242Implements \code{TOS2[TOS1:TOS] = TOS3}.
Fred Drake456035f1997-12-03 04:06:57 +0000243\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000244
Fred Drake456035f1997-12-03 04:06:57 +0000245\begin{opcodedesc}{DELETE_SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000246Implements \code{del TOS[:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000247\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000248
Fred Drake456035f1997-12-03 04:06:57 +0000249\begin{opcodedesc}{DELETE_SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000250Implements \code{del TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000251\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000252
Fred Drake456035f1997-12-03 04:06:57 +0000253\begin{opcodedesc}{DELETE_SLICE+2}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000254Implements \code{del TOS1[:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000255\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000256
Fred Drake456035f1997-12-03 04:06:57 +0000257\begin{opcodedesc}{DELETE_SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000258Implements \code{del TOS2[TOS1:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000259\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000260
Fred Drake456035f1997-12-03 04:06:57 +0000261\begin{opcodedesc}{STORE_SUBSCR}{}
Fred Drake7381e281997-12-04 04:51:12 +0000262Implements \code{TOS1[TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000263\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000264
Fred Drake456035f1997-12-03 04:06:57 +0000265\begin{opcodedesc}{DELETE_SUBSCR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000266Implements \code{del TOS1[TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000267\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000268
Fred Drake456035f1997-12-03 04:06:57 +0000269\begin{opcodedesc}{PRINT_EXPR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000270Implements the expression statement for the interactive mode. TOS is
271removed from the stack and printed. In non-interactive mode, an
Fred Drake456035f1997-12-03 04:06:57 +0000272expression statement is terminated with \code{POP_STACK}.
273\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000274
Fred Drake456035f1997-12-03 04:06:57 +0000275\begin{opcodedesc}{PRINT_ITEM}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000276Prints TOS. There is one such instruction for
277each item in the print statement.
Fred Drake456035f1997-12-03 04:06:57 +0000278\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000279
Fred Drake456035f1997-12-03 04:06:57 +0000280\begin{opcodedesc}{PRINT_NEWLINE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000281Prints a new line on \code{sys.stdout}. This is generated as the
282last operation of a print statement, unless the statement ends
283with a comma.
Fred Drake456035f1997-12-03 04:06:57 +0000284\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000285
Fred Drake456035f1997-12-03 04:06:57 +0000286\begin{opcodedesc}{BREAK_LOOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000287Terminates a loop due to a break statement.
Fred Drake456035f1997-12-03 04:06:57 +0000288\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000289
Fred Drake456035f1997-12-03 04:06:57 +0000290\begin{opcodedesc}{LOAD_LOCALS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000291Pushes a reference to the locals of the current scope on the stack.
292This is used in the code for a class definition: After the class body
293is evaluated, the locals are passed to the class definition.
Fred Drake456035f1997-12-03 04:06:57 +0000294\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000295
Fred Drake456035f1997-12-03 04:06:57 +0000296\begin{opcodedesc}{RETURN_VALUE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000297Returns with TOS to the caller of the function.
Fred Drake456035f1997-12-03 04:06:57 +0000298\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000299
Fred Drake456035f1997-12-03 04:06:57 +0000300\begin{opcodedesc}{EXEC_STMT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000301Implements \code{exec TOS2,TOS1,TOS}. The compiler fills
302missing optional parameters with None.
Fred Drake456035f1997-12-03 04:06:57 +0000303\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000304
Fred Drake456035f1997-12-03 04:06:57 +0000305\begin{opcodedesc}{POP_BLOCK}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000306Removes one block from the block stack. Per frame, there is a
307stack of blocks, denoting nested loops, try statements, and such.
Fred Drake456035f1997-12-03 04:06:57 +0000308\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000309
Fred Drake456035f1997-12-03 04:06:57 +0000310\begin{opcodedesc}{END_FINALLY}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000311Terminates a finally-block. The interpreter recalls whether the
312exception has to be re-raised, or whether the function returns,
313and continues with the outer-next block.
Fred Drake456035f1997-12-03 04:06:57 +0000314\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000315
Fred Drake456035f1997-12-03 04:06:57 +0000316\begin{opcodedesc}{BUILD_CLASS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000317Creates a new class object. TOS is the methods dictionary, TOS1
318the tuple of the names of the base classes, and TOS2 the class name.
Fred Drake456035f1997-12-03 04:06:57 +0000319\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000320
321All of the following opcodes expect arguments. An argument is two
322bytes, with the more significant byte last.
323
Fred Drake456035f1997-12-03 04:06:57 +0000324\begin{opcodedesc}{STORE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000325Implements \code{name = TOS}. \var{namei} is the index of \var{name}
326in the attribute \code{co_names} of the code object.
Fred Drake456035f1997-12-03 04:06:57 +0000327The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL}
328if possible.
329\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000330
Fred Drake456035f1997-12-03 04:06:57 +0000331\begin{opcodedesc}{DELETE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000332Implements \code{del name}, where \var{namei} is the index into
333\code{co_names} attribute of the code object.
Fred Drake456035f1997-12-03 04:06:57 +0000334\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000335
Fred Drake456035f1997-12-03 04:06:57 +0000336\begin{opcodedesc}{UNPACK_TUPLE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000337Unpacks TOS into \var{count} individual values, which are put onto
338the stack right-to-left.
Fred Drake456035f1997-12-03 04:06:57 +0000339\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000340
Fred Drake456035f1997-12-03 04:06:57 +0000341\begin{opcodedesc}{UNPACK_LIST}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000342Unpacks TOS into \var{count} individual values.
Fred Drake456035f1997-12-03 04:06:57 +0000343\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000344
Fred Drake456035f1997-12-03 04:06:57 +0000345%\begin{opcodedesc}{UNPACK_ARG}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000346%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000347%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000348
Fred Drake456035f1997-12-03 04:06:57 +0000349\begin{opcodedesc}{STORE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000350Implements \code{TOS.name = TOS1}, where \var{namei} is the index
351of name in \code{co_names}.
Fred Drake456035f1997-12-03 04:06:57 +0000352\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000353
Fred Drake456035f1997-12-03 04:06:57 +0000354\begin{opcodedesc}{DELETE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000355Implements \code{del TOS.name}, using \var{namei} as index into
356\code{co_names}.
Fred Drake456035f1997-12-03 04:06:57 +0000357\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000358
Fred Drake456035f1997-12-03 04:06:57 +0000359\begin{opcodedesc}{STORE_GLOBAL}{namei}
360Works as \code{STORE_NAME}, but stores the name as a global.
361\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000362
Fred Drake456035f1997-12-03 04:06:57 +0000363\begin{opcodedesc}{DELETE_GLOBAL}{namei}
364Works as \code{DELETE_NAME}, but deletes a global name.
365\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000366
Fred Drake456035f1997-12-03 04:06:57 +0000367%\begin{opcodedesc}{UNPACK_VARARG}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000368%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000369%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000370
Fred Drake456035f1997-12-03 04:06:57 +0000371\begin{opcodedesc}{LOAD_CONST}{consti}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000372Pushes \code{co_consts[consti]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000373\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000374
Fred Drake456035f1997-12-03 04:06:57 +0000375\begin{opcodedesc}{LOAD_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000376Pushes the value associated with \code{co_names[namei]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000377\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000378
Fred Drake456035f1997-12-03 04:06:57 +0000379\begin{opcodedesc}{BUILD_TUPLE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000380Creates a tuple consuming \var{count} items from the stack, and pushes
381the resulting tuple onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000382\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000383
Fred Drake456035f1997-12-03 04:06:57 +0000384\begin{opcodedesc}{BUILD_LIST}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000385Works as \code{BUILD_TUPLE}, but creates a list.
Fred Drake456035f1997-12-03 04:06:57 +0000386\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000387
Fred Drake456035f1997-12-03 04:06:57 +0000388\begin{opcodedesc}{BUILD_MAP}{zero}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000389Pushes an empty dictionary object onto the stack. The argument is ignored
390and set to zero by the compiler.
Fred Drake456035f1997-12-03 04:06:57 +0000391\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000392
Fred Drake456035f1997-12-03 04:06:57 +0000393\begin{opcodedesc}{LOAD_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000394Replaces TOS with \code{getattr(TOS,co_names[namei]}.
Fred Drake456035f1997-12-03 04:06:57 +0000395\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000396
Fred Drake456035f1997-12-03 04:06:57 +0000397\begin{opcodedesc}{COMPARE_OP}{opname}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000398Performs a boolean operation. The operation name can be found
399in \code{cmp_op[opname]}.
Fred Drake456035f1997-12-03 04:06:57 +0000400\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000401
Fred Drake456035f1997-12-03 04:06:57 +0000402\begin{opcodedesc}{IMPORT_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000403Imports the module \code{co_names[namei]}. The module object is
404pushed onto the stack. The current name space is not affect: for a
405proper import statement, a subsequent \code{STORE_FAST} instruction
406modifies the name space.
Fred Drake456035f1997-12-03 04:06:57 +0000407\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000408
Fred Drake456035f1997-12-03 04:06:57 +0000409\begin{opcodedesc}{IMPORT_FROM}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000410Imports the attribute \code{co_names[namei]}. The module to import
411from is found in TOS and left there.
Fred Drake456035f1997-12-03 04:06:57 +0000412\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000413
Fred Drake456035f1997-12-03 04:06:57 +0000414\begin{opcodedesc}{JUMP_FORWARD}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000415Increments byte code counter by \var{delta}.
Fred Drake456035f1997-12-03 04:06:57 +0000416\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000417
Fred Drake456035f1997-12-03 04:06:57 +0000418\begin{opcodedesc}{JUMP_IF_TRUE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000419If TOS is true, increment the byte code counter by \var{delta}. TOS is
420left on the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000421\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000422
Fred Drake456035f1997-12-03 04:06:57 +0000423\begin{opcodedesc}{JUMP_IF_FALSE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000424If TOS is false, increment the byte code counter by \var{delta}. TOS
425is not changed.
Fred Drake456035f1997-12-03 04:06:57 +0000426\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000427
Fred Drake456035f1997-12-03 04:06:57 +0000428\begin{opcodedesc}{JUMP_ABSOLUTE}{target}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000429Set byte code counter to \var{target}.
Fred Drake456035f1997-12-03 04:06:57 +0000430\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000431
Fred Drake456035f1997-12-03 04:06:57 +0000432\begin{opcodedesc}{FOR_LOOP}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000433Iterate over a sequence. TOS is the current index, TOS1 the sequence.
434First, the next element is computed. If the sequence is exhausted,
435increment byte code counter by \var{delta}. Otherwise, push the
436sequence, the incremented counter, and the current item onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000437\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000438
Fred Drake456035f1997-12-03 04:06:57 +0000439%\begin{opcodedesc}{LOAD_LOCAL}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000440%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000441%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000442
Fred Drake456035f1997-12-03 04:06:57 +0000443\begin{opcodedesc}{LOAD_GLOBAL}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000444Loads the global named \code{co_names[namei]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000445\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000446
Fred Drake456035f1997-12-03 04:06:57 +0000447%\begin{opcodedesc}{SET_FUNC_ARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000448%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000449%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000450
Fred Drake456035f1997-12-03 04:06:57 +0000451\begin{opcodedesc}{SETUP_LOOP}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000452Pushes a block for a loop onto the block stack. The block spans
453from the current instruction with a size of \var{delta} bytes.
Fred Drake456035f1997-12-03 04:06:57 +0000454\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000455
Fred Drake456035f1997-12-03 04:06:57 +0000456\begin{opcodedesc}{SETUP_EXCEPT}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000457Pushes a try block from a try-except clause onto the block stack.
458\var{delta} points to the first except block.
Fred Drake456035f1997-12-03 04:06:57 +0000459\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000460
Fred Drake456035f1997-12-03 04:06:57 +0000461\begin{opcodedesc}{SETUP_FINALLY}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000462Pushes a try block from a try-except clause onto the block stack.
463\var{delta} points to the finally block.
Fred Drake456035f1997-12-03 04:06:57 +0000464\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000465
Fred Drake456035f1997-12-03 04:06:57 +0000466\begin{opcodedesc}{LOAD_FAST}{var_num}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000467Pushes a reference to the local \code{co_varnames[var_num]} onto
468the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000469\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000470
Fred Drake456035f1997-12-03 04:06:57 +0000471\begin{opcodedesc}{STORE_FAST}{var_num}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000472Stores TOS into the local \code{co_varnames[var_num]}.
Fred Drake456035f1997-12-03 04:06:57 +0000473\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000474
Fred Drake456035f1997-12-03 04:06:57 +0000475\begin{opcodedesc}{DELETE_FAST}{var_num}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000476Deletes local \code{co_varnames[var_num]}.
Fred Drake456035f1997-12-03 04:06:57 +0000477\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000478
Fred Drake456035f1997-12-03 04:06:57 +0000479\begin{opcodedesc}{SET_LINE_NO}{lineno}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000480Sets the current line number to \var{lineno}.
Fred Drake456035f1997-12-03 04:06:57 +0000481\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000482
Fred Drake456035f1997-12-03 04:06:57 +0000483\begin{opcodedesc}{RAISE_VARARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000484Raises an exception. \var{argc} indicates the number of parameters
485to the raise statement, ranging from 1 to 3. The handler will find
486the traceback as TOS2, the parameter as TOS1, and the exception
487as TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000488\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000489
Fred Drake456035f1997-12-03 04:06:57 +0000490\begin{opcodedesc}{CALL_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000491Calls a function. The low byte of \var{argc} indicates the number of
492positional parameters, the high byte the number of keyword parameters.
493On the stack, the opcode finds the keyword parameters first. For each
494keyword argument, the value is on top of the key. Below the keyword
495parameters, the positional parameters are on the stack, with the
496right-most parameter on top. Below the parameters, the function object
497to call is on the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000498\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000499
Fred Drake456035f1997-12-03 04:06:57 +0000500\begin{opcodedesc}{MAKE_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000501Pushes a new function object on the stack. TOS is the code associated
502with the function. The function object is defined to have \var{argc}
503default parameters, which are found below TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000504\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000505
Fred Drake456035f1997-12-03 04:06:57 +0000506\begin{opcodedesc}{BUILD_SLICE}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000507Pushes a slice object on the stack. If \var{argc} is three, creates
508\code{TOS3[TOS2:TOS1:TOS]}. Otherwise, expects three arguments.
Fred Drake456035f1997-12-03 04:06:57 +0000509\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000510
511