Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 1 | \section{Standard module \sectcode{dis}} % If implemented in Python |
| 2 | \stmodindex{dis} |
| 3 | |
| 4 | \label{module-dis} |
| 5 | |
| 6 | The \code{dis} module supports the analysis of Python byte code by |
| 7 | disassembling it. Since there is no Python assembler, this module |
| 8 | defines the Python assembly language. The Python byte code which |
| 9 | this module takes as an input is defined in the file |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 10 | \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] | 11 | |
| 12 | Example: Given the function myfunc |
| 13 | |
| 14 | \bcode\begin{verbatim} |
| 15 | def myfunc(alist): |
| 16 | return len(alist) |
| 17 | \end{verbatim}\ecode |
| 18 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 19 | the following command can be used to get the disassembly of \code{myfunc()}: |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 20 | |
| 21 | \begin{verbatim} |
| 22 | >>> dis.dis(myfunc) |
| 23 | 0 SET_LINENO 1 |
| 24 | |
| 25 | 3 SET_LINENO 2 |
| 26 | 6 LOAD_GLOBAL 0 (len) |
| 27 | 9 LOAD_FAST 0 (alist) |
| 28 | 12 CALL_FUNCTION 1 |
| 29 | 15 RETURN_VALUE |
| 30 | 16 LOAD_CONST 0 (None) |
| 31 | 19 RETURN_VALUE |
| 32 | \end{verbatim} |
| 33 | |
| 34 | The \code{dis} module defines the following functions: |
| 35 | |
| 36 | \renewcommand{\indexsubitem}{(in module dis)} |
| 37 | |
| 38 | % ---- 3.2. ---- |
| 39 | % For each function, use a ``funcdesc'' block. This has exactly two |
| 40 | % parameters (each parameters is contained in a set of curly braces): |
| 41 | % the first parameter is the function name (this automatically |
| 42 | % generates an index entry); the second parameter is the function's |
| 43 | % argument list. If there are no arguments, use an empty pair of |
| 44 | % curly braces. If there is more than one argument, separate the |
| 45 | % arguments with backslash-comma. Optional parts of the parameter |
| 46 | % list are contained in \optional{...} (this generates a set of square |
| 47 | % brackets around its parameter). Arguments are automatically set in |
| 48 | % italics in the parameter list. Each argument should be mentioned at |
| 49 | % least once in the description; each usage (even inside \code{...}) |
| 50 | % should be enclosed in \var{...}. |
| 51 | |
| 52 | \begin{funcdesc}{dis}{\optional{bytesource}} |
| 53 | Disassemble the \var{bytesource} object. \var{bytesource} can denote |
| 54 | either a class, a method, a function, or a code object. For a class, |
| 55 | it disassembles all methods. For a single code sequence, it prints |
| 56 | one line per byte code instruction. If no object is provided, it |
| 57 | disassembles the last traceback. |
| 58 | \end{funcdesc} |
| 59 | |
| 60 | \begin{funcdesc}{distb}{\optional{tb}} |
| 61 | Disassembles the top-of-stack function of a traceback, using the last |
| 62 | traceback if none was passed. The instruction causing the exception |
| 63 | is indicated. |
| 64 | \end{funcdesc} |
| 65 | |
| 66 | \begin{funcdesc}{disassemble}{code\optional{\, lasti}} |
| 67 | Disassembles a code object, indicating the last instruction if \var{lasti} |
| 68 | was provided. The output is divided in the following columns: |
| 69 | \begin{itemize} |
| 70 | \item the current instruction, indicated as \code{-->}, |
| 71 | \item a labelled instruction, indicated with \code{>>}, |
| 72 | \item the address of the instruction, |
| 73 | \item the operation code name, |
| 74 | \item operation parameters, and |
| 75 | \item interpretation of the parameters in parentheses. |
| 76 | \end{itemize} |
| 77 | The parameter interpretation recognizes local and global |
| 78 | variable names, constant values, branch targets, and compare |
| 79 | operators. |
| 80 | \end{funcdesc} |
| 81 | |
| 82 | \begin{funcdesc}{disco}{code\optional{\, lasti}} |
| 83 | A synonym for disassemble. It is more convenient to type, and kept |
| 84 | for compatibility with earlier Python releases. |
| 85 | \end{funcdesc} |
| 86 | |
| 87 | \begin{datadesc}{opname} |
| 88 | Sequence of a operation names, indexable using the byte code. |
| 89 | \end{datadesc} |
| 90 | |
| 91 | \begin{datadesc}{cmp_op} |
| 92 | Sequence of all compare operation names. |
| 93 | \end{datadesc} |
| 94 | |
| 95 | \begin{datadesc}{hasconst} |
| 96 | Sequence of byte codes that have a constant parameter. |
| 97 | \end{datadesc} |
| 98 | |
| 99 | \begin{datadesc}{hasname} |
| 100 | Sequence of byte codes that access a attribute by name. |
| 101 | \end{datadesc} |
| 102 | |
| 103 | \begin{datadesc}{hasjrel} |
| 104 | Sequence of byte codes that have a relative jump target. |
| 105 | \end{datadesc} |
| 106 | |
| 107 | \begin{datadesc}{hasjabs} |
| 108 | Sequence of byte codes that have an absolute jump target. |
| 109 | \end{datadesc} |
| 110 | |
| 111 | \begin{datadesc}{haslocal} |
| 112 | Sequence of byte codes that access a a local variable. |
| 113 | \end{datadesc} |
| 114 | |
| 115 | \begin{datadesc}{hascompare} |
| 116 | Sequence of byte codes of boolean operations. |
| 117 | \end{datadesc} |
| 118 | |
| 119 | \subsection{Python Byte Code Instructions} |
| 120 | |
| 121 | The Python compiler currently generates the following byte code |
| 122 | instructions. |
| 123 | |
| 124 | \renewcommand{\indexsubitem}{(byte code insns)} |
| 125 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 126 | \begin{opcodedesc}{STOP_CODE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 127 | Indicates end-of-code to the compiler, not used by the interpreter. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 128 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 129 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 130 | \begin{opcodedesc}{POP_TOP}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 131 | Removes the top-of-stack (TOS) item. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 132 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 133 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 134 | \begin{opcodedesc}{ROT_TWO}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 135 | Swaps the two top-most stack items. |
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 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 138 | \begin{opcodedesc}{ROT_THREE}{} |
| 139 | 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] | 140 | to position three. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 141 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 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 | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 154 | \begin{opcodedesc}{UNARY_NEG}{} |
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}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +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 | |
| 170 | Binary operations remove the top of the stack (TOS) and the second top-most |
| 171 | stack item (TOS1) from the stack. They perform the operation, and put the |
| 172 | result back on the stack. |
| 173 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 174 | \begin{opcodedesc}{BINARY_POWER}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 175 | Implements \code{TOS = TOS1 ** TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 176 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 177 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 178 | \begin{opcodedesc}{BINARY_MULTIPLY}{} |
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_DIVIDE}{} |
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_MODULO}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 187 | Implements \code{TOS = TOS1 \% TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 188 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 189 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 190 | \begin{opcodedesc}{BINARY_ADD}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 191 | Implements \code{TOS = TOS1 + TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 192 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 193 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 194 | \begin{opcodedesc}{BINARY_SUBTRACT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 195 | Implements \code{TOS = TOS1 - TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 196 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 197 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 198 | \begin{opcodedesc}{BINARY_SUBSCR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 199 | Implements \code{TOS = TOS1[TOS] }. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 200 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 201 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 202 | \begin{opcodedesc}{BINARY_LSHIFT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 203 | Implements \code{TOS = TOS1 << TOS }. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 204 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 205 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 206 | \begin{opcodedesc}{BINARY_RSHIFT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 207 | Implements \code{TOS = TOS1 << TOS }. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 208 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 209 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 210 | \begin{opcodedesc}{BINARY_AND}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 211 | Implements \code{TOS = TOS1 and TOS }. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 212 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 213 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 214 | \begin{opcodedesc}{BINARY_XOR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 215 | Implements \code{TOS = TOS1 \^{ }TOS }. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 216 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 217 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 218 | \begin{opcodedesc}{BINARY_OR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 219 | Implements \code{TOS = TOS1 or TOS }. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 220 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 221 | |
| 222 | The slice opcodes take up to three parameters. |
| 223 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 224 | \begin{opcodedesc}{SLICE+0}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 225 | Implements \code{TOS = 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}{SLICE+1}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +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}{SLICE+2}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 233 | Implements \code{TOS = TOS1[:TOS1]}. |
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 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 236 | \begin{opcodedesc}{SLICE+3}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 237 | Implements \code{TOS = TOS2[TOS1:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 238 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 239 | |
| 240 | Slice assignment needs even an additional parameter. As any statement, |
| 241 | they put nothing on the stack. |
| 242 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 243 | \begin{opcodedesc}{STORE_SLICE+0}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 244 | Implements \code{TOS[:]=TOS1}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 245 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 246 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 247 | \begin{opcodedesc}{STORE_SLICE+1}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 248 | Implements \code{TOS1[TOS:]=TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 249 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 250 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 251 | \begin{opcodedesc}{STORE_SLICE+2}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 252 | Implements \code{TOS1[:TOS]=TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 253 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 254 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 255 | \begin{opcodedesc}{STORE_SLICE+3}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 256 | Implements \code{TOS2[TOS1:TOS]=TOS3}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 257 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 258 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 259 | \begin{opcodedesc}{DELETE_SLICE+0}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 260 | Implements \code{del TOS[:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 261 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 262 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 263 | \begin{opcodedesc}{DELETE_SLICE+1}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 264 | Implements \code{del TOS1[TOS:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 265 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 266 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 267 | \begin{opcodedesc}{DELETE_SLICE+2}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 268 | Implements \code{del TOS1[:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 269 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 270 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 271 | \begin{opcodedesc}{DELETE_SLICE+3}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 272 | Implements \code{del TOS2[TOS1:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 273 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 274 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 275 | \begin{opcodedesc}{STORE_SUBSCR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 276 | Implements \code{TOS1[TOS]=TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 277 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 278 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 279 | \begin{opcodedesc}{DELETE_SUBSCR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 280 | Implements \code{del TOS1[TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 281 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 282 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 283 | \begin{opcodedesc}{PRINT_EXPR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 284 | Implements the expression statement for the interactive mode. TOS is |
| 285 | removed from the stack and printed. In non-interactive mode, an |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 286 | expression statement is terminated with \code{POP_STACK}. |
| 287 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 288 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 289 | \begin{opcodedesc}{PRINT_ITEM}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 290 | Prints TOS. There is one such instruction for |
| 291 | each item in the print statement. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 292 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 293 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 294 | \begin{opcodedesc}{PRINT_NEWLINE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 295 | Prints a new line on \code{sys.stdout}. This is generated as the |
| 296 | last operation of a print statement, unless the statement ends |
| 297 | with a comma. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 298 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 299 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 300 | \begin{opcodedesc}{BREAK_LOOP}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 301 | Terminates a loop due to a break statement. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 302 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 303 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 304 | \begin{opcodedesc}{LOAD_LOCALS}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 305 | Pushes a reference to the locals of the current scope on the stack. |
| 306 | This is used in the code for a class definition: After the class body |
| 307 | is evaluated, the locals are passed to the class definition. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 308 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 309 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 310 | \begin{opcodedesc}{RETURN_VALUE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 311 | Returns with TOS to the caller of the function. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 312 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 313 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 314 | \begin{opcodedesc}{EXEC_STMT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 315 | Implements \code{exec TOS2,TOS1,TOS}. The compiler fills |
| 316 | missing optional parameters with None. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 317 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 318 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 319 | \begin{opcodedesc}{POP_BLOCK}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 320 | Removes one block from the block stack. Per frame, there is a |
| 321 | stack of blocks, denoting nested loops, try statements, and such. |
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}{END_FINALLY}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 325 | Terminates a finally-block. The interpreter recalls whether the |
| 326 | exception has to be re-raised, or whether the function returns, |
| 327 | and continues with the outer-next block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 328 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 329 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 330 | \begin{opcodedesc}{BUILD_CLASS}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 331 | Creates a new class object. TOS is the methods dictionary, TOS1 |
| 332 | 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] | 333 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 334 | |
| 335 | All of the following opcodes expect arguments. An argument is two |
| 336 | bytes, with the more significant byte last. |
| 337 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 338 | \begin{opcodedesc}{STORE_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 339 | Implements \code{name = TOS}. \var{namei} is the index of \var{name} |
| 340 | in the attribute \code{co_names} of the code object. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 341 | The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL} |
| 342 | if possible. |
| 343 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 344 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 345 | \begin{opcodedesc}{DELETE_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 346 | Implements \code{del name}, where \var{namei} is the index into |
| 347 | \code{co_names} attribute of the code object. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 348 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 349 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 350 | \begin{opcodedesc}{UNPACK_TUPLE}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 351 | Unpacks TOS into \var{count} individual values, which are put onto |
| 352 | the stack right-to-left. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 353 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 354 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 355 | \begin{opcodedesc}{UNPACK_LIST}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 356 | Unpacks TOS into \var{count} individual values. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 357 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 358 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 359 | %\begin{opcodedesc}{UNPACK_ARG}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 360 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 361 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 362 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 363 | \begin{opcodedesc}{STORE_ATTR}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 364 | Implements \code{TOS.name = TOS1}, where \var{namei} is the index |
| 365 | of name in \code{co_names}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 366 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 367 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 368 | \begin{opcodedesc}{DELETE_ATTR}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 369 | Implements \code{del TOS.name}, using \var{namei} as index into |
| 370 | \code{co_names}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 371 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 372 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 373 | \begin{opcodedesc}{STORE_GLOBAL}{namei} |
| 374 | Works as \code{STORE_NAME}, but stores the name as a global. |
| 375 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 376 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 377 | \begin{opcodedesc}{DELETE_GLOBAL}{namei} |
| 378 | Works as \code{DELETE_NAME}, but deletes a global name. |
| 379 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 380 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 381 | %\begin{opcodedesc}{UNPACK_VARARG}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 382 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 383 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 384 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 385 | \begin{opcodedesc}{LOAD_CONST}{consti} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 386 | Pushes \code{co_consts[consti]} onto the stack. |
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 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 389 | \begin{opcodedesc}{LOAD_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 390 | Pushes the value associated with \code{co_names[namei]} onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 391 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 392 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 393 | \begin{opcodedesc}{BUILD_TUPLE}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 394 | Creates a tuple consuming \var{count} items from the stack, and pushes |
| 395 | the resulting tuple onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 396 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 397 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 398 | \begin{opcodedesc}{BUILD_LIST}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 399 | Works as \code{BUILD_TUPLE}, but creates a list. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 400 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 401 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 402 | \begin{opcodedesc}{BUILD_MAP}{zero} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 403 | Pushes an empty dictionary object onto the stack. The argument is ignored |
| 404 | and set to zero by the compiler. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 405 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 406 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 407 | \begin{opcodedesc}{LOAD_ATTR}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 408 | Replaces TOS with \code{getattr(TOS,co_names[namei]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 409 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 410 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 411 | \begin{opcodedesc}{COMPARE_OP}{opname} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 412 | Performs a boolean operation. The operation name can be found |
| 413 | in \code{cmp_op[opname]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 414 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 415 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 416 | \begin{opcodedesc}{IMPORT_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 417 | Imports the module \code{co_names[namei]}. The module object is |
| 418 | pushed onto the stack. The current name space is not affect: for a |
| 419 | proper import statement, a subsequent \code{STORE_FAST} instruction |
| 420 | modifies the name space. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 421 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 422 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 423 | \begin{opcodedesc}{IMPORT_FROM}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 424 | Imports the attribute \code{co_names[namei]}. The module to import |
| 425 | from is found in TOS and left there. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 426 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 427 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 428 | \begin{opcodedesc}{JUMP_FORWARD}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 429 | Increments byte code counter by \var{delta}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 430 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 431 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 432 | \begin{opcodedesc}{JUMP_IF_TRUE}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 433 | If TOS is true, increment the byte code counter by \var{delta}. TOS is |
| 434 | left on the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 435 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 436 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 437 | \begin{opcodedesc}{JUMP_IF_FALSE}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 438 | If TOS is false, increment the byte code counter by \var{delta}. TOS |
| 439 | is not changed. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 440 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 441 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 442 | \begin{opcodedesc}{JUMP_ABSOLUTE}{target} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 443 | Set byte code counter to \var{target}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 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}{FOR_LOOP}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 447 | Iterate over a sequence. TOS is the current index, TOS1 the sequence. |
| 448 | First, the next element is computed. If the sequence is exhausted, |
| 449 | increment byte code counter by \var{delta}. Otherwise, push the |
| 450 | sequence, the incremented counter, and the current item onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 451 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 452 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 453 | %\begin{opcodedesc}{LOAD_LOCAL}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 454 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 455 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 456 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 457 | \begin{opcodedesc}{LOAD_GLOBAL}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 458 | Loads the global named \code{co_names[namei]} onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 459 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 460 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 461 | %\begin{opcodedesc}{SET_FUNC_ARGS}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 462 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 463 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 464 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 465 | \begin{opcodedesc}{SETUP_LOOP}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 466 | Pushes a block for a loop onto the block stack. The block spans |
| 467 | from the current instruction with a size of \var{delta} bytes. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 468 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 469 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 470 | \begin{opcodedesc}{SETUP_EXCEPT}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 471 | Pushes a try block from a try-except clause onto the block stack. |
| 472 | \var{delta} points to the first except block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 473 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 474 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 475 | \begin{opcodedesc}{SETUP_FINALLY}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 476 | Pushes a try block from a try-except clause onto the block stack. |
| 477 | \var{delta} points to the finally block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 478 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 479 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 480 | \begin{opcodedesc}{LOAD_FAST}{var_num} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 481 | Pushes a reference to the local \code{co_varnames[var_num]} onto |
| 482 | the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 483 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 484 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 485 | \begin{opcodedesc}{STORE_FAST}{var_num} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 486 | Stores TOS into the local \code{co_varnames[var_num]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 487 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 488 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 489 | \begin{opcodedesc}{DELETE_FAST}{var_num} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 490 | Deletes local \code{co_varnames[var_num]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 491 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 492 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 493 | \begin{opcodedesc}{SET_LINE_NO}{lineno} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 494 | Sets the current line number to \var{lineno}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 495 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 496 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 497 | \begin{opcodedesc}{RAISE_VARARGS}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 498 | Raises an exception. \var{argc} indicates the number of parameters |
| 499 | to the raise statement, ranging from 1 to 3. The handler will find |
| 500 | the traceback as TOS2, the parameter as TOS1, and the exception |
| 501 | as TOS. |
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}{CALL_FUNCTION}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 505 | Calls a function. The low byte of \var{argc} indicates the number of |
| 506 | positional parameters, the high byte the number of keyword parameters. |
| 507 | On the stack, the opcode finds the keyword parameters first. For each |
| 508 | keyword argument, the value is on top of the key. Below the keyword |
| 509 | parameters, the positional parameters are on the stack, with the |
| 510 | right-most parameter on top. Below the parameters, the function object |
| 511 | to call is on the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 512 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 513 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 514 | \begin{opcodedesc}{MAKE_FUNCTION}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 515 | Pushes a new function object on the stack. TOS is the code associated |
| 516 | with the function. The function object is defined to have \var{argc} |
| 517 | default parameters, which are found below TOS. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 518 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 519 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 520 | \begin{opcodedesc}{BUILD_SLICE}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 521 | Pushes a slice object on the stack. If \var{argc} is three, creates |
| 522 | \code{TOS3[TOS2:TOS1:TOS]}. Otherwise, expects three arguments. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 523 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 524 | |
| 525 | |