Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 1 | :mod:`dis` --- Disassembler for Python bytecode |
| 2 | =============================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 3 | |
| 4 | .. module:: dis |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 5 | :synopsis: Disassembler for Python bytecode. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 6 | |
Raymond Hettinger | 1048094 | 2011-01-10 03:26:08 +0000 | [diff] [blame] | 7 | **Source code:** :source:`Lib/dis.py` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 8 | |
Raymond Hettinger | 4f707fd | 2011-01-10 19:54:11 +0000 | [diff] [blame] | 9 | -------------- |
| 10 | |
Brett Cannon | 8315fd1 | 2010-07-02 22:03:00 +0000 | [diff] [blame] | 11 | The :mod:`dis` module supports the analysis of CPython :term:`bytecode` by |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 12 | disassembling it. The CPython bytecode which this module takes as an input is |
| 13 | defined in the file :file:`Include/opcode.h` and used by the compiler and the |
| 14 | interpreter. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 15 | |
Georg Brandl | 19b7a87 | 2010-07-03 10:21:50 +0000 | [diff] [blame] | 16 | .. impl-detail:: |
| 17 | |
Raymond Hettinger | 1048094 | 2011-01-10 03:26:08 +0000 | [diff] [blame] | 18 | Bytecode is an implementation detail of the CPython interpreter. No |
Georg Brandl | 19b7a87 | 2010-07-03 10:21:50 +0000 | [diff] [blame] | 19 | guarantees are made that bytecode will not be added, removed, or changed |
| 20 | between versions of Python. Use of this module should not be considered to |
| 21 | work across Python VMs or Python releases. |
| 22 | |
Brett Cannon | 8315fd1 | 2010-07-02 22:03:00 +0000 | [diff] [blame] | 23 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 24 | Example: Given the function :func:`myfunc`:: |
| 25 | |
| 26 | def myfunc(alist): |
| 27 | return len(alist) |
| 28 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 29 | the following command can be used to display the disassembly of |
| 30 | :func:`myfunc`:: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 31 | |
| 32 | >>> dis.dis(myfunc) |
| 33 | 2 0 LOAD_GLOBAL 0 (len) |
| 34 | 3 LOAD_FAST 0 (alist) |
| 35 | 6 CALL_FUNCTION 1 |
| 36 | 9 RETURN_VALUE |
| 37 | |
| 38 | (The "2" is a line number). |
| 39 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 40 | Bytecode analysis |
| 41 | ----------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 42 | |
R David Murray | 0bce6e7 | 2014-01-07 14:30:17 -0500 | [diff] [blame] | 43 | .. versionadded:: 3.4 |
| 44 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 45 | The bytecode analysis API allows pieces of Python code to be wrapped in a |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 46 | :class:`Bytecode` object that provides easy access to details of the compiled |
| 47 | code. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 48 | |
Nick Coghlan | 50c48b8 | 2013-11-23 00:57:00 +1000 | [diff] [blame] | 49 | .. class:: Bytecode(x, *, first_line=None, current_offset=None) |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 50 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 51 | Analyse the bytecode corresponding to a function, method, string of source |
| 52 | code, or a code object (as returned by :func:`compile`). |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 53 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 54 | This is a convenience wrapper around many of the functions listed below, most |
| 55 | notably :func:`get_instructions`, as iterating over a :class:`Bytecode` |
| 56 | instance yields the bytecode operations as :class:`Instruction` instances. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 57 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 58 | If *first_line* is not None, it indicates the line number that should be |
| 59 | reported for the first source line in the disassembled code. Otherwise, the |
| 60 | source line information (if any) is taken directly from the disassembled code |
| 61 | object. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 62 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 63 | If *current_offset* is not None, it refers to an instruction offset in the |
| 64 | disassembled code. Setting this means :meth:`.dis` will display a "current |
| 65 | instruction" marker against the specified opcode. |
Nick Coghlan | 50c48b8 | 2013-11-23 00:57:00 +1000 | [diff] [blame] | 66 | |
| 67 | .. classmethod:: from_traceback(tb) |
| 68 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 69 | Construct a :class:`Bytecode` instance from the given traceback, setting |
| 70 | *current_offset* to the instruction responsible for the exception. |
Nick Coghlan | 50c48b8 | 2013-11-23 00:57:00 +1000 | [diff] [blame] | 71 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 72 | .. data:: codeobj |
| 73 | |
| 74 | The compiled code object. |
| 75 | |
Nick Coghlan | 90b8e7d | 2013-11-06 22:08:36 +1000 | [diff] [blame] | 76 | .. data:: first_line |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 77 | |
Nick Coghlan | 90b8e7d | 2013-11-06 22:08:36 +1000 | [diff] [blame] | 78 | The first source line of the code object (if available) |
| 79 | |
| 80 | .. method:: dis() |
| 81 | |
Benjamin Peterson | 29fec92 | 2015-03-02 09:27:43 -0500 | [diff] [blame] | 82 | Return a formatted view of the bytecode operations (the same as printed by |
| 83 | :func:`dis.dis`, but returned as a multi-line string). |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 84 | |
| 85 | .. method:: info() |
| 86 | |
| 87 | Return a formatted multi-line string with detailed information about the |
| 88 | code object, like :func:`code_info`. |
| 89 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 90 | Example:: |
| 91 | |
| 92 | >>> bytecode = dis.Bytecode(myfunc) |
| 93 | >>> for instr in bytecode: |
| 94 | ... print(instr.opname) |
| 95 | ... |
| 96 | LOAD_GLOBAL |
| 97 | LOAD_FAST |
| 98 | CALL_FUNCTION |
| 99 | RETURN_VALUE |
| 100 | |
| 101 | |
| 102 | Analysis functions |
| 103 | ------------------ |
| 104 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 105 | The :mod:`dis` module also defines the following analysis functions that convert |
| 106 | the input directly to the desired output. They can be useful if only a single |
| 107 | operation is being performed, so the intermediate analysis object isn't useful: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 108 | |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 109 | .. function:: code_info(x) |
Nick Coghlan | eae2da1 | 2010-08-17 08:03:36 +0000 | [diff] [blame] | 110 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 111 | Return a formatted multi-line string with detailed code object information |
| 112 | for the supplied function, method, source code string or code object. |
Nick Coghlan | eae2da1 | 2010-08-17 08:03:36 +0000 | [diff] [blame] | 113 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 114 | Note that the exact contents of code info strings are highly implementation |
| 115 | dependent and they may change arbitrarily across Python VMs or Python |
| 116 | releases. |
Nick Coghlan | eae2da1 | 2010-08-17 08:03:36 +0000 | [diff] [blame] | 117 | |
| 118 | .. versionadded:: 3.2 |
| 119 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 120 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 121 | .. function:: show_code(x, *, file=None) |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 122 | |
| 123 | Print detailed code object information for the supplied function, method, |
Ezio Melotti | 6e6c6ac | 2013-08-23 22:41:39 +0300 | [diff] [blame] | 124 | source code string or code object to *file* (or ``sys.stdout`` if *file* |
| 125 | is not specified). |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 126 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 127 | This is a convenient shorthand for ``print(code_info(x), file=file)``, |
| 128 | intended for interactive exploration at the interpreter prompt. |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 129 | |
| 130 | .. versionadded:: 3.2 |
| 131 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 132 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 133 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 134 | |
| 135 | |
| 136 | .. function:: dis(x=None, *, file=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 137 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 138 | Disassemble the *x* object. *x* can denote either a module, a class, a |
| 139 | method, a function, a code object, a string of source code or a byte sequence |
| 140 | of raw bytecode. For a module, it disassembles all functions. For a class, |
| 141 | it disassembles all methods. For a code object or sequence of raw bytecode, |
| 142 | it prints one line per bytecode instruction. Strings are first compiled to |
| 143 | code objects with the :func:`compile` built-in function before being |
| 144 | disassembled. If no object is provided, this function disassembles the last |
| 145 | traceback. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 146 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 147 | The disassembly is written as text to the supplied *file* argument if |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 148 | provided and to ``sys.stdout`` otherwise. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 149 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 150 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 151 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 152 | |
| 153 | |
| 154 | .. function:: distb(tb=None, *, file=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 155 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 156 | Disassemble the top-of-stack function of a traceback, using the last |
| 157 | traceback if none was passed. The instruction causing the exception is |
| 158 | indicated. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 159 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 160 | The disassembly is written as text to the supplied *file* argument if |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 161 | provided and to ``sys.stdout`` otherwise. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 162 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 163 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 164 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 165 | |
| 166 | |
| 167 | .. function:: disassemble(code, lasti=-1, *, file=None) |
| 168 | disco(code, lasti=-1, *, file=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 169 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 170 | Disassemble a code object, indicating the last instruction if *lasti* was |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 171 | provided. The output is divided in the following columns: |
| 172 | |
| 173 | #. the line number, for the first instruction of each line |
| 174 | #. the current instruction, indicated as ``-->``, |
| 175 | #. a labelled instruction, indicated with ``>>``, |
| 176 | #. the address of the instruction, |
| 177 | #. the operation code name, |
| 178 | #. operation parameters, and |
| 179 | #. interpretation of the parameters in parentheses. |
| 180 | |
| 181 | The parameter interpretation recognizes local and global variable names, |
| 182 | constant values, branch targets, and compare operators. |
| 183 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 184 | The disassembly is written as text to the supplied *file* argument if |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 185 | provided and to ``sys.stdout`` otherwise. |
| 186 | |
| 187 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 188 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 189 | |
| 190 | |
Nick Coghlan | 90b8e7d | 2013-11-06 22:08:36 +1000 | [diff] [blame] | 191 | .. function:: get_instructions(x, *, first_line=None) |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 192 | |
| 193 | Return an iterator over the instructions in the supplied function, method, |
| 194 | source code string or code object. |
| 195 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 196 | The iterator generates a series of :class:`Instruction` named tuples giving |
| 197 | the details of each operation in the supplied code. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 198 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 199 | If *first_line* is not None, it indicates the line number that should be |
| 200 | reported for the first source line in the disassembled code. Otherwise, the |
| 201 | source line information (if any) is taken directly from the disassembled code |
| 202 | object. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 203 | |
| 204 | .. versionadded:: 3.4 |
| 205 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 206 | |
Benjamin Peterson | 75edad0 | 2009-01-01 15:05:06 +0000 | [diff] [blame] | 207 | .. function:: findlinestarts(code) |
| 208 | |
| 209 | This generator function uses the ``co_firstlineno`` and ``co_lnotab`` |
| 210 | attributes of the code object *code* to find the offsets which are starts of |
| 211 | lines in the source code. They are generated as ``(offset, lineno)`` pairs. |
| 212 | |
| 213 | |
| 214 | .. function:: findlabels(code) |
| 215 | |
| 216 | Detect all offsets in the code object *code* which are jump targets, and |
| 217 | return a list of these offsets. |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 218 | |
Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 219 | |
| 220 | .. function:: stack_effect(opcode, [oparg]) |
| 221 | |
| 222 | Compute the stack effect of *opcode* with argument *oparg*. |
| 223 | |
| 224 | .. versionadded:: 3.4 |
| 225 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 226 | .. _bytecodes: |
| 227 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 228 | Python Bytecode Instructions |
| 229 | ---------------------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 230 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 231 | The :func:`get_instructions` function and :class:`Bytecode` class provide |
| 232 | details of bytecode instructions as :class:`Instruction` instances: |
| 233 | |
| 234 | .. class:: Instruction |
| 235 | |
| 236 | Details for a bytecode operation |
| 237 | |
| 238 | .. data:: opcode |
| 239 | |
| 240 | numeric code for operation, corresponding to the opcode values listed |
| 241 | below and the bytecode values in the :ref:`opcode_collections`. |
| 242 | |
| 243 | |
| 244 | .. data:: opname |
| 245 | |
| 246 | human readable name for operation |
| 247 | |
| 248 | |
| 249 | .. data:: arg |
| 250 | |
| 251 | numeric argument to operation (if any), otherwise None |
| 252 | |
| 253 | |
| 254 | .. data:: argval |
| 255 | |
| 256 | resolved arg value (if known), otherwise same as arg |
| 257 | |
| 258 | |
| 259 | .. data:: argrepr |
| 260 | |
| 261 | human readable description of operation argument |
| 262 | |
| 263 | |
| 264 | .. data:: offset |
| 265 | |
| 266 | start index of operation within bytecode sequence |
| 267 | |
| 268 | |
| 269 | .. data:: starts_line |
| 270 | |
| 271 | line started by this opcode (if any), otherwise None |
| 272 | |
| 273 | |
| 274 | .. data:: is_jump_target |
| 275 | |
Serhiy Storchaka | 0e90e99 | 2013-11-29 12:19:53 +0200 | [diff] [blame] | 276 | ``True`` if other code jumps to here, otherwise ``False`` |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 277 | |
| 278 | .. versionadded:: 3.4 |
| 279 | |
| 280 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 281 | The Python compiler currently generates the following bytecode instructions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 282 | |
| 283 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 284 | **General instructions** |
| 285 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 286 | .. opcode:: NOP |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 287 | |
| 288 | Do nothing code. Used as a placeholder by the bytecode optimizer. |
| 289 | |
| 290 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 291 | .. opcode:: POP_TOP |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 292 | |
| 293 | Removes the top-of-stack (TOS) item. |
| 294 | |
| 295 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 296 | .. opcode:: ROT_TWO |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 297 | |
| 298 | Swaps the two top-most stack items. |
| 299 | |
| 300 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 301 | .. opcode:: ROT_THREE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 302 | |
| 303 | Lifts second and third stack item one position up, moves top down to position |
| 304 | three. |
| 305 | |
| 306 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 307 | .. opcode:: DUP_TOP |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 308 | |
| 309 | Duplicates the reference on top of the stack. |
| 310 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 311 | |
Antoine Pitrou | 74a69fa | 2010-09-04 18:43:52 +0000 | [diff] [blame] | 312 | .. opcode:: DUP_TOP_TWO |
| 313 | |
| 314 | Duplicates the two references on top of the stack, leaving them in the |
| 315 | same order. |
| 316 | |
| 317 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 318 | **Unary operations** |
| 319 | |
| 320 | Unary operations take the top of the stack, apply the operation, and push the |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 321 | result back on the stack. |
| 322 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 323 | .. opcode:: UNARY_POSITIVE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 324 | |
| 325 | Implements ``TOS = +TOS``. |
| 326 | |
| 327 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 328 | .. opcode:: UNARY_NEGATIVE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 329 | |
| 330 | Implements ``TOS = -TOS``. |
| 331 | |
| 332 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 333 | .. opcode:: UNARY_NOT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 334 | |
| 335 | Implements ``TOS = not TOS``. |
| 336 | |
| 337 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 338 | .. opcode:: UNARY_INVERT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 339 | |
| 340 | Implements ``TOS = ~TOS``. |
| 341 | |
| 342 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 343 | .. opcode:: GET_ITER |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 344 | |
| 345 | Implements ``TOS = iter(TOS)``. |
| 346 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 347 | |
| 348 | **Binary operations** |
| 349 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 350 | Binary operations remove the top of the stack (TOS) and the second top-most |
| 351 | stack item (TOS1) from the stack. They perform the operation, and put the |
| 352 | result back on the stack. |
| 353 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 354 | .. opcode:: BINARY_POWER |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 355 | |
| 356 | Implements ``TOS = TOS1 ** TOS``. |
| 357 | |
| 358 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 359 | .. opcode:: BINARY_MULTIPLY |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 360 | |
| 361 | Implements ``TOS = TOS1 * TOS``. |
| 362 | |
| 363 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 364 | .. opcode:: BINARY_FLOOR_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 365 | |
| 366 | Implements ``TOS = TOS1 // TOS``. |
| 367 | |
| 368 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 369 | .. opcode:: BINARY_TRUE_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 370 | |
Ezio Melotti | 7de0a6e | 2010-01-05 08:37:27 +0000 | [diff] [blame] | 371 | Implements ``TOS = TOS1 / TOS``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 372 | |
| 373 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 374 | .. opcode:: BINARY_MODULO |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 375 | |
| 376 | Implements ``TOS = TOS1 % TOS``. |
| 377 | |
| 378 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 379 | .. opcode:: BINARY_ADD |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 380 | |
| 381 | Implements ``TOS = TOS1 + TOS``. |
| 382 | |
| 383 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 384 | .. opcode:: BINARY_SUBTRACT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 385 | |
| 386 | Implements ``TOS = TOS1 - TOS``. |
| 387 | |
| 388 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 389 | .. opcode:: BINARY_SUBSCR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 390 | |
| 391 | Implements ``TOS = TOS1[TOS]``. |
| 392 | |
| 393 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 394 | .. opcode:: BINARY_LSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 395 | |
| 396 | Implements ``TOS = TOS1 << TOS``. |
| 397 | |
| 398 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 399 | .. opcode:: BINARY_RSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 400 | |
| 401 | Implements ``TOS = TOS1 >> TOS``. |
| 402 | |
| 403 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 404 | .. opcode:: BINARY_AND |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 405 | |
| 406 | Implements ``TOS = TOS1 & TOS``. |
| 407 | |
| 408 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 409 | .. opcode:: BINARY_XOR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 410 | |
| 411 | Implements ``TOS = TOS1 ^ TOS``. |
| 412 | |
| 413 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 414 | .. opcode:: BINARY_OR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 415 | |
| 416 | Implements ``TOS = TOS1 | TOS``. |
| 417 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 418 | |
| 419 | **In-place operations** |
| 420 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 421 | In-place operations are like binary operations, in that they remove TOS and |
| 422 | TOS1, and push the result back on the stack, but the operation is done in-place |
| 423 | when TOS1 supports it, and the resulting TOS may be (but does not have to be) |
| 424 | the original TOS1. |
| 425 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 426 | .. opcode:: INPLACE_POWER |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 427 | |
| 428 | Implements in-place ``TOS = TOS1 ** TOS``. |
| 429 | |
| 430 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 431 | .. opcode:: INPLACE_MULTIPLY |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 432 | |
| 433 | Implements in-place ``TOS = TOS1 * TOS``. |
| 434 | |
| 435 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 436 | .. opcode:: INPLACE_FLOOR_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 437 | |
| 438 | Implements in-place ``TOS = TOS1 // TOS``. |
| 439 | |
| 440 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 441 | .. opcode:: INPLACE_TRUE_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 442 | |
Ezio Melotti | 7de0a6e | 2010-01-05 08:37:27 +0000 | [diff] [blame] | 443 | Implements in-place ``TOS = TOS1 / TOS``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 444 | |
| 445 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 446 | .. opcode:: INPLACE_MODULO |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 447 | |
| 448 | Implements in-place ``TOS = TOS1 % TOS``. |
| 449 | |
| 450 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 451 | .. opcode:: INPLACE_ADD |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 452 | |
| 453 | Implements in-place ``TOS = TOS1 + TOS``. |
| 454 | |
| 455 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 456 | .. opcode:: INPLACE_SUBTRACT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 457 | |
| 458 | Implements in-place ``TOS = TOS1 - TOS``. |
| 459 | |
| 460 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 461 | .. opcode:: INPLACE_LSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 462 | |
| 463 | Implements in-place ``TOS = TOS1 << TOS``. |
| 464 | |
| 465 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 466 | .. opcode:: INPLACE_RSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 467 | |
| 468 | Implements in-place ``TOS = TOS1 >> TOS``. |
| 469 | |
| 470 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 471 | .. opcode:: INPLACE_AND |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 472 | |
| 473 | Implements in-place ``TOS = TOS1 & TOS``. |
| 474 | |
| 475 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 476 | .. opcode:: INPLACE_XOR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 477 | |
| 478 | Implements in-place ``TOS = TOS1 ^ TOS``. |
| 479 | |
| 480 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 481 | .. opcode:: INPLACE_OR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 482 | |
| 483 | Implements in-place ``TOS = TOS1 | TOS``. |
| 484 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 485 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 486 | .. opcode:: STORE_SUBSCR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 487 | |
| 488 | Implements ``TOS1[TOS] = TOS2``. |
| 489 | |
| 490 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 491 | .. opcode:: DELETE_SUBSCR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 492 | |
| 493 | Implements ``del TOS1[TOS]``. |
| 494 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 495 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 496 | **Miscellaneous opcodes** |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 497 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 498 | .. opcode:: PRINT_EXPR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 499 | |
| 500 | Implements the expression statement for the interactive mode. TOS is removed |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 501 | from the stack and printed. In non-interactive mode, an expression statement |
| 502 | is terminated with :opcode:`POP_TOP`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 503 | |
| 504 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 505 | .. opcode:: BREAK_LOOP |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 506 | |
| 507 | Terminates a loop due to a :keyword:`break` statement. |
| 508 | |
| 509 | |
| 510 | .. opcode:: CONTINUE_LOOP (target) |
| 511 | |
| 512 | Continues a loop due to a :keyword:`continue` statement. *target* is the |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 513 | address to jump to (which should be a :opcode:`FOR_ITER` instruction). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 514 | |
| 515 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 516 | .. opcode:: SET_ADD (i) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 517 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 518 | Calls ``set.add(TOS1[-i], TOS)``. Used to implement set comprehensions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 519 | |
| 520 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 521 | .. opcode:: LIST_APPEND (i) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 522 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 523 | Calls ``list.append(TOS[-i], TOS)``. Used to implement list comprehensions. |
| 524 | |
| 525 | |
| 526 | .. opcode:: MAP_ADD (i) |
| 527 | |
| 528 | Calls ``dict.setitem(TOS1[-i], TOS, TOS1)``. Used to implement dict |
| 529 | comprehensions. |
| 530 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 531 | For all of the :opcode:`SET_ADD`, :opcode:`LIST_APPEND` and :opcode:`MAP_ADD` |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 532 | instructions, while the added value or key/value pair is popped off, the |
| 533 | container object remains on the stack so that it is available for further |
| 534 | iterations of the loop. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 535 | |
| 536 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 537 | .. opcode:: RETURN_VALUE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 538 | |
| 539 | Returns with TOS to the caller of the function. |
| 540 | |
| 541 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 542 | .. opcode:: YIELD_VALUE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 543 | |
Berker Peksag | ab4040e | 2015-03-02 06:33:30 +0200 | [diff] [blame] | 544 | Pops TOS and yields it from a :term:`generator`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 545 | |
| 546 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 547 | .. opcode:: YIELD_FROM |
| 548 | |
Berker Peksag | ab4040e | 2015-03-02 06:33:30 +0200 | [diff] [blame] | 549 | Pops TOS and delegates to it as a subiterator from a :term:`generator`. |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 550 | |
| 551 | .. versionadded:: 3.3 |
| 552 | |
| 553 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 554 | .. opcode:: IMPORT_STAR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 555 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 556 | Loads all symbols not starting with ``'_'`` directly from the module TOS to |
| 557 | the local namespace. The module is popped after loading all names. This |
| 558 | opcode implements ``from module import *``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 559 | |
| 560 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 561 | .. opcode:: POP_BLOCK |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 562 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 563 | Removes one block from the block stack. Per frame, there is a stack of |
| 564 | blocks, denoting nested loops, try statements, and such. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 565 | |
| 566 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 567 | .. opcode:: POP_EXCEPT |
Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 568 | |
| 569 | Removes one block from the block stack. The popped block must be an exception |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 570 | handler block, as implicitly created when entering an except handler. In |
| 571 | addition to popping extraneous values from the frame stack, the last three |
| 572 | popped values are used to restore the exception state. |
Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 573 | |
| 574 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 575 | .. opcode:: END_FINALLY |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 576 | |
| 577 | Terminates a :keyword:`finally` clause. The interpreter recalls whether the |
| 578 | exception has to be re-raised, or whether the function returns, and continues |
| 579 | with the outer-next block. |
| 580 | |
| 581 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 582 | .. opcode:: LOAD_BUILD_CLASS |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 583 | |
Georg Brandl | 5ac2230 | 2008-07-20 21:39:03 +0000 | [diff] [blame] | 584 | Pushes :func:`builtins.__build_class__` onto the stack. It is later called |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 585 | by :opcode:`CALL_FUNCTION` to construct a class. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 586 | |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 587 | |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 588 | .. opcode:: SETUP_WITH (delta) |
| 589 | |
| 590 | This opcode performs several operations before a with block starts. First, |
| 591 | it loads :meth:`~object.__exit__` from the context manager and pushes it onto |
| 592 | the stack for later use by :opcode:`WITH_CLEANUP`. Then, |
| 593 | :meth:`~object.__enter__` is called, and a finally block pointing to *delta* |
| 594 | is pushed. Finally, the result of calling the enter method is pushed onto |
| 595 | the stack. The next opcode will either ignore it (:opcode:`POP_TOP`), or |
| 596 | store it in (a) variable(s) (:opcode:`STORE_FAST`, :opcode:`STORE_NAME`, or |
| 597 | :opcode:`UNPACK_SEQUENCE`). |
| 598 | |
| 599 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 600 | .. opcode:: WITH_CLEANUP |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 601 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 602 | Cleans up the stack when a :keyword:`with` statement block exits. TOS is the |
| 603 | context manager's :meth:`__exit__` bound method. Below TOS are 1--3 values |
| 604 | indicating how/why the finally clause was entered: |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 605 | |
Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 606 | * SECOND = ``None`` |
| 607 | * (SECOND, THIRD) = (``WHY_{RETURN,CONTINUE}``), retval |
| 608 | * SECOND = ``WHY_*``; no retval below it |
| 609 | * (SECOND, THIRD, FOURTH) = exc_info() |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 610 | |
Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 611 | In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise |
| 612 | ``TOS(None, None, None)``. In addition, TOS is removed from the stack. |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 613 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 614 | If the stack represents an exception, *and* the function call returns a |
| 615 | 'true' value, this information is "zapped" and replaced with a single |
| 616 | ``WHY_SILENCED`` to prevent :opcode:`END_FINALLY` from re-raising the |
| 617 | exception. (But non-local gotos will still be resumed.) |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 618 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 619 | .. XXX explain the WHY stuff! |
| 620 | |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 621 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 622 | All of the following opcodes expect arguments. An argument is two bytes, with |
| 623 | the more significant byte last. |
| 624 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 625 | .. opcode:: STORE_NAME (namei) |
| 626 | |
| 627 | Implements ``name = TOS``. *namei* is the index of *name* in the attribute |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 628 | :attr:`co_names` of the code object. The compiler tries to use |
| 629 | :opcode:`STORE_FAST` or :opcode:`STORE_GLOBAL` if possible. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 630 | |
| 631 | |
| 632 | .. opcode:: DELETE_NAME (namei) |
| 633 | |
| 634 | Implements ``del name``, where *namei* is the index into :attr:`co_names` |
| 635 | attribute of the code object. |
| 636 | |
| 637 | |
| 638 | .. opcode:: UNPACK_SEQUENCE (count) |
| 639 | |
| 640 | Unpacks TOS into *count* individual values, which are put onto the stack |
| 641 | right-to-left. |
| 642 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 643 | |
Georg Brandl | 5ac2230 | 2008-07-20 21:39:03 +0000 | [diff] [blame] | 644 | .. opcode:: UNPACK_EX (counts) |
| 645 | |
| 646 | Implements assignment with a starred target: Unpacks an iterable in TOS into |
| 647 | individual values, where the total number of values can be smaller than the |
| 648 | number of items in the iterable: one the new values will be a list of all |
| 649 | leftover items. |
| 650 | |
| 651 | The low byte of *counts* is the number of values before the list value, the |
| 652 | high byte of *counts* the number of values after it. The resulting values |
| 653 | are put onto the stack right-to-left. |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 654 | |
Georg Brandl | 5ac2230 | 2008-07-20 21:39:03 +0000 | [diff] [blame] | 655 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 656 | .. opcode:: STORE_ATTR (namei) |
| 657 | |
| 658 | Implements ``TOS.name = TOS1``, where *namei* is the index of name in |
| 659 | :attr:`co_names`. |
| 660 | |
| 661 | |
| 662 | .. opcode:: DELETE_ATTR (namei) |
| 663 | |
| 664 | Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`. |
| 665 | |
| 666 | |
| 667 | .. opcode:: STORE_GLOBAL (namei) |
| 668 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 669 | Works as :opcode:`STORE_NAME`, but stores the name as a global. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 670 | |
| 671 | |
| 672 | .. opcode:: DELETE_GLOBAL (namei) |
| 673 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 674 | Works as :opcode:`DELETE_NAME`, but deletes a global name. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 675 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 676 | |
| 677 | .. opcode:: LOAD_CONST (consti) |
| 678 | |
| 679 | Pushes ``co_consts[consti]`` onto the stack. |
| 680 | |
| 681 | |
| 682 | .. opcode:: LOAD_NAME (namei) |
| 683 | |
| 684 | Pushes the value associated with ``co_names[namei]`` onto the stack. |
| 685 | |
| 686 | |
| 687 | .. opcode:: BUILD_TUPLE (count) |
| 688 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 689 | Creates a tuple consuming *count* items from the stack, and pushes the |
| 690 | resulting tuple onto the stack. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 691 | |
| 692 | |
| 693 | .. opcode:: BUILD_LIST (count) |
| 694 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 695 | Works as :opcode:`BUILD_TUPLE`, but creates a list. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 696 | |
| 697 | |
| 698 | .. opcode:: BUILD_SET (count) |
| 699 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 700 | Works as :opcode:`BUILD_TUPLE`, but creates a set. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 701 | |
| 702 | |
Christian Heimes | a62da1d | 2008-01-12 19:39:10 +0000 | [diff] [blame] | 703 | .. opcode:: BUILD_MAP (count) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 704 | |
Christian Heimes | a62da1d | 2008-01-12 19:39:10 +0000 | [diff] [blame] | 705 | Pushes a new dictionary object onto the stack. The dictionary is pre-sized |
| 706 | to hold *count* entries. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 707 | |
| 708 | |
| 709 | .. opcode:: LOAD_ATTR (namei) |
| 710 | |
| 711 | Replaces TOS with ``getattr(TOS, co_names[namei])``. |
| 712 | |
| 713 | |
| 714 | .. opcode:: COMPARE_OP (opname) |
| 715 | |
| 716 | Performs a Boolean operation. The operation name can be found in |
| 717 | ``cmp_op[opname]``. |
| 718 | |
| 719 | |
| 720 | .. opcode:: IMPORT_NAME (namei) |
| 721 | |
Christian Heimes | a342c01 | 2008-04-20 21:01:16 +0000 | [diff] [blame] | 722 | Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide |
| 723 | the *fromlist* and *level* arguments of :func:`__import__`. The module |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 724 | object is pushed onto the stack. The current namespace is not affected: for |
| 725 | a proper import statement, a subsequent :opcode:`STORE_FAST` instruction |
Christian Heimes | a342c01 | 2008-04-20 21:01:16 +0000 | [diff] [blame] | 726 | modifies the namespace. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 727 | |
| 728 | |
| 729 | .. opcode:: IMPORT_FROM (namei) |
| 730 | |
| 731 | Loads the attribute ``co_names[namei]`` from the module found in TOS. The |
| 732 | resulting object is pushed onto the stack, to be subsequently stored by a |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 733 | :opcode:`STORE_FAST` instruction. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 734 | |
| 735 | |
| 736 | .. opcode:: JUMP_FORWARD (delta) |
| 737 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 738 | Increments bytecode counter by *delta*. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 739 | |
| 740 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 741 | .. opcode:: POP_JUMP_IF_TRUE (target) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 742 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 743 | If TOS is true, sets the bytecode counter to *target*. TOS is popped. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 744 | |
| 745 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 746 | .. opcode:: POP_JUMP_IF_FALSE (target) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 747 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 748 | If TOS is false, sets the bytecode counter to *target*. TOS is popped. |
| 749 | |
| 750 | |
| 751 | .. opcode:: JUMP_IF_TRUE_OR_POP (target) |
| 752 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 753 | If TOS is true, sets the bytecode counter to *target* and leaves TOS on the |
| 754 | stack. Otherwise (TOS is false), TOS is popped. |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 755 | |
| 756 | |
| 757 | .. opcode:: JUMP_IF_FALSE_OR_POP (target) |
| 758 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 759 | If TOS is false, sets the bytecode counter to *target* and leaves TOS on the |
| 760 | stack. Otherwise (TOS is true), TOS is popped. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 761 | |
| 762 | |
| 763 | .. opcode:: JUMP_ABSOLUTE (target) |
| 764 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 765 | Set bytecode counter to *target*. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 766 | |
| 767 | |
| 768 | .. opcode:: FOR_ITER (delta) |
| 769 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 770 | TOS is an :term:`iterator`. Call its :meth:`~iterator.__next__` method. If |
| 771 | this yields a new value, push it on the stack (leaving the iterator below |
| 772 | it). If the iterator indicates it is exhausted TOS is popped, and the byte |
| 773 | code counter is incremented by *delta*. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 774 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 775 | |
| 776 | .. opcode:: LOAD_GLOBAL (namei) |
| 777 | |
| 778 | Loads the global named ``co_names[namei]`` onto the stack. |
| 779 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 780 | |
| 781 | .. opcode:: SETUP_LOOP (delta) |
| 782 | |
| 783 | Pushes a block for a loop onto the block stack. The block spans from the |
| 784 | current instruction with a size of *delta* bytes. |
| 785 | |
| 786 | |
| 787 | .. opcode:: SETUP_EXCEPT (delta) |
| 788 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 789 | Pushes a try block from a try-except clause onto the block stack. *delta* |
| 790 | points to the first except block. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 791 | |
| 792 | |
| 793 | .. opcode:: SETUP_FINALLY (delta) |
| 794 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 795 | Pushes a try block from a try-except clause onto the block stack. *delta* |
| 796 | points to the finally block. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 797 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 798 | .. opcode:: STORE_MAP |
Christian Heimes | a62da1d | 2008-01-12 19:39:10 +0000 | [diff] [blame] | 799 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 800 | Store a key and value pair in a dictionary. Pops the key and value while |
| 801 | leaving the dictionary on the stack. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 802 | |
| 803 | .. opcode:: LOAD_FAST (var_num) |
| 804 | |
| 805 | Pushes a reference to the local ``co_varnames[var_num]`` onto the stack. |
| 806 | |
| 807 | |
| 808 | .. opcode:: STORE_FAST (var_num) |
| 809 | |
| 810 | Stores TOS into the local ``co_varnames[var_num]``. |
| 811 | |
| 812 | |
| 813 | .. opcode:: DELETE_FAST (var_num) |
| 814 | |
| 815 | Deletes local ``co_varnames[var_num]``. |
| 816 | |
| 817 | |
| 818 | .. opcode:: LOAD_CLOSURE (i) |
| 819 | |
| 820 | Pushes a reference to the cell contained in slot *i* of the cell and free |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 821 | variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is |
| 822 | less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i - |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 823 | len(co_cellvars)]``. |
| 824 | |
| 825 | |
| 826 | .. opcode:: LOAD_DEREF (i) |
| 827 | |
| 828 | Loads the cell contained in slot *i* of the cell and free variable storage. |
| 829 | Pushes a reference to the object the cell contains on the stack. |
| 830 | |
| 831 | |
Benjamin Peterson | 3b0431d | 2013-04-30 09:41:40 -0400 | [diff] [blame] | 832 | .. opcode:: LOAD_CLASSDEREF (i) |
| 833 | |
| 834 | Much like :opcode:`LOAD_DEREF` but first checks the locals dictionary before |
| 835 | consulting the cell. This is used for loading free variables in class |
| 836 | bodies. |
| 837 | |
| 838 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 839 | .. opcode:: STORE_DEREF (i) |
| 840 | |
| 841 | Stores TOS into the cell contained in slot *i* of the cell and free variable |
| 842 | storage. |
| 843 | |
| 844 | |
Amaury Forgeot d'Arc | ba117ef | 2010-09-10 21:39:53 +0000 | [diff] [blame] | 845 | .. opcode:: DELETE_DEREF (i) |
| 846 | |
| 847 | Empties the cell contained in slot *i* of the cell and free variable storage. |
| 848 | Used by the :keyword:`del` statement. |
| 849 | |
| 850 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 851 | .. opcode:: RAISE_VARARGS (argc) |
| 852 | |
| 853 | Raises an exception. *argc* indicates the number of parameters to the raise |
| 854 | statement, ranging from 0 to 3. The handler will find the traceback as TOS2, |
| 855 | the parameter as TOS1, and the exception as TOS. |
| 856 | |
| 857 | |
| 858 | .. opcode:: CALL_FUNCTION (argc) |
| 859 | |
| 860 | Calls a function. The low byte of *argc* indicates the number of positional |
| 861 | parameters, the high byte the number of keyword parameters. On the stack, the |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 862 | opcode finds the keyword parameters first. For each keyword argument, the |
| 863 | value is on top of the key. Below the keyword parameters, the positional |
| 864 | parameters are on the stack, with the right-most parameter on top. Below the |
| 865 | parameters, the function object to call is on the stack. Pops all function |
| 866 | arguments, and the function itself off the stack, and pushes the return |
| 867 | value. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 868 | |
| 869 | |
| 870 | .. opcode:: MAKE_FUNCTION (argc) |
| 871 | |
Georg Brandl | c96ef1f | 2013-10-12 18:41:18 +0200 | [diff] [blame] | 872 | Pushes a new function object on the stack. From bottom to top, the consumed |
| 873 | stack must consist of |
| 874 | |
| 875 | * ``argc & 0xFF`` default argument objects in positional order |
| 876 | * ``(argc >> 8) & 0xFF`` pairs of name and default argument, with the name |
| 877 | just below the object on the stack, for keyword-only parameters |
| 878 | * ``(argc >> 16) & 0x7FFF`` parameter annotation objects |
| 879 | * a tuple listing the parameter names for the annotations (only if there are |
| 880 | ony annotation objects) |
| 881 | * the code associated with the function (at TOS1) |
| 882 | * the :term:`qualified name` of the function (at TOS) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 883 | |
| 884 | |
| 885 | .. opcode:: MAKE_CLOSURE (argc) |
| 886 | |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 887 | Creates a new function object, sets its *__closure__* slot, and pushes it on |
Andrew Svetlov | a5c4309 | 2012-11-23 15:28:34 +0200 | [diff] [blame] | 888 | the stack. TOS is the :term:`qualified name` of the function, TOS1 is the |
| 889 | code associated with the function, and TOS2 is the tuple containing cells for |
Antoine Pitrou | 4ce4f97 | 2015-08-13 20:37:08 +0200 | [diff] [blame] | 890 | the closure's free variables. *argc* is interpreted as in ``MAKE_FUNCTION``; |
| 891 | the annotations and defaults are also in the same order below TOS2. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 892 | |
| 893 | |
| 894 | .. opcode:: BUILD_SLICE (argc) |
| 895 | |
| 896 | .. index:: builtin: slice |
| 897 | |
| 898 | Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2, |
| 899 | ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 900 | pushed. See the :func:`slice` built-in function for more information. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 901 | |
| 902 | |
| 903 | .. opcode:: EXTENDED_ARG (ext) |
| 904 | |
| 905 | Prefixes any opcode which has an argument too big to fit into the default two |
| 906 | bytes. *ext* holds two additional bytes which, taken together with the |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 907 | subsequent opcode's argument, comprise a four-byte argument, *ext* being the |
| 908 | two most-significant bytes. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 909 | |
| 910 | |
| 911 | .. opcode:: CALL_FUNCTION_VAR (argc) |
| 912 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 913 | Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The |
| 914 | top element on the stack contains the variable argument list, followed by |
| 915 | keyword and positional arguments. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 916 | |
| 917 | |
| 918 | .. opcode:: CALL_FUNCTION_KW (argc) |
| 919 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 920 | Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The |
| 921 | top element on the stack contains the keyword arguments dictionary, followed |
| 922 | by explicit keyword and positional arguments. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 923 | |
| 924 | |
| 925 | .. opcode:: CALL_FUNCTION_VAR_KW (argc) |
| 926 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 927 | Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The |
| 928 | top element on the stack contains the keyword arguments dictionary, followed |
| 929 | by the variable-arguments tuple, followed by explicit keyword and positional |
| 930 | arguments. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 931 | |
| 932 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 933 | .. opcode:: HAVE_ARGUMENT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 934 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 935 | This is not really an opcode. It identifies the dividing line between |
| 936 | opcodes which don't take arguments ``< HAVE_ARGUMENT`` and those which do |
| 937 | ``>= HAVE_ARGUMENT``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 938 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 939 | .. _opcode_collections: |
| 940 | |
| 941 | Opcode collections |
| 942 | ------------------ |
| 943 | |
| 944 | These collections are provided for automatic introspection of bytecode |
| 945 | instructions: |
| 946 | |
| 947 | .. data:: opname |
| 948 | |
| 949 | Sequence of operation names, indexable using the bytecode. |
| 950 | |
| 951 | |
| 952 | .. data:: opmap |
| 953 | |
| 954 | Dictionary mapping operation names to bytecodes. |
| 955 | |
| 956 | |
| 957 | .. data:: cmp_op |
| 958 | |
| 959 | Sequence of all compare operation names. |
| 960 | |
| 961 | |
| 962 | .. data:: hasconst |
| 963 | |
| 964 | Sequence of bytecodes that have a constant parameter. |
| 965 | |
| 966 | |
| 967 | .. data:: hasfree |
| 968 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 969 | Sequence of bytecodes that access a free variable (note that 'free' in this |
| 970 | context refers to names in the current scope that are referenced by inner |
| 971 | scopes or names in outer scopes that are referenced from this scope. It does |
| 972 | *not* include references to global or builtin scopes). |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 973 | |
| 974 | |
| 975 | .. data:: hasname |
| 976 | |
| 977 | Sequence of bytecodes that access an attribute by name. |
| 978 | |
| 979 | |
| 980 | .. data:: hasjrel |
| 981 | |
| 982 | Sequence of bytecodes that have a relative jump target. |
| 983 | |
| 984 | |
| 985 | .. data:: hasjabs |
| 986 | |
| 987 | Sequence of bytecodes that have an absolute jump target. |
| 988 | |
| 989 | |
| 990 | .. data:: haslocal |
| 991 | |
| 992 | Sequence of bytecodes that access a local variable. |
| 993 | |
| 994 | |
| 995 | .. data:: hascompare |
| 996 | |
| 997 | Sequence of bytecodes of Boolean operations. |