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