blob: c21a667ba17112a4521e59310f696d2580de18f0 [file] [log] [blame]
Georg Brandl9afde1c2007-11-01 20:32:30 +00001:mod:`dis` --- Disassembler for Python bytecode
2===============================================
Georg Brandl116aa622007-08-15 14:28:22 +00003
4.. module:: dis
Georg Brandl9afde1c2007-11-01 20:32:30 +00005 :synopsis: Disassembler for Python bytecode.
Georg Brandl116aa622007-08-15 14:28:22 +00006
Raymond Hettinger10480942011-01-10 03:26:08 +00007**Source code:** :source:`Lib/dis.py`
Georg Brandl116aa622007-08-15 14:28:22 +00008
Raymond Hettinger4f707fd2011-01-10 19:54:11 +00009--------------
10
Brett Cannon8315fd12010-07-02 22:03:00 +000011The :mod:`dis` module supports the analysis of CPython :term:`bytecode` by
Benjamin Petersonbdf525b2015-03-02 09:31:40 -050012disassembling it. The CPython bytecode which this module takes as an input is
13defined in the file :file:`Include/opcode.h` and used by the compiler and the
14interpreter.
Georg Brandl116aa622007-08-15 14:28:22 +000015
Georg Brandl19b7a872010-07-03 10:21:50 +000016.. impl-detail::
17
Raymond Hettinger10480942011-01-10 03:26:08 +000018 Bytecode is an implementation detail of the CPython interpreter. No
Georg Brandl19b7a872010-07-03 10:21:50 +000019 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 Levkivskyi8f9e1bbf2017-03-24 22:05:04 +010023 .. versionchanged:: 3.6
24 Use 2 bytes for each instruction. Previously the number of bytes varied
25 by instruction.
26
Brett Cannon8315fd12010-07-02 22:03:00 +000027
Georg Brandl116aa622007-08-15 14:28:22 +000028Example: Given the function :func:`myfunc`::
29
30 def myfunc(alist):
31 return len(alist)
32
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100033the following command can be used to display the disassembly of
34:func:`myfunc`::
Georg Brandl116aa622007-08-15 14:28:22 +000035
36 >>> dis.dis(myfunc)
37 2 0 LOAD_GLOBAL 0 (len)
Serhiy Storchakab0f80b02016-05-24 09:15:14 +030038 2 LOAD_FAST 0 (alist)
39 4 CALL_FUNCTION 1
40 6 RETURN_VALUE
Georg Brandl116aa622007-08-15 14:28:22 +000041
42(The "2" is a line number).
43
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100044Bytecode analysis
45-----------------
Georg Brandl116aa622007-08-15 14:28:22 +000046
R David Murray0bce6e72014-01-07 14:30:17 -050047.. versionadded:: 3.4
48
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100049The bytecode analysis API allows pieces of Python code to be wrapped in a
Benjamin Petersonbdf525b2015-03-02 09:31:40 -050050:class:`Bytecode` object that provides easy access to details of the compiled
51code.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100052
Nick Coghlan50c48b82013-11-23 00:57:00 +100053.. class:: Bytecode(x, *, first_line=None, current_offset=None)
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100054
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100055
syncosmicfe2b56a2017-08-17 19:29:21 -070056 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 Coghlanb39fd0c2013-05-06 23:59:20 +100059
Benjamin Petersonbdf525b2015-03-02 09:31:40 -050060 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 Coghlanb39fd0c2013-05-06 23:59:20 +100063
Serhiy Storchakaecf41da2016-10-19 16:29:26 +030064 If *first_line* is not ``None``, it indicates the line number that should be
Benjamin Petersonbdf525b2015-03-02 09:31:40 -050065 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 Coghlanb39fd0c2013-05-06 23:59:20 +100068
Serhiy Storchakaecf41da2016-10-19 16:29:26 +030069 If *current_offset* is not ``None``, it refers to an instruction offset in the
Benjamin Petersonbdf525b2015-03-02 09:31:40 -050070 disassembled code. Setting this means :meth:`.dis` will display a "current
71 instruction" marker against the specified opcode.
Nick Coghlan50c48b82013-11-23 00:57:00 +100072
73 .. classmethod:: from_traceback(tb)
74
Benjamin Petersonbdf525b2015-03-02 09:31:40 -050075 Construct a :class:`Bytecode` instance from the given traceback, setting
76 *current_offset* to the instruction responsible for the exception.
Nick Coghlan50c48b82013-11-23 00:57:00 +100077
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100078 .. data:: codeobj
79
80 The compiled code object.
81
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100082 .. data:: first_line
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100083
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100084 The first source line of the code object (if available)
85
86 .. method:: dis()
87
Benjamin Peterson29fec922015-03-02 09:27:43 -050088 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 Coghlanb39fd0c2013-05-06 23:59:20 +100090
91 .. method:: info()
92
93 Return a formatted multi-line string with detailed information about the
94 code object, like :func:`code_info`.
95
syncosmicfe2b56a2017-08-17 19:29:21 -070096 .. versionchanged:: 3.7
97 This can now handle coroutine and asynchronous generator objects.
98
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100099Example::
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
111Analysis functions
112------------------
113
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500114The :mod:`dis` module also defines the following analysis functions that convert
115the input directly to the desired output. They can be useful if only a single
116operation is being performed, so the intermediate analysis object isn't useful:
Georg Brandl116aa622007-08-15 14:28:22 +0000117
Nick Coghlane8814fb2010-09-10 14:08:04 +0000118.. function:: code_info(x)
Nick Coghlaneae2da12010-08-17 08:03:36 +0000119
Georg Brandl67b21b72010-08-17 15:07:14 +0000120 Return a formatted multi-line string with detailed code object information
syncosmicfe2b56a2017-08-17 19:29:21 -0700121 for the supplied function, generator, asynchronous generator, coroutine,
122 method, source code string or code object.
Nick Coghlaneae2da12010-08-17 08:03:36 +0000123
Georg Brandl67b21b72010-08-17 15:07:14 +0000124 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 Coghlaneae2da12010-08-17 08:03:36 +0000127
128 .. versionadded:: 3.2
129
syncosmicfe2b56a2017-08-17 19:29:21 -0700130 .. versionchanged:: 3.7
131 This can now handle coroutine and asynchronous generator objects.
132
Georg Brandl67b21b72010-08-17 15:07:14 +0000133
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000134.. function:: show_code(x, *, file=None)
Nick Coghlane8814fb2010-09-10 14:08:04 +0000135
136 Print detailed code object information for the supplied function, method,
Ezio Melotti6e6c6ac2013-08-23 22:41:39 +0300137 source code string or code object to *file* (or ``sys.stdout`` if *file*
138 is not specified).
Nick Coghlane8814fb2010-09-10 14:08:04 +0000139
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000140 This is a convenient shorthand for ``print(code_info(x), file=file)``,
141 intended for interactive exploration at the interpreter prompt.
Nick Coghlane8814fb2010-09-10 14:08:04 +0000142
143 .. versionadded:: 3.2
144
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000145 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200146 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000147
148
Serhiy Storchaka1efbf922017-06-11 14:09:39 +0300149.. function:: dis(x=None, *, file=None, depth=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000150
Georg Brandl67b21b72010-08-17 15:07:14 +0000151 Disassemble the *x* object. *x* can denote either a module, a class, a
Stéphane Wirtel07fbbfd2018-10-05 16:17:18 +0200152 method, a function, a generator, an asynchronous generator, a coroutine,
syncosmicfe2b56a2017-08-17 19:29:21 -0700153 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 Storchaka1efbf922017-06-11 14:09:39 +0300159 used for building nested classes).
160 Strings are first compiled to code objects with the :func:`compile`
Serhiy Storchaka585c93d2016-04-23 09:23:52 +0300161 built-in function before being disassembled. If no object is provided, this
162 function disassembles the last traceback.
Georg Brandl116aa622007-08-15 14:28:22 +0000163
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200164 The disassembly is written as text to the supplied *file* argument if
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000165 provided and to ``sys.stdout`` otherwise.
Georg Brandl116aa622007-08-15 14:28:22 +0000166
Serhiy Storchaka1efbf922017-06-11 14:09:39 +0300167 The maximal depth of recursion is limited by *depth* unless it is ``None``.
168 ``depth=0`` means no recursion.
169
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000170 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200171 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000172
Serhiy Storchaka1efbf922017-06-11 14:09:39 +0300173 .. versionchanged:: 3.7
174 Implemented recursive disassembling and added *depth* parameter.
175
syncosmicfe2b56a2017-08-17 19:29:21 -0700176 .. versionchanged:: 3.7
177 This can now handle coroutine and asynchronous generator objects.
178
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000179
180.. function:: distb(tb=None, *, file=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000181
Georg Brandl4833e5b2010-07-03 10:41:33 +0000182 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 Brandl116aa622007-08-15 14:28:22 +0000185
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200186 The disassembly is written as text to the supplied *file* argument if
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000187 provided and to ``sys.stdout`` otherwise.
Georg Brandl116aa622007-08-15 14:28:22 +0000188
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000189 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200190 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000191
192
193.. function:: disassemble(code, lasti=-1, *, file=None)
194 disco(code, lasti=-1, *, file=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000195
Georg Brandl4833e5b2010-07-03 10:41:33 +0000196 Disassemble a code object, indicating the last instruction if *lasti* was
Georg Brandl116aa622007-08-15 14:28:22 +0000197 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 Storchakaf751a9e2014-11-11 10:02:11 +0200210 The disassembly is written as text to the supplied *file* argument if
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000211 provided and to ``sys.stdout`` otherwise.
212
213 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200214 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000215
216
Nick Coghlan90b8e7d2013-11-06 22:08:36 +1000217.. function:: get_instructions(x, *, first_line=None)
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000218
219 Return an iterator over the instructions in the supplied function, method,
220 source code string or code object.
221
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500222 The iterator generates a series of :class:`Instruction` named tuples giving
223 the details of each operation in the supplied code.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000224
Serhiy Storchakaecf41da2016-10-19 16:29:26 +0300225 If *first_line* is not ``None``, it indicates the line number that should be
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500226 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 Coghlanb39fd0c2013-05-06 23:59:20 +1000229
230 .. versionadded:: 3.4
231
Georg Brandl116aa622007-08-15 14:28:22 +0000232
Benjamin Peterson75edad02009-01-01 15:05:06 +0000233.. 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 Levkivskyi8f9e1bbf2017-03-24 22:05:04 +0100238 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 Peterson75edad02009-01-01 15:05:06 +0000243
244
245.. function:: findlabels(code)
246
laike9mb74468e2020-04-03 01:00:28 -0700247 Detect all offsets in the raw compiled bytecode string *code* which are jump targets, and
Benjamin Peterson75edad02009-01-01 15:05:06 +0000248 return a list of these offsets.
Georg Brandl48310cd2009-01-03 21:18:54 +0000249
Larry Hastings3a907972013-11-23 14:49:22 -0800250
Serhiy Storchaka7bdf2822018-09-18 09:54:26 +0300251.. function:: stack_effect(opcode, oparg=None, *, jump=None)
Larry Hastings3a907972013-11-23 14:49:22 -0800252
253 Compute the stack effect of *opcode* with argument *oparg*.
254
Serhiy Storchaka7bdf2822018-09-18 09:54:26 +0300255 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 Hastings3a907972013-11-23 14:49:22 -0800260 .. versionadded:: 3.4
261
Serhiy Storchaka7bdf2822018-09-18 09:54:26 +0300262 .. versionchanged:: 3.8
263 Added *jump* parameter.
264
265
Georg Brandl116aa622007-08-15 14:28:22 +0000266.. _bytecodes:
267
Georg Brandl9afde1c2007-11-01 20:32:30 +0000268Python Bytecode Instructions
269----------------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000270
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000271The :func:`get_instructions` function and :class:`Bytecode` class provide
272details 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 Storchakaecf41da2016-10-19 16:29:26 +0300291 numeric argument to operation (if any), otherwise ``None``
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000292
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 Storchakaecf41da2016-10-19 16:29:26 +0300311 line started by this opcode (if any), otherwise ``None``
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000312
313
314 .. data:: is_jump_target
315
Serhiy Storchaka0e90e992013-11-29 12:19:53 +0200316 ``True`` if other code jumps to here, otherwise ``False``
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000317
318 .. versionadded:: 3.4
319
320
Georg Brandl9afde1c2007-11-01 20:32:30 +0000321The Python compiler currently generates the following bytecode instructions.
Georg Brandl116aa622007-08-15 14:28:22 +0000322
323
Georg Brandl4833e5b2010-07-03 10:41:33 +0000324**General instructions**
325
Georg Brandl4833e5b2010-07-03 10:41:33 +0000326.. opcode:: NOP
Georg Brandl116aa622007-08-15 14:28:22 +0000327
328 Do nothing code. Used as a placeholder by the bytecode optimizer.
329
330
Georg Brandl4833e5b2010-07-03 10:41:33 +0000331.. opcode:: POP_TOP
Georg Brandl116aa622007-08-15 14:28:22 +0000332
333 Removes the top-of-stack (TOS) item.
334
335
Georg Brandl4833e5b2010-07-03 10:41:33 +0000336.. opcode:: ROT_TWO
Georg Brandl116aa622007-08-15 14:28:22 +0000337
338 Swaps the two top-most stack items.
339
340
Georg Brandl4833e5b2010-07-03 10:41:33 +0000341.. opcode:: ROT_THREE
Georg Brandl116aa622007-08-15 14:28:22 +0000342
343 Lifts second and third stack item one position up, moves top down to position
344 three.
345
346
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200347.. opcode:: ROT_FOUR
348
Irit Katriel292f2312021-02-20 04:22:37 +0000349 Lifts second, third and fourth stack items one position up, moves top down
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200350 to position four.
351
352 .. versionadded:: 3.8
353
354
Georg Brandl4833e5b2010-07-03 10:41:33 +0000355.. opcode:: DUP_TOP
Georg Brandl116aa622007-08-15 14:28:22 +0000356
357 Duplicates the reference on top of the stack.
358
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200359 .. versionadded:: 3.2
360
Georg Brandl4833e5b2010-07-03 10:41:33 +0000361
Antoine Pitrou74a69fa2010-09-04 18:43:52 +0000362.. opcode:: DUP_TOP_TWO
363
364 Duplicates the two references on top of the stack, leaving them in the
365 same order.
366
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200367 .. versionadded:: 3.2
368
Antoine Pitrou74a69fa2010-09-04 18:43:52 +0000369
Georg Brandl4833e5b2010-07-03 10:41:33 +0000370**Unary operations**
371
372Unary operations take the top of the stack, apply the operation, and push the
Georg Brandl116aa622007-08-15 14:28:22 +0000373result back on the stack.
374
Georg Brandl4833e5b2010-07-03 10:41:33 +0000375.. opcode:: UNARY_POSITIVE
Georg Brandl116aa622007-08-15 14:28:22 +0000376
377 Implements ``TOS = +TOS``.
378
379
Georg Brandl4833e5b2010-07-03 10:41:33 +0000380.. opcode:: UNARY_NEGATIVE
Georg Brandl116aa622007-08-15 14:28:22 +0000381
382 Implements ``TOS = -TOS``.
383
384
Georg Brandl4833e5b2010-07-03 10:41:33 +0000385.. opcode:: UNARY_NOT
Georg Brandl116aa622007-08-15 14:28:22 +0000386
387 Implements ``TOS = not TOS``.
388
389
Georg Brandl4833e5b2010-07-03 10:41:33 +0000390.. opcode:: UNARY_INVERT
Georg Brandl116aa622007-08-15 14:28:22 +0000391
392 Implements ``TOS = ~TOS``.
393
394
Georg Brandl4833e5b2010-07-03 10:41:33 +0000395.. opcode:: GET_ITER
Georg Brandl116aa622007-08-15 14:28:22 +0000396
397 Implements ``TOS = iter(TOS)``.
398
Georg Brandl4833e5b2010-07-03 10:41:33 +0000399
Yury Selivanov5376ba92015-06-22 12:19:30 -0400400.. 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 Brandl4833e5b2010-07-03 10:41:33 +0000408**Binary operations**
409
Georg Brandl116aa622007-08-15 14:28:22 +0000410Binary operations remove the top of the stack (TOS) and the second top-most
411stack item (TOS1) from the stack. They perform the operation, and put the
412result back on the stack.
413
Georg Brandl4833e5b2010-07-03 10:41:33 +0000414.. opcode:: BINARY_POWER
Georg Brandl116aa622007-08-15 14:28:22 +0000415
416 Implements ``TOS = TOS1 ** TOS``.
417
418
Georg Brandl4833e5b2010-07-03 10:41:33 +0000419.. opcode:: BINARY_MULTIPLY
Georg Brandl116aa622007-08-15 14:28:22 +0000420
421 Implements ``TOS = TOS1 * TOS``.
422
423
Benjamin Petersond51374e2014-04-09 23:55:56 -0400424.. opcode:: BINARY_MATRIX_MULTIPLY
425
426 Implements ``TOS = TOS1 @ TOS``.
427
Berker Peksagda0870c2015-03-12 20:56:45 +0200428 .. versionadded:: 3.5
429
Benjamin Petersond51374e2014-04-09 23:55:56 -0400430
Georg Brandl4833e5b2010-07-03 10:41:33 +0000431.. opcode:: BINARY_FLOOR_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000432
433 Implements ``TOS = TOS1 // TOS``.
434
435
Georg Brandl4833e5b2010-07-03 10:41:33 +0000436.. opcode:: BINARY_TRUE_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000437
Ezio Melotti7de0a6e2010-01-05 08:37:27 +0000438 Implements ``TOS = TOS1 / TOS``.
Georg Brandl116aa622007-08-15 14:28:22 +0000439
440
Georg Brandl4833e5b2010-07-03 10:41:33 +0000441.. opcode:: BINARY_MODULO
Georg Brandl116aa622007-08-15 14:28:22 +0000442
443 Implements ``TOS = TOS1 % TOS``.
444
445
Georg Brandl4833e5b2010-07-03 10:41:33 +0000446.. opcode:: BINARY_ADD
Georg Brandl116aa622007-08-15 14:28:22 +0000447
448 Implements ``TOS = TOS1 + TOS``.
449
450
Georg Brandl4833e5b2010-07-03 10:41:33 +0000451.. opcode:: BINARY_SUBTRACT
Georg Brandl116aa622007-08-15 14:28:22 +0000452
453 Implements ``TOS = TOS1 - TOS``.
454
455
Georg Brandl4833e5b2010-07-03 10:41:33 +0000456.. opcode:: BINARY_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000457
458 Implements ``TOS = TOS1[TOS]``.
459
460
Georg Brandl4833e5b2010-07-03 10:41:33 +0000461.. opcode:: BINARY_LSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000462
463 Implements ``TOS = TOS1 << TOS``.
464
465
Georg Brandl4833e5b2010-07-03 10:41:33 +0000466.. opcode:: BINARY_RSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000467
468 Implements ``TOS = TOS1 >> TOS``.
469
470
Georg Brandl4833e5b2010-07-03 10:41:33 +0000471.. opcode:: BINARY_AND
Georg Brandl116aa622007-08-15 14:28:22 +0000472
473 Implements ``TOS = TOS1 & TOS``.
474
475
Georg Brandl4833e5b2010-07-03 10:41:33 +0000476.. opcode:: BINARY_XOR
Georg Brandl116aa622007-08-15 14:28:22 +0000477
478 Implements ``TOS = TOS1 ^ TOS``.
479
480
Georg Brandl4833e5b2010-07-03 10:41:33 +0000481.. opcode:: BINARY_OR
Georg Brandl116aa622007-08-15 14:28:22 +0000482
483 Implements ``TOS = TOS1 | TOS``.
484
Georg Brandl4833e5b2010-07-03 10:41:33 +0000485
486**In-place operations**
487
Georg Brandl116aa622007-08-15 14:28:22 +0000488In-place operations are like binary operations, in that they remove TOS and
489TOS1, and push the result back on the stack, but the operation is done in-place
490when TOS1 supports it, and the resulting TOS may be (but does not have to be)
491the original TOS1.
492
Georg Brandl4833e5b2010-07-03 10:41:33 +0000493.. opcode:: INPLACE_POWER
Georg Brandl116aa622007-08-15 14:28:22 +0000494
495 Implements in-place ``TOS = TOS1 ** TOS``.
496
497
Georg Brandl4833e5b2010-07-03 10:41:33 +0000498.. opcode:: INPLACE_MULTIPLY
Georg Brandl116aa622007-08-15 14:28:22 +0000499
500 Implements in-place ``TOS = TOS1 * TOS``.
501
502
Benjamin Petersond51374e2014-04-09 23:55:56 -0400503.. opcode:: INPLACE_MATRIX_MULTIPLY
504
505 Implements in-place ``TOS = TOS1 @ TOS``.
506
Berker Peksagda0870c2015-03-12 20:56:45 +0200507 .. versionadded:: 3.5
508
Benjamin Petersond51374e2014-04-09 23:55:56 -0400509
Georg Brandl4833e5b2010-07-03 10:41:33 +0000510.. opcode:: INPLACE_FLOOR_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000511
512 Implements in-place ``TOS = TOS1 // TOS``.
513
514
Georg Brandl4833e5b2010-07-03 10:41:33 +0000515.. opcode:: INPLACE_TRUE_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000516
Ezio Melotti7de0a6e2010-01-05 08:37:27 +0000517 Implements in-place ``TOS = TOS1 / TOS``.
Georg Brandl116aa622007-08-15 14:28:22 +0000518
519
Georg Brandl4833e5b2010-07-03 10:41:33 +0000520.. opcode:: INPLACE_MODULO
Georg Brandl116aa622007-08-15 14:28:22 +0000521
522 Implements in-place ``TOS = TOS1 % TOS``.
523
524
Georg Brandl4833e5b2010-07-03 10:41:33 +0000525.. opcode:: INPLACE_ADD
Georg Brandl116aa622007-08-15 14:28:22 +0000526
527 Implements in-place ``TOS = TOS1 + TOS``.
528
529
Georg Brandl4833e5b2010-07-03 10:41:33 +0000530.. opcode:: INPLACE_SUBTRACT
Georg Brandl116aa622007-08-15 14:28:22 +0000531
532 Implements in-place ``TOS = TOS1 - TOS``.
533
534
Georg Brandl4833e5b2010-07-03 10:41:33 +0000535.. opcode:: INPLACE_LSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000536
537 Implements in-place ``TOS = TOS1 << TOS``.
538
539
Georg Brandl4833e5b2010-07-03 10:41:33 +0000540.. opcode:: INPLACE_RSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000541
542 Implements in-place ``TOS = TOS1 >> TOS``.
543
544
Georg Brandl4833e5b2010-07-03 10:41:33 +0000545.. opcode:: INPLACE_AND
Georg Brandl116aa622007-08-15 14:28:22 +0000546
547 Implements in-place ``TOS = TOS1 & TOS``.
548
549
Georg Brandl4833e5b2010-07-03 10:41:33 +0000550.. opcode:: INPLACE_XOR
Georg Brandl116aa622007-08-15 14:28:22 +0000551
552 Implements in-place ``TOS = TOS1 ^ TOS``.
553
554
Georg Brandl4833e5b2010-07-03 10:41:33 +0000555.. opcode:: INPLACE_OR
Georg Brandl116aa622007-08-15 14:28:22 +0000556
557 Implements in-place ``TOS = TOS1 | TOS``.
558
Georg Brandl116aa622007-08-15 14:28:22 +0000559
Georg Brandl4833e5b2010-07-03 10:41:33 +0000560.. opcode:: STORE_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000561
562 Implements ``TOS1[TOS] = TOS2``.
563
564
Georg Brandl4833e5b2010-07-03 10:41:33 +0000565.. opcode:: DELETE_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000566
567 Implements ``del TOS1[TOS]``.
568
Georg Brandl116aa622007-08-15 14:28:22 +0000569
Yury Selivanov66f88282015-06-24 11:04:15 -0400570**Coroutine opcodes**
Yury Selivanov75445082015-05-11 22:57:16 -0400571
572.. opcode:: GET_AWAITABLE
573
Yury Selivanov66f88282015-06-24 11:04:15 -0400574 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 Selivanov75445082015-05-11 22:57:16 -0400578
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200579 .. versionadded:: 3.5
580
Yury Selivanov75445082015-05-11 22:57:16 -0400581
582.. opcode:: GET_AITER
583
Yury Selivanov02e82a02017-10-06 10:18:10 -0400584 Implements ``TOS = TOS.__aiter__()``.
585
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200586 .. versionadded:: 3.5
Yury Selivanov02e82a02017-10-06 10:18:10 -0400587 .. versionchanged:: 3.7
588 Returning awaitable objects from ``__aiter__`` is no longer
589 supported.
Yury Selivanov75445082015-05-11 22:57:16 -0400590
591
592.. opcode:: GET_ANEXT
593
594 Implements ``PUSH(get_awaitable(TOS.__anext__()))``. See ``GET_AWAITABLE``
595 for details about ``get_awaitable``
596
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200597 .. versionadded:: 3.5
598
Yury Selivanov75445082015-05-11 22:57:16 -0400599
Serhiy Storchaka702f8f32018-03-23 14:34:35 +0200600.. 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 Selivanov75445082015-05-11 22:57:16 -0400611.. 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 Storchaka12e7cd82018-02-01 13:48:33 +0200616 .. versionadded:: 3.5
617
Yury Selivanov75445082015-05-11 22:57:16 -0400618
619.. opcode:: SETUP_ASYNC_WITH
620
621 Creates a new frame object.
622
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200623 .. versionadded:: 3.5
624
Yury Selivanov75445082015-05-11 22:57:16 -0400625
626
Georg Brandl4833e5b2010-07-03 10:41:33 +0000627**Miscellaneous opcodes**
Georg Brandl116aa622007-08-15 14:28:22 +0000628
Georg Brandl4833e5b2010-07-03 10:41:33 +0000629.. opcode:: PRINT_EXPR
Georg Brandl116aa622007-08-15 14:28:22 +0000630
631 Implements the expression statement for the interactive mode. TOS is removed
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500632 from the stack and printed. In non-interactive mode, an expression statement
633 is terminated with :opcode:`POP_TOP`.
Georg Brandl116aa622007-08-15 14:28:22 +0000634
635
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000636.. opcode:: SET_ADD (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000637
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000638 Calls ``set.add(TOS1[-i], TOS)``. Used to implement set comprehensions.
Georg Brandl116aa622007-08-15 14:28:22 +0000639
640
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000641.. opcode:: LIST_APPEND (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000642
Xiang Zhang34cd3e92020-07-29 00:51:33 +0800643 Calls ``list.append(TOS1[-i], TOS)``. Used to implement list comprehensions.
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000644
645
646.. opcode:: MAP_ADD (i)
647
Jörn Heisslerc8a35412019-06-22 16:40:55 +0200648 Calls ``dict.__setitem__(TOS1[-i], TOS1, TOS)``. Used to implement dict
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000649 comprehensions.
650
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200651 .. versionadded:: 3.1
Jörn Heisslerc8a35412019-06-22 16:40:55 +0200652 .. versionchanged:: 3.8
653 Map value is TOS and map key is TOS1. Before, those were reversed.
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200654
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200655For all of the :opcode:`SET_ADD`, :opcode:`LIST_APPEND` and :opcode:`MAP_ADD`
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500656instructions, while the added value or key/value pair is popped off, the
657container object remains on the stack so that it is available for further
658iterations of the loop.
Georg Brandl116aa622007-08-15 14:28:22 +0000659
660
Georg Brandl4833e5b2010-07-03 10:41:33 +0000661.. opcode:: RETURN_VALUE
Georg Brandl116aa622007-08-15 14:28:22 +0000662
663 Returns with TOS to the caller of the function.
664
665
Georg Brandl4833e5b2010-07-03 10:41:33 +0000666.. opcode:: YIELD_VALUE
Georg Brandl116aa622007-08-15 14:28:22 +0000667
Berker Peksagab4040e2015-03-02 06:33:30 +0200668 Pops TOS and yields it from a :term:`generator`.
Georg Brandl116aa622007-08-15 14:28:22 +0000669
670
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000671.. opcode:: YIELD_FROM
672
Berker Peksagab4040e2015-03-02 06:33:30 +0200673 Pops TOS and delegates to it as a subiterator from a :term:`generator`.
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000674
675 .. versionadded:: 3.3
676
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200677
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700678.. opcode:: SETUP_ANNOTATIONS
679
680 Checks whether ``__annotations__`` is defined in ``locals()``, if not it is
Martin Panterb1321fb2016-10-10 00:38:21 +0000681 set up to an empty ``dict``. This opcode is only emitted if a class
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700682 or module body contains :term:`variable annotations <variable annotation>`
683 statically.
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000684
Berker Peksag34b74ff2016-09-12 08:00:01 +0300685 .. versionadded:: 3.6
686
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200687
Georg Brandl4833e5b2010-07-03 10:41:33 +0000688.. opcode:: IMPORT_STAR
Georg Brandl116aa622007-08-15 14:28:22 +0000689
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500690 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 Brandl116aa622007-08-15 14:28:22 +0000693
694
Georg Brandl4833e5b2010-07-03 10:41:33 +0000695.. opcode:: POP_BLOCK
Georg Brandl116aa622007-08-15 14:28:22 +0000696
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500697 Removes one block from the block stack. Per frame, there is a stack of
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200698 blocks, denoting :keyword:`try` statements, and such.
Georg Brandl116aa622007-08-15 14:28:22 +0000699
700
Georg Brandl4833e5b2010-07-03 10:41:33 +0000701.. opcode:: POP_EXCEPT
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000702
703 Removes one block from the block stack. The popped block must be an exception
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500704 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 Petersoneec3d712008-06-11 15:59:43 +0000707
708
Mark Shannonfee55262019-11-21 09:11:43 +0000709.. opcode:: RERAISE
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200710
Mark Shannonbf353f32020-12-17 13:55:28 +0000711 Re-raises the exception currently on top of the stack. If oparg is non-zero,
712 restores ``f_lasti`` of the current frame to its value when the exception was raised.
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200713
Mark Shannon82f897b2019-11-21 14:47:49 +0000714 .. versionadded:: 3.9
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200715
716
Mark Shannonfee55262019-11-21 09:11:43 +0000717.. opcode:: WITH_EXCEPT_START
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200718
Mark Shannonfee55262019-11-21 09:11:43 +0000719 Calls the function in position 7 on the stack with the top three
720 items on the stack as arguments.
721 Used to implement the call ``context_manager.__exit__(*exc_info())`` when an exception
722 has occurred in a :keyword:`with` statement.
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200723
Mark Shannon82f897b2019-11-21 14:47:49 +0000724 .. versionadded:: 3.9
Georg Brandl116aa622007-08-15 14:28:22 +0000725
726
Zackery Spytzce6a0702019-08-25 03:44:09 -0600727.. opcode:: LOAD_ASSERTION_ERROR
728
729 Pushes :exc:`AssertionError` onto the stack. Used by the :keyword:`assert`
730 statement.
731
732 .. versionadded:: 3.9
733
734
Georg Brandl4833e5b2010-07-03 10:41:33 +0000735.. opcode:: LOAD_BUILD_CLASS
Georg Brandl116aa622007-08-15 14:28:22 +0000736
Georg Brandl5ac22302008-07-20 21:39:03 +0000737 Pushes :func:`builtins.__build_class__` onto the stack. It is later called
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200738 by :opcode:`CALL_FUNCTION` to construct a class.
Georg Brandl116aa622007-08-15 14:28:22 +0000739
Guido van Rossum04110fb2007-08-24 16:32:05 +0000740
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000741.. opcode:: SETUP_WITH (delta)
742
743 This opcode performs several operations before a with block starts. First,
744 it loads :meth:`~object.__exit__` from the context manager and pushes it onto
Irit Katrieldea5bf92021-01-26 10:17:13 +0000745 the stack for later use by :opcode:`WITH_EXCEPT_START`. Then,
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000746 :meth:`~object.__enter__` is called, and a finally block pointing to *delta*
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200747 is pushed. Finally, the result of calling the ``__enter__()`` method is pushed onto
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000748 the stack. The next opcode will either ignore it (:opcode:`POP_TOP`), or
749 store it in (a) variable(s) (:opcode:`STORE_FAST`, :opcode:`STORE_NAME`, or
750 :opcode:`UNPACK_SEQUENCE`).
751
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200752 .. versionadded:: 3.2
753
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000754
Brandt Bucher145bf262021-02-26 14:51:55 -0800755.. opcode:: COPY_DICT_WITHOUT_KEYS
756
757 TOS is a tuple of mapping keys, and TOS1 is the match subject. Replace TOS
758 with a :class:`dict` formed from the items of TOS1, but without any of the
759 keys in TOS.
760
761 .. versionadded:: 3.10
762
763
764.. opcode:: GET_LEN
765
766 Push ``len(TOS)`` onto the stack.
767
768 .. versionadded:: 3.10
769
770
771.. opcode:: MATCH_MAPPING
772
773 If TOS is an instance of :class:`collections.abc.Mapping`, push ``True`` onto
774 the stack. Otherwise, push ``False``.
775
776 .. versionadded:: 3.10
777
778
779.. opcode:: MATCH_SEQUENCE
780
781 If TOS is an instance of :class:`collections.abc.Sequence` and is *not* an
782 instance of :class:`str`/:class:`bytes`/:class:`bytearray`, push ``True``
783 onto the stack. Otherwise, push ``False``.
784
785 .. versionadded:: 3.10
786
787
788.. opcode:: MATCH_KEYS
789
790 TOS is a tuple of mapping keys, and TOS1 is the match subject. If TOS1
791 contains all of the keys in TOS, push a :class:`tuple` containing the
792 corresponding values, followed by ``True``. Otherwise, push ``None``,
793 followed by ``False``.
794
795 .. versionadded:: 3.10
796
797
Serhiy Storchakab0f80b02016-05-24 09:15:14 +0300798All of the following opcodes use their arguments.
Georg Brandl116aa622007-08-15 14:28:22 +0000799
Georg Brandl116aa622007-08-15 14:28:22 +0000800.. opcode:: STORE_NAME (namei)
801
802 Implements ``name = TOS``. *namei* is the index of *name* in the attribute
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500803 :attr:`co_names` of the code object. The compiler tries to use
804 :opcode:`STORE_FAST` or :opcode:`STORE_GLOBAL` if possible.
Georg Brandl116aa622007-08-15 14:28:22 +0000805
806
807.. opcode:: DELETE_NAME (namei)
808
809 Implements ``del name``, where *namei* is the index into :attr:`co_names`
810 attribute of the code object.
811
812
813.. opcode:: UNPACK_SEQUENCE (count)
814
815 Unpacks TOS into *count* individual values, which are put onto the stack
816 right-to-left.
817
Georg Brandl116aa622007-08-15 14:28:22 +0000818
Georg Brandl5ac22302008-07-20 21:39:03 +0000819.. opcode:: UNPACK_EX (counts)
820
821 Implements assignment with a starred target: Unpacks an iterable in TOS into
822 individual values, where the total number of values can be smaller than the
Martin Pantercc71a792016-04-05 06:19:42 +0000823 number of items in the iterable: one of the new values will be a list of all
Georg Brandl5ac22302008-07-20 21:39:03 +0000824 leftover items.
825
826 The low byte of *counts* is the number of values before the list value, the
827 high byte of *counts* the number of values after it. The resulting values
828 are put onto the stack right-to-left.
Georg Brandl48310cd2009-01-03 21:18:54 +0000829
Georg Brandl5ac22302008-07-20 21:39:03 +0000830
Georg Brandl116aa622007-08-15 14:28:22 +0000831.. opcode:: STORE_ATTR (namei)
832
833 Implements ``TOS.name = TOS1``, where *namei* is the index of name in
834 :attr:`co_names`.
835
836
837.. opcode:: DELETE_ATTR (namei)
838
839 Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`.
840
841
842.. opcode:: STORE_GLOBAL (namei)
843
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200844 Works as :opcode:`STORE_NAME`, but stores the name as a global.
Georg Brandl116aa622007-08-15 14:28:22 +0000845
846
847.. opcode:: DELETE_GLOBAL (namei)
848
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200849 Works as :opcode:`DELETE_NAME`, but deletes a global name.
Georg Brandl116aa622007-08-15 14:28:22 +0000850
Georg Brandl116aa622007-08-15 14:28:22 +0000851
852.. opcode:: LOAD_CONST (consti)
853
854 Pushes ``co_consts[consti]`` onto the stack.
855
856
857.. opcode:: LOAD_NAME (namei)
858
859 Pushes the value associated with ``co_names[namei]`` onto the stack.
860
861
862.. opcode:: BUILD_TUPLE (count)
863
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500864 Creates a tuple consuming *count* items from the stack, and pushes the
865 resulting tuple onto the stack.
Georg Brandl116aa622007-08-15 14:28:22 +0000866
867
868.. opcode:: BUILD_LIST (count)
869
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200870 Works as :opcode:`BUILD_TUPLE`, but creates a list.
Georg Brandl116aa622007-08-15 14:28:22 +0000871
872
873.. opcode:: BUILD_SET (count)
874
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200875 Works as :opcode:`BUILD_TUPLE`, but creates a set.
Georg Brandl116aa622007-08-15 14:28:22 +0000876
877
Christian Heimesa62da1d2008-01-12 19:39:10 +0000878.. opcode:: BUILD_MAP (count)
Georg Brandl116aa622007-08-15 14:28:22 +0000879
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100880 Pushes a new dictionary object onto the stack. Pops ``2 * count`` items
881 so that the dictionary holds *count* entries:
882 ``{..., TOS3: TOS2, TOS1: TOS}``.
883
884 .. versionchanged:: 3.5
885 The dictionary is created from stack items instead of creating an
886 empty dictionary pre-sized to hold *count* items.
Georg Brandl116aa622007-08-15 14:28:22 +0000887
888
Serhiy Storchaka6a7506a2016-06-12 00:39:41 +0300889.. opcode:: BUILD_CONST_KEY_MAP (count)
890
laike9m85dd6bb2020-04-12 19:55:45 -0700891 The version of :opcode:`BUILD_MAP` specialized for constant keys. Pops the
892 top element on the stack which contains a tuple of keys, then starting from
893 ``TOS1``, pops *count* values to form values in the built dictionary.
Serhiy Storchaka6a7506a2016-06-12 00:39:41 +0300894
895 .. versionadded:: 3.6
896
897
Serhiy Storchakaea525a22016-09-06 22:07:53 +0300898.. opcode:: BUILD_STRING (count)
899
900 Concatenates *count* strings from the stack and pushes the resulting string
901 onto the stack.
902
903 .. versionadded:: 3.6
904
905
Mark Shannon13bc1392020-01-23 09:25:17 +0000906.. opcode:: LIST_TO_TUPLE
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100907
Andre Delfinofa840cc2020-11-28 18:43:22 -0300908 Pops a list from the stack and pushes a tuple containing the same values.
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100909
Mark Shannon13bc1392020-01-23 09:25:17 +0000910 .. versionadded:: 3.9
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100911
912
Mark Shannon13bc1392020-01-23 09:25:17 +0000913.. opcode:: LIST_EXTEND (i)
Ivan Levkivskyi7e52c3e2017-03-10 23:16:44 +0100914
Mark Shannon13bc1392020-01-23 09:25:17 +0000915 Calls ``list.extend(TOS1[-i], TOS)``. Used to build lists.
Ivan Levkivskyi7e52c3e2017-03-10 23:16:44 +0100916
Mark Shannon13bc1392020-01-23 09:25:17 +0000917 .. versionadded:: 3.9
Ivan Levkivskyi7e52c3e2017-03-10 23:16:44 +0100918
919
Mark Shannon8a4cd702020-01-27 09:57:45 +0000920.. opcode:: SET_UPDATE (i)
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100921
Mark Shannon13bc1392020-01-23 09:25:17 +0000922 Calls ``set.update(TOS1[-i], TOS)``. Used to build sets.
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100923
Mark Shannon13bc1392020-01-23 09:25:17 +0000924 .. versionadded:: 3.9
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100925
926
Mark Shannon8a4cd702020-01-27 09:57:45 +0000927.. opcode:: DICT_UPDATE (i)
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100928
Mark Shannon8a4cd702020-01-27 09:57:45 +0000929 Calls ``dict.update(TOS1[-i], TOS)``. Used to build dicts.
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100930
Mark Shannon8a4cd702020-01-27 09:57:45 +0000931 .. versionadded:: 3.9
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100932
933
Mark Shannon8a4cd702020-01-27 09:57:45 +0000934.. opcode:: DICT_MERGE
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100935
Andre Delfinofa840cc2020-11-28 18:43:22 -0300936 Like :opcode:`DICT_UPDATE` but raises an exception for duplicate keys.
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100937
Mark Shannon8a4cd702020-01-27 09:57:45 +0000938 .. versionadded:: 3.9
Ivan Levkivskyi0705f662017-03-03 22:46:39 +0100939
940
Georg Brandl116aa622007-08-15 14:28:22 +0000941.. opcode:: LOAD_ATTR (namei)
942
943 Replaces TOS with ``getattr(TOS, co_names[namei])``.
944
945
946.. opcode:: COMPARE_OP (opname)
947
948 Performs a Boolean operation. The operation name can be found in
949 ``cmp_op[opname]``.
950
951
Mark Shannon9af0e472020-01-14 10:12:45 +0000952.. opcode:: IS_OP (invert)
953
Andre Delfinofa840cc2020-11-28 18:43:22 -0300954 Performs ``is`` comparison, or ``is not`` if ``invert`` is 1.
Mark Shannon9af0e472020-01-14 10:12:45 +0000955
956 .. versionadded:: 3.9
957
958
959.. opcode:: CONTAINS_OP (invert)
960
Andre Delfinofa840cc2020-11-28 18:43:22 -0300961 Performs ``in`` comparison, or ``not in`` if ``invert`` is 1.
Mark Shannon9af0e472020-01-14 10:12:45 +0000962
963 .. versionadded:: 3.9
964
965
Georg Brandl116aa622007-08-15 14:28:22 +0000966.. opcode:: IMPORT_NAME (namei)
967
Christian Heimesa342c012008-04-20 21:01:16 +0000968 Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide
969 the *fromlist* and *level* arguments of :func:`__import__`. The module
Benjamin Petersonbdf525b2015-03-02 09:31:40 -0500970 object is pushed onto the stack. The current namespace is not affected: for
971 a proper import statement, a subsequent :opcode:`STORE_FAST` instruction
Christian Heimesa342c012008-04-20 21:01:16 +0000972 modifies the namespace.
Georg Brandl116aa622007-08-15 14:28:22 +0000973
974
975.. opcode:: IMPORT_FROM (namei)
976
977 Loads the attribute ``co_names[namei]`` from the module found in TOS. The
978 resulting object is pushed onto the stack, to be subsequently stored by a
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200979 :opcode:`STORE_FAST` instruction.
Georg Brandl116aa622007-08-15 14:28:22 +0000980
981
982.. opcode:: JUMP_FORWARD (delta)
983
Georg Brandl9afde1c2007-11-01 20:32:30 +0000984 Increments bytecode counter by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +0000985
986
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000987.. opcode:: POP_JUMP_IF_TRUE (target)
Georg Brandl116aa622007-08-15 14:28:22 +0000988
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000989 If TOS is true, sets the bytecode counter to *target*. TOS is popped.
Georg Brandl116aa622007-08-15 14:28:22 +0000990
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200991 .. versionadded:: 3.1
992
Georg Brandl116aa622007-08-15 14:28:22 +0000993
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000994.. opcode:: POP_JUMP_IF_FALSE (target)
Georg Brandl116aa622007-08-15 14:28:22 +0000995
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000996 If TOS is false, sets the bytecode counter to *target*. TOS is popped.
997
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +0200998 .. versionadded:: 3.1
999
Mark Shannon9af0e472020-01-14 10:12:45 +00001000.. opcode:: JUMP_IF_NOT_EXC_MATCH (target)
1001
Andre Delfinofa840cc2020-11-28 18:43:22 -03001002 Tests whether the second value on the stack is an exception matching TOS,
1003 and jumps if it is not. Pops two values from the stack.
Mark Shannon9af0e472020-01-14 10:12:45 +00001004
1005 .. versionadded:: 3.9
1006
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +00001007
1008.. opcode:: JUMP_IF_TRUE_OR_POP (target)
1009
Benjamin Petersonbdf525b2015-03-02 09:31:40 -05001010 If TOS is true, sets the bytecode counter to *target* and leaves TOS on the
1011 stack. Otherwise (TOS is false), TOS is popped.
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +00001012
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +02001013 .. versionadded:: 3.1
1014
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +00001015
1016.. opcode:: JUMP_IF_FALSE_OR_POP (target)
1017
Benjamin Petersonbdf525b2015-03-02 09:31:40 -05001018 If TOS is false, sets the bytecode counter to *target* and leaves TOS on the
1019 stack. Otherwise (TOS is true), TOS is popped.
Georg Brandl116aa622007-08-15 14:28:22 +00001020
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +02001021 .. versionadded:: 3.1
1022
Georg Brandl116aa622007-08-15 14:28:22 +00001023
1024.. opcode:: JUMP_ABSOLUTE (target)
1025
Georg Brandl9afde1c2007-11-01 20:32:30 +00001026 Set bytecode counter to *target*.
Georg Brandl116aa622007-08-15 14:28:22 +00001027
1028
1029.. opcode:: FOR_ITER (delta)
1030
Benjamin Petersonbdf525b2015-03-02 09:31:40 -05001031 TOS is an :term:`iterator`. Call its :meth:`~iterator.__next__` method. If
1032 this yields a new value, push it on the stack (leaving the iterator below
laike9m70d9d742020-03-23 18:03:06 -07001033 it). If the iterator indicates it is exhausted, TOS is popped, and the byte
Benjamin Petersonbdf525b2015-03-02 09:31:40 -05001034 code counter is incremented by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +00001035
Georg Brandl116aa622007-08-15 14:28:22 +00001036
1037.. opcode:: LOAD_GLOBAL (namei)
1038
1039 Loads the global named ``co_names[namei]`` onto the stack.
1040
Georg Brandl116aa622007-08-15 14:28:22 +00001041
Georg Brandl116aa622007-08-15 14:28:22 +00001042.. opcode:: SETUP_FINALLY (delta)
1043
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +02001044 Pushes a try block from a try-finally or try-except clause onto the block
1045 stack. *delta* points to the finally block or the first except block.
1046
1047
Georg Brandl116aa622007-08-15 14:28:22 +00001048.. opcode:: LOAD_FAST (var_num)
1049
1050 Pushes a reference to the local ``co_varnames[var_num]`` onto the stack.
1051
1052
1053.. opcode:: STORE_FAST (var_num)
1054
1055 Stores TOS into the local ``co_varnames[var_num]``.
1056
1057
1058.. opcode:: DELETE_FAST (var_num)
1059
1060 Deletes local ``co_varnames[var_num]``.
1061
1062
1063.. opcode:: LOAD_CLOSURE (i)
1064
1065 Pushes a reference to the cell contained in slot *i* of the cell and free
Benjamin Petersonbdf525b2015-03-02 09:31:40 -05001066 variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is
1067 less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i -
Georg Brandl116aa622007-08-15 14:28:22 +00001068 len(co_cellvars)]``.
1069
1070
1071.. opcode:: LOAD_DEREF (i)
1072
1073 Loads the cell contained in slot *i* of the cell and free variable storage.
1074 Pushes a reference to the object the cell contains on the stack.
1075
1076
Benjamin Peterson3b0431d2013-04-30 09:41:40 -04001077.. opcode:: LOAD_CLASSDEREF (i)
1078
1079 Much like :opcode:`LOAD_DEREF` but first checks the locals dictionary before
1080 consulting the cell. This is used for loading free variables in class
1081 bodies.
1082
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +02001083 .. versionadded:: 3.4
1084
Benjamin Peterson3b0431d2013-04-30 09:41:40 -04001085
Georg Brandl116aa622007-08-15 14:28:22 +00001086.. opcode:: STORE_DEREF (i)
1087
1088 Stores TOS into the cell contained in slot *i* of the cell and free variable
1089 storage.
1090
1091
Amaury Forgeot d'Arcba117ef2010-09-10 21:39:53 +00001092.. opcode:: DELETE_DEREF (i)
1093
1094 Empties the cell contained in slot *i* of the cell and free variable storage.
1095 Used by the :keyword:`del` statement.
1096
Serhiy Storchaka12e7cd82018-02-01 13:48:33 +02001097 .. versionadded:: 3.2
1098
Amaury Forgeot d'Arcba117ef2010-09-10 21:39:53 +00001099
Georg Brandl116aa622007-08-15 14:28:22 +00001100.. opcode:: RAISE_VARARGS (argc)
1101
Michele Angrisanoe1179a52019-06-02 23:34:12 +02001102 Raises an exception using one of the 3 forms of the ``raise`` statement,
1103 depending on the value of *argc*:
1104
1105 * 0: ``raise`` (re-raise previous exception)
1106 * 1: ``raise TOS`` (raise exception instance or type at ``TOS``)
1107 * 2: ``raise TOS1 from TOS`` (raise exception instance or type at ``TOS1``
1108 with ``__cause__`` set to ``TOS``)
Georg Brandl116aa622007-08-15 14:28:22 +00001109
1110
1111.. opcode:: CALL_FUNCTION (argc)
1112
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001113 Calls a callable object with positional arguments.
1114 *argc* indicates the number of positional arguments.
1115 The top of the stack contains positional arguments, with the right-most
1116 argument on top. Below the arguments is a callable object to call.
1117 ``CALL_FUNCTION`` pops all arguments and the callable object off the stack,
1118 calls the callable object with those arguments, and pushes the return value
1119 returned by the callable object.
Ivan Levkivskyi4b2a2a42017-03-10 23:52:35 +01001120
1121 .. versionchanged:: 3.6
1122 This opcode is used only for calls with positional arguments.
1123
1124
1125.. opcode:: CALL_FUNCTION_KW (argc)
1126
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001127 Calls a callable object with positional (if any) and keyword arguments.
1128 *argc* indicates the total number of positional and keyword arguments.
Jeroen Demeyer05677862019-08-16 12:41:27 +02001129 The top element on the stack contains a tuple with the names of the
1130 keyword arguments, which must be strings.
1131 Below that are the values for the keyword arguments,
1132 in the order corresponding to the tuple.
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001133 Below that are positional arguments, with the right-most parameter on
1134 top. Below the arguments is a callable object to call.
1135 ``CALL_FUNCTION_KW`` pops all arguments and the callable object off the stack,
1136 calls the callable object with those arguments, and pushes the return value
1137 returned by the callable object.
Ivan Levkivskyi4b2a2a42017-03-10 23:52:35 +01001138
1139 .. versionchanged:: 3.6
1140 Keyword arguments are packed in a tuple instead of a dictionary,
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001141 *argc* indicates the total number of arguments.
Ivan Levkivskyi4b2a2a42017-03-10 23:52:35 +01001142
1143
1144.. opcode:: CALL_FUNCTION_EX (flags)
1145
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001146 Calls a callable object with variable set of positional and keyword
1147 arguments. If the lowest bit of *flags* is set, the top of the stack
1148 contains a mapping object containing additional keyword arguments.
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001149 Before the callable is called, the mapping object and iterable object
1150 are each "unpacked" and their contents passed in as keyword and
1151 positional arguments respectively.
1152 ``CALL_FUNCTION_EX`` pops all arguments and the callable object off the stack,
1153 calls the callable object with those arguments, and pushes the return value
1154 returned by the callable object.
Ivan Levkivskyi4b2a2a42017-03-10 23:52:35 +01001155
1156 .. versionadded:: 3.6
Georg Brandl116aa622007-08-15 14:28:22 +00001157
1158
INADA Naoki015bce62017-01-16 17:23:30 +09001159.. opcode:: LOAD_METHOD (namei)
1160
Carl Friedrich Bolz-Tereick8698b342020-01-21 01:41:17 +01001161 Loads a method named ``co_names[namei]`` from the TOS object. TOS is popped.
1162 This bytecode distinguishes two cases: if TOS has a method with the correct
1163 name, the bytecode pushes the unbound method and TOS. TOS will be used as
1164 the first argument (``self``) by :opcode:`CALL_METHOD` when calling the
1165 unbound method. Otherwise, ``NULL`` and the object return by the attribute
1166 lookup are pushed.
INADA Naoki015bce62017-01-16 17:23:30 +09001167
1168 .. versionadded:: 3.7
1169
1170
1171.. opcode:: CALL_METHOD (argc)
1172
Carl Friedrich Bolz-Tereick8698b342020-01-21 01:41:17 +01001173 Calls a method. *argc* is the number of positional arguments.
INADA Naoki015bce62017-01-16 17:23:30 +09001174 Keyword arguments are not supported. This opcode is designed to be used
1175 with :opcode:`LOAD_METHOD`. Positional arguments are on top of the stack.
Carl Friedrich Bolz-Tereick8698b342020-01-21 01:41:17 +01001176 Below them, the two items described in :opcode:`LOAD_METHOD` are on the
1177 stack (either ``self`` and an unbound method object or ``NULL`` and an
1178 arbitrary callable). All of them are popped and the return value is pushed.
INADA Naoki015bce62017-01-16 17:23:30 +09001179
1180 .. versionadded:: 3.7
1181
1182
Taine Zhao6672c162020-03-14 23:24:06 +09001183.. opcode:: MAKE_FUNCTION (flags)
Georg Brandl116aa622007-08-15 14:28:22 +00001184
Georg Brandlc96ef1f2013-10-12 18:41:18 +02001185 Pushes a new function object on the stack. From bottom to top, the consumed
Serhiy Storchaka64204de2016-06-12 17:36:24 +03001186 stack must consist of values if the argument carries a specified flag value
Georg Brandlc96ef1f2013-10-12 18:41:18 +02001187
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001188 * ``0x01`` a tuple of default values for positional-only and
1189 positional-or-keyword parameters in positional order
Serhiy Storchaka64204de2016-06-12 17:36:24 +03001190 * ``0x02`` a dictionary of keyword-only parameters' default values
Yurii Karabas73019792020-11-25 12:43:18 +02001191 * ``0x04`` a tuple of strings containing parameters' annotations
Serhiy Storchaka64204de2016-06-12 17:36:24 +03001192 * ``0x08`` a tuple containing cells for free variables, making a closure
Georg Brandlc96ef1f2013-10-12 18:41:18 +02001193 * the code associated with the function (at TOS1)
1194 * the :term:`qualified name` of the function (at TOS)
Georg Brandl116aa622007-08-15 14:28:22 +00001195
Yurii Karabas73019792020-11-25 12:43:18 +02001196 .. versionchanged:: 3.10
1197 Flag value ``0x04`` is a tuple of strings instead of dictionary
Georg Brandl116aa622007-08-15 14:28:22 +00001198
Georg Brandl116aa622007-08-15 14:28:22 +00001199.. opcode:: BUILD_SLICE (argc)
1200
1201 .. index:: builtin: slice
1202
1203 Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2,
1204 ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is
Christian Heimes5b5e81c2007-12-31 16:14:33 +00001205 pushed. See the :func:`slice` built-in function for more information.
Georg Brandl116aa622007-08-15 14:28:22 +00001206
1207
1208.. opcode:: EXTENDED_ARG (ext)
1209
Yao Zuo405f6482019-06-11 20:46:09 -07001210 Prefixes any opcode which has an argument too big to fit into the default one
1211 byte. *ext* holds an additional byte which act as higher bits in the argument.
1212 For each opcode, at most three prefixal ``EXTENDED_ARG`` are allowed, forming
1213 an argument from two-byte to four-byte.
Georg Brandl116aa622007-08-15 14:28:22 +00001214
1215
Eric V. Smith281d5322015-11-03 13:09:01 -05001216.. opcode:: FORMAT_VALUE (flags)
1217
1218 Used for implementing formatted literal strings (f-strings). Pops
1219 an optional *fmt_spec* from the stack, then a required *value*.
1220 *flags* is interpreted as follows:
1221
Eric V. Smith9ce52e32015-11-03 16:30:49 -05001222 * ``(flags & 0x03) == 0x00``: *value* is formatted as-is.
Eric V. Smith281d5322015-11-03 13:09:01 -05001223 * ``(flags & 0x03) == 0x01``: call :func:`str` on *value* before
1224 formatting it.
1225 * ``(flags & 0x03) == 0x02``: call :func:`repr` on *value* before
1226 formatting it.
1227 * ``(flags & 0x03) == 0x03``: call :func:`ascii` on *value* before
1228 formatting it.
1229 * ``(flags & 0x04) == 0x04``: pop *fmt_spec* from the stack and use
1230 it, else use an empty *fmt_spec*.
1231
Eric V. Smitha3a3d732015-11-04 07:11:13 -05001232 Formatting is performed using :c:func:`PyObject_Format`. The
1233 result is pushed on the stack.
Eric V. Smith281d5322015-11-03 13:09:01 -05001234
Eric V. Smith9ce52e32015-11-03 16:30:49 -05001235 .. versionadded:: 3.6
1236
Eric V. Smith281d5322015-11-03 13:09:01 -05001237
Brandt Bucher145bf262021-02-26 14:51:55 -08001238.. opcode:: MATCH_CLASS (count)
1239
1240 TOS is a tuple of keyword attribute names, TOS1 is the class being matched
1241 against, and TOS2 is the match subject. *count* is the number of positional
1242 sub-patterns.
1243
1244 Pop TOS. If TOS2 is an instance of TOS1 and has the positional and keyword
1245 attributes required by *count* and TOS, set TOS to ``True`` and TOS1 to a
1246 tuple of extracted attributes. Otherwise, set TOS to ``False``.
1247
1248 .. versionadded:: 3.10
1249
1250
Georg Brandl4833e5b2010-07-03 10:41:33 +00001251.. opcode:: HAVE_ARGUMENT
Georg Brandl116aa622007-08-15 14:28:22 +00001252
Benjamin Petersonbdf525b2015-03-02 09:31:40 -05001253 This is not really an opcode. It identifies the dividing line between
Ivan Levkivskyi8f9e1bbf2017-03-24 22:05:04 +01001254 opcodes which don't use their argument and those that do
1255 (``< HAVE_ARGUMENT`` and ``>= HAVE_ARGUMENT``, respectively).
1256
1257 .. versionchanged:: 3.6
1258 Now every instruction has an argument, but opcodes ``< HAVE_ARGUMENT``
1259 ignore it. Before, only opcodes ``>= HAVE_ARGUMENT`` had an argument.
1260
Georg Brandl116aa622007-08-15 14:28:22 +00001261
Nick Coghlanb39fd0c2013-05-06 23:59:20 +10001262.. _opcode_collections:
1263
1264Opcode collections
1265------------------
1266
1267These collections are provided for automatic introspection of bytecode
1268instructions:
1269
1270.. data:: opname
1271
1272 Sequence of operation names, indexable using the bytecode.
1273
1274
1275.. data:: opmap
1276
1277 Dictionary mapping operation names to bytecodes.
1278
1279
1280.. data:: cmp_op
1281
1282 Sequence of all compare operation names.
1283
1284
1285.. data:: hasconst
1286
Serhiy Storchaka5e99b562018-09-17 15:15:03 +03001287 Sequence of bytecodes that access a constant.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +10001288
1289
1290.. data:: hasfree
1291
Benjamin Petersonbdf525b2015-03-02 09:31:40 -05001292 Sequence of bytecodes that access a free variable (note that 'free' in this
1293 context refers to names in the current scope that are referenced by inner
1294 scopes or names in outer scopes that are referenced from this scope. It does
1295 *not* include references to global or builtin scopes).
Nick Coghlanb39fd0c2013-05-06 23:59:20 +10001296
1297
1298.. data:: hasname
1299
1300 Sequence of bytecodes that access an attribute by name.
1301
1302
1303.. data:: hasjrel
1304
1305 Sequence of bytecodes that have a relative jump target.
1306
1307
1308.. data:: hasjabs
1309
1310 Sequence of bytecodes that have an absolute jump target.
1311
1312
1313.. data:: haslocal
1314
1315 Sequence of bytecodes that access a local variable.
1316
1317
1318.. data:: hascompare
1319
1320 Sequence of bytecodes of Boolean operations.