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) |
| 26 | 0 SET_LINENO 1 |
| 27 | |
| 28 | 3 SET_LINENO 2 |
| 29 | 6 LOAD_GLOBAL 0 (len) |
| 30 | 9 LOAD_FAST 0 (alist) |
| 31 | 12 CALL_FUNCTION 1 |
| 32 | 15 RETURN_VALUE |
| 33 | 16 LOAD_CONST 0 (None) |
| 34 | 19 RETURN_VALUE |
| 35 | \end{verbatim} |
| 36 | |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 37 | The \module{dis} module defines the following functions and constants: |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 38 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 39 | \begin{funcdesc}{dis}{\optional{bytesource}} |
| 40 | Disassemble the \var{bytesource} object. \var{bytesource} can denote |
| 41 | either a class, a method, a function, or a code object. For a class, |
| 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} |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 58 | \item the current instruction, indicated as \samp{-->}, |
| 59 | \item a labelled instruction, indicated with \samp{>>}, |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 60 | \item the address of the instruction, |
| 61 | \item the operation code name, |
| 62 | \item operation parameters, and |
| 63 | \item interpretation of the parameters in parentheses. |
Fred Drake | 3e7a48e | 1998-04-13 16:15:02 +0000 | [diff] [blame] | 64 | \end{enumerate} |
Fred Drake | 810349b | 1998-04-07 14:16:41 +0000 | [diff] [blame] | 65 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 66 | The parameter interpretation recognizes local and global |
| 67 | variable names, constant values, branch targets, and compare |
| 68 | operators. |
| 69 | \end{funcdesc} |
| 70 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 71 | \begin{funcdesc}{disco}{code\optional{, lasti}} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 72 | A synonym for disassemble. It is more convenient to type, and kept |
| 73 | for compatibility with earlier Python releases. |
| 74 | \end{funcdesc} |
| 75 | |
| 76 | \begin{datadesc}{opname} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 77 | Sequence of operation names, indexable using the byte code. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 78 | \end{datadesc} |
| 79 | |
| 80 | \begin{datadesc}{cmp_op} |
| 81 | Sequence of all compare operation names. |
| 82 | \end{datadesc} |
| 83 | |
| 84 | \begin{datadesc}{hasconst} |
| 85 | Sequence of byte codes that have a constant parameter. |
| 86 | \end{datadesc} |
| 87 | |
| 88 | \begin{datadesc}{hasname} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 89 | Sequence of byte codes that access an attribute by name. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 90 | \end{datadesc} |
| 91 | |
| 92 | \begin{datadesc}{hasjrel} |
| 93 | Sequence of byte codes that have a relative jump target. |
| 94 | \end{datadesc} |
| 95 | |
| 96 | \begin{datadesc}{hasjabs} |
| 97 | Sequence of byte codes that have an absolute jump target. |
| 98 | \end{datadesc} |
| 99 | |
| 100 | \begin{datadesc}{haslocal} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 101 | Sequence of byte codes that access a local variable. |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 102 | \end{datadesc} |
| 103 | |
| 104 | \begin{datadesc}{hascompare} |
| 105 | Sequence of byte codes of boolean operations. |
| 106 | \end{datadesc} |
| 107 | |
| 108 | \subsection{Python Byte Code Instructions} |
Fred Drake | 83efb54 | 1998-02-19 20:07:39 +0000 | [diff] [blame] | 109 | \label{bytecodes} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 110 | |
| 111 | The Python compiler currently generates the following byte code |
| 112 | instructions. |
| 113 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 114 | \setindexsubitem{(byte code insns)} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 115 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 116 | \begin{opcodedesc}{STOP_CODE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 117 | Indicates end-of-code to the compiler, not used by the interpreter. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 118 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 119 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 120 | \begin{opcodedesc}{POP_TOP}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 121 | Removes the top-of-stack (TOS) item. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 122 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 123 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 124 | \begin{opcodedesc}{ROT_TWO}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 125 | Swaps the two top-most stack items. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 126 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 127 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 128 | \begin{opcodedesc}{ROT_THREE}{} |
| 129 | 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] | 130 | to position three. |
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 | |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 133 | \begin{opcodedesc}{ROT_FOUR}{} |
| 134 | Lifts second, third and forth stack item one position up, moves top down to |
| 135 | position four. |
| 136 | \end{opcodedesc} |
| 137 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 138 | \begin{opcodedesc}{DUP_TOP}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 139 | Duplicates the reference on top of the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 140 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 141 | |
| 142 | Unary Operations take the top of the stack, apply the operation, and |
| 143 | push the result back on the stack. |
| 144 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 145 | \begin{opcodedesc}{UNARY_POSITIVE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 146 | Implements \code{TOS = +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 | 4c3f797 | 2000-08-31 16:26:35 +0000 | [diff] [blame] | 149 | \begin{opcodedesc}{UNARY_NEGATIVE}{} |
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_NOT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 154 | Implements \code{TOS = not 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 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 157 | \begin{opcodedesc}{UNARY_CONVERT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 158 | Implements \code{TOS = `TOS`}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 159 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 160 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 161 | \begin{opcodedesc}{UNARY_INVERT}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +0000 | [diff] [blame] | 162 | Implements \code{TOS = \~{}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 | |
| 165 | Binary operations remove the top of the stack (TOS) and the second top-most |
| 166 | stack item (TOS1) from the stack. They perform the operation, and put the |
| 167 | result back on the stack. |
| 168 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 169 | \begin{opcodedesc}{BINARY_POWER}{} |
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_MULTIPLY}{} |
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_DIVIDE}{} |
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_MODULO}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +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_ADD}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +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_SUBTRACT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +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_SUBSCR}{} |
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_LSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 198 | Implements \code{TOS = TOS1 <\code{}< 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_RSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 202 | Implements \code{TOS = TOS1 >\code{}> 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_AND}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +0000 | [diff] [blame] | 206 | Implements \code{TOS = TOS1 \&\ 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 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 209 | \begin{opcodedesc}{BINARY_XOR}{} |
Fred Drake | d7feffd | 1997-12-29 20:02:55 +0000 | [diff] [blame] | 210 | Implements \code{TOS = TOS1 \^\ TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 211 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 212 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 213 | \begin{opcodedesc}{BINARY_OR}{} |
Fred Drake | 9e759df | 2000-06-15 18:44:30 +0000 | [diff] [blame] | 214 | Implements \code{TOS = TOS1 | TOS}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 215 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 216 | |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 217 | In-place operations are like binary operations, in that they remove TOS and |
| 218 | TOS1, and push the result back on the stack, but the operation is done |
| 219 | in-place when TOS1 supports it, and the resulting TOS may be (but does not |
| 220 | have to be) the original TOS1. |
| 221 | |
| 222 | \begin{opcodedesc}{INPLACE_POWER}{} |
| 223 | Implements in-place \code{TOS = TOS1 ** TOS}. |
| 224 | \end{opcodedesc} |
| 225 | |
| 226 | \begin{opcodedesc}{INPLACE_MULTIPLY}{} |
| 227 | Implements in-place \code{TOS = TOS1 * TOS}. |
| 228 | \end{opcodedesc} |
| 229 | |
| 230 | \begin{opcodedesc}{INPLACE_DIVIDE}{} |
| 231 | Implements in-place \code{TOS = TOS1 / TOS}. |
| 232 | \end{opcodedesc} |
| 233 | |
| 234 | \begin{opcodedesc}{INPLACE_MODULO}{} |
| 235 | Implements in-place \code{TOS = TOS1 \%{} TOS}. |
| 236 | \end{opcodedesc} |
| 237 | |
| 238 | \begin{opcodedesc}{INPLACE_ADD}{} |
| 239 | Implements in-place \code{TOS = TOS1 + TOS}. |
| 240 | \end{opcodedesc} |
| 241 | |
| 242 | \begin{opcodedesc}{INPLACE_SUBTRACT}{} |
| 243 | Implements in-place \code{TOS = TOS1 - TOS}. |
| 244 | \end{opcodedesc} |
| 245 | |
| 246 | \begin{opcodedesc}{INPLACE_LSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 247 | Implements in-place \code{TOS = TOS1 <\code{}< TOS}. |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 248 | \end{opcodedesc} |
| 249 | |
| 250 | \begin{opcodedesc}{INPLACE_RSHIFT}{} |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 251 | Implements in-place \code{TOS = TOS1 >\code{}> TOS}. |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 252 | \end{opcodedesc} |
| 253 | |
| 254 | \begin{opcodedesc}{INPLACE_AND}{} |
| 255 | Implements in-place \code{TOS = TOS1 \&\ TOS}. |
| 256 | \end{opcodedesc} |
| 257 | |
| 258 | \begin{opcodedesc}{INPLACE_XOR}{} |
| 259 | Implements in-place \code{TOS = TOS1 \^\ TOS}. |
| 260 | \end{opcodedesc} |
| 261 | |
| 262 | \begin{opcodedesc}{INPLACE_OR}{} |
| 263 | Implements in-place \code{TOS = TOS1 | TOS}. |
| 264 | \end{opcodedesc} |
| 265 | |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 266 | The slice opcodes take up to three parameters. |
| 267 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 268 | \begin{opcodedesc}{SLICE+0}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 269 | Implements \code{TOS = TOS[:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 270 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 271 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 272 | \begin{opcodedesc}{SLICE+1}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 273 | Implements \code{TOS = TOS1[TOS:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 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}{SLICE+2}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 277 | Implements \code{TOS = TOS1[:TOS1]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 278 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 279 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 280 | \begin{opcodedesc}{SLICE+3}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 281 | Implements \code{TOS = TOS2[TOS1:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 282 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 283 | |
| 284 | Slice assignment needs even an additional parameter. As any statement, |
| 285 | they put nothing on the stack. |
| 286 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 287 | \begin{opcodedesc}{STORE_SLICE+0}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 288 | Implements \code{TOS[:] = TOS1}. |
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}{STORE_SLICE+1}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 292 | Implements \code{TOS1[TOS:] = TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 293 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 294 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 295 | \begin{opcodedesc}{STORE_SLICE+2}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 296 | Implements \code{TOS1[:TOS] = TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 297 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 298 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 299 | \begin{opcodedesc}{STORE_SLICE+3}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 300 | Implements \code{TOS2[TOS1:TOS] = TOS3}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 301 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 302 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 303 | \begin{opcodedesc}{DELETE_SLICE+0}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 304 | Implements \code{del TOS[:]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 305 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 306 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 307 | \begin{opcodedesc}{DELETE_SLICE+1}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 308 | Implements \code{del TOS1[TOS:]}. |
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}{DELETE_SLICE+2}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 312 | Implements \code{del TOS1[:TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 313 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 314 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 315 | \begin{opcodedesc}{DELETE_SLICE+3}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 316 | Implements \code{del TOS2[TOS1:TOS]}. |
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}{STORE_SUBSCR}{} |
Fred Drake | 7381e28 | 1997-12-04 04:51:12 +0000 | [diff] [blame] | 320 | Implements \code{TOS1[TOS] = TOS2}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 321 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 322 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 323 | \begin{opcodedesc}{DELETE_SUBSCR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 324 | Implements \code{del TOS1[TOS]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 325 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 326 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 327 | \begin{opcodedesc}{PRINT_EXPR}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 328 | Implements the expression statement for the interactive mode. TOS is |
| 329 | removed from the stack and printed. In non-interactive mode, an |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 330 | expression statement is terminated with \code{POP_STACK}. |
| 331 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 332 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 333 | \begin{opcodedesc}{PRINT_ITEM}{} |
Barry Warsaw | 9087688 | 2000-08-21 17:19:00 +0000 | [diff] [blame] | 334 | Prints TOS to the file-like object bound to \code{sys.stdout}. There |
| 335 | is one such instruction for each item in the \keyword{print} statement. |
| 336 | \end{opcodedesc} |
| 337 | |
| 338 | \begin{opcodedesc}{PRINT_ITEM_TO}{} |
| 339 | Like \code{PRINT_ITEM}, but prints the item second from TOS to the |
| 340 | 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] | 341 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 342 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 343 | \begin{opcodedesc}{PRINT_NEWLINE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 344 | 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] | 345 | last operation of a \keyword{print} statement, unless the statement |
| 346 | ends with a comma. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 347 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 348 | |
Barry Warsaw | 9087688 | 2000-08-21 17:19:00 +0000 | [diff] [blame] | 349 | \begin{opcodedesc}{PRINT_NEWLINE_TO}{} |
| 350 | Like \code{PRINT_NEWLINE}, but prints the new line on the file-like |
| 351 | object on the TOS. This is used by the extended print statement. |
| 352 | \end{opcodedesc} |
| 353 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 354 | \begin{opcodedesc}{BREAK_LOOP}{} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 355 | Terminates a loop due to a \keyword{break} statement. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 356 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 357 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 358 | \begin{opcodedesc}{LOAD_LOCALS}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 359 | Pushes a reference to the locals of the current scope on the stack. |
| 360 | This is used in the code for a class definition: After the class body |
| 361 | is evaluated, the locals are passed to the class definition. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 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}{RETURN_VALUE}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 365 | Returns with TOS to the caller of the function. |
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 | |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 368 | \begin{opcodedesc}{IMPORT_STAR}{} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 369 | Loads all symbols not starting with \character{_} directly from the module TOS |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 370 | to the local namespace. The module is popped after loading all names. |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 371 | This opcode implements \code{from module import *}. |
| 372 | \end{opcodedesc} |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 373 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 374 | \begin{opcodedesc}{EXEC_STMT}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 375 | Implements \code{exec TOS2,TOS1,TOS}. The compiler fills |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 376 | missing optional parameters with \code{None}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 377 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 378 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 379 | \begin{opcodedesc}{POP_BLOCK}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 380 | Removes one block from the block stack. Per frame, there is a |
| 381 | stack of blocks, denoting nested loops, try statements, and such. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 382 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 383 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 384 | \begin{opcodedesc}{END_FINALLY}{} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 385 | Terminates a \keyword{finally} clause. The interpreter recalls |
| 386 | whether the exception has to be re-raised, or whether the function |
| 387 | returns, and continues with the outer-next block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 388 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 389 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 390 | \begin{opcodedesc}{BUILD_CLASS}{} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 391 | Creates a new class object. TOS is the methods dictionary, TOS1 |
| 392 | 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] | 393 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 394 | |
| 395 | All of the following opcodes expect arguments. An argument is two |
| 396 | bytes, with the more significant byte last. |
| 397 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 398 | \begin{opcodedesc}{STORE_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 399 | Implements \code{name = TOS}. \var{namei} is the index of \var{name} |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 400 | in the attribute \member{co_names} of the code object. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 401 | The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL} |
| 402 | if possible. |
| 403 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 404 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 405 | \begin{opcodedesc}{DELETE_NAME}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 406 | Implements \code{del name}, where \var{namei} is the index into |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 407 | \member{co_names} attribute of the code object. |
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 | |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 410 | \begin{opcodedesc}{UNPACK_SEQUENCE}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 411 | Unpacks TOS into \var{count} individual values, which are put onto |
| 412 | the stack right-to-left. |
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 | |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 415 | %\begin{opcodedesc}{UNPACK_LIST}{count} |
| 416 | %This opcode is obsolete. |
| 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}{UNPACK_ARG}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 420 | %This opcode is obsolete. |
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 | |
Thomas Wouters | 12bba85 | 2000-08-24 20:06:04 +0000 | [diff] [blame] | 423 | \begin{opcodedesc}{DUP_TOPX}{count} |
| 424 | Duplicate \var{count} items, keeping them in the same order. Due to |
| 425 | implementation limits, \var{count} should be between 1 and 5 inclusive. |
| 426 | \end{opcodedesc} |
| 427 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 428 | \begin{opcodedesc}{STORE_ATTR}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 429 | Implements \code{TOS.name = TOS1}, where \var{namei} is the index |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 430 | of name in \member{co_names}. |
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}{DELETE_ATTR}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 434 | Implements \code{del TOS.name}, using \var{namei} as index into |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 435 | \member{co_names}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 436 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 437 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 438 | \begin{opcodedesc}{STORE_GLOBAL}{namei} |
| 439 | Works as \code{STORE_NAME}, but stores the name as a global. |
| 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}{DELETE_GLOBAL}{namei} |
| 443 | Works as \code{DELETE_NAME}, but deletes a global name. |
| 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}{UNPACK_VARARG}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 447 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 448 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 449 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 450 | \begin{opcodedesc}{LOAD_CONST}{consti} |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 451 | Pushes \samp{co_consts[\var{consti}]} onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 452 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 453 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 454 | \begin{opcodedesc}{LOAD_NAME}{namei} |
Fred Drake | dff21a6 | 1998-04-03 05:42:10 +0000 | [diff] [blame] | 455 | 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] | 456 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 457 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 458 | \begin{opcodedesc}{BUILD_TUPLE}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 459 | Creates a tuple consuming \var{count} items from the stack, and pushes |
| 460 | the resulting tuple onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 461 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 462 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 463 | \begin{opcodedesc}{BUILD_LIST}{count} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 464 | Works as \code{BUILD_TUPLE}, but creates a list. |
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}{BUILD_MAP}{zero} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 468 | Pushes a new empty dictionary object onto the stack. The argument is |
| 469 | ignored and set to zero by the compiler. |
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}{LOAD_ATTR}{namei} |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 473 | Replaces TOS with \code{getattr(TOS, co_names[\var{namei}]}. |
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}{COMPARE_OP}{opname} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 477 | Performs a boolean operation. The operation name can be found |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 478 | in \code{cmp_op[\var{opname}]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 479 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 480 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 481 | \begin{opcodedesc}{IMPORT_NAME}{namei} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 482 | Imports the module \code{co_names[\var{namei}]}. The module object is |
Fred Drake | 1349437 | 2000-09-12 16:23:48 +0000 | [diff] [blame] | 483 | 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] | 484 | proper import statement, a subsequent \code{STORE_FAST} instruction |
Fred Drake | 1349437 | 2000-09-12 16:23:48 +0000 | [diff] [blame] | 485 | modifies the namespace. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 486 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 487 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 488 | \begin{opcodedesc}{IMPORT_FROM}{namei} |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 489 | Loads the attribute \code{co_names[\var{namei}]} from the module found in |
| 490 | TOS. The resulting object is pushed onto the stack, to be subsequently |
| 491 | stored by a \code{STORE_FAST} instruction. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 492 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 493 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 494 | \begin{opcodedesc}{JUMP_FORWARD}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 495 | Increments byte code counter by \var{delta}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 496 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 497 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 498 | \begin{opcodedesc}{JUMP_IF_TRUE}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 499 | If TOS is true, increment the byte code counter by \var{delta}. TOS is |
| 500 | left on the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 501 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 502 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 503 | \begin{opcodedesc}{JUMP_IF_FALSE}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 504 | If TOS is false, increment the byte code counter by \var{delta}. TOS |
| 505 | is not changed. |
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}{JUMP_ABSOLUTE}{target} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 509 | Set byte code counter to \var{target}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 510 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 511 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 512 | \begin{opcodedesc}{FOR_LOOP}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 513 | Iterate over a sequence. TOS is the current index, TOS1 the sequence. |
| 514 | First, the next element is computed. If the sequence is exhausted, |
| 515 | increment byte code counter by \var{delta}. Otherwise, push the |
| 516 | sequence, the incremented counter, and the current item onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 517 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 518 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 519 | %\begin{opcodedesc}{LOAD_LOCAL}{namei} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 520 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 521 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 522 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 523 | \begin{opcodedesc}{LOAD_GLOBAL}{namei} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 524 | Loads the global named \code{co_names[\var{namei}]} onto the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 525 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 526 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 527 | %\begin{opcodedesc}{SET_FUNC_ARGS}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 528 | %This opcode is obsolete. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 529 | %\end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 530 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 531 | \begin{opcodedesc}{SETUP_LOOP}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 532 | Pushes a block for a loop onto the block stack. The block spans |
| 533 | from the current instruction with a size of \var{delta} bytes. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 534 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 535 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 536 | \begin{opcodedesc}{SETUP_EXCEPT}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 537 | Pushes a try block from a try-except clause onto the block stack. |
| 538 | \var{delta} points to the first except block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 539 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 540 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 541 | \begin{opcodedesc}{SETUP_FINALLY}{delta} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 542 | Pushes a try block from a try-except clause onto the block stack. |
| 543 | \var{delta} points to the finally block. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 544 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 545 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 546 | \begin{opcodedesc}{LOAD_FAST}{var_num} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 547 | 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] | 548 | the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 549 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 550 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 551 | \begin{opcodedesc}{STORE_FAST}{var_num} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 552 | Stores TOS into the local \code{co_varnames[\var{var_num}]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 553 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 554 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 555 | \begin{opcodedesc}{DELETE_FAST}{var_num} |
Fred Drake | dd1f6cc | 1998-02-12 03:32:18 +0000 | [diff] [blame] | 556 | Deletes local \code{co_varnames[\var{var_num}]}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 557 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 558 | |
Fred Drake | 338da93 | 1999-05-17 20:57:07 +0000 | [diff] [blame] | 559 | \begin{opcodedesc}{SET_LINENO}{lineno} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 560 | Sets the current line number to \var{lineno}. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 561 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 562 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 563 | \begin{opcodedesc}{RAISE_VARARGS}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 564 | Raises an exception. \var{argc} indicates the number of parameters |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 565 | 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] | 566 | the traceback as TOS2, the parameter as TOS1, and the exception |
| 567 | as TOS. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 568 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 569 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 570 | \begin{opcodedesc}{CALL_FUNCTION}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 571 | Calls a function. The low byte of \var{argc} indicates the number of |
| 572 | positional parameters, the high byte the number of keyword parameters. |
| 573 | On the stack, the opcode finds the keyword parameters first. For each |
| 574 | keyword argument, the value is on top of the key. Below the keyword |
| 575 | parameters, the positional parameters are on the stack, with the |
| 576 | right-most parameter on top. Below the parameters, the function object |
| 577 | to call is on the stack. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 578 | \end{opcodedesc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 579 | |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 580 | \begin{opcodedesc}{MAKE_FUNCTION}{argc} |
Guido van Rossum | b62b6d1 | 1997-11-18 15:10:53 +0000 | [diff] [blame] | 581 | Pushes a new function object on the stack. TOS is the code associated |
| 582 | with the function. The function object is defined to have \var{argc} |
| 583 | default parameters, which are found below TOS. |
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}{BUILD_SLICE}{argc} |
Guido van Rossum | da62398 | 1998-02-12 03:53:02 +0000 | [diff] [blame] | 587 | Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it |
| 588 | is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3, |
| 589 | \code{slice(TOS2, TOS1, TOS)} is pushed. |
Fred Drake | 304faf9 | 2000-08-18 02:15:55 +0000 | [diff] [blame] | 590 | See the \code{slice()}\bifuncindex{slice} built-in function for more |
| 591 | information. |
Fred Drake | 456035f | 1997-12-03 04:06:57 +0000 | [diff] [blame] | 592 | \end{opcodedesc} |
Fred Drake | 25699f9 | 2000-08-17 22:19:26 +0000 | [diff] [blame] | 593 | |
Fred Drake | 093272e | 2000-08-24 00:37:50 +0000 | [diff] [blame] | 594 | \begin{opcodedesc}{EXTENDED_ARG}{ext} |
| 595 | Prefixes any opcode which has an argument too big to fit into the |
| 596 | default two bytes. \var{ext} holds two additional bytes which, taken |
| 597 | together with the subsequent opcode's argument, comprise a four-byte |
Fred Drake | 4c3f797 | 2000-08-31 16:26:35 +0000 | [diff] [blame] | 598 | argument, \var{ext} being the two most-significant bytes. |
Fred Drake | 093272e | 2000-08-24 00:37:50 +0000 | [diff] [blame] | 599 | \end{opcodedesc} |
| 600 | |
Fred Drake | 25699f9 | 2000-08-17 22:19:26 +0000 | [diff] [blame] | 601 | \begin{opcodedesc}{CALL_FUNCTION_VAR}{argc} |
| 602 | Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}. |
| 603 | The top element on the stack contains the variable argument list, followed |
| 604 | by keyword and positional arguments. |
| 605 | \end{opcodedesc} |
| 606 | |
| 607 | \begin{opcodedesc}{CALL_FUNCTION_KW}{argc} |
| 608 | Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}. |
| 609 | The top element on the stack contains the keyword arguments dictionary, |
| 610 | followed by explicit keyword and positional arguments. |
| 611 | \end{opcodedesc} |
| 612 | |
| 613 | \begin{opcodedesc}{CALL_FUNCTION_VAR_KW}{argc} |
| 614 | Calls a function. \var{argc} is interpreted as in |
| 615 | \code{CALL_FUNCTION}. The top element on the stack contains the |
| 616 | keyword arguments dictionary, followed by the variable-arguments |
| 617 | tuple, followed by explicit keyword and positional arguments. |
| 618 | \end{opcodedesc} |