blob: 26ba96757def51c587fa3eaae6cf1a28586d6fc6 [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
29 9 RETURN_VALUE
Michael W. Hudson53d58bb2002-08-30 13:09:51 +000030 10 LOAD_CONST 0 (None)
31 13 RETURN_VALUE
Guido van Rossumb62b6d11997-11-18 15:10:53 +000032\end{verbatim}
33
Michael W. Hudsondd32a912002-08-15 14:59:02 +000034(The ``2'' is a line number).
35
Fred Drake2c4f5542000-10-10 22:00:03 +000036The \module{dis} module defines the following functions and constants:
Guido van Rossumb62b6d11997-11-18 15:10:53 +000037
Guido van Rossumb62b6d11997-11-18 15:10:53 +000038\begin{funcdesc}{dis}{\optional{bytesource}}
39Disassemble the \var{bytesource} object. \var{bytesource} can denote
Neal Norwitzdcd05002002-06-26 22:32:47 +000040either a module, a class, a method, a function, or a code object.
41For a module, it disassembles all functions. For a class,
Guido van Rossumb62b6d11997-11-18 15:10:53 +000042it 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}
Michael W. Hudsondd32a912002-08-15 14:59:02 +000058\item the line number, for the first instruction of each line
Fred Drakedff21a61998-04-03 05:42:10 +000059\item the current instruction, indicated as \samp{-->},
Fred Drakec054c752001-04-13 17:25:38 +000060\item a labelled instruction, indicated with \samp{>\code{>}},
Guido van Rossumb62b6d11997-11-18 15:10:53 +000061\item the address of the instruction,
62\item the operation code name,
63\item operation parameters, and
64\item interpretation of the parameters in parentheses.
Fred Drake3e7a48e1998-04-13 16:15:02 +000065\end{enumerate}
Fred Drake810349b1998-04-07 14:16:41 +000066
Guido van Rossumb62b6d11997-11-18 15:10:53 +000067The parameter interpretation recognizes local and global
68variable names, constant values, branch targets, and compare
69operators.
70\end{funcdesc}
71
Fred Drakecce10901998-03-17 06:33:25 +000072\begin{funcdesc}{disco}{code\optional{, lasti}}
Guido van Rossumb62b6d11997-11-18 15:10:53 +000073A synonym for disassemble. It is more convenient to type, and kept
74for compatibility with earlier Python releases.
75\end{funcdesc}
76
77\begin{datadesc}{opname}
Fred Drake2c4f5542000-10-10 22:00:03 +000078Sequence of operation names, indexable using the byte code.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000079\end{datadesc}
80
Skip Montanarobecbdec2005-01-05 07:19:11 +000081\begin{datadesc}{opmap}
82Dictionary mapping byte codes to operation names.
83\end{datadesc}
84
Guido van Rossumb62b6d11997-11-18 15:10:53 +000085\begin{datadesc}{cmp_op}
86Sequence of all compare operation names.
87\end{datadesc}
88
89\begin{datadesc}{hasconst}
90Sequence of byte codes that have a constant parameter.
91\end{datadesc}
92
Fred Drake47cdf6f2002-03-28 19:34:53 +000093\begin{datadesc}{hasfree}
94Sequence of byte codes that access a free variable.
95\end{datadesc}
96
Guido van Rossumb62b6d11997-11-18 15:10:53 +000097\begin{datadesc}{hasname}
Fred Drake2c4f5542000-10-10 22:00:03 +000098Sequence of byte codes that access an attribute by name.
Guido van Rossumb62b6d11997-11-18 15:10:53 +000099\end{datadesc}
100
101\begin{datadesc}{hasjrel}
102Sequence of byte codes that have a relative jump target.
103\end{datadesc}
104
105\begin{datadesc}{hasjabs}
106Sequence of byte codes that have an absolute jump target.
107\end{datadesc}
108
109\begin{datadesc}{haslocal}
Fred Drake2c4f5542000-10-10 22:00:03 +0000110Sequence of byte codes that access a local variable.
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000111\end{datadesc}
112
113\begin{datadesc}{hascompare}
Fred Drake6c81e2a2001-10-01 17:04:10 +0000114Sequence of byte codes of Boolean operations.
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000115\end{datadesc}
116
117\subsection{Python Byte Code Instructions}
Fred Drake83efb541998-02-19 20:07:39 +0000118\label{bytecodes}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000119
120The Python compiler currently generates the following byte code
121instructions.
122
Fred Drake19479911998-02-13 06:58:54 +0000123\setindexsubitem{(byte code insns)}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000124
Fred Drake456035f1997-12-03 04:06:57 +0000125\begin{opcodedesc}{STOP_CODE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000126Indicates end-of-code to the compiler, not used by the interpreter.
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}{POP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000130Removes the top-of-stack (TOS) item.
Fred Drake456035f1997-12-03 04:06:57 +0000131\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000132
Fred Drake456035f1997-12-03 04:06:57 +0000133\begin{opcodedesc}{ROT_TWO}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000134Swaps the two top-most stack items.
Fred Drake456035f1997-12-03 04:06:57 +0000135\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000136
Fred Drake456035f1997-12-03 04:06:57 +0000137\begin{opcodedesc}{ROT_THREE}{}
138Lifts second and third stack item one position up, moves top down
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000139to position three.
Fred Drake456035f1997-12-03 04:06:57 +0000140\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000141
Thomas Wouters12bba852000-08-24 20:06:04 +0000142\begin{opcodedesc}{ROT_FOUR}{}
143Lifts second, third and forth stack item one position up, moves top down to
144position four.
145\end{opcodedesc}
146
Fred Drake456035f1997-12-03 04:06:57 +0000147\begin{opcodedesc}{DUP_TOP}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000148Duplicates the reference on top of the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000149\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000150
151Unary Operations take the top of the stack, apply the operation, and
152push the result back on the stack.
153
Fred Drake456035f1997-12-03 04:06:57 +0000154\begin{opcodedesc}{UNARY_POSITIVE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000155Implements \code{TOS = +TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000156\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000157
Fred Drake4c3f7972000-08-31 16:26:35 +0000158\begin{opcodedesc}{UNARY_NEGATIVE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000159Implements \code{TOS = -TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000160\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000161
Fred Drake456035f1997-12-03 04:06:57 +0000162\begin{opcodedesc}{UNARY_NOT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000163Implements \code{TOS = not TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000164\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000165
Fred Drake456035f1997-12-03 04:06:57 +0000166\begin{opcodedesc}{UNARY_CONVERT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000167Implements \code{TOS = `TOS`}.
Fred Drake456035f1997-12-03 04:06:57 +0000168\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000169
Fred Drake456035f1997-12-03 04:06:57 +0000170\begin{opcodedesc}{UNARY_INVERT}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000171Implements \code{TOS = \~{}TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000172\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000173
Guido van Rossume3fdc972002-06-12 15:33:08 +0000174\begin{opcodedesc}{GET_ITER}{}
175Implements \code{TOS = iter(TOS)}.
176\end{opcodedesc}
177
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000178Binary operations remove the top of the stack (TOS) and the second top-most
179stack item (TOS1) from the stack. They perform the operation, and put the
180result back on the stack.
181
Fred Drake456035f1997-12-03 04:06:57 +0000182\begin{opcodedesc}{BINARY_POWER}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000183Implements \code{TOS = TOS1 ** TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000184\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000185
Fred Drake456035f1997-12-03 04:06:57 +0000186\begin{opcodedesc}{BINARY_MULTIPLY}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000187Implements \code{TOS = TOS1 * TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000188\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000189
Fred Drake456035f1997-12-03 04:06:57 +0000190\begin{opcodedesc}{BINARY_DIVIDE}{}
Guido van Rossume3fdc972002-06-12 15:33:08 +0000191Implements \code{TOS = TOS1 / TOS} when
192\code{from __future__ import division} is not in effect.
193\end{opcodedesc}
194
195\begin{opcodedesc}{BINARY_FLOOR_DIVIDE}{}
196Implements \code{TOS = TOS1 // TOS}.
197\end{opcodedesc}
198
199\begin{opcodedesc}{BINARY_TRUE_DIVIDE}{}
200Implements \code{TOS = TOS1 / TOS} when
201\code{from __future__ import division} is in effect.
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_MODULO}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000205Implements \code{TOS = TOS1 \%{} TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000206\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000207
Fred Drake456035f1997-12-03 04:06:57 +0000208\begin{opcodedesc}{BINARY_ADD}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000209Implements \code{TOS = TOS1 + TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000210\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000211
Fred Drake456035f1997-12-03 04:06:57 +0000212\begin{opcodedesc}{BINARY_SUBTRACT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000213Implements \code{TOS = TOS1 - TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000214\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000215
Fred Drake456035f1997-12-03 04:06:57 +0000216\begin{opcodedesc}{BINARY_SUBSCR}{}
Fred Drake1cf87491997-12-04 04:57:56 +0000217Implements \code{TOS = TOS1[TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000218\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000219
Fred Drake456035f1997-12-03 04:06:57 +0000220\begin{opcodedesc}{BINARY_LSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000221Implements \code{TOS = TOS1 <\code{}< TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000222\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000223
Fred Drake456035f1997-12-03 04:06:57 +0000224\begin{opcodedesc}{BINARY_RSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000225Implements \code{TOS = TOS1 >\code{}> TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000226\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000227
Fred Drake456035f1997-12-03 04:06:57 +0000228\begin{opcodedesc}{BINARY_AND}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000229Implements \code{TOS = TOS1 \&\ TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000230\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000231
Fred Drake456035f1997-12-03 04:06:57 +0000232\begin{opcodedesc}{BINARY_XOR}{}
Fred Draked7feffd1997-12-29 20:02:55 +0000233Implements \code{TOS = TOS1 \^\ TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000234\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000235
Fred Drake456035f1997-12-03 04:06:57 +0000236\begin{opcodedesc}{BINARY_OR}{}
Fred Drake9e759df2000-06-15 18:44:30 +0000237Implements \code{TOS = TOS1 | TOS}.
Fred Drake456035f1997-12-03 04:06:57 +0000238\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000239
Thomas Wouters12bba852000-08-24 20:06:04 +0000240In-place operations are like binary operations, in that they remove TOS and
241TOS1, and push the result back on the stack, but the operation is done
242in-place when TOS1 supports it, and the resulting TOS may be (but does not
243have to be) the original TOS1.
244
245\begin{opcodedesc}{INPLACE_POWER}{}
246Implements in-place \code{TOS = TOS1 ** TOS}.
247\end{opcodedesc}
248
249\begin{opcodedesc}{INPLACE_MULTIPLY}{}
250Implements in-place \code{TOS = TOS1 * TOS}.
251\end{opcodedesc}
252
253\begin{opcodedesc}{INPLACE_DIVIDE}{}
Guido van Rossume3fdc972002-06-12 15:33:08 +0000254Implements in-place \code{TOS = TOS1 / TOS} when
255\code{from __future__ import division} is not in effect.
256\end{opcodedesc}
257
258\begin{opcodedesc}{INPLACE_FLOOR_DIVIDE}{}
259Implements in-place \code{TOS = TOS1 // TOS}.
260\end{opcodedesc}
261
262\begin{opcodedesc}{INPLACE_TRUE_DIVIDE}{}
263Implements in-place \code{TOS = TOS1 / TOS} when
264\code{from __future__ import division} is in effect.
Thomas Wouters12bba852000-08-24 20:06:04 +0000265\end{opcodedesc}
266
267\begin{opcodedesc}{INPLACE_MODULO}{}
268Implements in-place \code{TOS = TOS1 \%{} TOS}.
269\end{opcodedesc}
270
271\begin{opcodedesc}{INPLACE_ADD}{}
272Implements in-place \code{TOS = TOS1 + TOS}.
273\end{opcodedesc}
274
275\begin{opcodedesc}{INPLACE_SUBTRACT}{}
276Implements in-place \code{TOS = TOS1 - TOS}.
277\end{opcodedesc}
278
279\begin{opcodedesc}{INPLACE_LSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000280Implements in-place \code{TOS = TOS1 <\code{}< TOS}.
Thomas Wouters12bba852000-08-24 20:06:04 +0000281\end{opcodedesc}
282
283\begin{opcodedesc}{INPLACE_RSHIFT}{}
Fred Drake2c4f5542000-10-10 22:00:03 +0000284Implements in-place \code{TOS = TOS1 >\code{}> TOS}.
Thomas Wouters12bba852000-08-24 20:06:04 +0000285\end{opcodedesc}
286
287\begin{opcodedesc}{INPLACE_AND}{}
288Implements in-place \code{TOS = TOS1 \&\ TOS}.
289\end{opcodedesc}
290
291\begin{opcodedesc}{INPLACE_XOR}{}
292Implements in-place \code{TOS = TOS1 \^\ TOS}.
293\end{opcodedesc}
294
295\begin{opcodedesc}{INPLACE_OR}{}
296Implements in-place \code{TOS = TOS1 | TOS}.
297\end{opcodedesc}
298
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000299The slice opcodes take up to three parameters.
300
Fred Drake456035f1997-12-03 04:06:57 +0000301\begin{opcodedesc}{SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000302Implements \code{TOS = TOS[:]}.
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}{SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000306Implements \code{TOS = TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000307\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000308
Fred Drake456035f1997-12-03 04:06:57 +0000309\begin{opcodedesc}{SLICE+2}{}
Neal Norwitze72a9a12002-08-05 23:33:54 +0000310Implements \code{TOS = TOS1[:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000311\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000312
Fred Drake456035f1997-12-03 04:06:57 +0000313\begin{opcodedesc}{SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000314Implements \code{TOS = TOS2[TOS1:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000315\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000316
317Slice assignment needs even an additional parameter. As any statement,
318they put nothing on the stack.
319
Fred Drake456035f1997-12-03 04:06:57 +0000320\begin{opcodedesc}{STORE_SLICE+0}{}
Fred Drake7381e281997-12-04 04:51:12 +0000321Implements \code{TOS[:] = TOS1}.
Fred Drake456035f1997-12-03 04:06:57 +0000322\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000323
Fred Drake456035f1997-12-03 04:06:57 +0000324\begin{opcodedesc}{STORE_SLICE+1}{}
Fred Drake7381e281997-12-04 04:51:12 +0000325Implements \code{TOS1[TOS:] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000326\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000327
Fred Drake456035f1997-12-03 04:06:57 +0000328\begin{opcodedesc}{STORE_SLICE+2}{}
Fred Drake7381e281997-12-04 04:51:12 +0000329Implements \code{TOS1[:TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000330\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000331
Fred Drake456035f1997-12-03 04:06:57 +0000332\begin{opcodedesc}{STORE_SLICE+3}{}
Fred Drake7381e281997-12-04 04:51:12 +0000333Implements \code{TOS2[TOS1:TOS] = TOS3}.
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}{DELETE_SLICE+0}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000337Implements \code{del TOS[:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000338\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000339
Fred Drake456035f1997-12-03 04:06:57 +0000340\begin{opcodedesc}{DELETE_SLICE+1}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000341Implements \code{del TOS1[TOS:]}.
Fred Drake456035f1997-12-03 04:06:57 +0000342\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000343
Fred Drake456035f1997-12-03 04:06:57 +0000344\begin{opcodedesc}{DELETE_SLICE+2}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000345Implements \code{del TOS1[:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000346\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000347
Fred Drake456035f1997-12-03 04:06:57 +0000348\begin{opcodedesc}{DELETE_SLICE+3}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000349Implements \code{del TOS2[TOS1:TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000350\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000351
Fred Drake456035f1997-12-03 04:06:57 +0000352\begin{opcodedesc}{STORE_SUBSCR}{}
Fred Drake7381e281997-12-04 04:51:12 +0000353Implements \code{TOS1[TOS] = TOS2}.
Fred Drake456035f1997-12-03 04:06:57 +0000354\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000355
Fred Drake456035f1997-12-03 04:06:57 +0000356\begin{opcodedesc}{DELETE_SUBSCR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000357Implements \code{del TOS1[TOS]}.
Fred Drake456035f1997-12-03 04:06:57 +0000358\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000359
Guido van Rossume3fdc972002-06-12 15:33:08 +0000360Miscellaneous opcodes.
361
Fred Drake456035f1997-12-03 04:06:57 +0000362\begin{opcodedesc}{PRINT_EXPR}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000363Implements the expression statement for the interactive mode. TOS is
364removed from the stack and printed. In non-interactive mode, an
Fred Drake456035f1997-12-03 04:06:57 +0000365expression statement is terminated with \code{POP_STACK}.
366\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000367
Fred Drake456035f1997-12-03 04:06:57 +0000368\begin{opcodedesc}{PRINT_ITEM}{}
Barry Warsaw90876882000-08-21 17:19:00 +0000369Prints TOS to the file-like object bound to \code{sys.stdout}. There
370is one such instruction for each item in the \keyword{print} statement.
371\end{opcodedesc}
372
373\begin{opcodedesc}{PRINT_ITEM_TO}{}
374Like \code{PRINT_ITEM}, but prints the item second from TOS to the
375file-like object at TOS. This is used by the extended print statement.
Fred Drake456035f1997-12-03 04:06:57 +0000376\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000377
Fred Drake456035f1997-12-03 04:06:57 +0000378\begin{opcodedesc}{PRINT_NEWLINE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000379Prints a new line on \code{sys.stdout}. This is generated as the
Fred Drake304faf92000-08-18 02:15:55 +0000380last operation of a \keyword{print} statement, unless the statement
381ends with a comma.
Fred Drake456035f1997-12-03 04:06:57 +0000382\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000383
Barry Warsaw90876882000-08-21 17:19:00 +0000384\begin{opcodedesc}{PRINT_NEWLINE_TO}{}
385Like \code{PRINT_NEWLINE}, but prints the new line on the file-like
386object on the TOS. This is used by the extended print statement.
387\end{opcodedesc}
388
Fred Drake456035f1997-12-03 04:06:57 +0000389\begin{opcodedesc}{BREAK_LOOP}{}
Fred Drake304faf92000-08-18 02:15:55 +0000390Terminates a loop due to a \keyword{break} statement.
Fred Drake456035f1997-12-03 04:06:57 +0000391\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000392
Guido van Rossume3fdc972002-06-12 15:33:08 +0000393\begin{opcodedesc}{CONTINUE_LOOP}{target}
394Continues a loop due to a \keyword{continue} statement. \var{target}
395is the address to jump to (which should be a \code{FOR_ITER}
396instruction).
397\end{opcodedesc}
398
Fred Drake456035f1997-12-03 04:06:57 +0000399\begin{opcodedesc}{LOAD_LOCALS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000400Pushes a reference to the locals of the current scope on the stack.
401This is used in the code for a class definition: After the class body
402is evaluated, the locals are passed to the class definition.
Fred Drake456035f1997-12-03 04:06:57 +0000403\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000404
Fred Drake456035f1997-12-03 04:06:57 +0000405\begin{opcodedesc}{RETURN_VALUE}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000406Returns with TOS to the caller of the function.
Fred Drake456035f1997-12-03 04:06:57 +0000407\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000408
Guido van Rossume3fdc972002-06-12 15:33:08 +0000409\begin{opcodedesc}{YIELD_VALUE}{}
410Pops \code{TOS} and yields it from a generator.
411\end{opcodedesc}
412
Thomas Wouters52152252000-08-17 22:55:00 +0000413\begin{opcodedesc}{IMPORT_STAR}{}
Fred Drake304faf92000-08-18 02:15:55 +0000414Loads all symbols not starting with \character{_} directly from the module TOS
Thomas Wouters52152252000-08-17 22:55:00 +0000415to the local namespace. The module is popped after loading all names.
Fred Drake304faf92000-08-18 02:15:55 +0000416This opcode implements \code{from module import *}.
417\end{opcodedesc}
Thomas Wouters52152252000-08-17 22:55:00 +0000418
Fred Drake456035f1997-12-03 04:06:57 +0000419\begin{opcodedesc}{EXEC_STMT}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000420Implements \code{exec TOS2,TOS1,TOS}. The compiler fills
Fred Drake304faf92000-08-18 02:15:55 +0000421missing optional parameters with \code{None}.
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}{POP_BLOCK}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000425Removes one block from the block stack. Per frame, there is a
426stack of blocks, denoting nested loops, try statements, and such.
Fred Drake456035f1997-12-03 04:06:57 +0000427\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000428
Fred Drake456035f1997-12-03 04:06:57 +0000429\begin{opcodedesc}{END_FINALLY}{}
Fred Drake304faf92000-08-18 02:15:55 +0000430Terminates a \keyword{finally} clause. The interpreter recalls
431whether the exception has to be re-raised, or whether the function
432returns, and continues with the outer-next block.
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}{BUILD_CLASS}{}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000436Creates a new class object. TOS is the methods dictionary, TOS1
437the tuple of the names of the base classes, and TOS2 the class name.
Fred Drake456035f1997-12-03 04:06:57 +0000438\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000439
440All of the following opcodes expect arguments. An argument is two
441bytes, with the more significant byte last.
442
Fred Drake456035f1997-12-03 04:06:57 +0000443\begin{opcodedesc}{STORE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000444Implements \code{name = TOS}. \var{namei} is the index of \var{name}
Fred Drakedff21a61998-04-03 05:42:10 +0000445in the attribute \member{co_names} of the code object.
Fred Drake456035f1997-12-03 04:06:57 +0000446The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL}
447if possible.
448\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000449
Fred Drake456035f1997-12-03 04:06:57 +0000450\begin{opcodedesc}{DELETE_NAME}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000451Implements \code{del name}, where \var{namei} is the index into
Fred Drakedff21a61998-04-03 05:42:10 +0000452\member{co_names} attribute of the code object.
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_SEQUENCE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000456Unpacks TOS into \var{count} individual values, which are put onto
457the stack right-to-left.
Fred Drake456035f1997-12-03 04:06:57 +0000458\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000459
Thomas Wouters0be5aab2000-08-11 22:15:52 +0000460%\begin{opcodedesc}{UNPACK_LIST}{count}
461%This opcode is obsolete.
462%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000463
Fred Drake456035f1997-12-03 04:06:57 +0000464%\begin{opcodedesc}{UNPACK_ARG}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000465%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000466%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000467
Thomas Wouters12bba852000-08-24 20:06:04 +0000468\begin{opcodedesc}{DUP_TOPX}{count}
469Duplicate \var{count} items, keeping them in the same order. Due to
470implementation limits, \var{count} should be between 1 and 5 inclusive.
471\end{opcodedesc}
472
Fred Drake456035f1997-12-03 04:06:57 +0000473\begin{opcodedesc}{STORE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000474Implements \code{TOS.name = TOS1}, where \var{namei} is the index
Fred Drakedff21a61998-04-03 05:42:10 +0000475of name in \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}{DELETE_ATTR}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000479Implements \code{del TOS.name}, using \var{namei} as index into
Fred Drakedff21a61998-04-03 05:42:10 +0000480\member{co_names}.
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}{STORE_GLOBAL}{namei}
484Works as \code{STORE_NAME}, but stores the name as a global.
485\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000486
Fred Drake456035f1997-12-03 04:06:57 +0000487\begin{opcodedesc}{DELETE_GLOBAL}{namei}
488Works as \code{DELETE_NAME}, but deletes a global name.
489\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000490
Fred Drake456035f1997-12-03 04:06:57 +0000491%\begin{opcodedesc}{UNPACK_VARARG}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000492%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000493%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000494
Fred Drake456035f1997-12-03 04:06:57 +0000495\begin{opcodedesc}{LOAD_CONST}{consti}
Fred Drakedff21a61998-04-03 05:42:10 +0000496Pushes \samp{co_consts[\var{consti}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000497\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000498
Fred Drake456035f1997-12-03 04:06:57 +0000499\begin{opcodedesc}{LOAD_NAME}{namei}
Fred Drakedff21a61998-04-03 05:42:10 +0000500Pushes the value associated with \samp{co_names[\var{namei}]} 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_TUPLE}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000504Creates a tuple consuming \var{count} items from the stack, and pushes
505the resulting tuple onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000506\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000507
Fred Drake456035f1997-12-03 04:06:57 +0000508\begin{opcodedesc}{BUILD_LIST}{count}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000509Works as \code{BUILD_TUPLE}, but creates a list.
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}{BUILD_MAP}{zero}
Fred Drake304faf92000-08-18 02:15:55 +0000513Pushes a new empty dictionary object onto the stack. The argument is
514ignored and set to zero by the compiler.
Fred Drake456035f1997-12-03 04:06:57 +0000515\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000516
Fred Drake456035f1997-12-03 04:06:57 +0000517\begin{opcodedesc}{LOAD_ATTR}{namei}
Raymond Hettingerb4c1d9b2003-05-10 08:51:28 +0000518Replaces TOS with \code{getattr(TOS, co_names[\var{namei}])}.
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}{COMPARE_OP}{opname}
Fred Drake6c81e2a2001-10-01 17:04:10 +0000522Performs a Boolean operation. The operation name can be found
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000523in \code{cmp_op[\var{opname}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000524\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000525
Fred Drake456035f1997-12-03 04:06:57 +0000526\begin{opcodedesc}{IMPORT_NAME}{namei}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000527Imports the module \code{co_names[\var{namei}]}. The module object is
Fred Drake13494372000-09-12 16:23:48 +0000528pushed onto the stack. The current namespace is not affected: for a
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000529proper import statement, a subsequent \code{STORE_FAST} instruction
Fred Drake13494372000-09-12 16:23:48 +0000530modifies the namespace.
Fred Drake456035f1997-12-03 04:06:57 +0000531\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000532
Fred Drake456035f1997-12-03 04:06:57 +0000533\begin{opcodedesc}{IMPORT_FROM}{namei}
Thomas Wouters52152252000-08-17 22:55:00 +0000534Loads the attribute \code{co_names[\var{namei}]} from the module found in
535TOS. The resulting object is pushed onto the stack, to be subsequently
536stored by a \code{STORE_FAST} instruction.
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}{JUMP_FORWARD}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000540Increments byte code counter by \var{delta}.
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_TRUE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000544If TOS is true, increment the byte code counter by \var{delta}. TOS is
545left on the stack.
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_IF_FALSE}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000549If TOS is false, increment the byte code counter by \var{delta}. TOS
550is not changed.
Fred Drake456035f1997-12-03 04:06:57 +0000551\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000552
Fred Drake456035f1997-12-03 04:06:57 +0000553\begin{opcodedesc}{JUMP_ABSOLUTE}{target}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000554Set byte code counter to \var{target}.
Fred Drake456035f1997-12-03 04:06:57 +0000555\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000556
Guido van Rossume3fdc972002-06-12 15:33:08 +0000557\begin{opcodedesc}{FOR_ITER}{delta}
558\code{TOS} is an iterator. Call its \method{next()} method. If this
559yields a new value, push it on the stack (leaving the iterator below
560it). If the iterator indicates it is exhausted \code{TOS} is
561popped, and the byte code counter is incremented by \var{delta}.
562\end{opcodedesc}
563
Guido van Rossumfea59e72002-06-13 17:59:51 +0000564%\begin{opcodedesc}{FOR_LOOP}{delta}
565%This opcode is obsolete.
566%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000567
Fred Drake456035f1997-12-03 04:06:57 +0000568%\begin{opcodedesc}{LOAD_LOCAL}{namei}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000569%This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000570%\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000571
Fred Drake456035f1997-12-03 04:06:57 +0000572\begin{opcodedesc}{LOAD_GLOBAL}{namei}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000573Loads the global named \code{co_names[\var{namei}]} onto the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000574\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000575
Fred Drake456035f1997-12-03 04:06:57 +0000576%\begin{opcodedesc}{SET_FUNC_ARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000577%This opcode is obsolete.
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_LOOP}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000581Pushes a block for a loop onto the block stack. The block spans
582from the current instruction with a size of \var{delta} bytes.
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_EXCEPT}{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 first except 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}{SETUP_FINALLY}{delta}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000591Pushes a try block from a try-except clause onto the block stack.
592\var{delta} points to the finally block.
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}{LOAD_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000596Pushes a reference to the local \code{co_varnames[\var{var_num}]} onto
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000597the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000598\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000599
Fred Drake456035f1997-12-03 04:06:57 +0000600\begin{opcodedesc}{STORE_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000601Stores TOS into the local \code{co_varnames[\var{var_num}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000602\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000603
Fred Drake456035f1997-12-03 04:06:57 +0000604\begin{opcodedesc}{DELETE_FAST}{var_num}
Fred Drakedd1f6cc1998-02-12 03:32:18 +0000605Deletes local \code{co_varnames[\var{var_num}]}.
Fred Drake456035f1997-12-03 04:06:57 +0000606\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000607
Jeremy Hyltonaa90adc2001-03-23 17:23:50 +0000608\begin{opcodedesc}{LOAD_CLOSURE}{i}
609Pushes a reference to the cell contained in slot \var{i} of the
610cell and free variable storage. The name of the variable is
611\code{co_cellvars[\var{i}]} if \var{i} is less than the length of
612\var{co_cellvars}. Otherwise it is
613\code{co_freevars[\var{i} - len(co_cellvars)]}.
614\end{opcodedesc}
615
616\begin{opcodedesc}{LOAD_DEREF}{i}
617Loads the cell contained in slot \var{i} of the cell and free variable
618storage. Pushes a reference to the object the cell contains on the
619stack.
620\end{opcodedesc}
621
622\begin{opcodedesc}{STORE_DEREF}{i}
623Stores TOS into the cell contained in slot \var{i} of the cell and
624free variable storage.
625\end{opcodedesc}
626
Fred Drake338da931999-05-17 20:57:07 +0000627\begin{opcodedesc}{SET_LINENO}{lineno}
Michael W. Hudsondd32a912002-08-15 14:59:02 +0000628This opcode is obsolete.
Fred Drake456035f1997-12-03 04:06:57 +0000629\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000630
Fred Drake456035f1997-12-03 04:06:57 +0000631\begin{opcodedesc}{RAISE_VARARGS}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000632Raises an exception. \var{argc} indicates the number of parameters
Fred Drake304faf92000-08-18 02:15:55 +0000633to the raise statement, ranging from 0 to 3. The handler will find
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000634the traceback as TOS2, the parameter as TOS1, and the exception
635as TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000636\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000637
Fred Drake456035f1997-12-03 04:06:57 +0000638\begin{opcodedesc}{CALL_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000639Calls a function. The low byte of \var{argc} indicates the number of
640positional parameters, the high byte the number of keyword parameters.
641On the stack, the opcode finds the keyword parameters first. For each
642keyword argument, the value is on top of the key. Below the keyword
643parameters, the positional parameters are on the stack, with the
644right-most parameter on top. Below the parameters, the function object
645to call is on the stack.
Fred Drake456035f1997-12-03 04:06:57 +0000646\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000647
Fred Drake456035f1997-12-03 04:06:57 +0000648\begin{opcodedesc}{MAKE_FUNCTION}{argc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000649Pushes a new function object on the stack. TOS is the code associated
650with the function. The function object is defined to have \var{argc}
651default parameters, which are found below TOS.
Fred Drake456035f1997-12-03 04:06:57 +0000652\end{opcodedesc}
Guido van Rossumb62b6d11997-11-18 15:10:53 +0000653
Jeremy Hyltonaa90adc2001-03-23 17:23:50 +0000654\begin{opcodedesc}{MAKE_CLOSURE}{argc}
655Creates a new function object, sets its \var{func_closure} slot, and
656pushes it on the stack. TOS is the code associated with the function.
657If the code object has N free variables, the next N items on the stack
658are the cells for these variables. The function also has \var{argc}
659default parameters, where are found before the cells.
660\end{opcodedesc}
661
Fred Drake456035f1997-12-03 04:06:57 +0000662\begin{opcodedesc}{BUILD_SLICE}{argc}
Guido van Rossumda623981998-02-12 03:53:02 +0000663Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it
664is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3,
665\code{slice(TOS2, TOS1, TOS)} is pushed.
Fred Drake304faf92000-08-18 02:15:55 +0000666See the \code{slice()}\bifuncindex{slice} built-in function for more
667information.
Fred Drake456035f1997-12-03 04:06:57 +0000668\end{opcodedesc}
Fred Drake25699f92000-08-17 22:19:26 +0000669
Fred Drake093272e2000-08-24 00:37:50 +0000670\begin{opcodedesc}{EXTENDED_ARG}{ext}
671Prefixes any opcode which has an argument too big to fit into the
672default two bytes. \var{ext} holds two additional bytes which, taken
673together with the subsequent opcode's argument, comprise a four-byte
Fred Drake4c3f7972000-08-31 16:26:35 +0000674argument, \var{ext} being the two most-significant bytes.
Fred Drake093272e2000-08-24 00:37:50 +0000675\end{opcodedesc}
676
Fred Drake25699f92000-08-17 22:19:26 +0000677\begin{opcodedesc}{CALL_FUNCTION_VAR}{argc}
678Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
679The top element on the stack contains the variable argument list, followed
680by keyword and positional arguments.
681\end{opcodedesc}
682
683\begin{opcodedesc}{CALL_FUNCTION_KW}{argc}
684Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
685The top element on the stack contains the keyword arguments dictionary,
686followed by explicit keyword and positional arguments.
687\end{opcodedesc}
688
689\begin{opcodedesc}{CALL_FUNCTION_VAR_KW}{argc}
690Calls a function. \var{argc} is interpreted as in
691\code{CALL_FUNCTION}. The top element on the stack contains the
692keyword arguments dictionary, followed by the variable-arguments
693tuple, followed by explicit keyword and positional arguments.
694\end{opcodedesc}
Skip Montanarobecbdec2005-01-05 07:19:11 +0000695
696\begin{opcodedesc}{HAVE_ARGUMENT}{}
697This is not really an opcode. It identifies the dividing line between
698opcodes which don't take arguments \code{< HAVE_ARGUMENT} and those which do
699\code{>= HAVE_ARGUMENT}.
700\end{opcodedesc}