Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{dis} --- |
Fred Drake | f8ca7d8 | 2000-10-10 17:03:45 +0000 | [diff] [blame] | 2 | Disassembler for Python byte code} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | |
Fred Drake | f8ca7d8 | 2000-10-10 17:03:45 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{dis} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 5 | \modulesynopsis{Disassembler for Python byte code.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 7 | |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 8 | The \module{dis} module supports the analysis of Python byte code by |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 9 | disassembling it. Since there is no Python assembler, this module |
| 10 | defines the Python assembly language. The Python byte code which |
| 11 | this module takes as an input is defined in the file |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 12 | \file{Include/opcode.h} and used by the compiler and the interpreter. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 13 | |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 14 | Example: Given the function \function{myfunc}: |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 15 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 16 | \begin{verbatim} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 17 | def myfunc(alist): |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 18 | return len(alist) |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 19 | \end{verbatim} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 20 | |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 21 | the following command can be used to get the disassembly of |
| 22 | \function{myfunc()}: |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 23 | |
| 24 | \begin{verbatim} |
| 25 | >>> dis.dis(myfunc) |
Michael W. Hudson | dd32a91 | 2002-08-15 14:59:02 +0000 | [diff] [blame] | 26 | 2 0 LOAD_GLOBAL 0 (len) |
| 27 | 3 LOAD_FAST 0 (alist) |
| 28 | 6 CALL_FUNCTION 1 |
| 29 | 9 RETURN_VALUE |
Michael W. Hudson | 53d58bb | 2002-08-30 13:09:51 +0000 | [diff] [blame] | 30 | 10 LOAD_CONST 0 (None) |
| 31 | 13 RETURN_VALUE |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 32 | \end{verbatim} |
| 33 | |
Michael W. Hudson | dd32a91 | 2002-08-15 14:59:02 +0000 | [diff] [blame] | 34 | (The ``2'' is a line number). |
| 35 | |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 36 | The \module{dis} module defines the following functions and constants: |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 37 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 38 | \begin{funcdesc}{dis}{\optional{bytesource}} |
| 39 | Disassemble the \var{bytesource} object. \var{bytesource} can denote |
Neal Norwitz | dcd0500 | 2002-06-26 22:32:47 +0000 | [diff] [blame] | 40 | either a module, a class, a method, a function, or a code object. |
| 41 | For a module, it disassembles all functions. For a class, |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 42 | it disassembles all methods. For a single code sequence, it prints |
| 43 | one line per byte code instruction. If no object is provided, it |
| 44 | disassembles the last traceback. |
| 45 | \end{funcdesc} |
| 46 | |
| 47 | \begin{funcdesc}{distb}{\optional{tb}} |
| 48 | Disassembles the top-of-stack function of a traceback, using the last |
| 49 | traceback if none was passed. The instruction causing the exception |
| 50 | is indicated. |
| 51 | \end{funcdesc} |
| 52 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 53 | \begin{funcdesc}{disassemble}{code\optional{, lasti}} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 54 | Disassembles a code object, indicating the last instruction if \var{lasti} |
| 55 | was provided. The output is divided in the following columns: |
Fred Drake | 810349b | 1998-04-07 14:16:41 +0000 | [diff] [blame] | 56 | |
Fred Drake | 3e7a48e | 1998-04-13 16:15:02 +0000 | [diff] [blame] | 57 | \begin{enumerate} |
Michael W. Hudson | dd32a91 | 2002-08-15 14:59:02 +0000 | [diff] [blame] | 58 | \item the line number, for the first instruction of each line |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 59 | \item the current instruction, indicated as \samp{-->}, |
Fred Drake | c054c75 | 2001-04-13 17:25:38 +0000 | [diff] [blame] | 60 | \item a labelled instruction, indicated with \samp{>\code{>}}, |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 61 | \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 Drake | 3e7a48e | 1998-04-13 16:15:02 +0000 | [diff] [blame] | 65 | \end{enumerate} |
Fred Drake | 810349b | 1998-04-07 14:16:41 +0000 | [diff] [blame] | 66 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 67 | The parameter interpretation recognizes local and global |
| 68 | variable names, constant values, branch targets, and compare |
| 69 | operators. |
| 70 | \end{funcdesc} |
| 71 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 72 | \begin{funcdesc}{disco}{code\optional{, lasti}} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 73 | A synonym for disassemble. It is more convenient to type, and kept |
| 74 | for compatibility with earlier Python releases. |
| 75 | \end{funcdesc} |
| 76 | |
| 77 | \begin{datadesc}{opname} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 78 | Sequence of operation names, indexable using the byte code. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 79 | \end{datadesc} |
| 80 | |
| 81 | \begin{datadesc}{cmp_op} |
| 82 | Sequence of all compare operation names. |
| 83 | \end{datadesc} |
| 84 | |
| 85 | \begin{datadesc}{hasconst} |
| 86 | Sequence of byte codes that have a constant parameter. |
| 87 | \end{datadesc} |
| 88 | |
Fred Drake | 47cdf6f | 2002-03-28 19:34:53 +0000 | [diff] [blame] | 89 | \begin{datadesc}{hasfree} |
| 90 | Sequence of byte codes that access a free variable. |
| 91 | \end{datadesc} |
| 92 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 93 | \begin{datadesc}{hasname} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 94 | Sequence of byte codes that access an attribute by name. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 95 | \end{datadesc} |
| 96 | |
| 97 | \begin{datadesc}{hasjrel} |
| 98 | Sequence of byte codes that have a relative jump target. |
| 99 | \end{datadesc} |
| 100 | |
| 101 | \begin{datadesc}{hasjabs} |
| 102 | Sequence of byte codes that have an absolute jump target. |
| 103 | \end{datadesc} |
| 104 | |
| 105 | \begin{datadesc}{haslocal} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 106 | Sequence of byte codes that access a local variable. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 107 | \end{datadesc} |
| 108 | |
| 109 | \begin{datadesc}{hascompare} |
Fred Drake | 6c81e2a | 2001-10-01 17:04:10 +0000 | [diff] [blame] | 110 | Sequence of byte codes of Boolean operations. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 111 | \end{datadesc} |
| 112 | |
| 113 | \subsection{Python Byte Code Instructions} |
Fred Drake | 83efb54 | 1998-02-19 20:07:39 +0000 | [diff] [blame] | 114 | \label{bytecodes} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 115 | |
| 116 | The Python compiler currently generates the following byte code |
| 117 | instructions. |
| 118 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 119 | \setindexsubitem{(byte code insns)} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 120 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 121 | \begin{opcodedesc}{STOP_CODE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 122 | Indicates end-of-code to the compiler, not used by the interpreter. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 123 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 124 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 125 | \begin{opcodedesc}{POP_TOP}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 126 | Removes the top-of-stack (TOS) item. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 127 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 128 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 129 | \begin{opcodedesc}{ROT_TWO}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 130 | Swaps the two top-most stack items. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 131 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 132 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 133 | \begin{opcodedesc}{ROT_THREE}{} |
| 134 | Lifts second and third stack item one position up, moves top down |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 135 | to position three. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 136 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 137 | |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 138 | \begin{opcodedesc}{ROT_FOUR}{} |
| 139 | Lifts second, third and forth stack item one position up, moves top down to |
| 140 | position four. |
| 141 | \end{opcodedesc} |
| 142 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 143 | \begin{opcodedesc}{DUP_TOP}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 144 | Duplicates the reference on top of the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 145 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 146 | |
| 147 | Unary Operations take the top of the stack, apply the operation, and |
| 148 | push the result back on the stack. |
| 149 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 150 | \begin{opcodedesc}{UNARY_POSITIVE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 151 | Implements \code{TOS = +TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 152 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 153 | |
Fred Drake | 4c3f797 | 2000-08-31 16:26:35 +0000 | [diff] [blame] | 154 | \begin{opcodedesc}{UNARY_NEGATIVE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 155 | Implements \code{TOS = -TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 156 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 157 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 158 | \begin{opcodedesc}{UNARY_NOT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 159 | Implements \code{TOS = not TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 160 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 161 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 162 | \begin{opcodedesc}{UNARY_CONVERT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 163 | Implements \code{TOS = `TOS`}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 164 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 165 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 166 | \begin{opcodedesc}{UNARY_INVERT}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +0000 | [diff] [blame] | 167 | Implements \code{TOS = \~{}TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 168 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 169 | |
Guido van Rossum | e3fdc97 | 2002-06-12 15:33:08 +0000 | [diff] [blame] | 170 | \begin{opcodedesc}{GET_ITER}{} |
| 171 | Implements \code{TOS = iter(TOS)}. |
| 172 | \end{opcodedesc} |
| 173 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 174 | Binary operations remove the top of the stack (TOS) and the second top-most |
| 175 | stack item (TOS1) from the stack. They perform the operation, and put the |
| 176 | result back on the stack. |
| 177 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 178 | \begin{opcodedesc}{BINARY_POWER}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 179 | Implements \code{TOS = TOS1 ** TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 180 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 181 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 182 | \begin{opcodedesc}{BINARY_MULTIPLY}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 183 | Implements \code{TOS = TOS1 * TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 184 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 185 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 186 | \begin{opcodedesc}{BINARY_DIVIDE}{} |
Guido van Rossum | e3fdc97 | 2002-06-12 15:33:08 +0000 | [diff] [blame] | 187 | Implements \code{TOS = TOS1 / TOS} when |
| 188 | \code{from __future__ import division} is not in effect. |
| 189 | \end{opcodedesc} |
| 190 | |
| 191 | \begin{opcodedesc}{BINARY_FLOOR_DIVIDE}{} |
| 192 | Implements \code{TOS = TOS1 // TOS}. |
| 193 | \end{opcodedesc} |
| 194 | |
| 195 | \begin{opcodedesc}{BINARY_TRUE_DIVIDE}{} |
| 196 | Implements \code{TOS = TOS1 / TOS} when |
| 197 | \code{from __future__ import division} is in effect. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 198 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 199 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 200 | \begin{opcodedesc}{BINARY_MODULO}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +0000 | [diff] [blame] | 201 | Implements \code{TOS = TOS1 \%{} TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 202 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 203 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 204 | \begin{opcodedesc}{BINARY_ADD}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 205 | Implements \code{TOS = TOS1 + TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 206 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 207 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 208 | \begin{opcodedesc}{BINARY_SUBTRACT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 209 | Implements \code{TOS = TOS1 - TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 210 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 211 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 212 | \begin{opcodedesc}{BINARY_SUBSCR}{} |
Fred Drake | 1cf8749 | 1997-12-04 04:57:56 +0000 | [diff] [blame] | 213 | Implements \code{TOS = TOS1[TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 214 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 215 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 216 | \begin{opcodedesc}{BINARY_LSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 217 | Implements \code{TOS = TOS1 <\code{}< TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 218 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 219 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 220 | \begin{opcodedesc}{BINARY_RSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 221 | Implements \code{TOS = TOS1 >\code{}> TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 222 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 223 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 224 | \begin{opcodedesc}{BINARY_AND}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +0000 | [diff] [blame] | 225 | Implements \code{TOS = TOS1 \&\ TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 226 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 227 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 228 | \begin{opcodedesc}{BINARY_XOR}{} |
Fred Drake | d7feffd | 1997-12-29 20:02:55 +0000 | [diff] [blame] | 229 | Implements \code{TOS = TOS1 \^\ TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 230 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 231 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 232 | \begin{opcodedesc}{BINARY_OR}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +0000 | [diff] [blame] | 233 | Implements \code{TOS = TOS1 | TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 234 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 235 | |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 236 | In-place operations are like binary operations, in that they remove TOS and |
| 237 | TOS1, and push the result back on the stack, but the operation is done |
| 238 | in-place when TOS1 supports it, and the resulting TOS may be (but does not |
| 239 | have to be) the original TOS1. |
| 240 | |
| 241 | \begin{opcodedesc}{INPLACE_POWER}{} |
| 242 | Implements in-place \code{TOS = TOS1 ** TOS}. |
| 243 | \end{opcodedesc} |
| 244 | |
| 245 | \begin{opcodedesc}{INPLACE_MULTIPLY}{} |
| 246 | Implements in-place \code{TOS = TOS1 * TOS}. |
| 247 | \end{opcodedesc} |
| 248 | |
| 249 | \begin{opcodedesc}{INPLACE_DIVIDE}{} |
Guido van Rossum | e3fdc97 | 2002-06-12 15:33:08 +0000 | [diff] [blame] | 250 | Implements in-place \code{TOS = TOS1 / TOS} when |
| 251 | \code{from __future__ import division} is not in effect. |
| 252 | \end{opcodedesc} |
| 253 | |
| 254 | \begin{opcodedesc}{INPLACE_FLOOR_DIVIDE}{} |
| 255 | Implements in-place \code{TOS = TOS1 // TOS}. |
| 256 | \end{opcodedesc} |
| 257 | |
| 258 | \begin{opcodedesc}{INPLACE_TRUE_DIVIDE}{} |
| 259 | Implements in-place \code{TOS = TOS1 / TOS} when |
| 260 | \code{from __future__ import division} is in effect. |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 261 | \end{opcodedesc} |
| 262 | |
| 263 | \begin{opcodedesc}{INPLACE_MODULO}{} |
| 264 | Implements in-place \code{TOS = TOS1 \%{} TOS}. |
| 265 | \end{opcodedesc} |
| 266 | |
| 267 | \begin{opcodedesc}{INPLACE_ADD}{} |
| 268 | Implements in-place \code{TOS = TOS1 + TOS}. |
| 269 | \end{opcodedesc} |
| 270 | |
| 271 | \begin{opcodedesc}{INPLACE_SUBTRACT}{} |
| 272 | Implements in-place \code{TOS = TOS1 - TOS}. |
| 273 | \end{opcodedesc} |
| 274 | |
| 275 | \begin{opcodedesc}{INPLACE_LSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 276 | Implements in-place \code{TOS = TOS1 <\code{}< TOS}. |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 277 | \end{opcodedesc} |
| 278 | |
| 279 | \begin{opcodedesc}{INPLACE_RSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 280 | Implements in-place \code{TOS = TOS1 >\code{}> TOS}. |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 281 | \end{opcodedesc} |
| 282 | |
| 283 | \begin{opcodedesc}{INPLACE_AND}{} |
| 284 | Implements in-place \code{TOS = TOS1 \&\ TOS}. |
| 285 | \end{opcodedesc} |
| 286 | |
| 287 | \begin{opcodedesc}{INPLACE_XOR}{} |
| 288 | Implements in-place \code{TOS = TOS1 \^\ TOS}. |
| 289 | \end{opcodedesc} |
| 290 | |
| 291 | \begin{opcodedesc}{INPLACE_OR}{} |
| 292 | Implements in-place \code{TOS = TOS1 | TOS}. |
| 293 | \end{opcodedesc} |
| 294 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 295 | The slice opcodes take up to three parameters. |
| 296 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 297 | \begin{opcodedesc}{SLICE+0}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 298 | Implements \code{TOS = TOS[:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 299 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 300 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 301 | \begin{opcodedesc}{SLICE+1}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 302 | Implements \code{TOS = TOS1[TOS:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 303 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 304 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 305 | \begin{opcodedesc}{SLICE+2}{} |
Neal Norwitz | e72a9a1 | 2002-08-05 23:33:54 +0000 | [diff] [blame] | 306 | Implements \code{TOS = TOS1[:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 307 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 308 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 309 | \begin{opcodedesc}{SLICE+3}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 310 | Implements \code{TOS = TOS2[TOS1:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 311 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 312 | |
| 313 | Slice assignment needs even an additional parameter. As any statement, |
| 314 | they put nothing on the stack. |
| 315 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 316 | \begin{opcodedesc}{STORE_SLICE+0}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 317 | Implements \code{TOS[:] = TOS1}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 318 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 319 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 320 | \begin{opcodedesc}{STORE_SLICE+1}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 321 | Implements \code{TOS1[TOS:] = TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 322 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 323 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 324 | \begin{opcodedesc}{STORE_SLICE+2}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 325 | Implements \code{TOS1[:TOS] = TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 326 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 327 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 328 | \begin{opcodedesc}{STORE_SLICE+3}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 329 | Implements \code{TOS2[TOS1:TOS] = TOS3}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 330 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 331 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 332 | \begin{opcodedesc}{DELETE_SLICE+0}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 333 | Implements \code{del TOS[:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 334 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 335 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 336 | \begin{opcodedesc}{DELETE_SLICE+1}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 337 | Implements \code{del TOS1[TOS:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 338 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 339 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 340 | \begin{opcodedesc}{DELETE_SLICE+2}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 341 | Implements \code{del TOS1[:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 342 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 343 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 344 | \begin{opcodedesc}{DELETE_SLICE+3}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 345 | Implements \code{del TOS2[TOS1:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 346 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 347 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 348 | \begin{opcodedesc}{STORE_SUBSCR}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 349 | Implements \code{TOS1[TOS] = TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 350 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 351 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 352 | \begin{opcodedesc}{DELETE_SUBSCR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 353 | Implements \code{del TOS1[TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 354 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 355 | |
Guido van Rossum | e3fdc97 | 2002-06-12 15:33:08 +0000 | [diff] [blame] | 356 | Miscellaneous opcodes. |
| 357 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 358 | \begin{opcodedesc}{PRINT_EXPR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 359 | Implements the expression statement for the interactive mode. TOS is |
| 360 | removed from the stack and printed. In non-interactive mode, an |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 361 | expression statement is terminated with \code{POP_STACK}. |
| 362 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 363 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 364 | \begin{opcodedesc}{PRINT_ITEM}{} |
Barry Warsaw | 9087688 | 2000-08-21 17:19:00 +0000 | [diff] [blame] | 365 | Prints TOS to the file-like object bound to \code{sys.stdout}. There |
| 366 | is one such instruction for each item in the \keyword{print} statement. |
| 367 | \end{opcodedesc} |
| 368 | |
| 369 | \begin{opcodedesc}{PRINT_ITEM_TO}{} |
| 370 | Like \code{PRINT_ITEM}, but prints the item second from TOS to the |
| 371 | file-like object at TOS. This is used by the extended print statement. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 372 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 373 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 374 | \begin{opcodedesc}{PRINT_NEWLINE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 375 | Prints a new line on \code{sys.stdout}. This is generated as the |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 376 | last operation of a \keyword{print} statement, unless the statement |
| 377 | ends with a comma. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 378 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 379 | |
Barry Warsaw | 9087688 | 2000-08-21 17:19:00 +0000 | [diff] [blame] | 380 | \begin{opcodedesc}{PRINT_NEWLINE_TO}{} |
| 381 | Like \code{PRINT_NEWLINE}, but prints the new line on the file-like |
| 382 | object on the TOS. This is used by the extended print statement. |
| 383 | \end{opcodedesc} |
| 384 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 385 | \begin{opcodedesc}{BREAK_LOOP}{} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 386 | Terminates a loop due to a \keyword{break} statement. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 387 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 388 | |
Guido van Rossum | e3fdc97 | 2002-06-12 15:33:08 +0000 | [diff] [blame] | 389 | \begin{opcodedesc}{CONTINUE_LOOP}{target} |
| 390 | Continues a loop due to a \keyword{continue} statement. \var{target} |
| 391 | is the address to jump to (which should be a \code{FOR_ITER} |
| 392 | instruction). |
| 393 | \end{opcodedesc} |
| 394 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 395 | \begin{opcodedesc}{LOAD_LOCALS}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 396 | Pushes a reference to the locals of the current scope on the stack. |
| 397 | This is used in the code for a class definition: After the class body |
| 398 | is evaluated, the locals are passed to the class definition. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 399 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 400 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 401 | \begin{opcodedesc}{RETURN_VALUE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 402 | Returns with TOS to the caller of the function. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 403 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 404 | |
Guido van Rossum | e3fdc97 | 2002-06-12 15:33:08 +0000 | [diff] [blame] | 405 | \begin{opcodedesc}{YIELD_VALUE}{} |
| 406 | Pops \code{TOS} and yields it from a generator. |
| 407 | \end{opcodedesc} |
| 408 | |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 409 | \begin{opcodedesc}{IMPORT_STAR}{} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 410 | Loads all symbols not starting with \character{_} directly from the module TOS |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 411 | to the local namespace. The module is popped after loading all names. |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 412 | This opcode implements \code{from module import *}. |
| 413 | \end{opcodedesc} |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 414 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 415 | \begin{opcodedesc}{EXEC_STMT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 416 | Implements \code{exec TOS2,TOS1,TOS}. The compiler fills |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 417 | missing optional parameters with \code{None}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 418 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 419 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 420 | \begin{opcodedesc}{POP_BLOCK}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 421 | Removes one block from the block stack. Per frame, there is a |
| 422 | stack of blocks, denoting nested loops, try statements, and such. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 423 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 424 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 425 | \begin{opcodedesc}{END_FINALLY}{} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 426 | Terminates a \keyword{finally} clause. The interpreter recalls |
| 427 | whether the exception has to be re-raised, or whether the function |
| 428 | returns, and continues with the outer-next block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 429 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 430 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 431 | \begin{opcodedesc}{BUILD_CLASS}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 432 | Creates a new class object. TOS is the methods dictionary, TOS1 |
| 433 | the tuple of the names of the base classes, and TOS2 the class name. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 434 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 435 | |
| 436 | All of the following opcodes expect arguments. An argument is two |
| 437 | bytes, with the more significant byte last. |
| 438 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 439 | \begin{opcodedesc}{STORE_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 440 | Implements \code{name = TOS}. \var{namei} is the index of \var{name} |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 441 | in the attribute \member{co_names} of the code object. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 442 | The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL} |
| 443 | if possible. |
| 444 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 445 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 446 | \begin{opcodedesc}{DELETE_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 447 | Implements \code{del name}, where \var{namei} is the index into |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 448 | \member{co_names} attribute of the code object. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 449 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 450 | |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 451 | \begin{opcodedesc}{UNPACK_SEQUENCE}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 452 | Unpacks TOS into \var{count} individual values, which are put onto |
| 453 | the stack right-to-left. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 454 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 455 | |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 456 | %\begin{opcodedesc}{UNPACK_LIST}{count} |
| 457 | %This opcode is obsolete. |
| 458 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 459 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 460 | %\begin{opcodedesc}{UNPACK_ARG}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 461 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 462 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 463 | |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 464 | \begin{opcodedesc}{DUP_TOPX}{count} |
| 465 | Duplicate \var{count} items, keeping them in the same order. Due to |
| 466 | implementation limits, \var{count} should be between 1 and 5 inclusive. |
| 467 | \end{opcodedesc} |
| 468 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 469 | \begin{opcodedesc}{STORE_ATTR}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 470 | Implements \code{TOS.name = TOS1}, where \var{namei} is the index |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 471 | of name in \member{co_names}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 472 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 473 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 474 | \begin{opcodedesc}{DELETE_ATTR}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 475 | Implements \code{del TOS.name}, using \var{namei} as index into |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 476 | \member{co_names}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 477 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 478 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 479 | \begin{opcodedesc}{STORE_GLOBAL}{namei} |
| 480 | Works as \code{STORE_NAME}, but stores the name as a global. |
| 481 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 482 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 483 | \begin{opcodedesc}{DELETE_GLOBAL}{namei} |
| 484 | Works as \code{DELETE_NAME}, but deletes a global name. |
| 485 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 486 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 487 | %\begin{opcodedesc}{UNPACK_VARARG}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 488 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 489 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 490 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 491 | \begin{opcodedesc}{LOAD_CONST}{consti} |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 492 | Pushes \samp{co_consts[\var{consti}]} onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 493 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 494 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 495 | \begin{opcodedesc}{LOAD_NAME}{namei} |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 496 | Pushes the value associated with \samp{co_names[\var{namei}]} onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 497 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 498 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 499 | \begin{opcodedesc}{BUILD_TUPLE}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 500 | Creates a tuple consuming \var{count} items from the stack, and pushes |
| 501 | the resulting tuple onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 502 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 503 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 504 | \begin{opcodedesc}{BUILD_LIST}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 505 | Works as \code{BUILD_TUPLE}, but creates a list. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 506 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 507 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 508 | \begin{opcodedesc}{BUILD_MAP}{zero} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 509 | Pushes a new empty dictionary object onto the stack. The argument is |
| 510 | ignored and set to zero by the compiler. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 511 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 512 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 513 | \begin{opcodedesc}{LOAD_ATTR}{namei} |
Raymond Hettinger | b4c1d9b | 2003-05-10 08:51:28 +0000 | [diff] [blame] | 514 | Replaces TOS with \code{getattr(TOS, co_names[\var{namei}])}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 515 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 516 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 517 | \begin{opcodedesc}{COMPARE_OP}{opname} |
Fred Drake | 6c81e2a | 2001-10-01 17:04:10 +0000 | [diff] [blame] | 518 | Performs a Boolean operation. The operation name can be found |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 519 | in \code{cmp_op[\var{opname}]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 520 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 521 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 522 | \begin{opcodedesc}{IMPORT_NAME}{namei} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 523 | Imports the module \code{co_names[\var{namei}]}. The module object is |
Fred Drake | 1349437 | 2000-09-12 16:23:48 +0000 | [diff] [blame] | 524 | pushed onto the stack. The current namespace is not affected: for a |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 525 | proper import statement, a subsequent \code{STORE_FAST} instruction |
Fred Drake | 1349437 | 2000-09-12 16:23:48 +0000 | [diff] [blame] | 526 | modifies the namespace. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 527 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 528 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 529 | \begin{opcodedesc}{IMPORT_FROM}{namei} |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 530 | Loads the attribute \code{co_names[\var{namei}]} from the module found in |
| 531 | TOS. The resulting object is pushed onto the stack, to be subsequently |
| 532 | stored by a \code{STORE_FAST} instruction. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 533 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 534 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 535 | \begin{opcodedesc}{JUMP_FORWARD}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 536 | Increments byte code counter by \var{delta}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 537 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 538 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 539 | \begin{opcodedesc}{JUMP_IF_TRUE}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 540 | If TOS is true, increment the byte code counter by \var{delta}. TOS is |
| 541 | left on the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 542 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 543 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 544 | \begin{opcodedesc}{JUMP_IF_FALSE}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 545 | If TOS is false, increment the byte code counter by \var{delta}. TOS |
| 546 | is not changed. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 547 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 548 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 549 | \begin{opcodedesc}{JUMP_ABSOLUTE}{target} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 550 | Set byte code counter to \var{target}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 551 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 552 | |
Guido van Rossum | e3fdc97 | 2002-06-12 15:33:08 +0000 | [diff] [blame] | 553 | \begin{opcodedesc}{FOR_ITER}{delta} |
| 554 | \code{TOS} is an iterator. Call its \method{next()} method. If this |
| 555 | yields a new value, push it on the stack (leaving the iterator below |
| 556 | it). If the iterator indicates it is exhausted \code{TOS} is |
| 557 | popped, and the byte code counter is incremented by \var{delta}. |
| 558 | \end{opcodedesc} |
| 559 | |
Guido van Rossum | fea59e7 | 2002-06-13 17:59:51 +0000 | [diff] [blame] | 560 | %\begin{opcodedesc}{FOR_LOOP}{delta} |
| 561 | %This opcode is obsolete. |
| 562 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 563 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 564 | %\begin{opcodedesc}{LOAD_LOCAL}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 565 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 566 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 567 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 568 | \begin{opcodedesc}{LOAD_GLOBAL}{namei} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 569 | Loads the global named \code{co_names[\var{namei}]} onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 570 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 571 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 572 | %\begin{opcodedesc}{SET_FUNC_ARGS}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 573 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 574 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 575 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 576 | \begin{opcodedesc}{SETUP_LOOP}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 577 | Pushes a block for a loop onto the block stack. The block spans |
| 578 | from the current instruction with a size of \var{delta} bytes. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 579 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 580 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 581 | \begin{opcodedesc}{SETUP_EXCEPT}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 582 | Pushes a try block from a try-except clause onto the block stack. |
| 583 | \var{delta} points to the first except block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 584 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 585 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 586 | \begin{opcodedesc}{SETUP_FINALLY}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 587 | Pushes a try block from a try-except clause onto the block stack. |
| 588 | \var{delta} points to the finally block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 589 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 590 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 591 | \begin{opcodedesc}{LOAD_FAST}{var_num} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 592 | Pushes a reference to the local \code{co_varnames[\var{var_num}]} onto |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 593 | the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 594 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 595 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 596 | \begin{opcodedesc}{STORE_FAST}{var_num} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 597 | Stores TOS into the local \code{co_varnames[\var{var_num}]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 598 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 599 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 600 | \begin{opcodedesc}{DELETE_FAST}{var_num} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 601 | Deletes local \code{co_varnames[\var{var_num}]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 602 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 603 | |
Jeremy Hylton | aa90adc | 2001-03-23 17:23:50 +0000 | [diff] [blame] | 604 | \begin{opcodedesc}{LOAD_CLOSURE}{i} |
| 605 | Pushes a reference to the cell contained in slot \var{i} of the |
| 606 | cell and free variable storage. The name of the variable is |
| 607 | \code{co_cellvars[\var{i}]} if \var{i} is less than the length of |
| 608 | \var{co_cellvars}. Otherwise it is |
| 609 | \code{co_freevars[\var{i} - len(co_cellvars)]}. |
| 610 | \end{opcodedesc} |
| 611 | |
| 612 | \begin{opcodedesc}{LOAD_DEREF}{i} |
| 613 | Loads the cell contained in slot \var{i} of the cell and free variable |
| 614 | storage. Pushes a reference to the object the cell contains on the |
| 615 | stack. |
| 616 | \end{opcodedesc} |
| 617 | |
| 618 | \begin{opcodedesc}{STORE_DEREF}{i} |
| 619 | Stores TOS into the cell contained in slot \var{i} of the cell and |
| 620 | free variable storage. |
| 621 | \end{opcodedesc} |
| 622 | |
Fred Drake | 338da93 | 1999-05-17 20:57:07 +0000 | [diff] [blame] | 623 | \begin{opcodedesc}{SET_LINENO}{lineno} |
Michael W. Hudson | dd32a91 | 2002-08-15 14:59:02 +0000 | [diff] [blame] | 624 | This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 625 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 626 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 627 | \begin{opcodedesc}{RAISE_VARARGS}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 628 | Raises an exception. \var{argc} indicates the number of parameters |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 629 | to the raise statement, ranging from 0 to 3. The handler will find |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 630 | the traceback as TOS2, the parameter as TOS1, and the exception |
| 631 | as TOS. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 632 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 633 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 634 | \begin{opcodedesc}{CALL_FUNCTION}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 635 | Calls a function. The low byte of \var{argc} indicates the number of |
| 636 | positional parameters, the high byte the number of keyword parameters. |
| 637 | On the stack, the opcode finds the keyword parameters first. For each |
| 638 | keyword argument, the value is on top of the key. Below the keyword |
| 639 | parameters, the positional parameters are on the stack, with the |
| 640 | right-most parameter on top. Below the parameters, the function object |
| 641 | to call is on the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 642 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 643 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 644 | \begin{opcodedesc}{MAKE_FUNCTION}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 645 | Pushes a new function object on the stack. TOS is the code associated |
| 646 | with the function. The function object is defined to have \var{argc} |
| 647 | default parameters, which are found below TOS. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 648 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 649 | |
Jeremy Hylton | aa90adc | 2001-03-23 17:23:50 +0000 | [diff] [blame] | 650 | \begin{opcodedesc}{MAKE_CLOSURE}{argc} |
| 651 | Creates a new function object, sets its \var{func_closure} slot, and |
| 652 | pushes it on the stack. TOS is the code associated with the function. |
| 653 | If the code object has N free variables, the next N items on the stack |
| 654 | are the cells for these variables. The function also has \var{argc} |
| 655 | default parameters, where are found before the cells. |
| 656 | \end{opcodedesc} |
| 657 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 658 | \begin{opcodedesc}{BUILD_SLICE}{argc} |
Guido van Rossum | da62398 | 1998-02-12 03:53:02 +0000 | [diff] [blame] | 659 | Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it |
| 660 | is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3, |
| 661 | \code{slice(TOS2, TOS1, TOS)} is pushed. |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 662 | See the \code{slice()}\bifuncindex{slice} built-in function for more |
| 663 | information. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 664 | \end{opcodedesc} |
Fred Drake | 25699f9 | 2000-08-17 22:19:26 +0000 | [diff] [blame] | 665 | |
Fred Drake | 093272e | 2000-08-24 00:37:50 +0000 | [diff] [blame] | 666 | \begin{opcodedesc}{EXTENDED_ARG}{ext} |
| 667 | Prefixes any opcode which has an argument too big to fit into the |
| 668 | default two bytes. \var{ext} holds two additional bytes which, taken |
| 669 | together with the subsequent opcode's argument, comprise a four-byte |
Fred Drake | 4c3f797 | 2000-08-31 16:26:35 +0000 | [diff] [blame] | 670 | argument, \var{ext} being the two most-significant bytes. |
Fred Drake | 093272e | 2000-08-24 00:37:50 +0000 | [diff] [blame] | 671 | \end{opcodedesc} |
| 672 | |
Fred Drake | 25699f9 | 2000-08-17 22:19:26 +0000 | [diff] [blame] | 673 | \begin{opcodedesc}{CALL_FUNCTION_VAR}{argc} |
| 674 | Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}. |
| 675 | The top element on the stack contains the variable argument list, followed |
| 676 | by keyword and positional arguments. |
| 677 | \end{opcodedesc} |
| 678 | |
| 679 | \begin{opcodedesc}{CALL_FUNCTION_KW}{argc} |
| 680 | Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}. |
| 681 | The top element on the stack contains the keyword arguments dictionary, |
| 682 | followed by explicit keyword and positional arguments. |
| 683 | \end{opcodedesc} |
| 684 | |
| 685 | \begin{opcodedesc}{CALL_FUNCTION_VAR_KW}{argc} |
| 686 | Calls a function. \var{argc} is interpreted as in |
| 687 | \code{CALL_FUNCTION}. The top element on the stack contains the |
| 688 | keyword arguments dictionary, followed by the variable-arguments |
| 689 | tuple, followed by explicit keyword and positional arguments. |
| 690 | \end{opcodedesc} |