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 | |
Ivan Levkivskyi | 8f9e1bbf | 2017-03-24 22:05:04 +0100 | [diff] [blame] | 23 | .. versionchanged:: 3.6 |
| 24 | Use 2 bytes for each instruction. Previously the number of bytes varied |
| 25 | by instruction. |
| 26 | |
Brett Cannon | 8315fd1 | 2010-07-02 22:03:00 +0000 | [diff] [blame] | 27 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 28 | Example: Given the function :func:`myfunc`:: |
| 29 | |
| 30 | def myfunc(alist): |
| 31 | return len(alist) |
| 32 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 33 | the following command can be used to display the disassembly of |
| 34 | :func:`myfunc`:: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 35 | |
| 36 | >>> dis.dis(myfunc) |
| 37 | 2 0 LOAD_GLOBAL 0 (len) |
Serhiy Storchaka | b0f80b0 | 2016-05-24 09:15:14 +0300 | [diff] [blame] | 38 | 2 LOAD_FAST 0 (alist) |
| 39 | 4 CALL_FUNCTION 1 |
| 40 | 6 RETURN_VALUE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 41 | |
| 42 | (The "2" is a line number). |
| 43 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 44 | Bytecode analysis |
| 45 | ----------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 46 | |
R David Murray | 0bce6e7 | 2014-01-07 14:30:17 -0500 | [diff] [blame] | 47 | .. versionadded:: 3.4 |
| 48 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 49 | 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] | 50 | :class:`Bytecode` object that provides easy access to details of the compiled |
| 51 | code. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 52 | |
Nick Coghlan | 50c48b8 | 2013-11-23 00:57:00 +1000 | [diff] [blame] | 53 | .. class:: Bytecode(x, *, first_line=None, current_offset=None) |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 54 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 55 | |
syncosmic | fe2b56a | 2017-08-17 19:29:21 -0700 | [diff] [blame] | 56 | Analyse the bytecode corresponding to a function, generator, asynchronous |
| 57 | generator, coroutine, method, string of source code, or a code object (as |
| 58 | returned by :func:`compile`). |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 59 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 60 | This is a convenience wrapper around many of the functions listed below, most |
| 61 | notably :func:`get_instructions`, as iterating over a :class:`Bytecode` |
| 62 | instance yields the bytecode operations as :class:`Instruction` instances. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 63 | |
Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 64 | If *first_line* is not ``None``, it indicates the line number that should be |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 65 | reported for the first source line in the disassembled code. Otherwise, the |
| 66 | source line information (if any) is taken directly from the disassembled code |
| 67 | object. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 68 | |
Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 69 | If *current_offset* is not ``None``, it refers to an instruction offset in the |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 70 | disassembled code. Setting this means :meth:`.dis` will display a "current |
| 71 | instruction" marker against the specified opcode. |
Nick Coghlan | 50c48b8 | 2013-11-23 00:57:00 +1000 | [diff] [blame] | 72 | |
| 73 | .. classmethod:: from_traceback(tb) |
| 74 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 75 | Construct a :class:`Bytecode` instance from the given traceback, setting |
| 76 | *current_offset* to the instruction responsible for the exception. |
Nick Coghlan | 50c48b8 | 2013-11-23 00:57:00 +1000 | [diff] [blame] | 77 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 78 | .. data:: codeobj |
| 79 | |
| 80 | The compiled code object. |
| 81 | |
Nick Coghlan | 90b8e7d | 2013-11-06 22:08:36 +1000 | [diff] [blame] | 82 | .. data:: first_line |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 83 | |
Nick Coghlan | 90b8e7d | 2013-11-06 22:08:36 +1000 | [diff] [blame] | 84 | The first source line of the code object (if available) |
| 85 | |
| 86 | .. method:: dis() |
| 87 | |
Benjamin Peterson | 29fec92 | 2015-03-02 09:27:43 -0500 | [diff] [blame] | 88 | Return a formatted view of the bytecode operations (the same as printed by |
| 89 | :func:`dis.dis`, but returned as a multi-line string). |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 90 | |
| 91 | .. method:: info() |
| 92 | |
| 93 | Return a formatted multi-line string with detailed information about the |
| 94 | code object, like :func:`code_info`. |
| 95 | |
syncosmic | fe2b56a | 2017-08-17 19:29:21 -0700 | [diff] [blame] | 96 | .. versionchanged:: 3.7 |
| 97 | This can now handle coroutine and asynchronous generator objects. |
| 98 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 99 | Example:: |
| 100 | |
| 101 | >>> bytecode = dis.Bytecode(myfunc) |
| 102 | >>> for instr in bytecode: |
| 103 | ... print(instr.opname) |
| 104 | ... |
| 105 | LOAD_GLOBAL |
| 106 | LOAD_FAST |
| 107 | CALL_FUNCTION |
| 108 | RETURN_VALUE |
| 109 | |
| 110 | |
| 111 | Analysis functions |
| 112 | ------------------ |
| 113 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 114 | The :mod:`dis` module also defines the following analysis functions that convert |
| 115 | the input directly to the desired output. They can be useful if only a single |
| 116 | operation is being performed, so the intermediate analysis object isn't useful: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 117 | |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 118 | .. function:: code_info(x) |
Nick Coghlan | eae2da1 | 2010-08-17 08:03:36 +0000 | [diff] [blame] | 119 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 120 | Return a formatted multi-line string with detailed code object information |
syncosmic | fe2b56a | 2017-08-17 19:29:21 -0700 | [diff] [blame] | 121 | for the supplied function, generator, asynchronous generator, coroutine, |
| 122 | method, source code string or code object. |
Nick Coghlan | eae2da1 | 2010-08-17 08:03:36 +0000 | [diff] [blame] | 123 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 124 | Note that the exact contents of code info strings are highly implementation |
| 125 | dependent and they may change arbitrarily across Python VMs or Python |
| 126 | releases. |
Nick Coghlan | eae2da1 | 2010-08-17 08:03:36 +0000 | [diff] [blame] | 127 | |
| 128 | .. versionadded:: 3.2 |
| 129 | |
syncosmic | fe2b56a | 2017-08-17 19:29:21 -0700 | [diff] [blame] | 130 | .. versionchanged:: 3.7 |
| 131 | This can now handle coroutine and asynchronous generator objects. |
| 132 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 133 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 134 | .. function:: show_code(x, *, file=None) |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 135 | |
| 136 | Print detailed code object information for the supplied function, method, |
Ezio Melotti | 6e6c6ac | 2013-08-23 22:41:39 +0300 | [diff] [blame] | 137 | source code string or code object to *file* (or ``sys.stdout`` if *file* |
| 138 | is not specified). |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 139 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 140 | This is a convenient shorthand for ``print(code_info(x), file=file)``, |
| 141 | intended for interactive exploration at the interpreter prompt. |
Nick Coghlan | e8814fb | 2010-09-10 14:08:04 +0000 | [diff] [blame] | 142 | |
| 143 | .. versionadded:: 3.2 |
| 144 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 145 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 146 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 147 | |
| 148 | |
Serhiy Storchaka | 1efbf92 | 2017-06-11 14:09:39 +0300 | [diff] [blame] | 149 | .. function:: dis(x=None, *, file=None, depth=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 150 | |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 151 | Disassemble the *x* object. *x* can denote either a module, a class, a |
Stéphane Wirtel | 07fbbfd | 2018-10-05 16:17:18 +0200 | [diff] [blame] | 152 | method, a function, a generator, an asynchronous generator, a coroutine, |
syncosmic | fe2b56a | 2017-08-17 19:29:21 -0700 | [diff] [blame] | 153 | a code object, a string of source code or a byte sequence of raw bytecode. |
| 154 | For a module, it disassembles all functions. For a class, it disassembles |
| 155 | all methods (including class and static methods). For a code object or |
| 156 | sequence of raw bytecode, it prints one line per bytecode instruction. |
| 157 | It also recursively disassembles nested code objects (the code of |
| 158 | comprehensions, generator expressions and nested functions, and the code |
Serhiy Storchaka | 1efbf92 | 2017-06-11 14:09:39 +0300 | [diff] [blame] | 159 | used for building nested classes). |
| 160 | Strings are first compiled to code objects with the :func:`compile` |
Serhiy Storchaka | 585c93d | 2016-04-23 09:23:52 +0300 | [diff] [blame] | 161 | built-in function before being disassembled. If no object is provided, this |
| 162 | function disassembles the last traceback. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 163 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 164 | The disassembly is written as text to the supplied *file* argument if |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 165 | provided and to ``sys.stdout`` otherwise. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 166 | |
Serhiy Storchaka | 1efbf92 | 2017-06-11 14:09:39 +0300 | [diff] [blame] | 167 | The maximal depth of recursion is limited by *depth* unless it is ``None``. |
| 168 | ``depth=0`` means no recursion. |
| 169 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 170 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 171 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 172 | |
Serhiy Storchaka | 1efbf92 | 2017-06-11 14:09:39 +0300 | [diff] [blame] | 173 | .. versionchanged:: 3.7 |
| 174 | Implemented recursive disassembling and added *depth* parameter. |
| 175 | |
syncosmic | fe2b56a | 2017-08-17 19:29:21 -0700 | [diff] [blame] | 176 | .. versionchanged:: 3.7 |
| 177 | This can now handle coroutine and asynchronous generator objects. |
| 178 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 179 | |
| 180 | .. function:: distb(tb=None, *, file=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 181 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 182 | Disassemble the top-of-stack function of a traceback, using the last |
| 183 | traceback if none was passed. The instruction causing the exception is |
| 184 | indicated. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 185 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 186 | The disassembly is written as text to the supplied *file* argument if |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 187 | provided and to ``sys.stdout`` otherwise. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 188 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 189 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 190 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 191 | |
| 192 | |
| 193 | .. function:: disassemble(code, lasti=-1, *, file=None) |
| 194 | disco(code, lasti=-1, *, file=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 195 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 196 | Disassemble a code object, indicating the last instruction if *lasti* was |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 197 | provided. The output is divided in the following columns: |
| 198 | |
| 199 | #. the line number, for the first instruction of each line |
| 200 | #. the current instruction, indicated as ``-->``, |
| 201 | #. a labelled instruction, indicated with ``>>``, |
| 202 | #. the address of the instruction, |
| 203 | #. the operation code name, |
| 204 | #. operation parameters, and |
| 205 | #. interpretation of the parameters in parentheses. |
| 206 | |
| 207 | The parameter interpretation recognizes local and global variable names, |
| 208 | constant values, branch targets, and compare operators. |
| 209 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 210 | The disassembly is written as text to the supplied *file* argument if |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 211 | provided and to ``sys.stdout`` otherwise. |
| 212 | |
| 213 | .. versionchanged:: 3.4 |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 214 | Added *file* parameter. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 215 | |
| 216 | |
Nick Coghlan | 90b8e7d | 2013-11-06 22:08:36 +1000 | [diff] [blame] | 217 | .. function:: get_instructions(x, *, first_line=None) |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 218 | |
| 219 | Return an iterator over the instructions in the supplied function, method, |
| 220 | source code string or code object. |
| 221 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 222 | The iterator generates a series of :class:`Instruction` named tuples giving |
| 223 | the details of each operation in the supplied code. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 224 | |
Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 225 | If *first_line* is not ``None``, it indicates the line number that should be |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 226 | reported for the first source line in the disassembled code. Otherwise, the |
| 227 | source line information (if any) is taken directly from the disassembled code |
| 228 | object. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 229 | |
| 230 | .. versionadded:: 3.4 |
| 231 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 232 | |
Benjamin Peterson | 75edad0 | 2009-01-01 15:05:06 +0000 | [diff] [blame] | 233 | .. function:: findlinestarts(code) |
| 234 | |
| 235 | This generator function uses the ``co_firstlineno`` and ``co_lnotab`` |
| 236 | attributes of the code object *code* to find the offsets which are starts of |
| 237 | lines in the source code. They are generated as ``(offset, lineno)`` pairs. |
Ivan Levkivskyi | 8f9e1bbf | 2017-03-24 22:05:04 +0100 | [diff] [blame] | 238 | See :source:`Objects/lnotab_notes.txt` for the ``co_lnotab`` format and |
| 239 | how to decode it. |
| 240 | |
| 241 | .. versionchanged:: 3.6 |
| 242 | Line numbers can be decreasing. Before, they were always increasing. |
Benjamin Peterson | 75edad0 | 2009-01-01 15:05:06 +0000 | [diff] [blame] | 243 | |
| 244 | |
| 245 | .. function:: findlabels(code) |
| 246 | |
| 247 | Detect all offsets in the code object *code* which are jump targets, and |
| 248 | return a list of these offsets. |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 249 | |
Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 250 | |
Serhiy Storchaka | 7bdf282 | 2018-09-18 09:54:26 +0300 | [diff] [blame] | 251 | .. function:: stack_effect(opcode, oparg=None, *, jump=None) |
Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 252 | |
| 253 | Compute the stack effect of *opcode* with argument *oparg*. |
| 254 | |
Serhiy Storchaka | 7bdf282 | 2018-09-18 09:54:26 +0300 | [diff] [blame] | 255 | If the code has a jump target and *jump* is ``True``, :func:`~stack_effect` |
| 256 | will return the stack effect of jumping. If *jump* is ``False``, |
| 257 | it will return the stack effect of not jumping. And if *jump* is |
| 258 | ``None`` (default), it will return the maximal stack effect of both cases. |
| 259 | |
Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 260 | .. versionadded:: 3.4 |
| 261 | |
Serhiy Storchaka | 7bdf282 | 2018-09-18 09:54:26 +0300 | [diff] [blame] | 262 | .. versionchanged:: 3.8 |
| 263 | Added *jump* parameter. |
| 264 | |
| 265 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 266 | .. _bytecodes: |
| 267 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 268 | Python Bytecode Instructions |
| 269 | ---------------------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 270 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 271 | The :func:`get_instructions` function and :class:`Bytecode` class provide |
| 272 | details of bytecode instructions as :class:`Instruction` instances: |
| 273 | |
| 274 | .. class:: Instruction |
| 275 | |
| 276 | Details for a bytecode operation |
| 277 | |
| 278 | .. data:: opcode |
| 279 | |
| 280 | numeric code for operation, corresponding to the opcode values listed |
| 281 | below and the bytecode values in the :ref:`opcode_collections`. |
| 282 | |
| 283 | |
| 284 | .. data:: opname |
| 285 | |
| 286 | human readable name for operation |
| 287 | |
| 288 | |
| 289 | .. data:: arg |
| 290 | |
Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 291 | numeric argument to operation (if any), otherwise ``None`` |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 292 | |
| 293 | |
| 294 | .. data:: argval |
| 295 | |
| 296 | resolved arg value (if known), otherwise same as arg |
| 297 | |
| 298 | |
| 299 | .. data:: argrepr |
| 300 | |
| 301 | human readable description of operation argument |
| 302 | |
| 303 | |
| 304 | .. data:: offset |
| 305 | |
| 306 | start index of operation within bytecode sequence |
| 307 | |
| 308 | |
| 309 | .. data:: starts_line |
| 310 | |
Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 311 | line started by this opcode (if any), otherwise ``None`` |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 312 | |
| 313 | |
| 314 | .. data:: is_jump_target |
| 315 | |
Serhiy Storchaka | 0e90e99 | 2013-11-29 12:19:53 +0200 | [diff] [blame] | 316 | ``True`` if other code jumps to here, otherwise ``False`` |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 317 | |
| 318 | .. versionadded:: 3.4 |
| 319 | |
| 320 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 321 | The Python compiler currently generates the following bytecode instructions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 322 | |
| 323 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 324 | **General instructions** |
| 325 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 326 | .. opcode:: NOP |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 327 | |
| 328 | Do nothing code. Used as a placeholder by the bytecode optimizer. |
| 329 | |
| 330 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 331 | .. opcode:: POP_TOP |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 332 | |
| 333 | Removes the top-of-stack (TOS) item. |
| 334 | |
| 335 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 336 | .. opcode:: ROT_TWO |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 337 | |
| 338 | Swaps the two top-most stack items. |
| 339 | |
| 340 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 341 | .. opcode:: ROT_THREE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 342 | |
| 343 | Lifts second and third stack item one position up, moves top down to position |
| 344 | three. |
| 345 | |
| 346 | |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 347 | .. opcode:: ROT_FOUR |
| 348 | |
| 349 | Lifts second, third and forth stack items one position up, moves top down |
| 350 | to position four. |
| 351 | |
| 352 | .. versionadded:: 3.8 |
| 353 | |
| 354 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 355 | .. opcode:: DUP_TOP |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 356 | |
| 357 | Duplicates the reference on top of the stack. |
| 358 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 359 | .. versionadded:: 3.2 |
| 360 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 361 | |
Antoine Pitrou | 74a69fa | 2010-09-04 18:43:52 +0000 | [diff] [blame] | 362 | .. opcode:: DUP_TOP_TWO |
| 363 | |
| 364 | Duplicates the two references on top of the stack, leaving them in the |
| 365 | same order. |
| 366 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 367 | .. versionadded:: 3.2 |
| 368 | |
Antoine Pitrou | 74a69fa | 2010-09-04 18:43:52 +0000 | [diff] [blame] | 369 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 370 | **Unary operations** |
| 371 | |
| 372 | 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] | 373 | result back on the stack. |
| 374 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 375 | .. opcode:: UNARY_POSITIVE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 376 | |
| 377 | Implements ``TOS = +TOS``. |
| 378 | |
| 379 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 380 | .. opcode:: UNARY_NEGATIVE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 381 | |
| 382 | Implements ``TOS = -TOS``. |
| 383 | |
| 384 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 385 | .. opcode:: UNARY_NOT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 386 | |
| 387 | Implements ``TOS = not TOS``. |
| 388 | |
| 389 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 390 | .. opcode:: UNARY_INVERT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 391 | |
| 392 | Implements ``TOS = ~TOS``. |
| 393 | |
| 394 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 395 | .. opcode:: GET_ITER |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 396 | |
| 397 | Implements ``TOS = iter(TOS)``. |
| 398 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 399 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 400 | .. opcode:: GET_YIELD_FROM_ITER |
| 401 | |
| 402 | If ``TOS`` is a :term:`generator iterator` or :term:`coroutine` object |
| 403 | it is left as is. Otherwise, implements ``TOS = iter(TOS)``. |
| 404 | |
| 405 | .. versionadded:: 3.5 |
| 406 | |
| 407 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 408 | **Binary operations** |
| 409 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 410 | Binary operations remove the top of the stack (TOS) and the second top-most |
| 411 | stack item (TOS1) from the stack. They perform the operation, and put the |
| 412 | result back on the stack. |
| 413 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 414 | .. opcode:: BINARY_POWER |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 415 | |
| 416 | Implements ``TOS = TOS1 ** TOS``. |
| 417 | |
| 418 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 419 | .. opcode:: BINARY_MULTIPLY |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 420 | |
| 421 | Implements ``TOS = TOS1 * TOS``. |
| 422 | |
| 423 | |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 424 | .. opcode:: BINARY_MATRIX_MULTIPLY |
| 425 | |
| 426 | Implements ``TOS = TOS1 @ TOS``. |
| 427 | |
Berker Peksag | da0870c | 2015-03-12 20:56:45 +0200 | [diff] [blame] | 428 | .. versionadded:: 3.5 |
| 429 | |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 430 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 431 | .. opcode:: BINARY_FLOOR_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 432 | |
| 433 | Implements ``TOS = TOS1 // TOS``. |
| 434 | |
| 435 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 436 | .. opcode:: BINARY_TRUE_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 437 | |
Ezio Melotti | 7de0a6e | 2010-01-05 08:37:27 +0000 | [diff] [blame] | 438 | Implements ``TOS = TOS1 / TOS``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 439 | |
| 440 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 441 | .. opcode:: BINARY_MODULO |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 442 | |
| 443 | Implements ``TOS = TOS1 % TOS``. |
| 444 | |
| 445 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 446 | .. opcode:: BINARY_ADD |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 447 | |
| 448 | Implements ``TOS = TOS1 + TOS``. |
| 449 | |
| 450 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 451 | .. opcode:: BINARY_SUBTRACT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 452 | |
| 453 | Implements ``TOS = TOS1 - TOS``. |
| 454 | |
| 455 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 456 | .. opcode:: BINARY_SUBSCR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 457 | |
| 458 | Implements ``TOS = TOS1[TOS]``. |
| 459 | |
| 460 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 461 | .. opcode:: BINARY_LSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 462 | |
| 463 | Implements ``TOS = TOS1 << TOS``. |
| 464 | |
| 465 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 466 | .. opcode:: BINARY_RSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 467 | |
| 468 | Implements ``TOS = TOS1 >> TOS``. |
| 469 | |
| 470 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 471 | .. opcode:: BINARY_AND |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 472 | |
| 473 | Implements ``TOS = TOS1 & TOS``. |
| 474 | |
| 475 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 476 | .. opcode:: BINARY_XOR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 477 | |
| 478 | Implements ``TOS = TOS1 ^ TOS``. |
| 479 | |
| 480 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 481 | .. opcode:: BINARY_OR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 482 | |
| 483 | Implements ``TOS = TOS1 | TOS``. |
| 484 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 485 | |
| 486 | **In-place operations** |
| 487 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 488 | In-place operations are like binary operations, in that they remove TOS and |
| 489 | TOS1, and push the result back on the stack, but the operation is done in-place |
| 490 | when TOS1 supports it, and the resulting TOS may be (but does not have to be) |
| 491 | the original TOS1. |
| 492 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 493 | .. opcode:: INPLACE_POWER |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 494 | |
| 495 | Implements in-place ``TOS = TOS1 ** TOS``. |
| 496 | |
| 497 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 498 | .. opcode:: INPLACE_MULTIPLY |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 499 | |
| 500 | Implements in-place ``TOS = TOS1 * TOS``. |
| 501 | |
| 502 | |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 503 | .. opcode:: INPLACE_MATRIX_MULTIPLY |
| 504 | |
| 505 | Implements in-place ``TOS = TOS1 @ TOS``. |
| 506 | |
Berker Peksag | da0870c | 2015-03-12 20:56:45 +0200 | [diff] [blame] | 507 | .. versionadded:: 3.5 |
| 508 | |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 509 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 510 | .. opcode:: INPLACE_FLOOR_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 511 | |
| 512 | Implements in-place ``TOS = TOS1 // TOS``. |
| 513 | |
| 514 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 515 | .. opcode:: INPLACE_TRUE_DIVIDE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 516 | |
Ezio Melotti | 7de0a6e | 2010-01-05 08:37:27 +0000 | [diff] [blame] | 517 | Implements in-place ``TOS = TOS1 / TOS``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 518 | |
| 519 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 520 | .. opcode:: INPLACE_MODULO |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 521 | |
| 522 | Implements in-place ``TOS = TOS1 % TOS``. |
| 523 | |
| 524 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 525 | .. opcode:: INPLACE_ADD |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 526 | |
| 527 | Implements in-place ``TOS = TOS1 + TOS``. |
| 528 | |
| 529 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 530 | .. opcode:: INPLACE_SUBTRACT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 531 | |
| 532 | Implements in-place ``TOS = TOS1 - TOS``. |
| 533 | |
| 534 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 535 | .. opcode:: INPLACE_LSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 536 | |
| 537 | Implements in-place ``TOS = TOS1 << TOS``. |
| 538 | |
| 539 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 540 | .. opcode:: INPLACE_RSHIFT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 541 | |
| 542 | Implements in-place ``TOS = TOS1 >> TOS``. |
| 543 | |
| 544 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 545 | .. opcode:: INPLACE_AND |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 546 | |
| 547 | Implements in-place ``TOS = TOS1 & TOS``. |
| 548 | |
| 549 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 550 | .. opcode:: INPLACE_XOR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 551 | |
| 552 | Implements in-place ``TOS = TOS1 ^ TOS``. |
| 553 | |
| 554 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 555 | .. opcode:: INPLACE_OR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 556 | |
| 557 | Implements in-place ``TOS = TOS1 | TOS``. |
| 558 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 559 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 560 | .. opcode:: STORE_SUBSCR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 561 | |
| 562 | Implements ``TOS1[TOS] = TOS2``. |
| 563 | |
| 564 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 565 | .. opcode:: DELETE_SUBSCR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 566 | |
| 567 | Implements ``del TOS1[TOS]``. |
| 568 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 569 | |
Yury Selivanov | 66f8828 | 2015-06-24 11:04:15 -0400 | [diff] [blame] | 570 | **Coroutine opcodes** |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 571 | |
| 572 | .. opcode:: GET_AWAITABLE |
| 573 | |
Yury Selivanov | 66f8828 | 2015-06-24 11:04:15 -0400 | [diff] [blame] | 574 | Implements ``TOS = get_awaitable(TOS)``, where ``get_awaitable(o)`` |
| 575 | returns ``o`` if ``o`` is a coroutine object or a generator object with |
| 576 | the CO_ITERABLE_COROUTINE flag, or resolves |
| 577 | ``o.__await__``. |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 578 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 579 | .. versionadded:: 3.5 |
| 580 | |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 581 | |
| 582 | .. opcode:: GET_AITER |
| 583 | |
Yury Selivanov | 02e82a0 | 2017-10-06 10:18:10 -0400 | [diff] [blame] | 584 | Implements ``TOS = TOS.__aiter__()``. |
| 585 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 586 | .. versionadded:: 3.5 |
Yury Selivanov | 02e82a0 | 2017-10-06 10:18:10 -0400 | [diff] [blame] | 587 | .. versionchanged:: 3.7 |
| 588 | Returning awaitable objects from ``__aiter__`` is no longer |
| 589 | supported. |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 590 | |
| 591 | |
| 592 | .. opcode:: GET_ANEXT |
| 593 | |
| 594 | Implements ``PUSH(get_awaitable(TOS.__anext__()))``. See ``GET_AWAITABLE`` |
| 595 | for details about ``get_awaitable`` |
| 596 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 597 | .. versionadded:: 3.5 |
| 598 | |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 599 | |
Serhiy Storchaka | 702f8f3 | 2018-03-23 14:34:35 +0200 | [diff] [blame] | 600 | .. opcode:: END_ASYNC_FOR |
| 601 | |
| 602 | Terminates an :keyword:`async for` loop. Handles an exception raised |
| 603 | when awaiting a next item. If TOS is :exc:`StopAsyncIteration` pop 7 |
| 604 | values from the stack and restore the exception state using the second |
| 605 | three of them. Otherwise re-raise the exception using the three values |
| 606 | from the stack. An exception handler block is removed from the block stack. |
| 607 | |
| 608 | .. versionadded:: 3.8 |
| 609 | |
| 610 | |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 611 | .. opcode:: BEFORE_ASYNC_WITH |
| 612 | |
| 613 | Resolves ``__aenter__`` and ``__aexit__`` from the object on top of the |
| 614 | stack. Pushes ``__aexit__`` and result of ``__aenter__()`` to the stack. |
| 615 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 616 | .. versionadded:: 3.5 |
| 617 | |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 618 | |
| 619 | .. opcode:: SETUP_ASYNC_WITH |
| 620 | |
| 621 | Creates a new frame object. |
| 622 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 623 | .. versionadded:: 3.5 |
| 624 | |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 625 | |
| 626 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 627 | **Miscellaneous opcodes** |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 628 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 629 | .. opcode:: PRINT_EXPR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 630 | |
| 631 | Implements the expression statement for the interactive mode. TOS is removed |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 632 | from the stack and printed. In non-interactive mode, an expression statement |
| 633 | is terminated with :opcode:`POP_TOP`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 634 | |
| 635 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 636 | .. opcode:: SET_ADD (i) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 637 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 638 | Calls ``set.add(TOS1[-i], TOS)``. Used to implement set comprehensions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 639 | |
| 640 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 641 | .. opcode:: LIST_APPEND (i) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 642 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 643 | Calls ``list.append(TOS[-i], TOS)``. Used to implement list comprehensions. |
| 644 | |
| 645 | |
| 646 | .. opcode:: MAP_ADD (i) |
| 647 | |
Jörn Heissler | c8a3541 | 2019-06-22 16:40:55 +0200 | [diff] [blame] | 648 | Calls ``dict.__setitem__(TOS1[-i], TOS1, TOS)``. Used to implement dict |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 649 | comprehensions. |
| 650 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 651 | .. versionadded:: 3.1 |
Jörn Heissler | c8a3541 | 2019-06-22 16:40:55 +0200 | [diff] [blame] | 652 | .. versionchanged:: 3.8 |
| 653 | Map value is TOS and map key is TOS1. Before, those were reversed. |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 654 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 655 | 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] | 656 | instructions, while the added value or key/value pair is popped off, the |
| 657 | container object remains on the stack so that it is available for further |
| 658 | iterations of the loop. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 659 | |
| 660 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 661 | .. opcode:: RETURN_VALUE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 662 | |
| 663 | Returns with TOS to the caller of the function. |
| 664 | |
| 665 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 666 | .. opcode:: YIELD_VALUE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 667 | |
Berker Peksag | ab4040e | 2015-03-02 06:33:30 +0200 | [diff] [blame] | 668 | Pops TOS and yields it from a :term:`generator`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 669 | |
| 670 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 671 | .. opcode:: YIELD_FROM |
| 672 | |
Berker Peksag | ab4040e | 2015-03-02 06:33:30 +0200 | [diff] [blame] | 673 | 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] | 674 | |
| 675 | .. versionadded:: 3.3 |
| 676 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 677 | |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 678 | .. opcode:: SETUP_ANNOTATIONS |
| 679 | |
| 680 | Checks whether ``__annotations__`` is defined in ``locals()``, if not it is |
Martin Panter | b1321fb | 2016-10-10 00:38:21 +0000 | [diff] [blame] | 681 | set up to an empty ``dict``. This opcode is only emitted if a class |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 682 | or module body contains :term:`variable annotations <variable annotation>` |
| 683 | statically. |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 684 | |
Berker Peksag | 34b74ff | 2016-09-12 08:00:01 +0300 | [diff] [blame] | 685 | .. versionadded:: 3.6 |
| 686 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 687 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 688 | .. opcode:: IMPORT_STAR |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 689 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 690 | Loads all symbols not starting with ``'_'`` directly from the module TOS to |
| 691 | the local namespace. The module is popped after loading all names. This |
| 692 | opcode implements ``from module import *``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 693 | |
| 694 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 695 | .. opcode:: POP_BLOCK |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 696 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 697 | Removes one block from the block stack. Per frame, there is a stack of |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 698 | blocks, denoting :keyword:`try` statements, and such. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 699 | |
| 700 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 701 | .. opcode:: POP_EXCEPT |
Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 702 | |
| 703 | 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] | 704 | handler block, as implicitly created when entering an except handler. In |
| 705 | addition to popping extraneous values from the frame stack, the last three |
| 706 | popped values are used to restore the exception state. |
Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 707 | |
| 708 | |
Mark Shannon | fee5526 | 2019-11-21 09:11:43 +0000 | [diff] [blame] | 709 | .. opcode:: RERAISE |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 710 | |
Mark Shannon | fee5526 | 2019-11-21 09:11:43 +0000 | [diff] [blame] | 711 | Re-raises the exception currently on top of the stack. |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 712 | |
Mark Shannon | 82f897b | 2019-11-21 14:47:49 +0000 | [diff] [blame^] | 713 | .. versionadded:: 3.9 |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 714 | |
| 715 | |
Mark Shannon | fee5526 | 2019-11-21 09:11:43 +0000 | [diff] [blame] | 716 | .. opcode:: WITH_EXCEPT_START |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 717 | |
Mark Shannon | fee5526 | 2019-11-21 09:11:43 +0000 | [diff] [blame] | 718 | Calls the function in position 7 on the stack with the top three |
| 719 | items on the stack as arguments. |
| 720 | Used to implement the call ``context_manager.__exit__(*exc_info())`` when an exception |
| 721 | has occurred in a :keyword:`with` statement. |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 722 | |
Mark Shannon | 82f897b | 2019-11-21 14:47:49 +0000 | [diff] [blame^] | 723 | .. versionadded:: 3.9 |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 724 | |
| 725 | |
Zackery Spytz | ce6a070 | 2019-08-25 03:44:09 -0600 | [diff] [blame] | 726 | .. opcode:: LOAD_ASSERTION_ERROR |
| 727 | |
| 728 | Pushes :exc:`AssertionError` onto the stack. Used by the :keyword:`assert` |
| 729 | statement. |
| 730 | |
| 731 | .. versionadded:: 3.9 |
| 732 | |
| 733 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 734 | .. opcode:: LOAD_BUILD_CLASS |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 735 | |
Georg Brandl | 5ac2230 | 2008-07-20 21:39:03 +0000 | [diff] [blame] | 736 | Pushes :func:`builtins.__build_class__` onto the stack. It is later called |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 737 | by :opcode:`CALL_FUNCTION` to construct a class. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 738 | |
Guido van Rossum | 04110fb | 2007-08-24 16:32:05 +0000 | [diff] [blame] | 739 | |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 740 | .. opcode:: SETUP_WITH (delta) |
| 741 | |
| 742 | This opcode performs several operations before a with block starts. First, |
| 743 | it loads :meth:`~object.__exit__` from the context manager and pushes it onto |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 744 | the stack for later use by :opcode:`WITH_CLEANUP_START`. Then, |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 745 | :meth:`~object.__enter__` is called, and a finally block pointing to *delta* |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 746 | is pushed. Finally, the result of calling the ``__enter__()`` method is pushed onto |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 747 | the stack. The next opcode will either ignore it (:opcode:`POP_TOP`), or |
| 748 | store it in (a) variable(s) (:opcode:`STORE_FAST`, :opcode:`STORE_NAME`, or |
| 749 | :opcode:`UNPACK_SEQUENCE`). |
| 750 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 751 | .. versionadded:: 3.2 |
| 752 | |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 753 | |
Serhiy Storchaka | b0f80b0 | 2016-05-24 09:15:14 +0300 | [diff] [blame] | 754 | All of the following opcodes use their arguments. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 755 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 756 | .. opcode:: STORE_NAME (namei) |
| 757 | |
| 758 | Implements ``name = TOS``. *namei* is the index of *name* in the attribute |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 759 | :attr:`co_names` of the code object. The compiler tries to use |
| 760 | :opcode:`STORE_FAST` or :opcode:`STORE_GLOBAL` if possible. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 761 | |
| 762 | |
| 763 | .. opcode:: DELETE_NAME (namei) |
| 764 | |
| 765 | Implements ``del name``, where *namei* is the index into :attr:`co_names` |
| 766 | attribute of the code object. |
| 767 | |
| 768 | |
| 769 | .. opcode:: UNPACK_SEQUENCE (count) |
| 770 | |
| 771 | Unpacks TOS into *count* individual values, which are put onto the stack |
| 772 | right-to-left. |
| 773 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 774 | |
Georg Brandl | 5ac2230 | 2008-07-20 21:39:03 +0000 | [diff] [blame] | 775 | .. opcode:: UNPACK_EX (counts) |
| 776 | |
| 777 | Implements assignment with a starred target: Unpacks an iterable in TOS into |
| 778 | individual values, where the total number of values can be smaller than the |
Martin Panter | cc71a79 | 2016-04-05 06:19:42 +0000 | [diff] [blame] | 779 | number of items in the iterable: one of the new values will be a list of all |
Georg Brandl | 5ac2230 | 2008-07-20 21:39:03 +0000 | [diff] [blame] | 780 | leftover items. |
| 781 | |
| 782 | The low byte of *counts* is the number of values before the list value, the |
| 783 | high byte of *counts* the number of values after it. The resulting values |
| 784 | are put onto the stack right-to-left. |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 785 | |
Georg Brandl | 5ac2230 | 2008-07-20 21:39:03 +0000 | [diff] [blame] | 786 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 787 | .. opcode:: STORE_ATTR (namei) |
| 788 | |
| 789 | Implements ``TOS.name = TOS1``, where *namei* is the index of name in |
| 790 | :attr:`co_names`. |
| 791 | |
| 792 | |
| 793 | .. opcode:: DELETE_ATTR (namei) |
| 794 | |
| 795 | Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`. |
| 796 | |
| 797 | |
| 798 | .. opcode:: STORE_GLOBAL (namei) |
| 799 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 800 | Works as :opcode:`STORE_NAME`, but stores the name as a global. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 801 | |
| 802 | |
| 803 | .. opcode:: DELETE_GLOBAL (namei) |
| 804 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 805 | Works as :opcode:`DELETE_NAME`, but deletes a global name. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 806 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 807 | |
| 808 | .. opcode:: LOAD_CONST (consti) |
| 809 | |
| 810 | Pushes ``co_consts[consti]`` onto the stack. |
| 811 | |
| 812 | |
| 813 | .. opcode:: LOAD_NAME (namei) |
| 814 | |
| 815 | Pushes the value associated with ``co_names[namei]`` onto the stack. |
| 816 | |
| 817 | |
| 818 | .. opcode:: BUILD_TUPLE (count) |
| 819 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 820 | Creates a tuple consuming *count* items from the stack, and pushes the |
| 821 | resulting tuple onto the stack. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 822 | |
| 823 | |
| 824 | .. opcode:: BUILD_LIST (count) |
| 825 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 826 | Works as :opcode:`BUILD_TUPLE`, but creates a list. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 827 | |
| 828 | |
| 829 | .. opcode:: BUILD_SET (count) |
| 830 | |
Serhiy Storchaka | f751a9e | 2014-11-11 10:02:11 +0200 | [diff] [blame] | 831 | Works as :opcode:`BUILD_TUPLE`, but creates a set. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 832 | |
| 833 | |
Christian Heimes | a62da1d | 2008-01-12 19:39:10 +0000 | [diff] [blame] | 834 | .. opcode:: BUILD_MAP (count) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 835 | |
Ivan Levkivskyi | 0705f66 | 2017-03-03 22:46:39 +0100 | [diff] [blame] | 836 | Pushes a new dictionary object onto the stack. Pops ``2 * count`` items |
| 837 | so that the dictionary holds *count* entries: |
| 838 | ``{..., TOS3: TOS2, TOS1: TOS}``. |
| 839 | |
| 840 | .. versionchanged:: 3.5 |
| 841 | The dictionary is created from stack items instead of creating an |
| 842 | empty dictionary pre-sized to hold *count* items. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 843 | |
| 844 | |
Serhiy Storchaka | 6a7506a | 2016-06-12 00:39:41 +0300 | [diff] [blame] | 845 | .. opcode:: BUILD_CONST_KEY_MAP (count) |
| 846 | |
| 847 | The version of :opcode:`BUILD_MAP` specialized for constant keys. *count* |
| 848 | values are consumed from the stack. The top element on the stack contains |
| 849 | a tuple of keys. |
| 850 | |
| 851 | .. versionadded:: 3.6 |
| 852 | |
| 853 | |
Serhiy Storchaka | ea525a2 | 2016-09-06 22:07:53 +0300 | [diff] [blame] | 854 | .. opcode:: BUILD_STRING (count) |
| 855 | |
| 856 | Concatenates *count* strings from the stack and pushes the resulting string |
| 857 | onto the stack. |
| 858 | |
| 859 | .. versionadded:: 3.6 |
| 860 | |
| 861 | |
Ivan Levkivskyi | 0705f66 | 2017-03-03 22:46:39 +0100 | [diff] [blame] | 862 | .. opcode:: BUILD_TUPLE_UNPACK (count) |
| 863 | |
| 864 | Pops *count* iterables from the stack, joins them in a single tuple, |
| 865 | and pushes the result. Implements iterable unpacking in tuple |
| 866 | displays ``(*x, *y, *z)``. |
| 867 | |
| 868 | .. versionadded:: 3.5 |
| 869 | |
| 870 | |
Ivan Levkivskyi | 7e52c3e | 2017-03-10 23:16:44 +0100 | [diff] [blame] | 871 | .. opcode:: BUILD_TUPLE_UNPACK_WITH_CALL (count) |
| 872 | |
| 873 | This is similar to :opcode:`BUILD_TUPLE_UNPACK`, |
| 874 | but is used for ``f(*x, *y, *z)`` call syntax. The stack item at position |
| 875 | ``count + 1`` should be the corresponding callable ``f``. |
| 876 | |
| 877 | .. versionadded:: 3.6 |
| 878 | |
| 879 | |
Ivan Levkivskyi | 0705f66 | 2017-03-03 22:46:39 +0100 | [diff] [blame] | 880 | .. opcode:: BUILD_LIST_UNPACK (count) |
| 881 | |
| 882 | This is similar to :opcode:`BUILD_TUPLE_UNPACK`, but pushes a list |
| 883 | instead of tuple. Implements iterable unpacking in list |
| 884 | displays ``[*x, *y, *z]``. |
| 885 | |
| 886 | .. versionadded:: 3.5 |
| 887 | |
| 888 | |
| 889 | .. opcode:: BUILD_SET_UNPACK (count) |
| 890 | |
| 891 | This is similar to :opcode:`BUILD_TUPLE_UNPACK`, but pushes a set |
| 892 | instead of tuple. Implements iterable unpacking in set |
| 893 | displays ``{*x, *y, *z}``. |
| 894 | |
| 895 | .. versionadded:: 3.5 |
| 896 | |
| 897 | |
| 898 | .. opcode:: BUILD_MAP_UNPACK (count) |
| 899 | |
| 900 | Pops *count* mappings from the stack, merges them into a single dictionary, |
| 901 | and pushes the result. Implements dictionary unpacking in dictionary |
| 902 | displays ``{**x, **y, **z}``. |
| 903 | |
| 904 | .. versionadded:: 3.5 |
| 905 | |
| 906 | |
Ivan Levkivskyi | 7e52c3e | 2017-03-10 23:16:44 +0100 | [diff] [blame] | 907 | .. opcode:: BUILD_MAP_UNPACK_WITH_CALL (count) |
Ivan Levkivskyi | 0705f66 | 2017-03-03 22:46:39 +0100 | [diff] [blame] | 908 | |
| 909 | This is similar to :opcode:`BUILD_MAP_UNPACK`, |
Ivan Levkivskyi | 7e52c3e | 2017-03-10 23:16:44 +0100 | [diff] [blame] | 910 | but is used for ``f(**x, **y, **z)`` call syntax. The stack item at |
| 911 | position ``count + 2`` should be the corresponding callable ``f``. |
Ivan Levkivskyi | 0705f66 | 2017-03-03 22:46:39 +0100 | [diff] [blame] | 912 | |
| 913 | .. versionadded:: 3.5 |
Ivan Levkivskyi | 7e52c3e | 2017-03-10 23:16:44 +0100 | [diff] [blame] | 914 | .. versionchanged:: 3.6 |
| 915 | The position of the callable is determined by adding 2 to the opcode |
| 916 | argument instead of encoding it in the second byte of the argument. |
Ivan Levkivskyi | 0705f66 | 2017-03-03 22:46:39 +0100 | [diff] [blame] | 917 | |
| 918 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 919 | .. opcode:: LOAD_ATTR (namei) |
| 920 | |
| 921 | Replaces TOS with ``getattr(TOS, co_names[namei])``. |
| 922 | |
| 923 | |
| 924 | .. opcode:: COMPARE_OP (opname) |
| 925 | |
| 926 | Performs a Boolean operation. The operation name can be found in |
| 927 | ``cmp_op[opname]``. |
| 928 | |
| 929 | |
| 930 | .. opcode:: IMPORT_NAME (namei) |
| 931 | |
Christian Heimes | a342c01 | 2008-04-20 21:01:16 +0000 | [diff] [blame] | 932 | Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide |
| 933 | the *fromlist* and *level* arguments of :func:`__import__`. The module |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 934 | object is pushed onto the stack. The current namespace is not affected: for |
| 935 | a proper import statement, a subsequent :opcode:`STORE_FAST` instruction |
Christian Heimes | a342c01 | 2008-04-20 21:01:16 +0000 | [diff] [blame] | 936 | modifies the namespace. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 937 | |
| 938 | |
| 939 | .. opcode:: IMPORT_FROM (namei) |
| 940 | |
| 941 | Loads the attribute ``co_names[namei]`` from the module found in TOS. The |
| 942 | 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] | 943 | :opcode:`STORE_FAST` instruction. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 944 | |
| 945 | |
| 946 | .. opcode:: JUMP_FORWARD (delta) |
| 947 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 948 | Increments bytecode counter by *delta*. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 949 | |
| 950 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 951 | .. opcode:: POP_JUMP_IF_TRUE (target) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 952 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 953 | 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] | 954 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 955 | .. versionadded:: 3.1 |
| 956 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 957 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 958 | .. opcode:: POP_JUMP_IF_FALSE (target) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 959 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 960 | If TOS is false, sets the bytecode counter to *target*. TOS is popped. |
| 961 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 962 | .. versionadded:: 3.1 |
| 963 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 964 | |
| 965 | .. opcode:: JUMP_IF_TRUE_OR_POP (target) |
| 966 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 967 | If TOS is true, sets the bytecode counter to *target* and leaves TOS on the |
| 968 | stack. Otherwise (TOS is false), TOS is popped. |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 969 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 970 | .. versionadded:: 3.1 |
| 971 | |
Jeffrey Yasskin | 9de7ec7 | 2009-02-25 02:25:04 +0000 | [diff] [blame] | 972 | |
| 973 | .. opcode:: JUMP_IF_FALSE_OR_POP (target) |
| 974 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 975 | If TOS is false, sets the bytecode counter to *target* and leaves TOS on the |
| 976 | stack. Otherwise (TOS is true), TOS is popped. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 977 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 978 | .. versionadded:: 3.1 |
| 979 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 980 | |
| 981 | .. opcode:: JUMP_ABSOLUTE (target) |
| 982 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 983 | Set bytecode counter to *target*. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 984 | |
| 985 | |
| 986 | .. opcode:: FOR_ITER (delta) |
| 987 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 988 | TOS is an :term:`iterator`. Call its :meth:`~iterator.__next__` method. If |
| 989 | this yields a new value, push it on the stack (leaving the iterator below |
| 990 | it). If the iterator indicates it is exhausted TOS is popped, and the byte |
| 991 | code counter is incremented by *delta*. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 992 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 993 | |
| 994 | .. opcode:: LOAD_GLOBAL (namei) |
| 995 | |
| 996 | Loads the global named ``co_names[namei]`` onto the stack. |
| 997 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 998 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 999 | .. opcode:: SETUP_FINALLY (delta) |
| 1000 | |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 1001 | Pushes a try block from a try-finally or try-except clause onto the block |
| 1002 | stack. *delta* points to the finally block or the first except block. |
| 1003 | |
| 1004 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1005 | .. opcode:: LOAD_FAST (var_num) |
| 1006 | |
| 1007 | Pushes a reference to the local ``co_varnames[var_num]`` onto the stack. |
| 1008 | |
| 1009 | |
| 1010 | .. opcode:: STORE_FAST (var_num) |
| 1011 | |
| 1012 | Stores TOS into the local ``co_varnames[var_num]``. |
| 1013 | |
| 1014 | |
| 1015 | .. opcode:: DELETE_FAST (var_num) |
| 1016 | |
| 1017 | Deletes local ``co_varnames[var_num]``. |
| 1018 | |
| 1019 | |
| 1020 | .. opcode:: LOAD_CLOSURE (i) |
| 1021 | |
| 1022 | 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] | 1023 | variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is |
| 1024 | 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] | 1025 | len(co_cellvars)]``. |
| 1026 | |
| 1027 | |
| 1028 | .. opcode:: LOAD_DEREF (i) |
| 1029 | |
| 1030 | Loads the cell contained in slot *i* of the cell and free variable storage. |
| 1031 | Pushes a reference to the object the cell contains on the stack. |
| 1032 | |
| 1033 | |
Benjamin Peterson | 3b0431d | 2013-04-30 09:41:40 -0400 | [diff] [blame] | 1034 | .. opcode:: LOAD_CLASSDEREF (i) |
| 1035 | |
| 1036 | Much like :opcode:`LOAD_DEREF` but first checks the locals dictionary before |
| 1037 | consulting the cell. This is used for loading free variables in class |
| 1038 | bodies. |
| 1039 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 1040 | .. versionadded:: 3.4 |
| 1041 | |
Benjamin Peterson | 3b0431d | 2013-04-30 09:41:40 -0400 | [diff] [blame] | 1042 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1043 | .. opcode:: STORE_DEREF (i) |
| 1044 | |
| 1045 | Stores TOS into the cell contained in slot *i* of the cell and free variable |
| 1046 | storage. |
| 1047 | |
| 1048 | |
Amaury Forgeot d'Arc | ba117ef | 2010-09-10 21:39:53 +0000 | [diff] [blame] | 1049 | .. opcode:: DELETE_DEREF (i) |
| 1050 | |
| 1051 | Empties the cell contained in slot *i* of the cell and free variable storage. |
| 1052 | Used by the :keyword:`del` statement. |
| 1053 | |
Serhiy Storchaka | 12e7cd8 | 2018-02-01 13:48:33 +0200 | [diff] [blame] | 1054 | .. versionadded:: 3.2 |
| 1055 | |
Amaury Forgeot d'Arc | ba117ef | 2010-09-10 21:39:53 +0000 | [diff] [blame] | 1056 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1057 | .. opcode:: RAISE_VARARGS (argc) |
| 1058 | |
Michele Angrisano | e1179a5 | 2019-06-02 23:34:12 +0200 | [diff] [blame] | 1059 | Raises an exception using one of the 3 forms of the ``raise`` statement, |
| 1060 | depending on the value of *argc*: |
| 1061 | |
| 1062 | * 0: ``raise`` (re-raise previous exception) |
| 1063 | * 1: ``raise TOS`` (raise exception instance or type at ``TOS``) |
| 1064 | * 2: ``raise TOS1 from TOS`` (raise exception instance or type at ``TOS1`` |
| 1065 | with ``__cause__`` set to ``TOS``) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1066 | |
| 1067 | |
| 1068 | .. opcode:: CALL_FUNCTION (argc) |
| 1069 | |
Serhiy Storchaka | 5e99b56 | 2018-09-17 15:15:03 +0300 | [diff] [blame] | 1070 | Calls a callable object with positional arguments. |
| 1071 | *argc* indicates the number of positional arguments. |
| 1072 | The top of the stack contains positional arguments, with the right-most |
| 1073 | argument on top. Below the arguments is a callable object to call. |
| 1074 | ``CALL_FUNCTION`` pops all arguments and the callable object off the stack, |
| 1075 | calls the callable object with those arguments, and pushes the return value |
| 1076 | returned by the callable object. |
Ivan Levkivskyi | 4b2a2a4 | 2017-03-10 23:52:35 +0100 | [diff] [blame] | 1077 | |
| 1078 | .. versionchanged:: 3.6 |
| 1079 | This opcode is used only for calls with positional arguments. |
| 1080 | |
| 1081 | |
| 1082 | .. opcode:: CALL_FUNCTION_KW (argc) |
| 1083 | |
Serhiy Storchaka | 5e99b56 | 2018-09-17 15:15:03 +0300 | [diff] [blame] | 1084 | Calls a callable object with positional (if any) and keyword arguments. |
| 1085 | *argc* indicates the total number of positional and keyword arguments. |
Jeroen Demeyer | 0567786 | 2019-08-16 12:41:27 +0200 | [diff] [blame] | 1086 | The top element on the stack contains a tuple with the names of the |
| 1087 | keyword arguments, which must be strings. |
| 1088 | Below that are the values for the keyword arguments, |
| 1089 | in the order corresponding to the tuple. |
Serhiy Storchaka | 5e99b56 | 2018-09-17 15:15:03 +0300 | [diff] [blame] | 1090 | Below that are positional arguments, with the right-most parameter on |
| 1091 | top. Below the arguments is a callable object to call. |
| 1092 | ``CALL_FUNCTION_KW`` pops all arguments and the callable object off the stack, |
| 1093 | calls the callable object with those arguments, and pushes the return value |
| 1094 | returned by the callable object. |
Ivan Levkivskyi | 4b2a2a4 | 2017-03-10 23:52:35 +0100 | [diff] [blame] | 1095 | |
| 1096 | .. versionchanged:: 3.6 |
| 1097 | Keyword arguments are packed in a tuple instead of a dictionary, |
Serhiy Storchaka | 5e99b56 | 2018-09-17 15:15:03 +0300 | [diff] [blame] | 1098 | *argc* indicates the total number of arguments. |
Ivan Levkivskyi | 4b2a2a4 | 2017-03-10 23:52:35 +0100 | [diff] [blame] | 1099 | |
| 1100 | |
| 1101 | .. opcode:: CALL_FUNCTION_EX (flags) |
| 1102 | |
Serhiy Storchaka | 5e99b56 | 2018-09-17 15:15:03 +0300 | [diff] [blame] | 1103 | Calls a callable object with variable set of positional and keyword |
| 1104 | arguments. If the lowest bit of *flags* is set, the top of the stack |
| 1105 | contains a mapping object containing additional keyword arguments. |
| 1106 | Below that is an iterable object containing positional arguments and |
| 1107 | a callable object to call. :opcode:`BUILD_MAP_UNPACK_WITH_CALL` and |
| 1108 | :opcode:`BUILD_TUPLE_UNPACK_WITH_CALL` can be used for merging multiple |
| 1109 | mapping objects and iterables containing arguments. |
| 1110 | Before the callable is called, the mapping object and iterable object |
| 1111 | are each "unpacked" and their contents passed in as keyword and |
| 1112 | positional arguments respectively. |
| 1113 | ``CALL_FUNCTION_EX`` pops all arguments and the callable object off the stack, |
| 1114 | calls the callable object with those arguments, and pushes the return value |
| 1115 | returned by the callable object. |
Ivan Levkivskyi | 4b2a2a4 | 2017-03-10 23:52:35 +0100 | [diff] [blame] | 1116 | |
| 1117 | .. versionadded:: 3.6 |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1118 | |
| 1119 | |
INADA Naoki | 015bce6 | 2017-01-16 17:23:30 +0900 | [diff] [blame] | 1120 | .. opcode:: LOAD_METHOD (namei) |
| 1121 | |
| 1122 | Loads a method named ``co_names[namei]`` from TOS object. TOS is popped and |
| 1123 | method and TOS are pushed when interpreter can call unbound method directly. |
Ivan Levkivskyi | 4b2a2a4 | 2017-03-10 23:52:35 +0100 | [diff] [blame] | 1124 | TOS will be used as the first argument (``self``) by :opcode:`CALL_METHOD`. |
INADA Naoki | 015bce6 | 2017-01-16 17:23:30 +0900 | [diff] [blame] | 1125 | Otherwise, ``NULL`` and method is pushed (method is bound method or |
| 1126 | something else). |
| 1127 | |
| 1128 | .. versionadded:: 3.7 |
| 1129 | |
| 1130 | |
| 1131 | .. opcode:: CALL_METHOD (argc) |
| 1132 | |
| 1133 | Calls a method. *argc* is number of positional arguments. |
| 1134 | Keyword arguments are not supported. This opcode is designed to be used |
| 1135 | with :opcode:`LOAD_METHOD`. Positional arguments are on top of the stack. |
| 1136 | Below them, two items described in :opcode:`LOAD_METHOD` on the stack. |
| 1137 | All of them are popped and return value is pushed. |
| 1138 | |
| 1139 | .. versionadded:: 3.7 |
| 1140 | |
| 1141 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1142 | .. opcode:: MAKE_FUNCTION (argc) |
| 1143 | |
Georg Brandl | c96ef1f | 2013-10-12 18:41:18 +0200 | [diff] [blame] | 1144 | Pushes a new function object on the stack. From bottom to top, the consumed |
Serhiy Storchaka | 64204de | 2016-06-12 17:36:24 +0300 | [diff] [blame] | 1145 | stack must consist of values if the argument carries a specified flag value |
Georg Brandl | c96ef1f | 2013-10-12 18:41:18 +0200 | [diff] [blame] | 1146 | |
Serhiy Storchaka | 5e99b56 | 2018-09-17 15:15:03 +0300 | [diff] [blame] | 1147 | * ``0x01`` a tuple of default values for positional-only and |
| 1148 | positional-or-keyword parameters in positional order |
Serhiy Storchaka | 64204de | 2016-06-12 17:36:24 +0300 | [diff] [blame] | 1149 | * ``0x02`` a dictionary of keyword-only parameters' default values |
| 1150 | * ``0x04`` an annotation dictionary |
| 1151 | * ``0x08`` a tuple containing cells for free variables, making a closure |
Georg Brandl | c96ef1f | 2013-10-12 18:41:18 +0200 | [diff] [blame] | 1152 | * the code associated with the function (at TOS1) |
| 1153 | * the :term:`qualified name` of the function (at TOS) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1154 | |
| 1155 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1156 | .. opcode:: BUILD_SLICE (argc) |
| 1157 | |
| 1158 | .. index:: builtin: slice |
| 1159 | |
| 1160 | Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2, |
| 1161 | ``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] | 1162 | pushed. See the :func:`slice` built-in function for more information. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1163 | |
| 1164 | |
| 1165 | .. opcode:: EXTENDED_ARG (ext) |
| 1166 | |
Yao Zuo | 405f648 | 2019-06-11 20:46:09 -0700 | [diff] [blame] | 1167 | Prefixes any opcode which has an argument too big to fit into the default one |
| 1168 | byte. *ext* holds an additional byte which act as higher bits in the argument. |
| 1169 | For each opcode, at most three prefixal ``EXTENDED_ARG`` are allowed, forming |
| 1170 | an argument from two-byte to four-byte. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1171 | |
| 1172 | |
Eric V. Smith | 281d532 | 2015-11-03 13:09:01 -0500 | [diff] [blame] | 1173 | .. opcode:: FORMAT_VALUE (flags) |
| 1174 | |
| 1175 | Used for implementing formatted literal strings (f-strings). Pops |
| 1176 | an optional *fmt_spec* from the stack, then a required *value*. |
| 1177 | *flags* is interpreted as follows: |
| 1178 | |
Eric V. Smith | 9ce52e3 | 2015-11-03 16:30:49 -0500 | [diff] [blame] | 1179 | * ``(flags & 0x03) == 0x00``: *value* is formatted as-is. |
Eric V. Smith | 281d532 | 2015-11-03 13:09:01 -0500 | [diff] [blame] | 1180 | * ``(flags & 0x03) == 0x01``: call :func:`str` on *value* before |
| 1181 | formatting it. |
| 1182 | * ``(flags & 0x03) == 0x02``: call :func:`repr` on *value* before |
| 1183 | formatting it. |
| 1184 | * ``(flags & 0x03) == 0x03``: call :func:`ascii` on *value* before |
| 1185 | formatting it. |
| 1186 | * ``(flags & 0x04) == 0x04``: pop *fmt_spec* from the stack and use |
| 1187 | it, else use an empty *fmt_spec*. |
| 1188 | |
Eric V. Smith | a3a3d73 | 2015-11-04 07:11:13 -0500 | [diff] [blame] | 1189 | Formatting is performed using :c:func:`PyObject_Format`. The |
| 1190 | result is pushed on the stack. |
Eric V. Smith | 281d532 | 2015-11-03 13:09:01 -0500 | [diff] [blame] | 1191 | |
Eric V. Smith | 9ce52e3 | 2015-11-03 16:30:49 -0500 | [diff] [blame] | 1192 | .. versionadded:: 3.6 |
| 1193 | |
Eric V. Smith | 281d532 | 2015-11-03 13:09:01 -0500 | [diff] [blame] | 1194 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 1195 | .. opcode:: HAVE_ARGUMENT |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1196 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 1197 | This is not really an opcode. It identifies the dividing line between |
Ivan Levkivskyi | 8f9e1bbf | 2017-03-24 22:05:04 +0100 | [diff] [blame] | 1198 | opcodes which don't use their argument and those that do |
| 1199 | (``< HAVE_ARGUMENT`` and ``>= HAVE_ARGUMENT``, respectively). |
| 1200 | |
| 1201 | .. versionchanged:: 3.6 |
| 1202 | Now every instruction has an argument, but opcodes ``< HAVE_ARGUMENT`` |
| 1203 | ignore it. Before, only opcodes ``>= HAVE_ARGUMENT`` had an argument. |
| 1204 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1205 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 1206 | .. _opcode_collections: |
| 1207 | |
| 1208 | Opcode collections |
| 1209 | ------------------ |
| 1210 | |
| 1211 | These collections are provided for automatic introspection of bytecode |
| 1212 | instructions: |
| 1213 | |
| 1214 | .. data:: opname |
| 1215 | |
| 1216 | Sequence of operation names, indexable using the bytecode. |
| 1217 | |
| 1218 | |
| 1219 | .. data:: opmap |
| 1220 | |
| 1221 | Dictionary mapping operation names to bytecodes. |
| 1222 | |
| 1223 | |
| 1224 | .. data:: cmp_op |
| 1225 | |
| 1226 | Sequence of all compare operation names. |
| 1227 | |
| 1228 | |
| 1229 | .. data:: hasconst |
| 1230 | |
Serhiy Storchaka | 5e99b56 | 2018-09-17 15:15:03 +0300 | [diff] [blame] | 1231 | Sequence of bytecodes that access a constant. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 1232 | |
| 1233 | |
| 1234 | .. data:: hasfree |
| 1235 | |
Benjamin Peterson | bdf525b | 2015-03-02 09:31:40 -0500 | [diff] [blame] | 1236 | Sequence of bytecodes that access a free variable (note that 'free' in this |
| 1237 | context refers to names in the current scope that are referenced by inner |
| 1238 | scopes or names in outer scopes that are referenced from this scope. It does |
| 1239 | *not* include references to global or builtin scopes). |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 1240 | |
| 1241 | |
| 1242 | .. data:: hasname |
| 1243 | |
| 1244 | Sequence of bytecodes that access an attribute by name. |
| 1245 | |
| 1246 | |
| 1247 | .. data:: hasjrel |
| 1248 | |
| 1249 | Sequence of bytecodes that have a relative jump target. |
| 1250 | |
| 1251 | |
| 1252 | .. data:: hasjabs |
| 1253 | |
| 1254 | Sequence of bytecodes that have an absolute jump target. |
| 1255 | |
| 1256 | |
| 1257 | .. data:: haslocal |
| 1258 | |
| 1259 | Sequence of bytecodes that access a local variable. |
| 1260 | |
| 1261 | |
| 1262 | .. data:: hascompare |
| 1263 | |
| 1264 | Sequence of bytecodes of Boolean operations. |