blob: 67691b709b1683c02f606acd1650e775878a51b4 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{dis} ---
Fred Drakef8ca7d82000-10-10 17:03:45 +00002 Disassembler for Python byte code}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakef8ca7d82000-10-10 17:03:45 +00004\declaremodule{standard}{dis}
Fred Drake2c4f5542000-10-10 22:00:03 +00005\modulesynopsis{Disassembler for Python byte code.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Guido van Rossumb62b6d11997-11-18 15:10:53 +00007
Fred Drakedff21a61998-04-03 05:42:10 +00008The \module{dis} module supports the analysis of Python byte code by
Guido van Rossumb62b6d11997-11-18 15:10:53 +00009disassembling it. Since there is no Python assembler, this module
10defines the Python assembly language. The Python byte code which
11this module takes as an input is defined in the file
Fred Drake456035f1997-12-03 04:06:57 +000012\file{Include/opcode.h} and used by the compiler and the interpreter.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000013
Fred Drakedff21a61998-04-03 05:42:10 +000014Example: Given the function \function{myfunc}:
Guido van Rossumb62b6d11997-11-18 15:10:53 +000015
Fred Drake19479911998-02-13 06:58:54 +000016\begin{verbatim}
Guido van Rossumb62b6d11997-11-18 15:10:53 +000017def myfunc(alist):
Fred Drakedff21a61998-04-03 05:42:10 +000018 return len(alist)
Fred Drake19479911998-02-13 06:58:54 +000019\end{verbatim}
Guido van Rossumb62b6d11997-11-18 15:10:53 +000020
Fred Drakedff21a61998-04-03 05:42:10 +000021the following command can be used to get the disassembly of
22\function{myfunc()}:
Guido van Rossumb62b6d11997-11-18 15:10:53 +000023
24\begin{verbatim}
25>>> dis.dis(myfunc)
Michael W. Hudsondd32a912002-08-15 14:59:02 +000026 2 0 LOAD_GLOBAL 0 (len)
27 3 LOAD_FAST 0 (alist)
28 6 CALL_FUNCTION 1
Raymond Hettingerbc2c21e2005-02-23 20:40:42 +000029 9 RETURN_VALUE
Guido van Rossumb62b6d11997-11-18 15:10:53 +000030\end{verbatim}
31
Michael W. Hudsondd32a912002-08-15 14:59:02 +000032(The ``2'' is a line number).
33
Fred Drake2c4f5542000-10-10 22:00:03 +000034The \module{dis} module defines the following functions and constants:
Guido van Rossumb62b6d11997-11-18 15:10:53 +000035
Guido van Rossumb62b6d11997-11-18 15:10:53 +000036\begin{funcdesc}{dis}{\optional{bytesource}}
37Disassemble the \var{bytesource} object. \var{bytesource} can denote
Neal Norwitzdcd05002002-06-26 22:32:47 +000038either a module, a class, a method, a function, or a code object.
39For a module, it disassembles all functions. For a class,
Guido van Rossumb62b6d11997-11-18 15:10:53 +000040it disassembles all methods. For a single code sequence, it prints
41one line per byte code instruction. If no object is provided, it
42disassembles the last traceback.
43\end{funcdesc}
44
45\begin{funcdesc}{distb}{\optional{tb}}
46Disassembles the top-of-stack function of a traceback, using the last
47traceback if none was passed. The instruction causing the exception
48is indicated.
49\end{funcdesc}
50
Fred Drakecce10901998-03-17 06:33:25 +000051\begin{funcdesc}{disassemble}{code\optional{, lasti}}
Guido van Rossumb62b6d11997-11-18 15:10:53 +000052Disassembles a code object, indicating the last instruction if \var{lasti}
53was provided. The output is divided in the following columns:
Fred Drake810349b1998-04-07 14:16:41 +000054
Fred Drake3e7a48e1998-04-13 16:15:02 +000055\begin{enumerate}
Michael W. Hudsondd32a912002-08-15 14:59:02 +000056\item the line number, for the first instruction of each line
Fred Drakedff21a61998-04-03 05:42:10 +000057\item the current instruction, indicated as \samp{-->},
Fred Drakec054c752001-04-13 17:25:38 +000058\item a labelled instruction, indicated with \samp{>\code{>}},
Guido van Rossumb62b6d11997-11-18 15:10:53 +000059\item the address of the instruction,
60\item the operation code name,
61\item operation parameters, and
62\item interpretation of the parameters in parentheses.
Fred Drake3e7a48e1998-04-13 16:15:02 +000063\end{enumerate}
Fred Drake810349b1998-04-07 14:16:41 +000064
Guido van Rossumb62b6d11997-11-18 15:10:53 +000065The parameter interpretation recognizes local and global
66variable names, constant values, branch targets, and compare
67operators.
68\end{funcdesc}
69
Fred Drakecce10901998-03-17 06:33:25 +000070\begin{funcdesc}{disco}{code\optional{, lasti}}
Guido van Rossumb62b6d11997-11-18 15:10:53 +000071A synonym for disassemble. It is more convenient to type, and kept
72for compatibility with earlier Python releases.
73\end{funcdesc}
74
75\begin{datadesc}{opname}
Fred Drake2c4f5542000-10-10 22:00:03 +000076Sequence of operation names, indexable using the byte code.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000077\end{datadesc}
78
Skip Montanarobecbdec2005-01-05 07:19:11 +000079\begin{datadesc}{opmap}
80Dictionary mapping byte codes to operation names.
81\end{datadesc}
82
Guido van Rossumb62b6d11997-11-18 15:10:53 +000083\begin{datadesc}{cmp_op}
84Sequence of all compare operation names.
85\end{datadesc}
86
87\begin{datadesc}{hasconst}
88Sequence of byte codes that have a constant parameter.
89\end{datadesc}
90
Fred Drake47cdf6f2002-03-28 19:34:53 +000091\begin{datadesc}{hasfree}
92Sequence of byte codes that access a free variable.
93\end{datadesc}
94
Guido van Rossumb62b6d11997-11-18 15:10:53 +000095\begin{datadesc}{hasname}
Fred Drake2c4f5542000-10-10 22:00:03 +000096Sequence of byte codes that access an attribute by name.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000097\end{datadesc}
98
99\begin{datadesc}{hasjrel}
100Sequence of byte codes that have a relative jump target.
101\end{datadesc}
102
103\begin{datadesc}{hasjabs}
104Sequence of byte codes that have an absolute jump target.
105\end{datadesc}
106
107\begin{datadesc}{haslocal}
Fred Drake2c4f5542000-10-10 22:00:03 +0000108Sequence of byte codes that access a local variable.
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000109\end{datadesc}
110
111\begin{datadesc}{hascompare}
Fred Drake6c81e2a2001-10-01 17:04:10 +0000112Sequence of byte codes of Boolean operations.
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000113\end{datadesc}
114
115\subsection{Python Byte Code Instructions}
Fred Drake83efb541998-02-19 20:07:39 +0000116\label{bytecodes}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000117
118The Python compiler currently generates the following byte code
119instructions.
120
Fred Drake19479911998-02-13 06:58:54 +0000121\setindexsubitem{(byte code insns)}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000122
Fred Drake456035f1997-12-03 04:06:57 +0000123\begin{opcodedesc}{STOP_CODE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000124Indicates end-of-code to the compiler, not used by the interpreter.
Fred Drake456035f1997-12-03 04:06:57 +0000125\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000126
Raymond Hettinger2b0d0582005-02-21 20:28:07 +0000127\begin{opcodedesc}{NOP}{}
128Do nothing code. Used as a placeholder by the bytecode optimizer.
129\end{opcodedesc}
130
Fred Drake456035f1997-12-03 04:06:57 +0000131\begin{opcodedesc}{POP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000132Removes the top-of-stack (TOS) item.
Fred Drake456035f1997-12-03 04:06:57 +0000133\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000134
Fred Drake456035f1997-12-03 04:06:57 +0000135\begin{opcodedesc}{ROT_TWO}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000136Swaps the two top-most stack items.
Fred Drake456035f1997-12-03 04:06:57 +0000137\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000138
Fred Drake456035f1997-12-03 04:06:57 +0000139\begin{opcodedesc}{ROT_THREE}{}
140Lifts second and third stack item one position up, moves top down
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000141to position three.
Fred Drake456035f1997-12-03 04:06:57 +0000142\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000143
Thomas Wouters12bba852000-08-24 20:06:04 +0000144\begin{opcodedesc}{ROT_FOUR}{}
145Lifts second, third and forth stack item one position up, moves top down to
146position four.
147\end{opcodedesc}
148
Fred Drake456035f1997-12-03 04:06:57 +0000149\begin{opcodedesc}{DUP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000150Duplicates the reference on top of the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000151\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000152
153Unary Operations take the top of the stack, apply the operation, and
154push the result back on the stack.
155
Fred Drake456035f1997-12-03 04:06:57 +0000156\begin{opcodedesc}{UNARY_POSITIVE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000157Implements \code{TOS = +TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000158\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000159
Fred Drake4c3f7972000-08-31 16:26:35 +0000160\begin{opcodedesc}{UNARY_NEGATIVE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000161Implements \code{TOS = -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}{UNARY_NOT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000165Implements \code{TOS = not 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}{UNARY_CONVERT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000169Implements \code{TOS = `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}{UNARY_INVERT}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000173Implements \code{TOS = \~{}TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000174\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000175
Guido van Rossume3fdc972002-06-12 15:33:08 +0000176\begin{opcodedesc}{GET_ITER}{}
177Implements \code{TOS = iter(TOS)}.
178\end{opcodedesc}
179
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000180Binary operations remove the top of the stack (TOS) and the second top-most
181stack item (TOS1) from the stack. They perform the operation, and put the
182result back on the stack.
183
Fred Drake456035f1997-12-03 04:06:57 +0000184\begin{opcodedesc}{BINARY_POWER}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +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_MULTIPLY}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +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_DIVIDE}{}
Guido van Rossume3fdc972002-06-12 15:33:08 +0000193Implements \code{TOS = TOS1 / TOS} when
194\code{from __future__ import division} is not in effect.
195\end{opcodedesc}
196
197\begin{opcodedesc}{BINARY_FLOOR_DIVIDE}{}
198Implements \code{TOS = TOS1 // TOS}.
199\end{opcodedesc}
200
201\begin{opcodedesc}{BINARY_TRUE_DIVIDE}{}
202Implements \code{TOS = TOS1 / TOS} when
203\code{from __future__ import division} is in effect.
Fred Drake456035f1997-12-03 04:06:57 +0000204\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000205
Fred Drake456035f1997-12-03 04:06:57 +0000206\begin{opcodedesc}{BINARY_MODULO}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000207Implements \code{TOS = TOS1 \%{} TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000208\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000209
Fred Drake456035f1997-12-03 04:06:57 +0000210\begin{opcodedesc}{BINARY_ADD}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000211Implements \code{TOS = TOS1 + 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}{BINARY_SUBTRACT}{}
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}{BINARY_SUBSCR}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000219Implements \code{TOS = TOS1[TOS]}.
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}{BINARY_LSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000223Implements \code{TOS = TOS1 <\code{}< TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000224\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000225
Fred Drake456035f1997-12-03 04:06:57 +0000226\begin{opcodedesc}{BINARY_RSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000227Implements \code{TOS = TOS1 >\code{}> TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000228\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000229
Fred Drake456035f1997-12-03 04:06:57 +0000230\begin{opcodedesc}{BINARY_AND}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000231Implements \code{TOS = TOS1 \&\ TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000232\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000233
Fred Drake456035f1997-12-03 04:06:57 +0000234\begin{opcodedesc}{BINARY_XOR}{}
Fred Draked7feffd1997-12-29 20:02:55 +0000235Implements \code{TOS = TOS1 \^\ TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000236\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000237
Fred Drake456035f1997-12-03 04:06:57 +0000238\begin{opcodedesc}{BINARY_OR}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000239Implements \code{TOS = TOS1 | TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000240\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000241
Thomas Wouters12bba852000-08-24 20:06:04 +0000242In-place operations are like binary operations, in that they remove TOS and
243TOS1, and push the result back on the stack, but the operation is done
244in-place when TOS1 supports it, and the resulting TOS may be (but does not
245have to be) the original TOS1.
246
247\begin{opcodedesc}{INPLACE_POWER}{}
248Implements in-place \code{TOS = TOS1 ** TOS}.
249\end{opcodedesc}
250
251\begin{opcodedesc}{INPLACE_MULTIPLY}{}
252Implements in-place \code{TOS = TOS1 * TOS}.
253\end{opcodedesc}
254
255\begin{opcodedesc}{INPLACE_DIVIDE}{}
Guido van Rossume3fdc972002-06-12 15:33:08 +0000256Implements in-place \code{TOS = TOS1 / TOS} when
257\code{from __future__ import division} is not in effect.
258\end{opcodedesc}
259
260\begin{opcodedesc}{INPLACE_FLOOR_DIVIDE}{}
261Implements in-place \code{TOS = TOS1 // TOS}.
262\end{opcodedesc}
263
264\begin{opcodedesc}{INPLACE_TRUE_DIVIDE}{}
265Implements in-place \code{TOS = TOS1 / TOS} when
266\code{from __future__ import division} is in effect.
Thomas Wouters12bba852000-08-24 20:06:04 +0000267\end{opcodedesc}
268
269\begin{opcodedesc}{INPLACE_MODULO}{}
270Implements in-place \code{TOS = TOS1 \%{} TOS}.
271\end{opcodedesc}
272
273\begin{opcodedesc}{INPLACE_ADD}{}
274Implements in-place \code{TOS = TOS1 + TOS}.
275\end{opcodedesc}
276
277\begin{opcodedesc}{INPLACE_SUBTRACT}{}
278Implements in-place \code{TOS = TOS1 - TOS}.
279\end{opcodedesc}
280
281\begin{opcodedesc}{INPLACE_LSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000282Implements in-place \code{TOS = TOS1 <\code{}< TOS}.
Thomas Wouters12bba852000-08-24 20:06:04 +0000283\end{opcodedesc}
284
285\begin{opcodedesc}{INPLACE_RSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000286Implements in-place \code{TOS = TOS1 >\code{}> TOS}.
Thomas Wouters12bba852000-08-24 20:06:04 +0000287\end{opcodedesc}
288
289\begin{opcodedesc}{INPLACE_AND}{}
290Implements in-place \code{TOS = TOS1 \&\ TOS}.
291\end{opcodedesc}
292
293\begin{opcodedesc}{INPLACE_XOR}{}
294Implements in-place \code{TOS = TOS1 \^\ TOS}.
295\end{opcodedesc}
296
297\begin{opcodedesc}{INPLACE_OR}{}
298Implements in-place \code{TOS = TOS1 | TOS}.
299\end{opcodedesc}
300
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000301The slice opcodes take up to three parameters.
302
Fred Drake456035f1997-12-03 04:06:57 +0000303\begin{opcodedesc}{SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000304Implements \code{TOS = TOS[:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000305\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000306
Fred Drake456035f1997-12-03 04:06:57 +0000307\begin{opcodedesc}{SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000308Implements \code{TOS = TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000309\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000310
Fred Drake456035f1997-12-03 04:06:57 +0000311\begin{opcodedesc}{SLICE+2}{}
Neal Norwitze72a9a12002-08-05 23:33:54 +0000312Implements \code{TOS = TOS1[:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000313\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000314
Fred Drake456035f1997-12-03 04:06:57 +0000315\begin{opcodedesc}{SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000316Implements \code{TOS = TOS2[TOS1:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000317\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000318
319Slice assignment needs even an additional parameter. As any statement,
320they put nothing on the stack.
321
Fred Drake456035f1997-12-03 04:06:57 +0000322\begin{opcodedesc}{STORE_SLICE+0}{}
Fred Drake7381e281997-12-04 04:51:12 +0000323Implements \code{TOS[:] = TOS1}.
Fred Drake456035f1997-12-03 04:06:57 +0000324\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000325
Fred Drake456035f1997-12-03 04:06:57 +0000326\begin{opcodedesc}{STORE_SLICE+1}{}
Fred Drake7381e281997-12-04 04:51:12 +0000327Implements \code{TOS1[TOS:] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000328\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000329
Fred Drake456035f1997-12-03 04:06:57 +0000330\begin{opcodedesc}{STORE_SLICE+2}{}
Fred Drake7381e281997-12-04 04:51:12 +0000331Implements \code{TOS1[:TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000332\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000333
Fred Drake456035f1997-12-03 04:06:57 +0000334\begin{opcodedesc}{STORE_SLICE+3}{}
Fred Drake7381e281997-12-04 04:51:12 +0000335Implements \code{TOS2[TOS1:TOS] = TOS3}.
Fred Drake456035f1997-12-03 04:06:57 +0000336\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000337
Fred Drake456035f1997-12-03 04:06:57 +0000338\begin{opcodedesc}{DELETE_SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000339Implements \code{del TOS[:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000340\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000341
Fred Drake456035f1997-12-03 04:06:57 +0000342\begin{opcodedesc}{DELETE_SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000343Implements \code{del TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000344\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000345
Fred Drake456035f1997-12-03 04:06:57 +0000346\begin{opcodedesc}{DELETE_SLICE+2}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000347Implements \code{del TOS1[:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000348\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000349
Fred Drake456035f1997-12-03 04:06:57 +0000350\begin{opcodedesc}{DELETE_SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000351Implements \code{del TOS2[TOS1:TOS]}.
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}{STORE_SUBSCR}{}
Fred Drake7381e281997-12-04 04:51:12 +0000355Implements \code{TOS1[TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000356\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000357
Fred Drake456035f1997-12-03 04:06:57 +0000358\begin{opcodedesc}{DELETE_SUBSCR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000359Implements \code{del TOS1[TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000360\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000361
Guido van Rossume3fdc972002-06-12 15:33:08 +0000362Miscellaneous opcodes.
363
Fred Drake456035f1997-12-03 04:06:57 +0000364\begin{opcodedesc}{PRINT_EXPR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000365Implements the expression statement for the interactive mode. TOS is
366removed from the stack and printed. In non-interactive mode, an
Fred Drake456035f1997-12-03 04:06:57 +0000367expression statement is terminated with \code{POP_STACK}.
368\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000369
Fred Drake456035f1997-12-03 04:06:57 +0000370\begin{opcodedesc}{PRINT_ITEM}{}
Barry Warsaw90876882000-08-21 17:19:00 +0000371Prints TOS to the file-like object bound to \code{sys.stdout}. There
372is one such instruction for each item in the \keyword{print} statement.
373\end{opcodedesc}
374
375\begin{opcodedesc}{PRINT_ITEM_TO}{}
376Like \code{PRINT_ITEM}, but prints the item second from TOS to the
377file-like object at TOS. This is used by the extended print statement.
Fred Drake456035f1997-12-03 04:06:57 +0000378\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000379
Fred Drake456035f1997-12-03 04:06:57 +0000380\begin{opcodedesc}{PRINT_NEWLINE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000381Prints a new line on \code{sys.stdout}. This is generated as the
Fred Drake304faf92000-08-18 02:15:55 +0000382last operation of a \keyword{print} statement, unless the statement
383ends with a comma.
Fred Drake456035f1997-12-03 04:06:57 +0000384\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000385
Barry Warsaw90876882000-08-21 17:19:00 +0000386\begin{opcodedesc}{PRINT_NEWLINE_TO}{}
387Like \code{PRINT_NEWLINE}, but prints the new line on the file-like
388object on the TOS. This is used by the extended print statement.
389\end{opcodedesc}
390
Fred Drake456035f1997-12-03 04:06:57 +0000391\begin{opcodedesc}{BREAK_LOOP}{}
Fred Drake304faf92000-08-18 02:15:55 +0000392Terminates a loop due to a \keyword{break} statement.
Fred Drake456035f1997-12-03 04:06:57 +0000393\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000394
Guido van Rossume3fdc972002-06-12 15:33:08 +0000395\begin{opcodedesc}{CONTINUE_LOOP}{target}
396Continues a loop due to a \keyword{continue} statement. \var{target}
397is the address to jump to (which should be a \code{FOR_ITER}
398instruction).
399\end{opcodedesc}
400
Raymond Hettinger2b0d0582005-02-21 20:28:07 +0000401\begin{opcodedesc}{LIST_APPEND}{}
402Calls \code{list.append(TOS1, TOS)}. Used to implement list comprehensions.
403\end{opcodedesc}
404
Fred Drake456035f1997-12-03 04:06:57 +0000405\begin{opcodedesc}{LOAD_LOCALS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000406Pushes a reference to the locals of the current scope on the stack.
407This is used in the code for a class definition: After the class body
408is evaluated, the locals are passed to the class definition.
Fred Drake456035f1997-12-03 04:06:57 +0000409\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000410
Fred Drake456035f1997-12-03 04:06:57 +0000411\begin{opcodedesc}{RETURN_VALUE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000412Returns with TOS to the caller of the function.
Fred Drake456035f1997-12-03 04:06:57 +0000413\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000414
Guido van Rossume3fdc972002-06-12 15:33:08 +0000415\begin{opcodedesc}{YIELD_VALUE}{}
416Pops \code{TOS} and yields it from a generator.
417\end{opcodedesc}
418
Thomas Wouters52152252000-08-17 22:55:00 +0000419\begin{opcodedesc}{IMPORT_STAR}{}
Fred Drake304faf92000-08-18 02:15:55 +0000420Loads all symbols not starting with \character{_} directly from the module TOS
Thomas Wouters52152252000-08-17 22:55:00 +0000421to the local namespace. The module is popped after loading all names.
Fred Drake304faf92000-08-18 02:15:55 +0000422This opcode implements \code{from module import *}.
423\end{opcodedesc}
Thomas Wouters52152252000-08-17 22:55:00 +0000424
Fred Drake456035f1997-12-03 04:06:57 +0000425\begin{opcodedesc}{EXEC_STMT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000426Implements \code{exec TOS2,TOS1,TOS}. The compiler fills
Fred Drake304faf92000-08-18 02:15:55 +0000427missing optional parameters with \code{None}.
Fred Drake456035f1997-12-03 04:06:57 +0000428\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000429
Fred Drake456035f1997-12-03 04:06:57 +0000430\begin{opcodedesc}{POP_BLOCK}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000431Removes one block from the block stack. Per frame, there is a
432stack of blocks, denoting nested loops, try statements, and such.
Fred Drake456035f1997-12-03 04:06:57 +0000433\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000434
Fred Drake456035f1997-12-03 04:06:57 +0000435\begin{opcodedesc}{END_FINALLY}{}
Fred Drake304faf92000-08-18 02:15:55 +0000436Terminates a \keyword{finally} clause. The interpreter recalls
437whether the exception has to be re-raised, or whether the function
438returns, and continues with the outer-next block.
Fred Drake456035f1997-12-03 04:06:57 +0000439\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000440
Fred Drake456035f1997-12-03 04:06:57 +0000441\begin{opcodedesc}{BUILD_CLASS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000442Creates a new class object. TOS is the methods dictionary, TOS1
443the tuple of the names of the base classes, and TOS2 the class name.
Fred Drake456035f1997-12-03 04:06:57 +0000444\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000445
446All of the following opcodes expect arguments. An argument is two
447bytes, with the more significant byte last.
448
Fred Drake456035f1997-12-03 04:06:57 +0000449\begin{opcodedesc}{STORE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000450Implements \code{name = TOS}. \var{namei} is the index of \var{name}
Fred Drakedff21a61998-04-03 05:42:10 +0000451in the attribute \member{co_names} of the code object.
Fred Drake456035f1997-12-03 04:06:57 +0000452The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL}
453if possible.
454\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000455
Fred Drake456035f1997-12-03 04:06:57 +0000456\begin{opcodedesc}{DELETE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000457Implements \code{del name}, where \var{namei} is the index into
Fred Drakedff21a61998-04-03 05:42:10 +0000458\member{co_names} attribute of the code object.
Fred Drake456035f1997-12-03 04:06:57 +0000459\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000460
Thomas Wouters0be5aab2000-08-11 22:15:52 +0000461\begin{opcodedesc}{UNPACK_SEQUENCE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000462Unpacks TOS into \var{count} individual values, which are put onto
463the stack right-to-left.
Fred Drake456035f1997-12-03 04:06:57 +0000464\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000465
Thomas Wouters0be5aab2000-08-11 22:15:52 +0000466%\begin{opcodedesc}{UNPACK_LIST}{count}
467%This opcode is obsolete.
468%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000469
Fred Drake456035f1997-12-03 04:06:57 +0000470%\begin{opcodedesc}{UNPACK_ARG}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000471%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000472%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000473
Thomas Wouters12bba852000-08-24 20:06:04 +0000474\begin{opcodedesc}{DUP_TOPX}{count}
475Duplicate \var{count} items, keeping them in the same order. Due to
476implementation limits, \var{count} should be between 1 and 5 inclusive.
477\end{opcodedesc}
478
Fred Drake456035f1997-12-03 04:06:57 +0000479\begin{opcodedesc}{STORE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000480Implements \code{TOS.name = TOS1}, where \var{namei} is the index
Fred Drakedff21a61998-04-03 05:42:10 +0000481of name in \member{co_names}.
Fred Drake456035f1997-12-03 04:06:57 +0000482\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000483
Fred Drake456035f1997-12-03 04:06:57 +0000484\begin{opcodedesc}{DELETE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000485Implements \code{del TOS.name}, using \var{namei} as index into
Fred Drakedff21a61998-04-03 05:42:10 +0000486\member{co_names}.
Fred Drake456035f1997-12-03 04:06:57 +0000487\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000488
Fred Drake456035f1997-12-03 04:06:57 +0000489\begin{opcodedesc}{STORE_GLOBAL}{namei}
490Works as \code{STORE_NAME}, but stores the name as a global.
491\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000492
Fred Drake456035f1997-12-03 04:06:57 +0000493\begin{opcodedesc}{DELETE_GLOBAL}{namei}
494Works as \code{DELETE_NAME}, but deletes a global name.
495\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000496
Fred Drake456035f1997-12-03 04:06:57 +0000497%\begin{opcodedesc}{UNPACK_VARARG}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000498%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000499%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000500
Fred Drake456035f1997-12-03 04:06:57 +0000501\begin{opcodedesc}{LOAD_CONST}{consti}
Fred Drakedff21a61998-04-03 05:42:10 +0000502Pushes \samp{co_consts[\var{consti}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000503\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000504
Fred Drake456035f1997-12-03 04:06:57 +0000505\begin{opcodedesc}{LOAD_NAME}{namei}
Fred Drakedff21a61998-04-03 05:42:10 +0000506Pushes the value associated with \samp{co_names[\var{namei}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000507\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000508
Fred Drake456035f1997-12-03 04:06:57 +0000509\begin{opcodedesc}{BUILD_TUPLE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000510Creates a tuple consuming \var{count} items from the stack, and pushes
511the resulting tuple onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000512\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000513
Fred Drake456035f1997-12-03 04:06:57 +0000514\begin{opcodedesc}{BUILD_LIST}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000515Works as \code{BUILD_TUPLE}, but creates a list.
Fred Drake456035f1997-12-03 04:06:57 +0000516\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000517
Fred Drake456035f1997-12-03 04:06:57 +0000518\begin{opcodedesc}{BUILD_MAP}{zero}
Fred Drake304faf92000-08-18 02:15:55 +0000519Pushes a new empty dictionary object onto the stack. The argument is
520ignored and set to zero by the compiler.
Fred Drake456035f1997-12-03 04:06:57 +0000521\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000522
Fred Drake456035f1997-12-03 04:06:57 +0000523\begin{opcodedesc}{LOAD_ATTR}{namei}
Raymond Hettingerb4c1d9b2003-05-10 08:51:28 +0000524Replaces TOS with \code{getattr(TOS, co_names[\var{namei}])}.
Fred Drake456035f1997-12-03 04:06:57 +0000525\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000526
Fred Drake456035f1997-12-03 04:06:57 +0000527\begin{opcodedesc}{COMPARE_OP}{opname}
Fred Drake6c81e2a2001-10-01 17:04:10 +0000528Performs a Boolean operation. The operation name can be found
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000529in \code{cmp_op[\var{opname}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000530\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000531
Fred Drake456035f1997-12-03 04:06:57 +0000532\begin{opcodedesc}{IMPORT_NAME}{namei}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000533Imports the module \code{co_names[\var{namei}]}. The module object is
Fred Drake13494372000-09-12 16:23:48 +0000534pushed onto the stack. The current namespace is not affected: for a
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000535proper import statement, a subsequent \code{STORE_FAST} instruction
Fred Drake13494372000-09-12 16:23:48 +0000536modifies the namespace.
Fred Drake456035f1997-12-03 04:06:57 +0000537\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000538
Fred Drake456035f1997-12-03 04:06:57 +0000539\begin{opcodedesc}{IMPORT_FROM}{namei}
Thomas Wouters52152252000-08-17 22:55:00 +0000540Loads the attribute \code{co_names[\var{namei}]} from the module found in
541TOS. The resulting object is pushed onto the stack, to be subsequently
542stored by a \code{STORE_FAST} instruction.
Fred Drake456035f1997-12-03 04:06:57 +0000543\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000544
Fred Drake456035f1997-12-03 04:06:57 +0000545\begin{opcodedesc}{JUMP_FORWARD}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000546Increments byte code counter by \var{delta}.
Fred Drake456035f1997-12-03 04:06:57 +0000547\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000548
Fred Drake456035f1997-12-03 04:06:57 +0000549\begin{opcodedesc}{JUMP_IF_TRUE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000550If TOS is true, increment the byte code counter by \var{delta}. TOS is
551left on the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000552\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000553
Fred Drake456035f1997-12-03 04:06:57 +0000554\begin{opcodedesc}{JUMP_IF_FALSE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000555If TOS is false, increment the byte code counter by \var{delta}. TOS
556is not changed.
Fred Drake456035f1997-12-03 04:06:57 +0000557\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000558
Fred Drake456035f1997-12-03 04:06:57 +0000559\begin{opcodedesc}{JUMP_ABSOLUTE}{target}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000560Set byte code counter to \var{target}.
Fred Drake456035f1997-12-03 04:06:57 +0000561\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000562
Guido van Rossume3fdc972002-06-12 15:33:08 +0000563\begin{opcodedesc}{FOR_ITER}{delta}
564\code{TOS} is an iterator. Call its \method{next()} method. If this
565yields a new value, push it on the stack (leaving the iterator below
566it). If the iterator indicates it is exhausted \code{TOS} is
567popped, and the byte code counter is incremented by \var{delta}.
568\end{opcodedesc}
569
Guido van Rossumfea59e72002-06-13 17:59:51 +0000570%\begin{opcodedesc}{FOR_LOOP}{delta}
571%This opcode is obsolete.
572%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000573
Fred Drake456035f1997-12-03 04:06:57 +0000574%\begin{opcodedesc}{LOAD_LOCAL}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000575%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000576%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000577
Fred Drake456035f1997-12-03 04:06:57 +0000578\begin{opcodedesc}{LOAD_GLOBAL}{namei}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000579Loads the global named \code{co_names[\var{namei}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000580\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000581
Fred Drake456035f1997-12-03 04:06:57 +0000582%\begin{opcodedesc}{SET_FUNC_ARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000583%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000584%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000585
Fred Drake456035f1997-12-03 04:06:57 +0000586\begin{opcodedesc}{SETUP_LOOP}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000587Pushes a block for a loop onto the block stack. The block spans
588from the current instruction with a size of \var{delta} bytes.
Fred Drake456035f1997-12-03 04:06:57 +0000589\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000590
Fred Drake456035f1997-12-03 04:06:57 +0000591\begin{opcodedesc}{SETUP_EXCEPT}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000592Pushes a try block from a try-except clause onto the block stack.
593\var{delta} points to the first except block.
Fred Drake456035f1997-12-03 04:06:57 +0000594\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000595
Fred Drake456035f1997-12-03 04:06:57 +0000596\begin{opcodedesc}{SETUP_FINALLY}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000597Pushes a try block from a try-except clause onto the block stack.
598\var{delta} points to the finally block.
Fred Drake456035f1997-12-03 04:06:57 +0000599\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000600
Fred Drake456035f1997-12-03 04:06:57 +0000601\begin{opcodedesc}{LOAD_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000602Pushes a reference to the local \code{co_varnames[\var{var_num}]} onto
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000603the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000604\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000605
Fred Drake456035f1997-12-03 04:06:57 +0000606\begin{opcodedesc}{STORE_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000607Stores TOS into the local \code{co_varnames[\var{var_num}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000608\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000609
Fred Drake456035f1997-12-03 04:06:57 +0000610\begin{opcodedesc}{DELETE_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000611Deletes local \code{co_varnames[\var{var_num}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000612\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000613
Jeremy Hyltonaa90adc2001-03-23 17:23:50 +0000614\begin{opcodedesc}{LOAD_CLOSURE}{i}
615Pushes a reference to the cell contained in slot \var{i} of the
616cell and free variable storage. The name of the variable is
617\code{co_cellvars[\var{i}]} if \var{i} is less than the length of
618\var{co_cellvars}. Otherwise it is
619\code{co_freevars[\var{i} - len(co_cellvars)]}.
620\end{opcodedesc}
621
622\begin{opcodedesc}{LOAD_DEREF}{i}
623Loads the cell contained in slot \var{i} of the cell and free variable
624storage. Pushes a reference to the object the cell contains on the
625stack.
626\end{opcodedesc}
627
628\begin{opcodedesc}{STORE_DEREF}{i}
629Stores TOS into the cell contained in slot \var{i} of the cell and
630free variable storage.
631\end{opcodedesc}
632
Fred Drake338da931999-05-17 20:57:07 +0000633\begin{opcodedesc}{SET_LINENO}{lineno}
Michael W. Hudsondd32a912002-08-15 14:59:02 +0000634This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000635\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000636
Fred Drake456035f1997-12-03 04:06:57 +0000637\begin{opcodedesc}{RAISE_VARARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000638Raises an exception. \var{argc} indicates the number of parameters
Fred Drake304faf92000-08-18 02:15:55 +0000639to the raise statement, ranging from 0 to 3. The handler will find
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000640the traceback as TOS2, the parameter as TOS1, and the exception
641as TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000642\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000643
Fred Drake456035f1997-12-03 04:06:57 +0000644\begin{opcodedesc}{CALL_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000645Calls a function. The low byte of \var{argc} indicates the number of
646positional parameters, the high byte the number of keyword parameters.
647On the stack, the opcode finds the keyword parameters first. For each
648keyword argument, the value is on top of the key. Below the keyword
649parameters, the positional parameters are on the stack, with the
650right-most parameter on top. Below the parameters, the function object
651to call is on the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000652\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000653
Fred Drake456035f1997-12-03 04:06:57 +0000654\begin{opcodedesc}{MAKE_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000655Pushes a new function object on the stack. TOS is the code associated
656with the function. The function object is defined to have \var{argc}
657default parameters, which are found below TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000658\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000659
Jeremy Hyltonaa90adc2001-03-23 17:23:50 +0000660\begin{opcodedesc}{MAKE_CLOSURE}{argc}
661Creates a new function object, sets its \var{func_closure} slot, and
662pushes it on the stack. TOS is the code associated with the function.
663If the code object has N free variables, the next N items on the stack
664are the cells for these variables. The function also has \var{argc}
665default parameters, where are found before the cells.
666\end{opcodedesc}
667
Fred Drake456035f1997-12-03 04:06:57 +0000668\begin{opcodedesc}{BUILD_SLICE}{argc}
Guido van Rossumda623981998-02-12 03:53:02 +0000669Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it
670is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3,
671\code{slice(TOS2, TOS1, TOS)} is pushed.
Fred Drake304faf92000-08-18 02:15:55 +0000672See the \code{slice()}\bifuncindex{slice} built-in function for more
673information.
Fred Drake456035f1997-12-03 04:06:57 +0000674\end{opcodedesc}
Fred Drake25699f92000-08-17 22:19:26 +0000675
Fred Drake093272e2000-08-24 00:37:50 +0000676\begin{opcodedesc}{EXTENDED_ARG}{ext}
677Prefixes any opcode which has an argument too big to fit into the
678default two bytes. \var{ext} holds two additional bytes which, taken
679together with the subsequent opcode's argument, comprise a four-byte
Fred Drake4c3f7972000-08-31 16:26:35 +0000680argument, \var{ext} being the two most-significant bytes.
Fred Drake093272e2000-08-24 00:37:50 +0000681\end{opcodedesc}
682
Fred Drake25699f92000-08-17 22:19:26 +0000683\begin{opcodedesc}{CALL_FUNCTION_VAR}{argc}
684Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
685The top element on the stack contains the variable argument list, followed
686by keyword and positional arguments.
687\end{opcodedesc}
688
689\begin{opcodedesc}{CALL_FUNCTION_KW}{argc}
690Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
691The top element on the stack contains the keyword arguments dictionary,
692followed by explicit keyword and positional arguments.
693\end{opcodedesc}
694
695\begin{opcodedesc}{CALL_FUNCTION_VAR_KW}{argc}
696Calls a function. \var{argc} is interpreted as in
697\code{CALL_FUNCTION}. The top element on the stack contains the
698keyword arguments dictionary, followed by the variable-arguments
699tuple, followed by explicit keyword and positional arguments.
700\end{opcodedesc}
Skip Montanarobecbdec2005-01-05 07:19:11 +0000701
702\begin{opcodedesc}{HAVE_ARGUMENT}{}
703This is not really an opcode. It identifies the dividing line between
704opcodes which don't take arguments \code{< HAVE_ARGUMENT} and those which do
705\code{>= HAVE_ARGUMENT}.
706\end{opcodedesc}