blob: 1b7cfe1b3476fc4b426979253242f724d5ea61af [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
12disassembling it. The CPython bytecode which this module takes as an
Georg Brandl71515ca2009-05-17 12:29:12 +000013input is defined in the file :file:`Include/opcode.h` and used by the compiler
14and the interpreter.
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
Brett Cannon8315fd12010-07-02 22:03:00 +000023
Georg Brandl116aa622007-08-15 14:28:22 +000024Example: Given the function :func:`myfunc`::
25
26 def myfunc(alist):
27 return len(alist)
28
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100029the following command can be used to display the disassembly of
30:func:`myfunc`::
Georg Brandl116aa622007-08-15 14:28:22 +000031
32 >>> dis.dis(myfunc)
33 2 0 LOAD_GLOBAL 0 (len)
34 3 LOAD_FAST 0 (alist)
35 6 CALL_FUNCTION 1
36 9 RETURN_VALUE
37
38(The "2" is a line number).
39
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100040Bytecode analysis
41-----------------
Georg Brandl116aa622007-08-15 14:28:22 +000042
R David Murray0bce6e72014-01-07 14:30:17 -050043.. versionadded:: 3.4
44
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100045The bytecode analysis API allows pieces of Python code to be wrapped in a
46:class:`Bytecode` object that provides easy access to details of the
47compiled code.
48
Nick Coghlan50c48b82013-11-23 00:57:00 +100049.. class:: Bytecode(x, *, first_line=None, current_offset=None)
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100050
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100051 Analyse the bytecode corresponding to a function, method, string of
52 source code, or a code object (as returned by :func:`compile`).
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100053
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100054 This is a convenience wrapper around many of the functions listed below,
55 most notably :func:`get_instructions`, as iterating over a
Nick Coghlan07155c92013-11-06 22:12:07 +100056 :class:`Bytecode` instance yields the bytecode operations as
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100057 :class:`Instruction` instances.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100058
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100059 If *first_line* is not None, it indicates the line number that should
60 be reported for the first source line in the disassembled code.
61 Otherwise, the source line information (if any) is taken directly from
62 the disassembled code object.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100063
Nick Coghlan50c48b82013-11-23 00:57:00 +100064 If *current_offset* is not None, it refers to an instruction offset
65 in the disassembled code. Setting this means :meth:`dis` will display
66 a "current instruction" marker against the specified opcode.
67
68 .. classmethod:: from_traceback(tb)
69
70 Construct a :class:`Bytecode` instance from the given traceback,
71 setting *current_offset* to the instruction responsible for the
72 exception.
73
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100074 .. data:: codeobj
75
76 The compiled code object.
77
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100078 .. data:: first_line
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100079
Nick Coghlan90b8e7d2013-11-06 22:08:36 +100080 The first source line of the code object (if available)
81
82 .. method:: dis()
83
84 Return a formatted view of the bytecode operations (the same as
85 printed by :func:`dis`, but returned as a multi-line string).
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100086
87 .. method:: info()
88
89 Return a formatted multi-line string with detailed information about the
90 code object, like :func:`code_info`.
91
Nick Coghlanb39fd0c2013-05-06 23:59:20 +100092Example::
93
94 >>> bytecode = dis.Bytecode(myfunc)
95 >>> for instr in bytecode:
96 ... print(instr.opname)
97 ...
98 LOAD_GLOBAL
99 LOAD_FAST
100 CALL_FUNCTION
101 RETURN_VALUE
102
103
104Analysis functions
105------------------
106
107The :mod:`dis` module also defines the following analysis functions that
108convert the input directly to the desired output. They can be useful if
109only a single operation is being performed, so the intermediate analysis
110object isn't useful:
Georg Brandl116aa622007-08-15 14:28:22 +0000111
Nick Coghlane8814fb2010-09-10 14:08:04 +0000112.. function:: code_info(x)
Nick Coghlaneae2da12010-08-17 08:03:36 +0000113
Georg Brandl67b21b72010-08-17 15:07:14 +0000114 Return a formatted multi-line string with detailed code object information
115 for the supplied function, method, source code string or code object.
Nick Coghlaneae2da12010-08-17 08:03:36 +0000116
Georg Brandl67b21b72010-08-17 15:07:14 +0000117 Note that the exact contents of code info strings are highly implementation
118 dependent and they may change arbitrarily across Python VMs or Python
119 releases.
Nick Coghlaneae2da12010-08-17 08:03:36 +0000120
121 .. versionadded:: 3.2
122
Georg Brandl67b21b72010-08-17 15:07:14 +0000123
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000124.. function:: show_code(x, *, file=None)
Nick Coghlane8814fb2010-09-10 14:08:04 +0000125
126 Print detailed code object information for the supplied function, method,
Ezio Melotti6e6c6ac2013-08-23 22:41:39 +0300127 source code string or code object to *file* (or ``sys.stdout`` if *file*
128 is not specified).
Nick Coghlane8814fb2010-09-10 14:08:04 +0000129
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000130 This is a convenient shorthand for ``print(code_info(x), file=file)``,
131 intended for interactive exploration at the interpreter prompt.
Nick Coghlane8814fb2010-09-10 14:08:04 +0000132
133 .. versionadded:: 3.2
134
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000135 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200136 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000137
138
139.. function:: dis(x=None, *, file=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000140
Georg Brandl67b21b72010-08-17 15:07:14 +0000141 Disassemble the *x* object. *x* can denote either a module, a class, a
142 method, a function, a code object, a string of source code or a byte sequence
143 of raw bytecode. For a module, it disassembles all functions. For a class,
144 it disassembles all methods. For a code object or sequence of raw bytecode,
145 it prints one line per bytecode instruction. Strings are first compiled to
146 code objects with the :func:`compile` built-in function before being
147 disassembled. If no object is provided, this function disassembles the last
148 traceback.
Georg Brandl116aa622007-08-15 14:28:22 +0000149
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200150 The disassembly is written as text to the supplied *file* argument if
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000151 provided and to ``sys.stdout`` otherwise.
Georg Brandl116aa622007-08-15 14:28:22 +0000152
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000153 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200154 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000155
156
157.. function:: distb(tb=None, *, file=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000158
Georg Brandl4833e5b2010-07-03 10:41:33 +0000159 Disassemble the top-of-stack function of a traceback, using the last
160 traceback if none was passed. The instruction causing the exception is
161 indicated.
Georg Brandl116aa622007-08-15 14:28:22 +0000162
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200163 The disassembly is written as text to the supplied *file* argument if
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000164 provided and to ``sys.stdout`` otherwise.
Georg Brandl116aa622007-08-15 14:28:22 +0000165
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000166 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200167 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000168
169
170.. function:: disassemble(code, lasti=-1, *, file=None)
171 disco(code, lasti=-1, *, file=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000172
Georg Brandl4833e5b2010-07-03 10:41:33 +0000173 Disassemble a code object, indicating the last instruction if *lasti* was
Georg Brandl116aa622007-08-15 14:28:22 +0000174 provided. The output is divided in the following columns:
175
176 #. the line number, for the first instruction of each line
177 #. the current instruction, indicated as ``-->``,
178 #. a labelled instruction, indicated with ``>>``,
179 #. the address of the instruction,
180 #. the operation code name,
181 #. operation parameters, and
182 #. interpretation of the parameters in parentheses.
183
184 The parameter interpretation recognizes local and global variable names,
185 constant values, branch targets, and compare operators.
186
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200187 The disassembly is written as text to the supplied *file* argument if
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000188 provided and to ``sys.stdout`` otherwise.
189
190 .. versionchanged:: 3.4
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200191 Added *file* parameter.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000192
193
Nick Coghlan90b8e7d2013-11-06 22:08:36 +1000194.. function:: get_instructions(x, *, first_line=None)
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000195
196 Return an iterator over the instructions in the supplied function, method,
197 source code string or code object.
198
199 The iterator generates a series of :class:`Instruction` named tuples
200 giving the details of each operation in the supplied code.
201
Nick Coghlan90b8e7d2013-11-06 22:08:36 +1000202 If *first_line* is not None, it indicates the line number that should
203 be reported for the first source line in the disassembled code.
204 Otherwise, the source line information (if any) is taken directly from
205 the disassembled code object.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000206
207 .. versionadded:: 3.4
208
Georg Brandl116aa622007-08-15 14:28:22 +0000209
Benjamin Peterson75edad02009-01-01 15:05:06 +0000210.. function:: findlinestarts(code)
211
212 This generator function uses the ``co_firstlineno`` and ``co_lnotab``
213 attributes of the code object *code* to find the offsets which are starts of
214 lines in the source code. They are generated as ``(offset, lineno)`` pairs.
215
216
217.. function:: findlabels(code)
218
219 Detect all offsets in the code object *code* which are jump targets, and
220 return a list of these offsets.
Georg Brandl48310cd2009-01-03 21:18:54 +0000221
Larry Hastings3a907972013-11-23 14:49:22 -0800222
223.. function:: stack_effect(opcode, [oparg])
224
225 Compute the stack effect of *opcode* with argument *oparg*.
226
227 .. versionadded:: 3.4
228
Georg Brandl116aa622007-08-15 14:28:22 +0000229.. _bytecodes:
230
Georg Brandl9afde1c2007-11-01 20:32:30 +0000231Python Bytecode Instructions
232----------------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000233
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000234The :func:`get_instructions` function and :class:`Bytecode` class provide
235details of bytecode instructions as :class:`Instruction` instances:
236
237.. class:: Instruction
238
239 Details for a bytecode operation
240
241 .. data:: opcode
242
243 numeric code for operation, corresponding to the opcode values listed
244 below and the bytecode values in the :ref:`opcode_collections`.
245
246
247 .. data:: opname
248
249 human readable name for operation
250
251
252 .. data:: arg
253
254 numeric argument to operation (if any), otherwise None
255
256
257 .. data:: argval
258
259 resolved arg value (if known), otherwise same as arg
260
261
262 .. data:: argrepr
263
264 human readable description of operation argument
265
266
267 .. data:: offset
268
269 start index of operation within bytecode sequence
270
271
272 .. data:: starts_line
273
274 line started by this opcode (if any), otherwise None
275
276
277 .. data:: is_jump_target
278
Serhiy Storchaka0e90e992013-11-29 12:19:53 +0200279 ``True`` if other code jumps to here, otherwise ``False``
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000280
281 .. versionadded:: 3.4
282
283
Georg Brandl9afde1c2007-11-01 20:32:30 +0000284The Python compiler currently generates the following bytecode instructions.
Georg Brandl116aa622007-08-15 14:28:22 +0000285
286
Georg Brandl4833e5b2010-07-03 10:41:33 +0000287**General instructions**
288
Georg Brandl4833e5b2010-07-03 10:41:33 +0000289.. opcode:: NOP
Georg Brandl116aa622007-08-15 14:28:22 +0000290
291 Do nothing code. Used as a placeholder by the bytecode optimizer.
292
293
Georg Brandl4833e5b2010-07-03 10:41:33 +0000294.. opcode:: POP_TOP
Georg Brandl116aa622007-08-15 14:28:22 +0000295
296 Removes the top-of-stack (TOS) item.
297
298
Georg Brandl4833e5b2010-07-03 10:41:33 +0000299.. opcode:: ROT_TWO
Georg Brandl116aa622007-08-15 14:28:22 +0000300
301 Swaps the two top-most stack items.
302
303
Georg Brandl4833e5b2010-07-03 10:41:33 +0000304.. opcode:: ROT_THREE
Georg Brandl116aa622007-08-15 14:28:22 +0000305
306 Lifts second and third stack item one position up, moves top down to position
307 three.
308
309
Georg Brandl4833e5b2010-07-03 10:41:33 +0000310.. opcode:: DUP_TOP
Georg Brandl116aa622007-08-15 14:28:22 +0000311
312 Duplicates the reference on top of the stack.
313
Georg Brandl4833e5b2010-07-03 10:41:33 +0000314
Antoine Pitrou74a69fa2010-09-04 18:43:52 +0000315.. opcode:: DUP_TOP_TWO
316
317 Duplicates the two references on top of the stack, leaving them in the
318 same order.
319
320
Georg Brandl4833e5b2010-07-03 10:41:33 +0000321**Unary operations**
322
323Unary operations take the top of the stack, apply the operation, and push the
Georg Brandl116aa622007-08-15 14:28:22 +0000324result back on the stack.
325
Georg Brandl4833e5b2010-07-03 10:41:33 +0000326.. opcode:: UNARY_POSITIVE
Georg Brandl116aa622007-08-15 14:28:22 +0000327
328 Implements ``TOS = +TOS``.
329
330
Georg Brandl4833e5b2010-07-03 10:41:33 +0000331.. opcode:: UNARY_NEGATIVE
Georg Brandl116aa622007-08-15 14:28:22 +0000332
333 Implements ``TOS = -TOS``.
334
335
Georg Brandl4833e5b2010-07-03 10:41:33 +0000336.. opcode:: UNARY_NOT
Georg Brandl116aa622007-08-15 14:28:22 +0000337
338 Implements ``TOS = not TOS``.
339
340
Georg Brandl4833e5b2010-07-03 10:41:33 +0000341.. opcode:: UNARY_INVERT
Georg Brandl116aa622007-08-15 14:28:22 +0000342
343 Implements ``TOS = ~TOS``.
344
345
Georg Brandl4833e5b2010-07-03 10:41:33 +0000346.. opcode:: GET_ITER
Georg Brandl116aa622007-08-15 14:28:22 +0000347
348 Implements ``TOS = iter(TOS)``.
349
Georg Brandl4833e5b2010-07-03 10:41:33 +0000350
351**Binary operations**
352
Georg Brandl116aa622007-08-15 14:28:22 +0000353Binary operations remove the top of the stack (TOS) and the second top-most
354stack item (TOS1) from the stack. They perform the operation, and put the
355result back on the stack.
356
Georg Brandl4833e5b2010-07-03 10:41:33 +0000357.. opcode:: BINARY_POWER
Georg Brandl116aa622007-08-15 14:28:22 +0000358
359 Implements ``TOS = TOS1 ** TOS``.
360
361
Georg Brandl4833e5b2010-07-03 10:41:33 +0000362.. opcode:: BINARY_MULTIPLY
Georg Brandl116aa622007-08-15 14:28:22 +0000363
364 Implements ``TOS = TOS1 * TOS``.
365
366
Georg Brandl4833e5b2010-07-03 10:41:33 +0000367.. opcode:: BINARY_FLOOR_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000368
369 Implements ``TOS = TOS1 // TOS``.
370
371
Georg Brandl4833e5b2010-07-03 10:41:33 +0000372.. opcode:: BINARY_TRUE_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000373
Ezio Melotti7de0a6e2010-01-05 08:37:27 +0000374 Implements ``TOS = TOS1 / TOS``.
Georg Brandl116aa622007-08-15 14:28:22 +0000375
376
Georg Brandl4833e5b2010-07-03 10:41:33 +0000377.. opcode:: BINARY_MODULO
Georg Brandl116aa622007-08-15 14:28:22 +0000378
379 Implements ``TOS = TOS1 % TOS``.
380
381
Georg Brandl4833e5b2010-07-03 10:41:33 +0000382.. opcode:: BINARY_ADD
Georg Brandl116aa622007-08-15 14:28:22 +0000383
384 Implements ``TOS = TOS1 + TOS``.
385
386
Georg Brandl4833e5b2010-07-03 10:41:33 +0000387.. opcode:: BINARY_SUBTRACT
Georg Brandl116aa622007-08-15 14:28:22 +0000388
389 Implements ``TOS = TOS1 - TOS``.
390
391
Georg Brandl4833e5b2010-07-03 10:41:33 +0000392.. opcode:: BINARY_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000393
394 Implements ``TOS = TOS1[TOS]``.
395
396
Georg Brandl4833e5b2010-07-03 10:41:33 +0000397.. opcode:: BINARY_LSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000398
399 Implements ``TOS = TOS1 << TOS``.
400
401
Georg Brandl4833e5b2010-07-03 10:41:33 +0000402.. opcode:: BINARY_RSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000403
404 Implements ``TOS = TOS1 >> TOS``.
405
406
Georg Brandl4833e5b2010-07-03 10:41:33 +0000407.. opcode:: BINARY_AND
Georg Brandl116aa622007-08-15 14:28:22 +0000408
409 Implements ``TOS = TOS1 & TOS``.
410
411
Georg Brandl4833e5b2010-07-03 10:41:33 +0000412.. opcode:: BINARY_XOR
Georg Brandl116aa622007-08-15 14:28:22 +0000413
414 Implements ``TOS = TOS1 ^ TOS``.
415
416
Georg Brandl4833e5b2010-07-03 10:41:33 +0000417.. opcode:: BINARY_OR
Georg Brandl116aa622007-08-15 14:28:22 +0000418
419 Implements ``TOS = TOS1 | TOS``.
420
Georg Brandl4833e5b2010-07-03 10:41:33 +0000421
422**In-place operations**
423
Georg Brandl116aa622007-08-15 14:28:22 +0000424In-place operations are like binary operations, in that they remove TOS and
425TOS1, and push the result back on the stack, but the operation is done in-place
426when TOS1 supports it, and the resulting TOS may be (but does not have to be)
427the original TOS1.
428
Georg Brandl4833e5b2010-07-03 10:41:33 +0000429.. opcode:: INPLACE_POWER
Georg Brandl116aa622007-08-15 14:28:22 +0000430
431 Implements in-place ``TOS = TOS1 ** TOS``.
432
433
Georg Brandl4833e5b2010-07-03 10:41:33 +0000434.. opcode:: INPLACE_MULTIPLY
Georg Brandl116aa622007-08-15 14:28:22 +0000435
436 Implements in-place ``TOS = TOS1 * TOS``.
437
438
Georg Brandl4833e5b2010-07-03 10:41:33 +0000439.. opcode:: INPLACE_FLOOR_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000440
441 Implements in-place ``TOS = TOS1 // TOS``.
442
443
Georg Brandl4833e5b2010-07-03 10:41:33 +0000444.. opcode:: INPLACE_TRUE_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000445
Ezio Melotti7de0a6e2010-01-05 08:37:27 +0000446 Implements in-place ``TOS = TOS1 / TOS``.
Georg Brandl116aa622007-08-15 14:28:22 +0000447
448
Georg Brandl4833e5b2010-07-03 10:41:33 +0000449.. opcode:: INPLACE_MODULO
Georg Brandl116aa622007-08-15 14:28:22 +0000450
451 Implements in-place ``TOS = TOS1 % TOS``.
452
453
Georg Brandl4833e5b2010-07-03 10:41:33 +0000454.. opcode:: INPLACE_ADD
Georg Brandl116aa622007-08-15 14:28:22 +0000455
456 Implements in-place ``TOS = TOS1 + TOS``.
457
458
Georg Brandl4833e5b2010-07-03 10:41:33 +0000459.. opcode:: INPLACE_SUBTRACT
Georg Brandl116aa622007-08-15 14:28:22 +0000460
461 Implements in-place ``TOS = TOS1 - TOS``.
462
463
Georg Brandl4833e5b2010-07-03 10:41:33 +0000464.. opcode:: INPLACE_LSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000465
466 Implements in-place ``TOS = TOS1 << TOS``.
467
468
Georg Brandl4833e5b2010-07-03 10:41:33 +0000469.. opcode:: INPLACE_RSHIFT
Georg Brandl116aa622007-08-15 14:28:22 +0000470
471 Implements in-place ``TOS = TOS1 >> TOS``.
472
473
Georg Brandl4833e5b2010-07-03 10:41:33 +0000474.. opcode:: INPLACE_AND
Georg Brandl116aa622007-08-15 14:28:22 +0000475
476 Implements in-place ``TOS = TOS1 & TOS``.
477
478
Georg Brandl4833e5b2010-07-03 10:41:33 +0000479.. opcode:: INPLACE_XOR
Georg Brandl116aa622007-08-15 14:28:22 +0000480
481 Implements in-place ``TOS = TOS1 ^ TOS``.
482
483
Georg Brandl4833e5b2010-07-03 10:41:33 +0000484.. opcode:: INPLACE_OR
Georg Brandl116aa622007-08-15 14:28:22 +0000485
486 Implements in-place ``TOS = TOS1 | TOS``.
487
Georg Brandl116aa622007-08-15 14:28:22 +0000488
Georg Brandl4833e5b2010-07-03 10:41:33 +0000489.. opcode:: STORE_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000490
491 Implements ``TOS1[TOS] = TOS2``.
492
493
Georg Brandl4833e5b2010-07-03 10:41:33 +0000494.. opcode:: DELETE_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000495
496 Implements ``del TOS1[TOS]``.
497
Georg Brandl116aa622007-08-15 14:28:22 +0000498
Georg Brandl4833e5b2010-07-03 10:41:33 +0000499**Miscellaneous opcodes**
Georg Brandl116aa622007-08-15 14:28:22 +0000500
Georg Brandl4833e5b2010-07-03 10:41:33 +0000501.. opcode:: PRINT_EXPR
Georg Brandl116aa622007-08-15 14:28:22 +0000502
503 Implements the expression statement for the interactive mode. TOS is removed
504 from the stack and printed. In non-interactive mode, an expression statement is
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200505 terminated with :opcode:`POP_TOP`.
Georg Brandl116aa622007-08-15 14:28:22 +0000506
507
Georg Brandl4833e5b2010-07-03 10:41:33 +0000508.. opcode:: BREAK_LOOP
Georg Brandl116aa622007-08-15 14:28:22 +0000509
510 Terminates a loop due to a :keyword:`break` statement.
511
512
513.. opcode:: CONTINUE_LOOP (target)
514
515 Continues a loop due to a :keyword:`continue` statement. *target* is the
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200516 address to jump to (which should be a :opcode:`FOR_ITER` instruction).
Georg Brandl116aa622007-08-15 14:28:22 +0000517
518
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000519.. opcode:: SET_ADD (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000520
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000521 Calls ``set.add(TOS1[-i], TOS)``. Used to implement set comprehensions.
Georg Brandl116aa622007-08-15 14:28:22 +0000522
523
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000524.. opcode:: LIST_APPEND (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000525
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000526 Calls ``list.append(TOS[-i], TOS)``. Used to implement list comprehensions.
527
528
529.. opcode:: MAP_ADD (i)
530
531 Calls ``dict.setitem(TOS1[-i], TOS, TOS1)``. Used to implement dict
532 comprehensions.
533
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200534For all of the :opcode:`SET_ADD`, :opcode:`LIST_APPEND` and :opcode:`MAP_ADD`
535instructions, while the
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000536added value or key/value pair is popped off, the container object remains on
537the stack so that it is available for further iterations of the loop.
Georg Brandl116aa622007-08-15 14:28:22 +0000538
539
Georg Brandl4833e5b2010-07-03 10:41:33 +0000540.. opcode:: RETURN_VALUE
Georg Brandl116aa622007-08-15 14:28:22 +0000541
542 Returns with TOS to the caller of the function.
543
544
Georg Brandl4833e5b2010-07-03 10:41:33 +0000545.. opcode:: YIELD_VALUE
Georg Brandl116aa622007-08-15 14:28:22 +0000546
Georg Brandl9afde1c2007-11-01 20:32:30 +0000547 Pops ``TOS`` and yields it from a :term:`generator`.
Georg Brandl116aa622007-08-15 14:28:22 +0000548
549
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000550.. opcode:: YIELD_FROM
551
552 Pops ``TOS`` and delegates to it as a subiterator from a :term:`generator`.
553
554 .. versionadded:: 3.3
555
556
Georg Brandl4833e5b2010-07-03 10:41:33 +0000557.. opcode:: IMPORT_STAR
Georg Brandl116aa622007-08-15 14:28:22 +0000558
559 Loads all symbols not starting with ``'_'`` directly from the module TOS to the
560 local namespace. The module is popped after loading all names. This opcode
561 implements ``from module import *``.
562
563
Georg Brandl4833e5b2010-07-03 10:41:33 +0000564.. opcode:: POP_BLOCK
Georg Brandl116aa622007-08-15 14:28:22 +0000565
566 Removes one block from the block stack. Per frame, there is a stack of blocks,
567 denoting nested loops, try statements, and such.
568
569
Georg Brandl4833e5b2010-07-03 10:41:33 +0000570.. opcode:: POP_EXCEPT
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000571
572 Removes one block from the block stack. The popped block must be an exception
573 handler block, as implicitly created when entering an except handler.
574 In addition to popping extraneous values from the frame stack, the
575 last three popped values are used to restore the exception state.
576
577
Georg Brandl4833e5b2010-07-03 10:41:33 +0000578.. opcode:: END_FINALLY
Georg Brandl116aa622007-08-15 14:28:22 +0000579
580 Terminates a :keyword:`finally` clause. The interpreter recalls whether the
581 exception has to be re-raised, or whether the function returns, and continues
582 with the outer-next block.
583
584
Georg Brandl4833e5b2010-07-03 10:41:33 +0000585.. opcode:: LOAD_BUILD_CLASS
Georg Brandl116aa622007-08-15 14:28:22 +0000586
Georg Brandl5ac22302008-07-20 21:39:03 +0000587 Pushes :func:`builtins.__build_class__` onto the stack. It is later called
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200588 by :opcode:`CALL_FUNCTION` to construct a class.
Georg Brandl116aa622007-08-15 14:28:22 +0000589
Guido van Rossum04110fb2007-08-24 16:32:05 +0000590
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000591.. opcode:: SETUP_WITH (delta)
592
593 This opcode performs several operations before a with block starts. First,
594 it loads :meth:`~object.__exit__` from the context manager and pushes it onto
595 the stack for later use by :opcode:`WITH_CLEANUP`. Then,
596 :meth:`~object.__enter__` is called, and a finally block pointing to *delta*
597 is pushed. Finally, the result of calling the enter method is pushed onto
598 the stack. The next opcode will either ignore it (:opcode:`POP_TOP`), or
599 store it in (a) variable(s) (:opcode:`STORE_FAST`, :opcode:`STORE_NAME`, or
600 :opcode:`UNPACK_SEQUENCE`).
601
602
Georg Brandl4833e5b2010-07-03 10:41:33 +0000603.. opcode:: WITH_CLEANUP
Guido van Rossum04110fb2007-08-24 16:32:05 +0000604
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000605 Cleans up the stack when a :keyword:`with` statement block exits. TOS is
606 the context manager's :meth:`__exit__` bound method. Below TOS are 1--3
607 values indicating how/why the finally clause was entered:
Guido van Rossum04110fb2007-08-24 16:32:05 +0000608
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000609 * SECOND = ``None``
610 * (SECOND, THIRD) = (``WHY_{RETURN,CONTINUE}``), retval
611 * SECOND = ``WHY_*``; no retval below it
612 * (SECOND, THIRD, FOURTH) = exc_info()
Guido van Rossum04110fb2007-08-24 16:32:05 +0000613
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000614 In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise
615 ``TOS(None, None, None)``. In addition, TOS is removed from the stack.
Guido van Rossum04110fb2007-08-24 16:32:05 +0000616
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000617 If the stack represents an exception, *and* the function call returns
618 a 'true' value, this information is "zapped" and replaced with a single
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200619 ``WHY_SILENCED`` to prevent :opcode:`END_FINALLY` from re-raising the exception.
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000620 (But non-local gotos will still be resumed.)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000621
Georg Brandl9afde1c2007-11-01 20:32:30 +0000622 .. XXX explain the WHY stuff!
623
Guido van Rossum04110fb2007-08-24 16:32:05 +0000624
Georg Brandl116aa622007-08-15 14:28:22 +0000625All of the following opcodes expect arguments. An argument is two bytes, with
626the more significant byte last.
627
Georg Brandl116aa622007-08-15 14:28:22 +0000628.. opcode:: STORE_NAME (namei)
629
630 Implements ``name = TOS``. *namei* is the index of *name* in the attribute
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200631 :attr:`co_names` of the code object. The compiler tries to use :opcode:`STORE_FAST`
632 or :opcode:`STORE_GLOBAL` if possible.
Georg Brandl116aa622007-08-15 14:28:22 +0000633
634
635.. opcode:: DELETE_NAME (namei)
636
637 Implements ``del name``, where *namei* is the index into :attr:`co_names`
638 attribute of the code object.
639
640
641.. opcode:: UNPACK_SEQUENCE (count)
642
643 Unpacks TOS into *count* individual values, which are put onto the stack
644 right-to-left.
645
Georg Brandl116aa622007-08-15 14:28:22 +0000646
Georg Brandl5ac22302008-07-20 21:39:03 +0000647.. opcode:: UNPACK_EX (counts)
648
649 Implements assignment with a starred target: Unpacks an iterable in TOS into
650 individual values, where the total number of values can be smaller than the
651 number of items in the iterable: one the new values will be a list of all
652 leftover items.
653
654 The low byte of *counts* is the number of values before the list value, the
655 high byte of *counts* the number of values after it. The resulting values
656 are put onto the stack right-to-left.
Georg Brandl48310cd2009-01-03 21:18:54 +0000657
Georg Brandl5ac22302008-07-20 21:39:03 +0000658
Georg Brandl116aa622007-08-15 14:28:22 +0000659.. opcode:: STORE_ATTR (namei)
660
661 Implements ``TOS.name = TOS1``, where *namei* is the index of name in
662 :attr:`co_names`.
663
664
665.. opcode:: DELETE_ATTR (namei)
666
667 Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`.
668
669
670.. opcode:: STORE_GLOBAL (namei)
671
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200672 Works as :opcode:`STORE_NAME`, but stores the name as a global.
Georg Brandl116aa622007-08-15 14:28:22 +0000673
674
675.. opcode:: DELETE_GLOBAL (namei)
676
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200677 Works as :opcode:`DELETE_NAME`, but deletes a global name.
Georg Brandl116aa622007-08-15 14:28:22 +0000678
Georg Brandl116aa622007-08-15 14:28:22 +0000679
680.. opcode:: LOAD_CONST (consti)
681
682 Pushes ``co_consts[consti]`` onto the stack.
683
684
685.. opcode:: LOAD_NAME (namei)
686
687 Pushes the value associated with ``co_names[namei]`` onto the stack.
688
689
690.. opcode:: BUILD_TUPLE (count)
691
692 Creates a tuple consuming *count* items from the stack, and pushes the resulting
693 tuple onto the stack.
694
695
696.. opcode:: BUILD_LIST (count)
697
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200698 Works as :opcode:`BUILD_TUPLE`, but creates a list.
Georg Brandl116aa622007-08-15 14:28:22 +0000699
700
701.. opcode:: BUILD_SET (count)
702
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200703 Works as :opcode:`BUILD_TUPLE`, but creates a set.
Georg Brandl116aa622007-08-15 14:28:22 +0000704
705
Christian Heimesa62da1d2008-01-12 19:39:10 +0000706.. opcode:: BUILD_MAP (count)
Georg Brandl116aa622007-08-15 14:28:22 +0000707
Christian Heimesa62da1d2008-01-12 19:39:10 +0000708 Pushes a new dictionary object onto the stack. The dictionary is pre-sized
709 to hold *count* entries.
Georg Brandl116aa622007-08-15 14:28:22 +0000710
711
712.. opcode:: LOAD_ATTR (namei)
713
714 Replaces TOS with ``getattr(TOS, co_names[namei])``.
715
716
717.. opcode:: COMPARE_OP (opname)
718
719 Performs a Boolean operation. The operation name can be found in
720 ``cmp_op[opname]``.
721
722
723.. opcode:: IMPORT_NAME (namei)
724
Christian Heimesa342c012008-04-20 21:01:16 +0000725 Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide
726 the *fromlist* and *level* arguments of :func:`__import__`. The module
727 object is pushed onto the stack. The current namespace is not affected:
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200728 for a proper import statement, a subsequent :opcode:`STORE_FAST` instruction
Christian Heimesa342c012008-04-20 21:01:16 +0000729 modifies the namespace.
Georg Brandl116aa622007-08-15 14:28:22 +0000730
731
732.. opcode:: IMPORT_FROM (namei)
733
734 Loads the attribute ``co_names[namei]`` from the module found in TOS. The
735 resulting object is pushed onto the stack, to be subsequently stored by a
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200736 :opcode:`STORE_FAST` instruction.
Georg Brandl116aa622007-08-15 14:28:22 +0000737
738
739.. opcode:: JUMP_FORWARD (delta)
740
Georg Brandl9afde1c2007-11-01 20:32:30 +0000741 Increments bytecode counter by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +0000742
743
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000744.. opcode:: POP_JUMP_IF_TRUE (target)
Georg Brandl116aa622007-08-15 14:28:22 +0000745
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000746 If TOS is true, sets the bytecode counter to *target*. TOS is popped.
Georg Brandl116aa622007-08-15 14:28:22 +0000747
748
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000749.. opcode:: POP_JUMP_IF_FALSE (target)
Georg Brandl116aa622007-08-15 14:28:22 +0000750
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000751 If TOS is false, sets the bytecode counter to *target*. TOS is popped.
752
753
754.. opcode:: JUMP_IF_TRUE_OR_POP (target)
755
756 If TOS is true, sets the bytecode counter to *target* and leaves TOS
757 on the stack. Otherwise (TOS is false), TOS is popped.
758
759
760.. opcode:: JUMP_IF_FALSE_OR_POP (target)
761
762 If TOS is false, sets the bytecode counter to *target* and leaves
763 TOS on the stack. Otherwise (TOS is true), TOS is popped.
Georg Brandl116aa622007-08-15 14:28:22 +0000764
765
766.. opcode:: JUMP_ABSOLUTE (target)
767
Georg Brandl9afde1c2007-11-01 20:32:30 +0000768 Set bytecode counter to *target*.
Georg Brandl116aa622007-08-15 14:28:22 +0000769
770
771.. opcode:: FOR_ITER (delta)
772
Ezio Melotti7fa82222012-10-12 13:42:08 +0300773 ``TOS`` is an :term:`iterator`. Call its :meth:`~iterator.__next__` method.
774 If this yields a new value, push it on the stack (leaving the iterator below
775 it). If the iterator indicates it is exhausted ``TOS`` is popped, and the
776 byte code counter is incremented by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +0000777
Georg Brandl116aa622007-08-15 14:28:22 +0000778
779.. opcode:: LOAD_GLOBAL (namei)
780
781 Loads the global named ``co_names[namei]`` onto the stack.
782
Georg Brandl116aa622007-08-15 14:28:22 +0000783
784.. opcode:: SETUP_LOOP (delta)
785
786 Pushes a block for a loop onto the block stack. The block spans from the
787 current instruction with a size of *delta* bytes.
788
789
790.. opcode:: SETUP_EXCEPT (delta)
791
792 Pushes a try block from a try-except clause onto the block stack. *delta* points
793 to the first except block.
794
795
796.. opcode:: SETUP_FINALLY (delta)
797
798 Pushes a try block from a try-except clause onto the block stack. *delta* points
799 to the finally block.
800
Georg Brandl4833e5b2010-07-03 10:41:33 +0000801.. opcode:: STORE_MAP
Christian Heimesa62da1d2008-01-12 19:39:10 +0000802
803 Store a key and value pair in a dictionary. Pops the key and value while leaving
804 the dictionary on the stack.
Georg Brandl116aa622007-08-15 14:28:22 +0000805
806.. opcode:: LOAD_FAST (var_num)
807
808 Pushes a reference to the local ``co_varnames[var_num]`` onto the stack.
809
810
811.. opcode:: STORE_FAST (var_num)
812
813 Stores TOS into the local ``co_varnames[var_num]``.
814
815
816.. opcode:: DELETE_FAST (var_num)
817
818 Deletes local ``co_varnames[var_num]``.
819
820
821.. opcode:: LOAD_CLOSURE (i)
822
823 Pushes a reference to the cell contained in slot *i* of the cell and free
824 variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is
825 less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i -
826 len(co_cellvars)]``.
827
828
829.. opcode:: LOAD_DEREF (i)
830
831 Loads the cell contained in slot *i* of the cell and free variable storage.
832 Pushes a reference to the object the cell contains on the stack.
833
834
Benjamin Peterson3b0431d2013-04-30 09:41:40 -0400835.. opcode:: LOAD_CLASSDEREF (i)
836
837 Much like :opcode:`LOAD_DEREF` but first checks the locals dictionary before
838 consulting the cell. This is used for loading free variables in class
839 bodies.
840
841
Georg Brandl116aa622007-08-15 14:28:22 +0000842.. opcode:: STORE_DEREF (i)
843
844 Stores TOS into the cell contained in slot *i* of the cell and free variable
845 storage.
846
847
Amaury Forgeot d'Arcba117ef2010-09-10 21:39:53 +0000848.. opcode:: DELETE_DEREF (i)
849
850 Empties the cell contained in slot *i* of the cell and free variable storage.
851 Used by the :keyword:`del` statement.
852
853
Georg Brandl116aa622007-08-15 14:28:22 +0000854.. opcode:: RAISE_VARARGS (argc)
855
856 Raises an exception. *argc* indicates the number of parameters to the raise
857 statement, ranging from 0 to 3. The handler will find the traceback as TOS2,
858 the parameter as TOS1, and the exception as TOS.
859
860
861.. opcode:: CALL_FUNCTION (argc)
862
863 Calls a function. The low byte of *argc* indicates the number of positional
864 parameters, the high byte the number of keyword parameters. On the stack, the
865 opcode finds the keyword parameters first. For each keyword argument, the value
866 is on top of the key. Below the keyword parameters, the positional parameters
867 are on the stack, with the right-most parameter on top. Below the parameters,
Georg Brandl48310cd2009-01-03 21:18:54 +0000868 the function object to call is on the stack. Pops all function arguments, and
Benjamin Peterson206e3072008-10-19 14:07:49 +0000869 the function itself off the stack, and pushes the return value.
Georg Brandl116aa622007-08-15 14:28:22 +0000870
871
872.. opcode:: MAKE_FUNCTION (argc)
873
Georg Brandlc96ef1f2013-10-12 18:41:18 +0200874 Pushes a new function object on the stack. From bottom to top, the consumed
875 stack must consist of
876
877 * ``argc & 0xFF`` default argument objects in positional order
878 * ``(argc >> 8) & 0xFF`` pairs of name and default argument, with the name
879 just below the object on the stack, for keyword-only parameters
880 * ``(argc >> 16) & 0x7FFF`` parameter annotation objects
881 * a tuple listing the parameter names for the annotations (only if there are
882 ony annotation objects)
883 * the code associated with the function (at TOS1)
884 * the :term:`qualified name` of the function (at TOS)
Georg Brandl116aa622007-08-15 14:28:22 +0000885
886
887.. opcode:: MAKE_CLOSURE (argc)
888
Guido van Rossum04110fb2007-08-24 16:32:05 +0000889 Creates a new function object, sets its *__closure__* slot, and pushes it on
Andrew Svetlova5c43092012-11-23 15:28:34 +0200890 the stack. TOS is the :term:`qualified name` of the function, TOS1 is the
891 code associated with the function, and TOS2 is the tuple containing cells for
892 the closure's free variables. The function also has *argc* default parameters,
893 which are found below the cells.
Georg Brandl116aa622007-08-15 14:28:22 +0000894
895
896.. opcode:: BUILD_SLICE (argc)
897
898 .. index:: builtin: slice
899
900 Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2,
901 ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000902 pushed. See the :func:`slice` built-in function for more information.
Georg Brandl116aa622007-08-15 14:28:22 +0000903
904
905.. opcode:: EXTENDED_ARG (ext)
906
907 Prefixes any opcode which has an argument too big to fit into the default two
908 bytes. *ext* holds two additional bytes which, taken together with the
909 subsequent opcode's argument, comprise a four-byte argument, *ext* being the two
910 most-significant bytes.
911
912
913.. opcode:: CALL_FUNCTION_VAR (argc)
914
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200915 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The top element
Georg Brandl116aa622007-08-15 14:28:22 +0000916 on the stack contains the variable argument list, followed by keyword and
917 positional arguments.
918
919
920.. opcode:: CALL_FUNCTION_KW (argc)
921
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200922 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The top element
Georg Brandl116aa622007-08-15 14:28:22 +0000923 on the stack contains the keyword arguments dictionary, followed by explicit
924 keyword and positional arguments.
925
926
927.. opcode:: CALL_FUNCTION_VAR_KW (argc)
928
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200929 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The top
Georg Brandl116aa622007-08-15 14:28:22 +0000930 element on the stack contains the keyword arguments dictionary, followed by the
931 variable-arguments tuple, followed by explicit keyword and positional arguments.
932
933
Georg Brandl4833e5b2010-07-03 10:41:33 +0000934.. opcode:: HAVE_ARGUMENT
Georg Brandl116aa622007-08-15 14:28:22 +0000935
936 This is not really an opcode. It identifies the dividing line between opcodes
937 which don't take arguments ``< HAVE_ARGUMENT`` and those which do ``>=
938 HAVE_ARGUMENT``.
939
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000940.. _opcode_collections:
941
942Opcode collections
943------------------
944
945These collections are provided for automatic introspection of bytecode
946instructions:
947
948.. data:: opname
949
950 Sequence of operation names, indexable using the bytecode.
951
952
953.. data:: opmap
954
955 Dictionary mapping operation names to bytecodes.
956
957
958.. data:: cmp_op
959
960 Sequence of all compare operation names.
961
962
963.. data:: hasconst
964
965 Sequence of bytecodes that have a constant parameter.
966
967
968.. data:: hasfree
969
970 Sequence of bytecodes that access a free variable (note that 'free' in
971 this context refers to names in the current scope that are referenced by
972 inner scopes or names in outer scopes that are referenced from this scope.
973 It does *not* include references to global or builtin scopes).
974
975
976.. data:: hasname
977
978 Sequence of bytecodes that access an attribute by name.
979
980
981.. data:: hasjrel
982
983 Sequence of bytecodes that have a relative jump target.
984
985
986.. data:: hasjabs
987
988 Sequence of bytecodes that have an absolute jump target.
989
990
991.. data:: haslocal
992
993 Sequence of bytecodes that access a local variable.
994
995
996.. data:: hascompare
997
998 Sequence of bytecodes of Boolean operations.