blob: 3b419e6c8a4d07157755645fedb3f146d29bde23 [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 Coghlanefd5df92014-07-25 23:02:56 +100051 Analyse the bytecode corresponding to a function, generator, method,
52 string of 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
Nick Coghlanefd5df92014-07-25 23:02:56 +1000115 for the supplied function, generator, 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
Nick Coghlanefd5df92014-07-25 23:02:56 +1000142 method, a function, a generator, a code object, a string of source code or
143 a byte sequence of raw bytecode. For a module, it disassembles all functions.
144 For a class, it disassembles all methods. For a code object or sequence of
145 raw bytecode, it prints one line per bytecode instruction. Strings are first
146 compiled to code objects with the :func:`compile` built-in function before being
Georg Brandl67b21b72010-08-17 15:07:14 +0000147 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
Benjamin Petersond51374e2014-04-09 23:55:56 -0400367.. opcode:: BINARY_MATRIX_MULTIPLY
368
369 Implements ``TOS = TOS1 @ TOS``.
370
371
Georg Brandl4833e5b2010-07-03 10:41:33 +0000372.. opcode:: BINARY_FLOOR_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000373
374 Implements ``TOS = TOS1 // TOS``.
375
376
Georg Brandl4833e5b2010-07-03 10:41:33 +0000377.. opcode:: BINARY_TRUE_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000378
Ezio Melotti7de0a6e2010-01-05 08:37:27 +0000379 Implements ``TOS = TOS1 / TOS``.
Georg Brandl116aa622007-08-15 14:28:22 +0000380
381
Georg Brandl4833e5b2010-07-03 10:41:33 +0000382.. opcode:: BINARY_MODULO
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_ADD
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_SUBTRACT
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_SUBSCR
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_LSHIFT
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_RSHIFT
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_AND
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_XOR
Georg Brandl116aa622007-08-15 14:28:22 +0000418
419 Implements ``TOS = TOS1 ^ TOS``.
420
421
Georg Brandl4833e5b2010-07-03 10:41:33 +0000422.. opcode:: BINARY_OR
Georg Brandl116aa622007-08-15 14:28:22 +0000423
424 Implements ``TOS = TOS1 | TOS``.
425
Georg Brandl4833e5b2010-07-03 10:41:33 +0000426
427**In-place operations**
428
Georg Brandl116aa622007-08-15 14:28:22 +0000429In-place operations are like binary operations, in that they remove TOS and
430TOS1, and push the result back on the stack, but the operation is done in-place
431when TOS1 supports it, and the resulting TOS may be (but does not have to be)
432the original TOS1.
433
Georg Brandl4833e5b2010-07-03 10:41:33 +0000434.. opcode:: INPLACE_POWER
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_MULTIPLY
Georg Brandl116aa622007-08-15 14:28:22 +0000440
441 Implements in-place ``TOS = TOS1 * TOS``.
442
443
Benjamin Petersond51374e2014-04-09 23:55:56 -0400444.. opcode:: INPLACE_MATRIX_MULTIPLY
445
446 Implements in-place ``TOS = TOS1 @ TOS``.
447
448
Georg Brandl4833e5b2010-07-03 10:41:33 +0000449.. opcode:: INPLACE_FLOOR_DIVIDE
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_TRUE_DIVIDE
Georg Brandl116aa622007-08-15 14:28:22 +0000455
Ezio Melotti7de0a6e2010-01-05 08:37:27 +0000456 Implements in-place ``TOS = TOS1 / TOS``.
Georg Brandl116aa622007-08-15 14:28:22 +0000457
458
Georg Brandl4833e5b2010-07-03 10:41:33 +0000459.. opcode:: INPLACE_MODULO
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_ADD
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_SUBTRACT
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_LSHIFT
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_RSHIFT
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_AND
Georg Brandl116aa622007-08-15 14:28:22 +0000485
486 Implements in-place ``TOS = TOS1 & TOS``.
487
488
Georg Brandl4833e5b2010-07-03 10:41:33 +0000489.. opcode:: INPLACE_XOR
Georg Brandl116aa622007-08-15 14:28:22 +0000490
491 Implements in-place ``TOS = TOS1 ^ TOS``.
492
493
Georg Brandl4833e5b2010-07-03 10:41:33 +0000494.. opcode:: INPLACE_OR
Georg Brandl116aa622007-08-15 14:28:22 +0000495
496 Implements in-place ``TOS = TOS1 | TOS``.
497
Georg Brandl116aa622007-08-15 14:28:22 +0000498
Georg Brandl4833e5b2010-07-03 10:41:33 +0000499.. opcode:: STORE_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000500
501 Implements ``TOS1[TOS] = TOS2``.
502
503
Georg Brandl4833e5b2010-07-03 10:41:33 +0000504.. opcode:: DELETE_SUBSCR
Georg Brandl116aa622007-08-15 14:28:22 +0000505
506 Implements ``del TOS1[TOS]``.
507
Georg Brandl116aa622007-08-15 14:28:22 +0000508
Georg Brandl4833e5b2010-07-03 10:41:33 +0000509**Miscellaneous opcodes**
Georg Brandl116aa622007-08-15 14:28:22 +0000510
Georg Brandl4833e5b2010-07-03 10:41:33 +0000511.. opcode:: PRINT_EXPR
Georg Brandl116aa622007-08-15 14:28:22 +0000512
513 Implements the expression statement for the interactive mode. TOS is removed
514 from the stack and printed. In non-interactive mode, an expression statement is
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200515 terminated with :opcode:`POP_TOP`.
Georg Brandl116aa622007-08-15 14:28:22 +0000516
517
Georg Brandl4833e5b2010-07-03 10:41:33 +0000518.. opcode:: BREAK_LOOP
Georg Brandl116aa622007-08-15 14:28:22 +0000519
520 Terminates a loop due to a :keyword:`break` statement.
521
522
523.. opcode:: CONTINUE_LOOP (target)
524
525 Continues a loop due to a :keyword:`continue` statement. *target* is the
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200526 address to jump to (which should be a :opcode:`FOR_ITER` instruction).
Georg Brandl116aa622007-08-15 14:28:22 +0000527
528
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000529.. opcode:: SET_ADD (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000530
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000531 Calls ``set.add(TOS1[-i], TOS)``. Used to implement set comprehensions.
Georg Brandl116aa622007-08-15 14:28:22 +0000532
533
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000534.. opcode:: LIST_APPEND (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000535
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000536 Calls ``list.append(TOS[-i], TOS)``. Used to implement list comprehensions.
537
538
539.. opcode:: MAP_ADD (i)
540
541 Calls ``dict.setitem(TOS1[-i], TOS, TOS1)``. Used to implement dict
542 comprehensions.
543
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200544For all of the :opcode:`SET_ADD`, :opcode:`LIST_APPEND` and :opcode:`MAP_ADD`
545instructions, while the
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000546added value or key/value pair is popped off, the container object remains on
547the stack so that it is available for further iterations of the loop.
Georg Brandl116aa622007-08-15 14:28:22 +0000548
549
Georg Brandl4833e5b2010-07-03 10:41:33 +0000550.. opcode:: RETURN_VALUE
Georg Brandl116aa622007-08-15 14:28:22 +0000551
552 Returns with TOS to the caller of the function.
553
554
Georg Brandl4833e5b2010-07-03 10:41:33 +0000555.. opcode:: YIELD_VALUE
Georg Brandl116aa622007-08-15 14:28:22 +0000556
Georg Brandl9afde1c2007-11-01 20:32:30 +0000557 Pops ``TOS`` and yields it from a :term:`generator`.
Georg Brandl116aa622007-08-15 14:28:22 +0000558
559
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000560.. opcode:: YIELD_FROM
561
562 Pops ``TOS`` and delegates to it as a subiterator from a :term:`generator`.
563
564 .. versionadded:: 3.3
565
566
Georg Brandl4833e5b2010-07-03 10:41:33 +0000567.. opcode:: IMPORT_STAR
Georg Brandl116aa622007-08-15 14:28:22 +0000568
569 Loads all symbols not starting with ``'_'`` directly from the module TOS to the
570 local namespace. The module is popped after loading all names. This opcode
571 implements ``from module import *``.
572
573
Georg Brandl4833e5b2010-07-03 10:41:33 +0000574.. opcode:: POP_BLOCK
Georg Brandl116aa622007-08-15 14:28:22 +0000575
576 Removes one block from the block stack. Per frame, there is a stack of blocks,
577 denoting nested loops, try statements, and such.
578
579
Georg Brandl4833e5b2010-07-03 10:41:33 +0000580.. opcode:: POP_EXCEPT
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000581
582 Removes one block from the block stack. The popped block must be an exception
583 handler block, as implicitly created when entering an except handler.
584 In addition to popping extraneous values from the frame stack, the
585 last three popped values are used to restore the exception state.
586
587
Georg Brandl4833e5b2010-07-03 10:41:33 +0000588.. opcode:: END_FINALLY
Georg Brandl116aa622007-08-15 14:28:22 +0000589
590 Terminates a :keyword:`finally` clause. The interpreter recalls whether the
591 exception has to be re-raised, or whether the function returns, and continues
592 with the outer-next block.
593
594
Georg Brandl4833e5b2010-07-03 10:41:33 +0000595.. opcode:: LOAD_BUILD_CLASS
Georg Brandl116aa622007-08-15 14:28:22 +0000596
Georg Brandl5ac22302008-07-20 21:39:03 +0000597 Pushes :func:`builtins.__build_class__` onto the stack. It is later called
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200598 by :opcode:`CALL_FUNCTION` to construct a class.
Georg Brandl116aa622007-08-15 14:28:22 +0000599
Guido van Rossum04110fb2007-08-24 16:32:05 +0000600
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000601.. opcode:: SETUP_WITH (delta)
602
603 This opcode performs several operations before a with block starts. First,
604 it loads :meth:`~object.__exit__` from the context manager and pushes it onto
605 the stack for later use by :opcode:`WITH_CLEANUP`. Then,
606 :meth:`~object.__enter__` is called, and a finally block pointing to *delta*
607 is pushed. Finally, the result of calling the enter method is pushed onto
608 the stack. The next opcode will either ignore it (:opcode:`POP_TOP`), or
609 store it in (a) variable(s) (:opcode:`STORE_FAST`, :opcode:`STORE_NAME`, or
610 :opcode:`UNPACK_SEQUENCE`).
611
612
Georg Brandl4833e5b2010-07-03 10:41:33 +0000613.. opcode:: WITH_CLEANUP
Guido van Rossum04110fb2007-08-24 16:32:05 +0000614
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000615 Cleans up the stack when a :keyword:`with` statement block exits. TOS is
616 the context manager's :meth:`__exit__` bound method. Below TOS are 1--3
617 values indicating how/why the finally clause was entered:
Guido van Rossum04110fb2007-08-24 16:32:05 +0000618
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000619 * SECOND = ``None``
620 * (SECOND, THIRD) = (``WHY_{RETURN,CONTINUE}``), retval
621 * SECOND = ``WHY_*``; no retval below it
622 * (SECOND, THIRD, FOURTH) = exc_info()
Guido van Rossum04110fb2007-08-24 16:32:05 +0000623
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000624 In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise
625 ``TOS(None, None, None)``. In addition, TOS is removed from the stack.
Guido van Rossum04110fb2007-08-24 16:32:05 +0000626
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000627 If the stack represents an exception, *and* the function call returns
628 a 'true' value, this information is "zapped" and replaced with a single
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200629 ``WHY_SILENCED`` to prevent :opcode:`END_FINALLY` from re-raising the exception.
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000630 (But non-local gotos will still be resumed.)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000631
Georg Brandl9afde1c2007-11-01 20:32:30 +0000632 .. XXX explain the WHY stuff!
633
Guido van Rossum04110fb2007-08-24 16:32:05 +0000634
Georg Brandl116aa622007-08-15 14:28:22 +0000635All of the following opcodes expect arguments. An argument is two bytes, with
636the more significant byte last.
637
Georg Brandl116aa622007-08-15 14:28:22 +0000638.. opcode:: STORE_NAME (namei)
639
640 Implements ``name = TOS``. *namei* is the index of *name* in the attribute
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200641 :attr:`co_names` of the code object. The compiler tries to use :opcode:`STORE_FAST`
642 or :opcode:`STORE_GLOBAL` if possible.
Georg Brandl116aa622007-08-15 14:28:22 +0000643
644
645.. opcode:: DELETE_NAME (namei)
646
647 Implements ``del name``, where *namei* is the index into :attr:`co_names`
648 attribute of the code object.
649
650
651.. opcode:: UNPACK_SEQUENCE (count)
652
653 Unpacks TOS into *count* individual values, which are put onto the stack
654 right-to-left.
655
Georg Brandl116aa622007-08-15 14:28:22 +0000656
Georg Brandl5ac22302008-07-20 21:39:03 +0000657.. opcode:: UNPACK_EX (counts)
658
659 Implements assignment with a starred target: Unpacks an iterable in TOS into
660 individual values, where the total number of values can be smaller than the
661 number of items in the iterable: one the new values will be a list of all
662 leftover items.
663
664 The low byte of *counts* is the number of values before the list value, the
665 high byte of *counts* the number of values after it. The resulting values
666 are put onto the stack right-to-left.
Georg Brandl48310cd2009-01-03 21:18:54 +0000667
Georg Brandl5ac22302008-07-20 21:39:03 +0000668
Georg Brandl116aa622007-08-15 14:28:22 +0000669.. opcode:: STORE_ATTR (namei)
670
671 Implements ``TOS.name = TOS1``, where *namei* is the index of name in
672 :attr:`co_names`.
673
674
675.. opcode:: DELETE_ATTR (namei)
676
677 Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`.
678
679
680.. opcode:: STORE_GLOBAL (namei)
681
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200682 Works as :opcode:`STORE_NAME`, but stores the name as a global.
Georg Brandl116aa622007-08-15 14:28:22 +0000683
684
685.. opcode:: DELETE_GLOBAL (namei)
686
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200687 Works as :opcode:`DELETE_NAME`, but deletes a global name.
Georg Brandl116aa622007-08-15 14:28:22 +0000688
Georg Brandl116aa622007-08-15 14:28:22 +0000689
690.. opcode:: LOAD_CONST (consti)
691
692 Pushes ``co_consts[consti]`` onto the stack.
693
694
695.. opcode:: LOAD_NAME (namei)
696
697 Pushes the value associated with ``co_names[namei]`` onto the stack.
698
699
700.. opcode:: BUILD_TUPLE (count)
701
702 Creates a tuple consuming *count* items from the stack, and pushes the resulting
703 tuple onto the stack.
704
705
706.. opcode:: BUILD_LIST (count)
707
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200708 Works as :opcode:`BUILD_TUPLE`, but creates a list.
Georg Brandl116aa622007-08-15 14:28:22 +0000709
710
711.. opcode:: BUILD_SET (count)
712
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200713 Works as :opcode:`BUILD_TUPLE`, but creates a set.
Georg Brandl116aa622007-08-15 14:28:22 +0000714
715
Christian Heimesa62da1d2008-01-12 19:39:10 +0000716.. opcode:: BUILD_MAP (count)
Georg Brandl116aa622007-08-15 14:28:22 +0000717
Christian Heimesa62da1d2008-01-12 19:39:10 +0000718 Pushes a new dictionary object onto the stack. The dictionary is pre-sized
719 to hold *count* entries.
Georg Brandl116aa622007-08-15 14:28:22 +0000720
721
722.. opcode:: LOAD_ATTR (namei)
723
724 Replaces TOS with ``getattr(TOS, co_names[namei])``.
725
726
727.. opcode:: COMPARE_OP (opname)
728
729 Performs a Boolean operation. The operation name can be found in
730 ``cmp_op[opname]``.
731
732
733.. opcode:: IMPORT_NAME (namei)
734
Christian Heimesa342c012008-04-20 21:01:16 +0000735 Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide
736 the *fromlist* and *level* arguments of :func:`__import__`. The module
737 object is pushed onto the stack. The current namespace is not affected:
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200738 for a proper import statement, a subsequent :opcode:`STORE_FAST` instruction
Christian Heimesa342c012008-04-20 21:01:16 +0000739 modifies the namespace.
Georg Brandl116aa622007-08-15 14:28:22 +0000740
741
742.. opcode:: IMPORT_FROM (namei)
743
744 Loads the attribute ``co_names[namei]`` from the module found in TOS. The
745 resulting object is pushed onto the stack, to be subsequently stored by a
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200746 :opcode:`STORE_FAST` instruction.
Georg Brandl116aa622007-08-15 14:28:22 +0000747
748
749.. opcode:: JUMP_FORWARD (delta)
750
Georg Brandl9afde1c2007-11-01 20:32:30 +0000751 Increments bytecode counter by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +0000752
753
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000754.. opcode:: POP_JUMP_IF_TRUE (target)
Georg Brandl116aa622007-08-15 14:28:22 +0000755
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000756 If TOS is true, sets the bytecode counter to *target*. TOS is popped.
Georg Brandl116aa622007-08-15 14:28:22 +0000757
758
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000759.. opcode:: POP_JUMP_IF_FALSE (target)
Georg Brandl116aa622007-08-15 14:28:22 +0000760
Jeffrey Yasskin9de7ec72009-02-25 02:25:04 +0000761 If TOS is false, sets the bytecode counter to *target*. TOS is popped.
762
763
764.. opcode:: JUMP_IF_TRUE_OR_POP (target)
765
766 If TOS is true, sets the bytecode counter to *target* and leaves TOS
767 on the stack. Otherwise (TOS is false), TOS is popped.
768
769
770.. opcode:: JUMP_IF_FALSE_OR_POP (target)
771
772 If TOS is false, sets the bytecode counter to *target* and leaves
773 TOS on the stack. Otherwise (TOS is true), TOS is popped.
Georg Brandl116aa622007-08-15 14:28:22 +0000774
775
776.. opcode:: JUMP_ABSOLUTE (target)
777
Georg Brandl9afde1c2007-11-01 20:32:30 +0000778 Set bytecode counter to *target*.
Georg Brandl116aa622007-08-15 14:28:22 +0000779
780
781.. opcode:: FOR_ITER (delta)
782
Ezio Melotti7fa82222012-10-12 13:42:08 +0300783 ``TOS`` is an :term:`iterator`. Call its :meth:`~iterator.__next__` method.
784 If this yields a new value, push it on the stack (leaving the iterator below
785 it). If the iterator indicates it is exhausted ``TOS`` is popped, and the
786 byte code counter is incremented by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +0000787
Georg Brandl116aa622007-08-15 14:28:22 +0000788
789.. opcode:: LOAD_GLOBAL (namei)
790
791 Loads the global named ``co_names[namei]`` onto the stack.
792
Georg Brandl116aa622007-08-15 14:28:22 +0000793
794.. opcode:: SETUP_LOOP (delta)
795
796 Pushes a block for a loop onto the block stack. The block spans from the
797 current instruction with a size of *delta* bytes.
798
799
800.. opcode:: SETUP_EXCEPT (delta)
801
802 Pushes a try block from a try-except clause onto the block stack. *delta* points
803 to the first except block.
804
805
806.. opcode:: SETUP_FINALLY (delta)
807
808 Pushes a try block from a try-except clause onto the block stack. *delta* points
809 to the finally block.
810
Georg Brandl4833e5b2010-07-03 10:41:33 +0000811.. opcode:: STORE_MAP
Christian Heimesa62da1d2008-01-12 19:39:10 +0000812
813 Store a key and value pair in a dictionary. Pops the key and value while leaving
814 the dictionary on the stack.
Georg Brandl116aa622007-08-15 14:28:22 +0000815
816.. opcode:: LOAD_FAST (var_num)
817
818 Pushes a reference to the local ``co_varnames[var_num]`` onto the stack.
819
820
821.. opcode:: STORE_FAST (var_num)
822
823 Stores TOS into the local ``co_varnames[var_num]``.
824
825
826.. opcode:: DELETE_FAST (var_num)
827
828 Deletes local ``co_varnames[var_num]``.
829
830
831.. opcode:: LOAD_CLOSURE (i)
832
833 Pushes a reference to the cell contained in slot *i* of the cell and free
834 variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is
835 less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i -
836 len(co_cellvars)]``.
837
838
839.. opcode:: LOAD_DEREF (i)
840
841 Loads the cell contained in slot *i* of the cell and free variable storage.
842 Pushes a reference to the object the cell contains on the stack.
843
844
Benjamin Peterson3b0431d2013-04-30 09:41:40 -0400845.. opcode:: LOAD_CLASSDEREF (i)
846
847 Much like :opcode:`LOAD_DEREF` but first checks the locals dictionary before
848 consulting the cell. This is used for loading free variables in class
849 bodies.
850
851
Georg Brandl116aa622007-08-15 14:28:22 +0000852.. opcode:: STORE_DEREF (i)
853
854 Stores TOS into the cell contained in slot *i* of the cell and free variable
855 storage.
856
857
Amaury Forgeot d'Arcba117ef2010-09-10 21:39:53 +0000858.. opcode:: DELETE_DEREF (i)
859
860 Empties the cell contained in slot *i* of the cell and free variable storage.
861 Used by the :keyword:`del` statement.
862
863
Georg Brandl116aa622007-08-15 14:28:22 +0000864.. opcode:: RAISE_VARARGS (argc)
865
866 Raises an exception. *argc* indicates the number of parameters to the raise
867 statement, ranging from 0 to 3. The handler will find the traceback as TOS2,
868 the parameter as TOS1, and the exception as TOS.
869
870
871.. opcode:: CALL_FUNCTION (argc)
872
873 Calls a function. The low byte of *argc* indicates the number of positional
874 parameters, the high byte the number of keyword parameters. On the stack, the
875 opcode finds the keyword parameters first. For each keyword argument, the value
876 is on top of the key. Below the keyword parameters, the positional parameters
877 are on the stack, with the right-most parameter on top. Below the parameters,
Georg Brandl48310cd2009-01-03 21:18:54 +0000878 the function object to call is on the stack. Pops all function arguments, and
Benjamin Peterson206e3072008-10-19 14:07:49 +0000879 the function itself off the stack, and pushes the return value.
Georg Brandl116aa622007-08-15 14:28:22 +0000880
881
882.. opcode:: MAKE_FUNCTION (argc)
883
Georg Brandlc96ef1f2013-10-12 18:41:18 +0200884 Pushes a new function object on the stack. From bottom to top, the consumed
885 stack must consist of
886
887 * ``argc & 0xFF`` default argument objects in positional order
888 * ``(argc >> 8) & 0xFF`` pairs of name and default argument, with the name
889 just below the object on the stack, for keyword-only parameters
890 * ``(argc >> 16) & 0x7FFF`` parameter annotation objects
891 * a tuple listing the parameter names for the annotations (only if there are
892 ony annotation objects)
893 * the code associated with the function (at TOS1)
894 * the :term:`qualified name` of the function (at TOS)
Georg Brandl116aa622007-08-15 14:28:22 +0000895
896
897.. opcode:: MAKE_CLOSURE (argc)
898
Guido van Rossum04110fb2007-08-24 16:32:05 +0000899 Creates a new function object, sets its *__closure__* slot, and pushes it on
Andrew Svetlova5c43092012-11-23 15:28:34 +0200900 the stack. TOS is the :term:`qualified name` of the function, TOS1 is the
901 code associated with the function, and TOS2 is the tuple containing cells for
902 the closure's free variables. The function also has *argc* default parameters,
903 which are found below the cells.
Georg Brandl116aa622007-08-15 14:28:22 +0000904
905
906.. opcode:: BUILD_SLICE (argc)
907
908 .. index:: builtin: slice
909
910 Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2,
911 ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000912 pushed. See the :func:`slice` built-in function for more information.
Georg Brandl116aa622007-08-15 14:28:22 +0000913
914
915.. opcode:: EXTENDED_ARG (ext)
916
917 Prefixes any opcode which has an argument too big to fit into the default two
918 bytes. *ext* holds two additional bytes which, taken together with the
919 subsequent opcode's argument, comprise a four-byte argument, *ext* being the two
920 most-significant bytes.
921
922
923.. opcode:: CALL_FUNCTION_VAR (argc)
924
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200925 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The top element
Georg Brandl116aa622007-08-15 14:28:22 +0000926 on the stack contains the variable argument list, followed by keyword and
927 positional arguments.
928
929
930.. opcode:: CALL_FUNCTION_KW (argc)
931
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200932 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The top element
Georg Brandl116aa622007-08-15 14:28:22 +0000933 on the stack contains the keyword arguments dictionary, followed by explicit
934 keyword and positional arguments.
935
936
937.. opcode:: CALL_FUNCTION_VAR_KW (argc)
938
Serhiy Storchakaf751a9e2014-11-11 10:02:11 +0200939 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The top
Georg Brandl116aa622007-08-15 14:28:22 +0000940 element on the stack contains the keyword arguments dictionary, followed by the
941 variable-arguments tuple, followed by explicit keyword and positional arguments.
942
943
Georg Brandl4833e5b2010-07-03 10:41:33 +0000944.. opcode:: HAVE_ARGUMENT
Georg Brandl116aa622007-08-15 14:28:22 +0000945
946 This is not really an opcode. It identifies the dividing line between opcodes
947 which don't take arguments ``< HAVE_ARGUMENT`` and those which do ``>=
948 HAVE_ARGUMENT``.
949
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000950.. _opcode_collections:
951
952Opcode collections
953------------------
954
955These collections are provided for automatic introspection of bytecode
956instructions:
957
958.. data:: opname
959
960 Sequence of operation names, indexable using the bytecode.
961
962
963.. data:: opmap
964
965 Dictionary mapping operation names to bytecodes.
966
967
968.. data:: cmp_op
969
970 Sequence of all compare operation names.
971
972
973.. data:: hasconst
974
975 Sequence of bytecodes that have a constant parameter.
976
977
978.. data:: hasfree
979
980 Sequence of bytecodes that access a free variable (note that 'free' in
981 this context refers to names in the current scope that are referenced by
982 inner scopes or names in outer scopes that are referenced from this scope.
983 It does *not* include references to global or builtin scopes).
984
985
986.. data:: hasname
987
988 Sequence of bytecodes that access an attribute by name.
989
990
991.. data:: hasjrel
992
993 Sequence of bytecodes that have a relative jump target.
994
995
996.. data:: hasjabs
997
998 Sequence of bytecodes that have an absolute jump target.
999
1000
1001.. data:: haslocal
1002
1003 Sequence of bytecodes that access a local variable.
1004
1005
1006.. data:: hascompare
1007
1008 Sequence of bytecodes of Boolean operations.