blob: 90f83a3624f9615e3103ff3318f143f1ebdd504e [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)
26 0 SET_LINENO 1
27
28 3 SET_LINENO 2
29 6 LOAD_GLOBAL 0 (len)
30 9 LOAD_FAST 0 (alist)
31 12 CALL_FUNCTION 1
32 15 RETURN_VALUE
33 16 LOAD_CONST 0 (None)
34 19 RETURN_VALUE
35\end{verbatim}
36
Fred Drake2c4f5542000-10-10 22:00:03 +000037The \module{dis} module defines the following functions and constants:
Guido van Rossumb62b6d11997-11-18 15:10:53 +000038
Guido van Rossumb62b6d11997-11-18 15:10:53 +000039\begin{funcdesc}{dis}{\optional{bytesource}}
40Disassemble the \var{bytesource} object. \var{bytesource} can denote
41either a class, a method, a function, or a code object. For a class,
42it disassembles all methods. For a single code sequence, it prints
43one line per byte code instruction. If no object is provided, it
44disassembles the last traceback.
45\end{funcdesc}
46
47\begin{funcdesc}{distb}{\optional{tb}}
48Disassembles the top-of-stack function of a traceback, using the last
49traceback if none was passed. The instruction causing the exception
50is indicated.
51\end{funcdesc}
52
Fred Drakecce10901998-03-17 06:33:25 +000053\begin{funcdesc}{disassemble}{code\optional{, lasti}}
Guido van Rossumb62b6d11997-11-18 15:10:53 +000054Disassembles a code object, indicating the last instruction if \var{lasti}
55was provided. The output is divided in the following columns:
Fred Drake810349b1998-04-07 14:16:41 +000056
Fred Drake3e7a48e1998-04-13 16:15:02 +000057\begin{enumerate}
Fred Drakedff21a61998-04-03 05:42:10 +000058\item the current instruction, indicated as \samp{-->},
Fred Drakec054c752001-04-13 17:25:38 +000059\item a labelled instruction, indicated with \samp{>\code{>}},
Guido van Rossumb62b6d11997-11-18 15:10:53 +000060\item the address of the instruction,
61\item the operation code name,
62\item operation parameters, and
63\item interpretation of the parameters in parentheses.
Fred Drake3e7a48e1998-04-13 16:15:02 +000064\end{enumerate}
Fred Drake810349b1998-04-07 14:16:41 +000065
Guido van Rossumb62b6d11997-11-18 15:10:53 +000066The parameter interpretation recognizes local and global
67variable names, constant values, branch targets, and compare
68operators.
69\end{funcdesc}
70
Fred Drakecce10901998-03-17 06:33:25 +000071\begin{funcdesc}{disco}{code\optional{, lasti}}
Guido van Rossumb62b6d11997-11-18 15:10:53 +000072A synonym for disassemble. It is more convenient to type, and kept
73for compatibility with earlier Python releases.
74\end{funcdesc}
75
76\begin{datadesc}{opname}
Fred Drake2c4f5542000-10-10 22:00:03 +000077Sequence of operation names, indexable using the byte code.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000078\end{datadesc}
79
80\begin{datadesc}{cmp_op}
81Sequence of all compare operation names.
82\end{datadesc}
83
84\begin{datadesc}{hasconst}
85Sequence of byte codes that have a constant parameter.
86\end{datadesc}
87
Fred Drake47cdf6f2002-03-28 19:34:53 +000088\begin{datadesc}{hasfree}
89Sequence of byte codes that access a free variable.
90\end{datadesc}
91
Guido van Rossumb62b6d11997-11-18 15:10:53 +000092\begin{datadesc}{hasname}
Fred Drake2c4f5542000-10-10 22:00:03 +000093Sequence of byte codes that access an attribute by name.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000094\end{datadesc}
95
96\begin{datadesc}{hasjrel}
97Sequence of byte codes that have a relative jump target.
98\end{datadesc}
99
100\begin{datadesc}{hasjabs}
101Sequence of byte codes that have an absolute jump target.
102\end{datadesc}
103
104\begin{datadesc}{haslocal}
Fred Drake2c4f5542000-10-10 22:00:03 +0000105Sequence of byte codes that access a local variable.
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000106\end{datadesc}
107
108\begin{datadesc}{hascompare}
Fred Drake6c81e2a2001-10-01 17:04:10 +0000109Sequence of byte codes of Boolean operations.
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000110\end{datadesc}
111
112\subsection{Python Byte Code Instructions}
Fred Drake83efb541998-02-19 20:07:39 +0000113\label{bytecodes}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000114
115The Python compiler currently generates the following byte code
116instructions.
117
Fred Drake19479911998-02-13 06:58:54 +0000118\setindexsubitem{(byte code insns)}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000119
Fred Drake456035f1997-12-03 04:06:57 +0000120\begin{opcodedesc}{STOP_CODE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000121Indicates end-of-code to the compiler, not used by the interpreter.
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}{POP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000125Removes the top-of-stack (TOS) item.
Fred Drake456035f1997-12-03 04:06:57 +0000126\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000127
Fred Drake456035f1997-12-03 04:06:57 +0000128\begin{opcodedesc}{ROT_TWO}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000129Swaps the two top-most stack items.
Fred Drake456035f1997-12-03 04:06:57 +0000130\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000131
Fred Drake456035f1997-12-03 04:06:57 +0000132\begin{opcodedesc}{ROT_THREE}{}
133Lifts second and third stack item one position up, moves top down
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000134to position three.
Fred Drake456035f1997-12-03 04:06:57 +0000135\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000136
Thomas Wouters12bba852000-08-24 20:06:04 +0000137\begin{opcodedesc}{ROT_FOUR}{}
138Lifts second, third and forth stack item one position up, moves top down to
139position four.
140\end{opcodedesc}
141
Fred Drake456035f1997-12-03 04:06:57 +0000142\begin{opcodedesc}{DUP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000143Duplicates the reference on top of the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000144\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000145
146Unary Operations take the top of the stack, apply the operation, and
147push the result back on the stack.
148
Fred Drake456035f1997-12-03 04:06:57 +0000149\begin{opcodedesc}{UNARY_POSITIVE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000150Implements \code{TOS = +TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000151\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000152
Fred Drake4c3f7972000-08-31 16:26:35 +0000153\begin{opcodedesc}{UNARY_NEGATIVE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000154Implements \code{TOS = -TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000155\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000156
Fred Drake456035f1997-12-03 04:06:57 +0000157\begin{opcodedesc}{UNARY_NOT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000158Implements \code{TOS = not TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000159\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000160
Fred Drake456035f1997-12-03 04:06:57 +0000161\begin{opcodedesc}{UNARY_CONVERT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000162Implements \code{TOS = `TOS`}.
Fred Drake456035f1997-12-03 04:06:57 +0000163\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000164
Fred Drake456035f1997-12-03 04:06:57 +0000165\begin{opcodedesc}{UNARY_INVERT}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000166Implements \code{TOS = \~{}TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000167\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000168
Guido van Rossume3fdc972002-06-12 15:33:08 +0000169\begin{opcodedesc}{GET_ITER}{}
170Implements \code{TOS = iter(TOS)}.
171\end{opcodedesc}
172
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000173Binary operations remove the top of the stack (TOS) and the second top-most
174stack item (TOS1) from the stack. They perform the operation, and put the
175result back on the stack.
176
Fred Drake456035f1997-12-03 04:06:57 +0000177\begin{opcodedesc}{BINARY_POWER}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000178Implements \code{TOS = TOS1 ** TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000179\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000180
Fred Drake456035f1997-12-03 04:06:57 +0000181\begin{opcodedesc}{BINARY_MULTIPLY}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000182Implements \code{TOS = TOS1 * TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000183\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000184
Fred Drake456035f1997-12-03 04:06:57 +0000185\begin{opcodedesc}{BINARY_DIVIDE}{}
Guido van Rossume3fdc972002-06-12 15:33:08 +0000186Implements \code{TOS = TOS1 / TOS} when
187\code{from __future__ import division} is not in effect.
188\end{opcodedesc}
189
190\begin{opcodedesc}{BINARY_FLOOR_DIVIDE}{}
191Implements \code{TOS = TOS1 // TOS}.
192\end{opcodedesc}
193
194\begin{opcodedesc}{BINARY_TRUE_DIVIDE}{}
195Implements \code{TOS = TOS1 / TOS} when
196\code{from __future__ import division} is in effect.
Fred Drake456035f1997-12-03 04:06:57 +0000197\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000198
Fred Drake456035f1997-12-03 04:06:57 +0000199\begin{opcodedesc}{BINARY_MODULO}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000200Implements \code{TOS = TOS1 \%{} TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000201\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000202
Fred Drake456035f1997-12-03 04:06:57 +0000203\begin{opcodedesc}{BINARY_ADD}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000204Implements \code{TOS = TOS1 + TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000205\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000206
Fred Drake456035f1997-12-03 04:06:57 +0000207\begin{opcodedesc}{BINARY_SUBTRACT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000208Implements \code{TOS = TOS1 - TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000209\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000210
Fred Drake456035f1997-12-03 04:06:57 +0000211\begin{opcodedesc}{BINARY_SUBSCR}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000212Implements \code{TOS = TOS1[TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000213\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000214
Fred Drake456035f1997-12-03 04:06:57 +0000215\begin{opcodedesc}{BINARY_LSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000216Implements \code{TOS = TOS1 <\code{}< TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000217\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000218
Fred Drake456035f1997-12-03 04:06:57 +0000219\begin{opcodedesc}{BINARY_RSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000220Implements \code{TOS = TOS1 >\code{}> TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000221\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000222
Fred Drake456035f1997-12-03 04:06:57 +0000223\begin{opcodedesc}{BINARY_AND}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000224Implements \code{TOS = TOS1 \&\ TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000225\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000226
Fred Drake456035f1997-12-03 04:06:57 +0000227\begin{opcodedesc}{BINARY_XOR}{}
Fred Draked7feffd1997-12-29 20:02:55 +0000228Implements \code{TOS = TOS1 \^\ TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000229\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000230
Fred Drake456035f1997-12-03 04:06:57 +0000231\begin{opcodedesc}{BINARY_OR}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000232Implements \code{TOS = TOS1 | TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000233\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000234
Thomas Wouters12bba852000-08-24 20:06:04 +0000235In-place operations are like binary operations, in that they remove TOS and
236TOS1, and push the result back on the stack, but the operation is done
237in-place when TOS1 supports it, and the resulting TOS may be (but does not
238have to be) the original TOS1.
239
240\begin{opcodedesc}{INPLACE_POWER}{}
241Implements in-place \code{TOS = TOS1 ** TOS}.
242\end{opcodedesc}
243
244\begin{opcodedesc}{INPLACE_MULTIPLY}{}
245Implements in-place \code{TOS = TOS1 * TOS}.
246\end{opcodedesc}
247
248\begin{opcodedesc}{INPLACE_DIVIDE}{}
Guido van Rossume3fdc972002-06-12 15:33:08 +0000249Implements in-place \code{TOS = TOS1 / TOS} when
250\code{from __future__ import division} is not in effect.
251\end{opcodedesc}
252
253\begin{opcodedesc}{INPLACE_FLOOR_DIVIDE}{}
254Implements in-place \code{TOS = TOS1 // TOS}.
255\end{opcodedesc}
256
257\begin{opcodedesc}{INPLACE_TRUE_DIVIDE}{}
258Implements in-place \code{TOS = TOS1 / TOS} when
259\code{from __future__ import division} is in effect.
Thomas Wouters12bba852000-08-24 20:06:04 +0000260\end{opcodedesc}
261
262\begin{opcodedesc}{INPLACE_MODULO}{}
263Implements in-place \code{TOS = TOS1 \%{} TOS}.
264\end{opcodedesc}
265
266\begin{opcodedesc}{INPLACE_ADD}{}
267Implements in-place \code{TOS = TOS1 + TOS}.
268\end{opcodedesc}
269
270\begin{opcodedesc}{INPLACE_SUBTRACT}{}
271Implements in-place \code{TOS = TOS1 - TOS}.
272\end{opcodedesc}
273
274\begin{opcodedesc}{INPLACE_LSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000275Implements in-place \code{TOS = TOS1 <\code{}< TOS}.
Thomas Wouters12bba852000-08-24 20:06:04 +0000276\end{opcodedesc}
277
278\begin{opcodedesc}{INPLACE_RSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000279Implements in-place \code{TOS = TOS1 >\code{}> TOS}.
Thomas Wouters12bba852000-08-24 20:06:04 +0000280\end{opcodedesc}
281
282\begin{opcodedesc}{INPLACE_AND}{}
283Implements in-place \code{TOS = TOS1 \&\ TOS}.
284\end{opcodedesc}
285
286\begin{opcodedesc}{INPLACE_XOR}{}
287Implements in-place \code{TOS = TOS1 \^\ TOS}.
288\end{opcodedesc}
289
290\begin{opcodedesc}{INPLACE_OR}{}
291Implements in-place \code{TOS = TOS1 | TOS}.
292\end{opcodedesc}
293
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000294The slice opcodes take up to three parameters.
295
Fred Drake456035f1997-12-03 04:06:57 +0000296\begin{opcodedesc}{SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000297Implements \code{TOS = TOS[:]}.
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}{SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000301Implements \code{TOS = TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000302\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000303
Fred Drake456035f1997-12-03 04:06:57 +0000304\begin{opcodedesc}{SLICE+2}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000305Implements \code{TOS = TOS1[:TOS1]}.
Fred Drake456035f1997-12-03 04:06:57 +0000306\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000307
Fred Drake456035f1997-12-03 04:06:57 +0000308\begin{opcodedesc}{SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000309Implements \code{TOS = TOS2[TOS1:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000310\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000311
312Slice assignment needs even an additional parameter. As any statement,
313they put nothing on the stack.
314
Fred Drake456035f1997-12-03 04:06:57 +0000315\begin{opcodedesc}{STORE_SLICE+0}{}
Fred Drake7381e281997-12-04 04:51:12 +0000316Implements \code{TOS[:] = TOS1}.
Fred Drake456035f1997-12-03 04:06:57 +0000317\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000318
Fred Drake456035f1997-12-03 04:06:57 +0000319\begin{opcodedesc}{STORE_SLICE+1}{}
Fred Drake7381e281997-12-04 04:51:12 +0000320Implements \code{TOS1[TOS:] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000321\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000322
Fred Drake456035f1997-12-03 04:06:57 +0000323\begin{opcodedesc}{STORE_SLICE+2}{}
Fred Drake7381e281997-12-04 04:51:12 +0000324Implements \code{TOS1[:TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000325\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000326
Fred Drake456035f1997-12-03 04:06:57 +0000327\begin{opcodedesc}{STORE_SLICE+3}{}
Fred Drake7381e281997-12-04 04:51:12 +0000328Implements \code{TOS2[TOS1:TOS] = TOS3}.
Fred Drake456035f1997-12-03 04:06:57 +0000329\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000330
Fred Drake456035f1997-12-03 04:06:57 +0000331\begin{opcodedesc}{DELETE_SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000332Implements \code{del TOS[:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000333\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000334
Fred Drake456035f1997-12-03 04:06:57 +0000335\begin{opcodedesc}{DELETE_SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000336Implements \code{del TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000337\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000338
Fred Drake456035f1997-12-03 04:06:57 +0000339\begin{opcodedesc}{DELETE_SLICE+2}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000340Implements \code{del TOS1[:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000341\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000342
Fred Drake456035f1997-12-03 04:06:57 +0000343\begin{opcodedesc}{DELETE_SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000344Implements \code{del TOS2[TOS1:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000345\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000346
Fred Drake456035f1997-12-03 04:06:57 +0000347\begin{opcodedesc}{STORE_SUBSCR}{}
Fred Drake7381e281997-12-04 04:51:12 +0000348Implements \code{TOS1[TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000349\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000350
Fred Drake456035f1997-12-03 04:06:57 +0000351\begin{opcodedesc}{DELETE_SUBSCR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000352Implements \code{del TOS1[TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000353\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000354
Guido van Rossume3fdc972002-06-12 15:33:08 +0000355Miscellaneous opcodes.
356
Fred Drake456035f1997-12-03 04:06:57 +0000357\begin{opcodedesc}{PRINT_EXPR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000358Implements the expression statement for the interactive mode. TOS is
359removed from the stack and printed. In non-interactive mode, an
Fred Drake456035f1997-12-03 04:06:57 +0000360expression statement is terminated with \code{POP_STACK}.
361\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000362
Fred Drake456035f1997-12-03 04:06:57 +0000363\begin{opcodedesc}{PRINT_ITEM}{}
Barry Warsaw90876882000-08-21 17:19:00 +0000364Prints TOS to the file-like object bound to \code{sys.stdout}. There
365is one such instruction for each item in the \keyword{print} statement.
366\end{opcodedesc}
367
368\begin{opcodedesc}{PRINT_ITEM_TO}{}
369Like \code{PRINT_ITEM}, but prints the item second from TOS to the
370file-like object at TOS. This is used by the extended print statement.
Fred Drake456035f1997-12-03 04:06:57 +0000371\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000372
Fred Drake456035f1997-12-03 04:06:57 +0000373\begin{opcodedesc}{PRINT_NEWLINE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000374Prints a new line on \code{sys.stdout}. This is generated as the
Fred Drake304faf92000-08-18 02:15:55 +0000375last operation of a \keyword{print} statement, unless the statement
376ends with a comma.
Fred Drake456035f1997-12-03 04:06:57 +0000377\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000378
Barry Warsaw90876882000-08-21 17:19:00 +0000379\begin{opcodedesc}{PRINT_NEWLINE_TO}{}
380Like \code{PRINT_NEWLINE}, but prints the new line on the file-like
381object on the TOS. This is used by the extended print statement.
382\end{opcodedesc}
383
Fred Drake456035f1997-12-03 04:06:57 +0000384\begin{opcodedesc}{BREAK_LOOP}{}
Fred Drake304faf92000-08-18 02:15:55 +0000385Terminates a loop due to a \keyword{break} statement.
Fred Drake456035f1997-12-03 04:06:57 +0000386\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000387
Guido van Rossume3fdc972002-06-12 15:33:08 +0000388\begin{opcodedesc}{CONTINUE_LOOP}{target}
389Continues a loop due to a \keyword{continue} statement. \var{target}
390is the address to jump to (which should be a \code{FOR_ITER}
391instruction).
392\end{opcodedesc}
393
Fred Drake456035f1997-12-03 04:06:57 +0000394\begin{opcodedesc}{LOAD_LOCALS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000395Pushes a reference to the locals of the current scope on the stack.
396This is used in the code for a class definition: After the class body
397is evaluated, the locals are passed to the class definition.
Fred Drake456035f1997-12-03 04:06:57 +0000398\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000399
Fred Drake456035f1997-12-03 04:06:57 +0000400\begin{opcodedesc}{RETURN_VALUE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000401Returns with TOS to the caller of the function.
Fred Drake456035f1997-12-03 04:06:57 +0000402\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000403
Guido van Rossume3fdc972002-06-12 15:33:08 +0000404\begin{opcodedesc}{YIELD_VALUE}{}
405Pops \code{TOS} and yields it from a generator.
406\end{opcodedesc}
407
Thomas Wouters52152252000-08-17 22:55:00 +0000408\begin{opcodedesc}{IMPORT_STAR}{}
Fred Drake304faf92000-08-18 02:15:55 +0000409Loads all symbols not starting with \character{_} directly from the module TOS
Thomas Wouters52152252000-08-17 22:55:00 +0000410to the local namespace. The module is popped after loading all names.
Fred Drake304faf92000-08-18 02:15:55 +0000411This opcode implements \code{from module import *}.
412\end{opcodedesc}
Thomas Wouters52152252000-08-17 22:55:00 +0000413
Fred Drake456035f1997-12-03 04:06:57 +0000414\begin{opcodedesc}{EXEC_STMT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000415Implements \code{exec TOS2,TOS1,TOS}. The compiler fills
Fred Drake304faf92000-08-18 02:15:55 +0000416missing optional parameters with \code{None}.
Fred Drake456035f1997-12-03 04:06:57 +0000417\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000418
Fred Drake456035f1997-12-03 04:06:57 +0000419\begin{opcodedesc}{POP_BLOCK}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000420Removes one block from the block stack. Per frame, there is a
421stack of blocks, denoting nested loops, try statements, and such.
Fred Drake456035f1997-12-03 04:06:57 +0000422\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000423
Fred Drake456035f1997-12-03 04:06:57 +0000424\begin{opcodedesc}{END_FINALLY}{}
Fred Drake304faf92000-08-18 02:15:55 +0000425Terminates a \keyword{finally} clause. The interpreter recalls
426whether the exception has to be re-raised, or whether the function
427returns, and continues with the outer-next block.
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}{BUILD_CLASS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000431Creates a new class object. TOS is the methods dictionary, TOS1
432the tuple of the names of the base classes, and TOS2 the class name.
Fred Drake456035f1997-12-03 04:06:57 +0000433\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000434
435All of the following opcodes expect arguments. An argument is two
436bytes, with the more significant byte last.
437
Fred Drake456035f1997-12-03 04:06:57 +0000438\begin{opcodedesc}{STORE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000439Implements \code{name = TOS}. \var{namei} is the index of \var{name}
Fred Drakedff21a61998-04-03 05:42:10 +0000440in the attribute \member{co_names} of the code object.
Fred Drake456035f1997-12-03 04:06:57 +0000441The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL}
442if possible.
443\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000444
Fred Drake456035f1997-12-03 04:06:57 +0000445\begin{opcodedesc}{DELETE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000446Implements \code{del name}, where \var{namei} is the index into
Fred Drakedff21a61998-04-03 05:42:10 +0000447\member{co_names} attribute of the code object.
Fred Drake456035f1997-12-03 04:06:57 +0000448\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000449
Thomas Wouters0be5aab2000-08-11 22:15:52 +0000450\begin{opcodedesc}{UNPACK_SEQUENCE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000451Unpacks TOS into \var{count} individual values, which are put onto
452the stack right-to-left.
Fred Drake456035f1997-12-03 04:06:57 +0000453\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000454
Thomas Wouters0be5aab2000-08-11 22:15:52 +0000455%\begin{opcodedesc}{UNPACK_LIST}{count}
456%This opcode is obsolete.
457%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000458
Fred Drake456035f1997-12-03 04:06:57 +0000459%\begin{opcodedesc}{UNPACK_ARG}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000460%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000461%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000462
Thomas Wouters12bba852000-08-24 20:06:04 +0000463\begin{opcodedesc}{DUP_TOPX}{count}
464Duplicate \var{count} items, keeping them in the same order. Due to
465implementation limits, \var{count} should be between 1 and 5 inclusive.
466\end{opcodedesc}
467
Fred Drake456035f1997-12-03 04:06:57 +0000468\begin{opcodedesc}{STORE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000469Implements \code{TOS.name = TOS1}, where \var{namei} is the index
Fred Drakedff21a61998-04-03 05:42:10 +0000470of name in \member{co_names}.
Fred Drake456035f1997-12-03 04:06:57 +0000471\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000472
Fred Drake456035f1997-12-03 04:06:57 +0000473\begin{opcodedesc}{DELETE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000474Implements \code{del TOS.name}, using \var{namei} as index into
Fred Drakedff21a61998-04-03 05:42:10 +0000475\member{co_names}.
Fred Drake456035f1997-12-03 04:06:57 +0000476\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000477
Fred Drake456035f1997-12-03 04:06:57 +0000478\begin{opcodedesc}{STORE_GLOBAL}{namei}
479Works as \code{STORE_NAME}, but stores the name as a global.
480\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000481
Fred Drake456035f1997-12-03 04:06:57 +0000482\begin{opcodedesc}{DELETE_GLOBAL}{namei}
483Works as \code{DELETE_NAME}, but deletes a global name.
484\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000485
Fred Drake456035f1997-12-03 04:06:57 +0000486%\begin{opcodedesc}{UNPACK_VARARG}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000487%This opcode is obsolete.
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}{LOAD_CONST}{consti}
Fred Drakedff21a61998-04-03 05:42:10 +0000491Pushes \samp{co_consts[\var{consti}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000492\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000493
Fred Drake456035f1997-12-03 04:06:57 +0000494\begin{opcodedesc}{LOAD_NAME}{namei}
Fred Drakedff21a61998-04-03 05:42:10 +0000495Pushes the value associated with \samp{co_names[\var{namei}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000496\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000497
Fred Drake456035f1997-12-03 04:06:57 +0000498\begin{opcodedesc}{BUILD_TUPLE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000499Creates a tuple consuming \var{count} items from the stack, and pushes
500the resulting tuple onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000501\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000502
Fred Drake456035f1997-12-03 04:06:57 +0000503\begin{opcodedesc}{BUILD_LIST}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000504Works as \code{BUILD_TUPLE}, but creates a list.
Fred Drake456035f1997-12-03 04:06:57 +0000505\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000506
Fred Drake456035f1997-12-03 04:06:57 +0000507\begin{opcodedesc}{BUILD_MAP}{zero}
Fred Drake304faf92000-08-18 02:15:55 +0000508Pushes a new empty dictionary object onto the stack. The argument is
509ignored and set to zero by the compiler.
Fred Drake456035f1997-12-03 04:06:57 +0000510\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000511
Fred Drake456035f1997-12-03 04:06:57 +0000512\begin{opcodedesc}{LOAD_ATTR}{namei}
Fred Drake304faf92000-08-18 02:15:55 +0000513Replaces TOS with \code{getattr(TOS, co_names[\var{namei}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000514\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000515
Fred Drake456035f1997-12-03 04:06:57 +0000516\begin{opcodedesc}{COMPARE_OP}{opname}
Fred Drake6c81e2a2001-10-01 17:04:10 +0000517Performs a Boolean operation. The operation name can be found
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000518in \code{cmp_op[\var{opname}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000519\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000520
Fred Drake456035f1997-12-03 04:06:57 +0000521\begin{opcodedesc}{IMPORT_NAME}{namei}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000522Imports the module \code{co_names[\var{namei}]}. The module object is
Fred Drake13494372000-09-12 16:23:48 +0000523pushed onto the stack. The current namespace is not affected: for a
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000524proper import statement, a subsequent \code{STORE_FAST} instruction
Fred Drake13494372000-09-12 16:23:48 +0000525modifies the namespace.
Fred Drake456035f1997-12-03 04:06:57 +0000526\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000527
Fred Drake456035f1997-12-03 04:06:57 +0000528\begin{opcodedesc}{IMPORT_FROM}{namei}
Thomas Wouters52152252000-08-17 22:55:00 +0000529Loads the attribute \code{co_names[\var{namei}]} from the module found in
530TOS. The resulting object is pushed onto the stack, to be subsequently
531stored by a \code{STORE_FAST} instruction.
Fred Drake456035f1997-12-03 04:06:57 +0000532\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000533
Fred Drake456035f1997-12-03 04:06:57 +0000534\begin{opcodedesc}{JUMP_FORWARD}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000535Increments byte code counter by \var{delta}.
Fred Drake456035f1997-12-03 04:06:57 +0000536\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000537
Fred Drake456035f1997-12-03 04:06:57 +0000538\begin{opcodedesc}{JUMP_IF_TRUE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000539If TOS is true, increment the byte code counter by \var{delta}. TOS is
540left on the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000541\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000542
Fred Drake456035f1997-12-03 04:06:57 +0000543\begin{opcodedesc}{JUMP_IF_FALSE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000544If TOS is false, increment the byte code counter by \var{delta}. TOS
545is not changed.
Fred Drake456035f1997-12-03 04:06:57 +0000546\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000547
Fred Drake456035f1997-12-03 04:06:57 +0000548\begin{opcodedesc}{JUMP_ABSOLUTE}{target}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000549Set byte code counter to \var{target}.
Fred Drake456035f1997-12-03 04:06:57 +0000550\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000551
Guido van Rossume3fdc972002-06-12 15:33:08 +0000552\begin{opcodedesc}{FOR_ITER}{delta}
553\code{TOS} is an iterator. Call its \method{next()} method. If this
554yields a new value, push it on the stack (leaving the iterator below
555it). If the iterator indicates it is exhausted \code{TOS} is
556popped, and the byte code counter is incremented by \var{delta}.
557\end{opcodedesc}
558
Guido van Rossumfea59e72002-06-13 17:59:51 +0000559%\begin{opcodedesc}{FOR_LOOP}{delta}
560%This opcode is obsolete.
561%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000562
Fred Drake456035f1997-12-03 04:06:57 +0000563%\begin{opcodedesc}{LOAD_LOCAL}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000564%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000565%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000566
Fred Drake456035f1997-12-03 04:06:57 +0000567\begin{opcodedesc}{LOAD_GLOBAL}{namei}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000568Loads the global named \code{co_names[\var{namei}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000569\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000570
Fred Drake456035f1997-12-03 04:06:57 +0000571%\begin{opcodedesc}{SET_FUNC_ARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000572%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000573%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000574
Fred Drake456035f1997-12-03 04:06:57 +0000575\begin{opcodedesc}{SETUP_LOOP}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000576Pushes a block for a loop onto the block stack. The block spans
577from the current instruction with a size of \var{delta} bytes.
Fred Drake456035f1997-12-03 04:06:57 +0000578\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000579
Fred Drake456035f1997-12-03 04:06:57 +0000580\begin{opcodedesc}{SETUP_EXCEPT}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000581Pushes a try block from a try-except clause onto the block stack.
582\var{delta} points to the first except block.
Fred Drake456035f1997-12-03 04:06:57 +0000583\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000584
Fred Drake456035f1997-12-03 04:06:57 +0000585\begin{opcodedesc}{SETUP_FINALLY}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000586Pushes a try block from a try-except clause onto the block stack.
587\var{delta} points to the finally block.
Fred Drake456035f1997-12-03 04:06:57 +0000588\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000589
Fred Drake456035f1997-12-03 04:06:57 +0000590\begin{opcodedesc}{LOAD_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000591Pushes a reference to the local \code{co_varnames[\var{var_num}]} onto
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000592the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000593\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000594
Fred Drake456035f1997-12-03 04:06:57 +0000595\begin{opcodedesc}{STORE_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000596Stores TOS into the local \code{co_varnames[\var{var_num}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000597\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000598
Fred Drake456035f1997-12-03 04:06:57 +0000599\begin{opcodedesc}{DELETE_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000600Deletes local \code{co_varnames[\var{var_num}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000601\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000602
Jeremy Hyltonaa90adc2001-03-23 17:23:50 +0000603\begin{opcodedesc}{LOAD_CLOSURE}{i}
604Pushes a reference to the cell contained in slot \var{i} of the
605cell and free variable storage. The name of the variable is
606\code{co_cellvars[\var{i}]} if \var{i} is less than the length of
607\var{co_cellvars}. Otherwise it is
608\code{co_freevars[\var{i} - len(co_cellvars)]}.
609\end{opcodedesc}
610
611\begin{opcodedesc}{LOAD_DEREF}{i}
612Loads the cell contained in slot \var{i} of the cell and free variable
613storage. Pushes a reference to the object the cell contains on the
614stack.
615\end{opcodedesc}
616
617\begin{opcodedesc}{STORE_DEREF}{i}
618Stores TOS into the cell contained in slot \var{i} of the cell and
619free variable storage.
620\end{opcodedesc}
621
Fred Drake338da931999-05-17 20:57:07 +0000622\begin{opcodedesc}{SET_LINENO}{lineno}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000623Sets the current line number to \var{lineno}.
Fred Drake456035f1997-12-03 04:06:57 +0000624\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000625
Fred Drake456035f1997-12-03 04:06:57 +0000626\begin{opcodedesc}{RAISE_VARARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000627Raises an exception. \var{argc} indicates the number of parameters
Fred Drake304faf92000-08-18 02:15:55 +0000628to the raise statement, ranging from 0 to 3. The handler will find
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000629the traceback as TOS2, the parameter as TOS1, and the exception
630as TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000631\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000632
Fred Drake456035f1997-12-03 04:06:57 +0000633\begin{opcodedesc}{CALL_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000634Calls a function. The low byte of \var{argc} indicates the number of
635positional parameters, the high byte the number of keyword parameters.
636On the stack, the opcode finds the keyword parameters first. For each
637keyword argument, the value is on top of the key. Below the keyword
638parameters, the positional parameters are on the stack, with the
639right-most parameter on top. Below the parameters, the function object
640to call is on the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000641\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000642
Fred Drake456035f1997-12-03 04:06:57 +0000643\begin{opcodedesc}{MAKE_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000644Pushes a new function object on the stack. TOS is the code associated
645with the function. The function object is defined to have \var{argc}
646default parameters, which are found below TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000647\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000648
Jeremy Hyltonaa90adc2001-03-23 17:23:50 +0000649\begin{opcodedesc}{MAKE_CLOSURE}{argc}
650Creates a new function object, sets its \var{func_closure} slot, and
651pushes it on the stack. TOS is the code associated with the function.
652If the code object has N free variables, the next N items on the stack
653are the cells for these variables. The function also has \var{argc}
654default parameters, where are found before the cells.
655\end{opcodedesc}
656
Fred Drake456035f1997-12-03 04:06:57 +0000657\begin{opcodedesc}{BUILD_SLICE}{argc}
Guido van Rossumda623981998-02-12 03:53:02 +0000658Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it
659is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3,
660\code{slice(TOS2, TOS1, TOS)} is pushed.
Fred Drake304faf92000-08-18 02:15:55 +0000661See the \code{slice()}\bifuncindex{slice} built-in function for more
662information.
Fred Drake456035f1997-12-03 04:06:57 +0000663\end{opcodedesc}
Fred Drake25699f92000-08-17 22:19:26 +0000664
Fred Drake093272e2000-08-24 00:37:50 +0000665\begin{opcodedesc}{EXTENDED_ARG}{ext}
666Prefixes any opcode which has an argument too big to fit into the
667default two bytes. \var{ext} holds two additional bytes which, taken
668together with the subsequent opcode's argument, comprise a four-byte
Fred Drake4c3f7972000-08-31 16:26:35 +0000669argument, \var{ext} being the two most-significant bytes.
Fred Drake093272e2000-08-24 00:37:50 +0000670\end{opcodedesc}
671
Fred Drake25699f92000-08-17 22:19:26 +0000672\begin{opcodedesc}{CALL_FUNCTION_VAR}{argc}
673Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
674The top element on the stack contains the variable argument list, followed
675by keyword and positional arguments.
676\end{opcodedesc}
677
678\begin{opcodedesc}{CALL_FUNCTION_KW}{argc}
679Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
680The top element on the stack contains the keyword arguments dictionary,
681followed by explicit keyword and positional arguments.
682\end{opcodedesc}
683
684\begin{opcodedesc}{CALL_FUNCTION_VAR_KW}{argc}
685Calls a function. \var{argc} is interpreted as in
686\code{CALL_FUNCTION}. The top element on the stack contains the
687keyword arguments dictionary, followed by the variable-arguments
688tuple, followed by explicit keyword and positional arguments.
689\end{opcodedesc}