blob: ab06542b88d9eff2788bffc58ecf7efa535f2949 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
Georg Brandl9afde1c2007-11-01 20:32:30 +00002:mod:`dis` --- Disassembler for Python bytecode
3===============================================
Georg Brandl116aa622007-08-15 14:28:22 +00004
5.. module:: dis
Georg Brandl9afde1c2007-11-01 20:32:30 +00006 :synopsis: Disassembler for Python bytecode.
Georg Brandl116aa622007-08-15 14:28:22 +00007
8
Georg Brandl9afde1c2007-11-01 20:32:30 +00009The :mod:`dis` module supports the analysis of Python :term:`bytecode` by disassembling
Georg Brandl116aa622007-08-15 14:28:22 +000010it. Since there is no Python assembler, this module defines the Python assembly
Georg Brandl9afde1c2007-11-01 20:32:30 +000011language. The Python bytecode which this module takes as an input is defined
Georg Brandl116aa622007-08-15 14:28:22 +000012in the file :file:`Include/opcode.h` and used by the compiler and the
13interpreter.
14
15Example: Given the function :func:`myfunc`::
16
17 def myfunc(alist):
18 return len(alist)
19
20the following command can be used to get the disassembly of :func:`myfunc`::
21
22 >>> dis.dis(myfunc)
23 2 0 LOAD_GLOBAL 0 (len)
24 3 LOAD_FAST 0 (alist)
25 6 CALL_FUNCTION 1
26 9 RETURN_VALUE
27
28(The "2" is a line number).
29
30The :mod:`dis` module defines the following functions and constants:
31
32
33.. function:: dis([bytesource])
34
35 Disassemble the *bytesource* object. *bytesource* can denote either a module, a
36 class, a method, a function, or a code object. For a module, it disassembles
37 all functions. For a class, it disassembles all methods. For a single code
Georg Brandl9afde1c2007-11-01 20:32:30 +000038 sequence, it prints one line per bytecode instruction. If no object is
Georg Brandl116aa622007-08-15 14:28:22 +000039 provided, it disassembles the last traceback.
40
41
42.. function:: distb([tb])
43
44 Disassembles the top-of-stack function of a traceback, using the last traceback
45 if none was passed. The instruction causing the exception is indicated.
46
47
48.. function:: disassemble(code[, lasti])
49
50 Disassembles a code object, indicating the last instruction if *lasti* was
51 provided. The output is divided in the following columns:
52
53 #. the line number, for the first instruction of each line
54 #. the current instruction, indicated as ``-->``,
55 #. a labelled instruction, indicated with ``>>``,
56 #. the address of the instruction,
57 #. the operation code name,
58 #. operation parameters, and
59 #. interpretation of the parameters in parentheses.
60
61 The parameter interpretation recognizes local and global variable names,
62 constant values, branch targets, and compare operators.
63
64
65.. function:: disco(code[, lasti])
66
67 A synonym for disassemble. It is more convenient to type, and kept for
68 compatibility with earlier Python releases.
69
70
71.. data:: opname
72
Georg Brandl9afde1c2007-11-01 20:32:30 +000073 Sequence of operation names, indexable using the bytecode.
Georg Brandl116aa622007-08-15 14:28:22 +000074
75
76.. data:: opmap
77
Georg Brandl9afde1c2007-11-01 20:32:30 +000078 Dictionary mapping bytecodes to operation names.
Georg Brandl116aa622007-08-15 14:28:22 +000079
80
81.. data:: cmp_op
82
83 Sequence of all compare operation names.
84
85
86.. data:: hasconst
87
Georg Brandl9afde1c2007-11-01 20:32:30 +000088 Sequence of bytecodes that have a constant parameter.
Georg Brandl116aa622007-08-15 14:28:22 +000089
90
91.. data:: hasfree
92
Georg Brandl9afde1c2007-11-01 20:32:30 +000093 Sequence of bytecodes that access a free variable.
Georg Brandl116aa622007-08-15 14:28:22 +000094
95
96.. data:: hasname
97
Georg Brandl9afde1c2007-11-01 20:32:30 +000098 Sequence of bytecodes that access an attribute by name.
Georg Brandl116aa622007-08-15 14:28:22 +000099
100
101.. data:: hasjrel
102
Georg Brandl9afde1c2007-11-01 20:32:30 +0000103 Sequence of bytecodes that have a relative jump target.
Georg Brandl116aa622007-08-15 14:28:22 +0000104
105
106.. data:: hasjabs
107
Georg Brandl9afde1c2007-11-01 20:32:30 +0000108 Sequence of bytecodes that have an absolute jump target.
Georg Brandl116aa622007-08-15 14:28:22 +0000109
110
111.. data:: haslocal
112
Georg Brandl9afde1c2007-11-01 20:32:30 +0000113 Sequence of bytecodes that access a local variable.
Georg Brandl116aa622007-08-15 14:28:22 +0000114
115
116.. data:: hascompare
117
Georg Brandl9afde1c2007-11-01 20:32:30 +0000118 Sequence of bytecodes of Boolean operations.
Georg Brandl116aa622007-08-15 14:28:22 +0000119
120
121.. _bytecodes:
122
Georg Brandl9afde1c2007-11-01 20:32:30 +0000123Python Bytecode Instructions
124----------------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000125
Georg Brandl9afde1c2007-11-01 20:32:30 +0000126The Python compiler currently generates the following bytecode instructions.
Georg Brandl116aa622007-08-15 14:28:22 +0000127
128
129.. opcode:: STOP_CODE ()
130
131 Indicates end-of-code to the compiler, not used by the interpreter.
132
133
134.. opcode:: NOP ()
135
136 Do nothing code. Used as a placeholder by the bytecode optimizer.
137
138
139.. opcode:: POP_TOP ()
140
141 Removes the top-of-stack (TOS) item.
142
143
144.. opcode:: ROT_TWO ()
145
146 Swaps the two top-most stack items.
147
148
149.. opcode:: ROT_THREE ()
150
151 Lifts second and third stack item one position up, moves top down to position
152 three.
153
154
155.. opcode:: ROT_FOUR ()
156
157 Lifts second, third and forth stack item one position up, moves top down to
158 position four.
159
160
161.. opcode:: DUP_TOP ()
162
163 Duplicates the reference on top of the stack.
164
165Unary Operations take the top of the stack, apply the operation, and push the
166result back on the stack.
167
168
169.. opcode:: UNARY_POSITIVE ()
170
171 Implements ``TOS = +TOS``.
172
173
174.. opcode:: UNARY_NEGATIVE ()
175
176 Implements ``TOS = -TOS``.
177
178
179.. opcode:: UNARY_NOT ()
180
181 Implements ``TOS = not TOS``.
182
183
184.. opcode:: UNARY_INVERT ()
185
186 Implements ``TOS = ~TOS``.
187
188
189.. opcode:: GET_ITER ()
190
191 Implements ``TOS = iter(TOS)``.
192
193Binary operations remove the top of the stack (TOS) and the second top-most
194stack item (TOS1) from the stack. They perform the operation, and put the
195result back on the stack.
196
197
198.. opcode:: BINARY_POWER ()
199
200 Implements ``TOS = TOS1 ** TOS``.
201
202
203.. opcode:: BINARY_MULTIPLY ()
204
205 Implements ``TOS = TOS1 * TOS``.
206
207
208.. opcode:: BINARY_FLOOR_DIVIDE ()
209
210 Implements ``TOS = TOS1 // TOS``.
211
212
213.. opcode:: BINARY_TRUE_DIVIDE ()
214
215 Implements ``TOS = TOS1 / TOS`` when ``from __future__ import division`` is in
216 effect.
217
218
219.. opcode:: BINARY_MODULO ()
220
221 Implements ``TOS = TOS1 % TOS``.
222
223
224.. opcode:: BINARY_ADD ()
225
226 Implements ``TOS = TOS1 + TOS``.
227
228
229.. opcode:: BINARY_SUBTRACT ()
230
231 Implements ``TOS = TOS1 - TOS``.
232
233
234.. opcode:: BINARY_SUBSCR ()
235
236 Implements ``TOS = TOS1[TOS]``.
237
238
239.. opcode:: BINARY_LSHIFT ()
240
241 Implements ``TOS = TOS1 << TOS``.
242
243
244.. opcode:: BINARY_RSHIFT ()
245
246 Implements ``TOS = TOS1 >> TOS``.
247
248
249.. opcode:: BINARY_AND ()
250
251 Implements ``TOS = TOS1 & TOS``.
252
253
254.. opcode:: BINARY_XOR ()
255
256 Implements ``TOS = TOS1 ^ TOS``.
257
258
259.. opcode:: BINARY_OR ()
260
261 Implements ``TOS = TOS1 | TOS``.
262
263In-place operations are like binary operations, in that they remove TOS and
264TOS1, and push the result back on the stack, but the operation is done in-place
265when TOS1 supports it, and the resulting TOS may be (but does not have to be)
266the original TOS1.
267
268
269.. opcode:: INPLACE_POWER ()
270
271 Implements in-place ``TOS = TOS1 ** TOS``.
272
273
274.. opcode:: INPLACE_MULTIPLY ()
275
276 Implements in-place ``TOS = TOS1 * TOS``.
277
278
279.. opcode:: INPLACE_FLOOR_DIVIDE ()
280
281 Implements in-place ``TOS = TOS1 // TOS``.
282
283
284.. opcode:: INPLACE_TRUE_DIVIDE ()
285
286 Implements in-place ``TOS = TOS1 / TOS`` when ``from __future__ import
287 division`` is in effect.
288
289
290.. opcode:: INPLACE_MODULO ()
291
292 Implements in-place ``TOS = TOS1 % TOS``.
293
294
295.. opcode:: INPLACE_ADD ()
296
297 Implements in-place ``TOS = TOS1 + TOS``.
298
299
300.. opcode:: INPLACE_SUBTRACT ()
301
302 Implements in-place ``TOS = TOS1 - TOS``.
303
304
305.. opcode:: INPLACE_LSHIFT ()
306
307 Implements in-place ``TOS = TOS1 << TOS``.
308
309
310.. opcode:: INPLACE_RSHIFT ()
311
312 Implements in-place ``TOS = TOS1 >> TOS``.
313
314
315.. opcode:: INPLACE_AND ()
316
317 Implements in-place ``TOS = TOS1 & TOS``.
318
319
320.. opcode:: INPLACE_XOR ()
321
322 Implements in-place ``TOS = TOS1 ^ TOS``.
323
324
325.. opcode:: INPLACE_OR ()
326
327 Implements in-place ``TOS = TOS1 | TOS``.
328
Georg Brandl116aa622007-08-15 14:28:22 +0000329
330.. opcode:: STORE_SUBSCR ()
331
332 Implements ``TOS1[TOS] = TOS2``.
333
334
335.. opcode:: DELETE_SUBSCR ()
336
337 Implements ``del TOS1[TOS]``.
338
339Miscellaneous opcodes.
340
341
342.. opcode:: PRINT_EXPR ()
343
344 Implements the expression statement for the interactive mode. TOS is removed
345 from the stack and printed. In non-interactive mode, an expression statement is
346 terminated with ``POP_STACK``.
347
348
349.. opcode:: BREAK_LOOP ()
350
351 Terminates a loop due to a :keyword:`break` statement.
352
353
354.. opcode:: CONTINUE_LOOP (target)
355
356 Continues a loop due to a :keyword:`continue` statement. *target* is the
357 address to jump to (which should be a ``FOR_ITER`` instruction).
358
359
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000360.. opcode:: SET_ADD (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000361
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000362 Calls ``set.add(TOS1[-i], TOS)``. Used to implement set comprehensions.
Georg Brandl116aa622007-08-15 14:28:22 +0000363
364
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000365.. opcode:: LIST_APPEND (i)
Georg Brandl116aa622007-08-15 14:28:22 +0000366
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000367 Calls ``list.append(TOS[-i], TOS)``. Used to implement list comprehensions.
368
369
370.. opcode:: MAP_ADD (i)
371
372 Calls ``dict.setitem(TOS1[-i], TOS, TOS1)``. Used to implement dict
373 comprehensions.
374
375
376For all of the SET_ADD, LIST_APPEND and MAP_ADD instructions, while the
377added value or key/value pair is popped off, the container object remains on
378the stack so that it is available for further iterations of the loop.
Georg Brandl116aa622007-08-15 14:28:22 +0000379
380
381.. opcode:: LOAD_LOCALS ()
382
383 Pushes a reference to the locals of the current scope on the stack. This is used
384 in the code for a class definition: After the class body is evaluated, the
385 locals are passed to the class definition.
386
387
388.. opcode:: RETURN_VALUE ()
389
390 Returns with TOS to the caller of the function.
391
392
393.. opcode:: YIELD_VALUE ()
394
Georg Brandl9afde1c2007-11-01 20:32:30 +0000395 Pops ``TOS`` and yields it from a :term:`generator`.
Georg Brandl116aa622007-08-15 14:28:22 +0000396
397
398.. opcode:: IMPORT_STAR ()
399
400 Loads all symbols not starting with ``'_'`` directly from the module TOS to the
401 local namespace. The module is popped after loading all names. This opcode
402 implements ``from module import *``.
403
404
405.. opcode:: POP_BLOCK ()
406
407 Removes one block from the block stack. Per frame, there is a stack of blocks,
408 denoting nested loops, try statements, and such.
409
410
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000411.. opcode:: POP_EXCEPT ()
412
413 Removes one block from the block stack. The popped block must be an exception
414 handler block, as implicitly created when entering an except handler.
415 In addition to popping extraneous values from the frame stack, the
416 last three popped values are used to restore the exception state.
417
418
Georg Brandl116aa622007-08-15 14:28:22 +0000419.. opcode:: END_FINALLY ()
420
421 Terminates a :keyword:`finally` clause. The interpreter recalls whether the
422 exception has to be re-raised, or whether the function returns, and continues
423 with the outer-next block.
424
425
Benjamin Peterson69164c72008-07-03 14:45:20 +0000426.. opcode:: LOAD_BUILD_CLASS ()
Georg Brandl116aa622007-08-15 14:28:22 +0000427
Georg Brandl5ac22302008-07-20 21:39:03 +0000428 Pushes :func:`builtins.__build_class__` onto the stack. It is later called
Benjamin Petersonaac8fd32008-07-20 22:02:26 +0000429 by ``CALL_FUNCTION`` to construct a class.
Georg Brandl116aa622007-08-15 14:28:22 +0000430
Guido van Rossum04110fb2007-08-24 16:32:05 +0000431
432.. opcode:: WITH_CLEANUP ()
433
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000434 Cleans up the stack when a :keyword:`with` statement block exits. TOS is
435 the context manager's :meth:`__exit__` bound method. Below TOS are 1--3
436 values indicating how/why the finally clause was entered:
Guido van Rossum04110fb2007-08-24 16:32:05 +0000437
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000438 * SECOND = ``None``
439 * (SECOND, THIRD) = (``WHY_{RETURN,CONTINUE}``), retval
440 * SECOND = ``WHY_*``; no retval below it
441 * (SECOND, THIRD, FOURTH) = exc_info()
Guido van Rossum04110fb2007-08-24 16:32:05 +0000442
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000443 In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise
444 ``TOS(None, None, None)``. In addition, TOS is removed from the stack.
Guido van Rossum04110fb2007-08-24 16:32:05 +0000445
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000446 If the stack represents an exception, *and* the function call returns
447 a 'true' value, this information is "zapped" and replaced with a single
448 ``WHY_SILENCED`` to prevent ``END_FINALLY`` from re-raising the exception.
449 (But non-local gotos will still be resumed.)
Guido van Rossum04110fb2007-08-24 16:32:05 +0000450
Georg Brandl9afde1c2007-11-01 20:32:30 +0000451 .. XXX explain the WHY stuff!
452
Guido van Rossum04110fb2007-08-24 16:32:05 +0000453
Georg Brandl5ac22302008-07-20 21:39:03 +0000454.. opcode:: STORE_LOCALS
455
456 Pops TOS from the stack and stores it as the current frame's ``f_locals``.
457 This is used in class construction.
458
459
Georg Brandl116aa622007-08-15 14:28:22 +0000460All of the following opcodes expect arguments. An argument is two bytes, with
461the more significant byte last.
462
Georg Brandl116aa622007-08-15 14:28:22 +0000463.. opcode:: STORE_NAME (namei)
464
465 Implements ``name = TOS``. *namei* is the index of *name* in the attribute
Christian Heimes8640e742008-02-23 16:23:06 +0000466 :attr:`co_names` of the code object. The compiler tries to use ``STORE_FAST``
Georg Brandl116aa622007-08-15 14:28:22 +0000467 or ``STORE_GLOBAL`` if possible.
468
469
470.. opcode:: DELETE_NAME (namei)
471
472 Implements ``del name``, where *namei* is the index into :attr:`co_names`
473 attribute of the code object.
474
475
476.. opcode:: UNPACK_SEQUENCE (count)
477
478 Unpacks TOS into *count* individual values, which are put onto the stack
479 right-to-left.
480
Georg Brandl116aa622007-08-15 14:28:22 +0000481
Georg Brandl5ac22302008-07-20 21:39:03 +0000482.. opcode:: UNPACK_EX (counts)
483
484 Implements assignment with a starred target: Unpacks an iterable in TOS into
485 individual values, where the total number of values can be smaller than the
486 number of items in the iterable: one the new values will be a list of all
487 leftover items.
488
489 The low byte of *counts* is the number of values before the list value, the
490 high byte of *counts* the number of values after it. The resulting values
491 are put onto the stack right-to-left.
492
493
Georg Brandl116aa622007-08-15 14:28:22 +0000494.. opcode:: DUP_TOPX (count)
495
496 Duplicate *count* items, keeping them in the same order. Due to implementation
497 limits, *count* should be between 1 and 5 inclusive.
498
499
500.. opcode:: STORE_ATTR (namei)
501
502 Implements ``TOS.name = TOS1``, where *namei* is the index of name in
503 :attr:`co_names`.
504
505
506.. opcode:: DELETE_ATTR (namei)
507
508 Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`.
509
510
511.. opcode:: STORE_GLOBAL (namei)
512
513 Works as ``STORE_NAME``, but stores the name as a global.
514
515
516.. opcode:: DELETE_GLOBAL (namei)
517
518 Works as ``DELETE_NAME``, but deletes a global name.
519
Georg Brandl116aa622007-08-15 14:28:22 +0000520
521.. opcode:: LOAD_CONST (consti)
522
523 Pushes ``co_consts[consti]`` onto the stack.
524
525
526.. opcode:: LOAD_NAME (namei)
527
528 Pushes the value associated with ``co_names[namei]`` onto the stack.
529
530
531.. opcode:: BUILD_TUPLE (count)
532
533 Creates a tuple consuming *count* items from the stack, and pushes the resulting
534 tuple onto the stack.
535
536
537.. opcode:: BUILD_LIST (count)
538
539 Works as ``BUILD_TUPLE``, but creates a list.
540
541
542.. opcode:: BUILD_SET (count)
543
544 Works as ``BUILD_TUPLE``, but creates a set.
545
546
Christian Heimesa62da1d2008-01-12 19:39:10 +0000547.. opcode:: BUILD_MAP (count)
Georg Brandl116aa622007-08-15 14:28:22 +0000548
Christian Heimesa62da1d2008-01-12 19:39:10 +0000549 Pushes a new dictionary object onto the stack. The dictionary is pre-sized
550 to hold *count* entries.
Georg Brandl116aa622007-08-15 14:28:22 +0000551
552
553.. opcode:: LOAD_ATTR (namei)
554
555 Replaces TOS with ``getattr(TOS, co_names[namei])``.
556
557
558.. opcode:: COMPARE_OP (opname)
559
560 Performs a Boolean operation. The operation name can be found in
561 ``cmp_op[opname]``.
562
563
564.. opcode:: IMPORT_NAME (namei)
565
Christian Heimesa342c012008-04-20 21:01:16 +0000566 Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide
567 the *fromlist* and *level* arguments of :func:`__import__`. The module
568 object is pushed onto the stack. The current namespace is not affected:
569 for a proper import statement, a subsequent ``STORE_FAST`` instruction
570 modifies the namespace.
Georg Brandl116aa622007-08-15 14:28:22 +0000571
572
573.. opcode:: IMPORT_FROM (namei)
574
575 Loads the attribute ``co_names[namei]`` from the module found in TOS. The
576 resulting object is pushed onto the stack, to be subsequently stored by a
577 ``STORE_FAST`` instruction.
578
579
580.. opcode:: JUMP_FORWARD (delta)
581
Georg Brandl9afde1c2007-11-01 20:32:30 +0000582 Increments bytecode counter by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +0000583
584
585.. opcode:: JUMP_IF_TRUE (delta)
586
Georg Brandl9afde1c2007-11-01 20:32:30 +0000587 If TOS is true, increment the bytecode counter by *delta*. TOS is left on the
Georg Brandl116aa622007-08-15 14:28:22 +0000588 stack.
589
590
591.. opcode:: JUMP_IF_FALSE (delta)
592
Georg Brandl9afde1c2007-11-01 20:32:30 +0000593 If TOS is false, increment the bytecode counter by *delta*. TOS is not
Georg Brandl116aa622007-08-15 14:28:22 +0000594 changed.
595
596
597.. opcode:: JUMP_ABSOLUTE (target)
598
Georg Brandl9afde1c2007-11-01 20:32:30 +0000599 Set bytecode counter to *target*.
Georg Brandl116aa622007-08-15 14:28:22 +0000600
601
602.. opcode:: FOR_ITER (delta)
603
Georg Brandl9afde1c2007-11-01 20:32:30 +0000604 ``TOS`` is an :term:`iterator`. Call its :meth:`__next__` method. If this
605 yields a new value, push it on the stack (leaving the iterator below it). If
606 the iterator indicates it is exhausted ``TOS`` is popped, and the byte code
607 counter is incremented by *delta*.
Georg Brandl116aa622007-08-15 14:28:22 +0000608
Georg Brandl116aa622007-08-15 14:28:22 +0000609
610.. opcode:: LOAD_GLOBAL (namei)
611
612 Loads the global named ``co_names[namei]`` onto the stack.
613
Georg Brandl116aa622007-08-15 14:28:22 +0000614
615.. opcode:: SETUP_LOOP (delta)
616
617 Pushes a block for a loop onto the block stack. The block spans from the
618 current instruction with a size of *delta* bytes.
619
620
621.. opcode:: SETUP_EXCEPT (delta)
622
623 Pushes a try block from a try-except clause onto the block stack. *delta* points
624 to the first except block.
625
626
627.. opcode:: SETUP_FINALLY (delta)
628
629 Pushes a try block from a try-except clause onto the block stack. *delta* points
630 to the finally block.
631
Christian Heimesa62da1d2008-01-12 19:39:10 +0000632.. opcode:: STORE_MAP ()
633
634 Store a key and value pair in a dictionary. Pops the key and value while leaving
635 the dictionary on the stack.
Georg Brandl116aa622007-08-15 14:28:22 +0000636
637.. opcode:: LOAD_FAST (var_num)
638
639 Pushes a reference to the local ``co_varnames[var_num]`` onto the stack.
640
641
642.. opcode:: STORE_FAST (var_num)
643
644 Stores TOS into the local ``co_varnames[var_num]``.
645
646
647.. opcode:: DELETE_FAST (var_num)
648
649 Deletes local ``co_varnames[var_num]``.
650
651
652.. opcode:: LOAD_CLOSURE (i)
653
654 Pushes a reference to the cell contained in slot *i* of the cell and free
655 variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is
656 less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i -
657 len(co_cellvars)]``.
658
659
660.. opcode:: LOAD_DEREF (i)
661
662 Loads the cell contained in slot *i* of the cell and free variable storage.
663 Pushes a reference to the object the cell contains on the stack.
664
665
666.. opcode:: STORE_DEREF (i)
667
668 Stores TOS into the cell contained in slot *i* of the cell and free variable
669 storage.
670
671
672.. opcode:: SET_LINENO (lineno)
673
674 This opcode is obsolete.
675
676
677.. opcode:: RAISE_VARARGS (argc)
678
679 Raises an exception. *argc* indicates the number of parameters to the raise
680 statement, ranging from 0 to 3. The handler will find the traceback as TOS2,
681 the parameter as TOS1, and the exception as TOS.
682
683
684.. opcode:: CALL_FUNCTION (argc)
685
686 Calls a function. The low byte of *argc* indicates the number of positional
687 parameters, the high byte the number of keyword parameters. On the stack, the
688 opcode finds the keyword parameters first. For each keyword argument, the value
689 is on top of the key. Below the keyword parameters, the positional parameters
690 are on the stack, with the right-most parameter on top. Below the parameters,
Benjamin Peterson206e3072008-10-19 14:07:49 +0000691 the function object to call is on the stack. Pops all function arguments, and
692 the function itself off the stack, and pushes the return value.
Georg Brandl116aa622007-08-15 14:28:22 +0000693
694
695.. opcode:: MAKE_FUNCTION (argc)
696
697 Pushes a new function object on the stack. TOS is the code associated with the
698 function. The function object is defined to have *argc* default parameters,
699 which are found below TOS.
700
701
702.. opcode:: MAKE_CLOSURE (argc)
703
Guido van Rossum04110fb2007-08-24 16:32:05 +0000704 Creates a new function object, sets its *__closure__* slot, and pushes it on
705 the stack. TOS is the code associated with the function, TOS1 the tuple
706 containing cells for the closure's free variables. The function also has
707 *argc* default parameters, which are found below the cells.
Georg Brandl116aa622007-08-15 14:28:22 +0000708
709
710.. opcode:: BUILD_SLICE (argc)
711
712 .. index:: builtin: slice
713
714 Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2,
715 ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000716 pushed. See the :func:`slice` built-in function for more information.
Georg Brandl116aa622007-08-15 14:28:22 +0000717
718
719.. opcode:: EXTENDED_ARG (ext)
720
721 Prefixes any opcode which has an argument too big to fit into the default two
722 bytes. *ext* holds two additional bytes which, taken together with the
723 subsequent opcode's argument, comprise a four-byte argument, *ext* being the two
724 most-significant bytes.
725
726
727.. opcode:: CALL_FUNCTION_VAR (argc)
728
729 Calls a function. *argc* is interpreted as in ``CALL_FUNCTION``. The top element
730 on the stack contains the variable argument list, followed by keyword and
731 positional arguments.
732
733
734.. opcode:: CALL_FUNCTION_KW (argc)
735
736 Calls a function. *argc* is interpreted as in ``CALL_FUNCTION``. The top element
737 on the stack contains the keyword arguments dictionary, followed by explicit
738 keyword and positional arguments.
739
740
741.. opcode:: CALL_FUNCTION_VAR_KW (argc)
742
743 Calls a function. *argc* is interpreted as in ``CALL_FUNCTION``. The top
744 element on the stack contains the keyword arguments dictionary, followed by the
745 variable-arguments tuple, followed by explicit keyword and positional arguments.
746
747
748.. opcode:: HAVE_ARGUMENT ()
749
750 This is not really an opcode. It identifies the dividing line between opcodes
751 which don't take arguments ``< HAVE_ARGUMENT`` and those which do ``>=
752 HAVE_ARGUMENT``.
753