|
1 |
|
2 :mod:`dis` --- Disassembler for Python bytecode |
|
3 =============================================== |
|
4 |
|
5 .. module:: dis |
|
6 :synopsis: Disassembler for Python bytecode. |
|
7 |
|
8 |
|
9 The :mod:`dis` module supports the analysis of Python :term:`bytecode` by disassembling |
|
10 it. Since there is no Python assembler, this module defines the Python assembly |
|
11 language. The Python bytecode which this module takes as an input is defined |
|
12 in the file :file:`Include/opcode.h` and used by the compiler and the |
|
13 interpreter. |
|
14 |
|
15 Example: Given the function :func:`myfunc`:: |
|
16 |
|
17 def myfunc(alist): |
|
18 return len(alist) |
|
19 |
|
20 the 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 |
|
30 The :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 |
|
38 sequence, it prints one line per bytecode instruction. If no object is |
|
39 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 |
|
73 Sequence of operation names, indexable using the bytecode. |
|
74 |
|
75 |
|
76 .. data:: opmap |
|
77 |
|
78 Dictionary mapping bytecodes to operation names. |
|
79 |
|
80 |
|
81 .. data:: cmp_op |
|
82 |
|
83 Sequence of all compare operation names. |
|
84 |
|
85 |
|
86 .. data:: hasconst |
|
87 |
|
88 Sequence of bytecodes that have a constant parameter. |
|
89 |
|
90 |
|
91 .. data:: hasfree |
|
92 |
|
93 Sequence of bytecodes that access a free variable. |
|
94 |
|
95 |
|
96 .. data:: hasname |
|
97 |
|
98 Sequence of bytecodes that access an attribute by name. |
|
99 |
|
100 |
|
101 .. data:: hasjrel |
|
102 |
|
103 Sequence of bytecodes that have a relative jump target. |
|
104 |
|
105 |
|
106 .. data:: hasjabs |
|
107 |
|
108 Sequence of bytecodes that have an absolute jump target. |
|
109 |
|
110 |
|
111 .. data:: haslocal |
|
112 |
|
113 Sequence of bytecodes that access a local variable. |
|
114 |
|
115 |
|
116 .. data:: hascompare |
|
117 |
|
118 Sequence of bytecodes of Boolean operations. |
|
119 |
|
120 |
|
121 .. _bytecodes: |
|
122 |
|
123 Python Bytecode Instructions |
|
124 ---------------------------- |
|
125 |
|
126 The Python compiler currently generates the following bytecode instructions. |
|
127 |
|
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 |
|
165 Unary Operations take the top of the stack, apply the operation, and push the |
|
166 result 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_CONVERT () |
|
185 |
|
186 Implements ``TOS = `TOS```. |
|
187 |
|
188 |
|
189 .. opcode:: UNARY_INVERT () |
|
190 |
|
191 Implements ``TOS = ~TOS``. |
|
192 |
|
193 |
|
194 .. opcode:: GET_ITER () |
|
195 |
|
196 Implements ``TOS = iter(TOS)``. |
|
197 |
|
198 Binary operations remove the top of the stack (TOS) and the second top-most |
|
199 stack item (TOS1) from the stack. They perform the operation, and put the |
|
200 result back on the stack. |
|
201 |
|
202 |
|
203 .. opcode:: BINARY_POWER () |
|
204 |
|
205 Implements ``TOS = TOS1 ** TOS``. |
|
206 |
|
207 |
|
208 .. opcode:: BINARY_MULTIPLY () |
|
209 |
|
210 Implements ``TOS = TOS1 * TOS``. |
|
211 |
|
212 |
|
213 .. opcode:: BINARY_DIVIDE () |
|
214 |
|
215 Implements ``TOS = TOS1 / TOS`` when ``from __future__ import division`` is not |
|
216 in effect. |
|
217 |
|
218 |
|
219 .. opcode:: BINARY_FLOOR_DIVIDE () |
|
220 |
|
221 Implements ``TOS = TOS1 // TOS``. |
|
222 |
|
223 |
|
224 .. opcode:: BINARY_TRUE_DIVIDE () |
|
225 |
|
226 Implements ``TOS = TOS1 / TOS`` when ``from __future__ import division`` is in |
|
227 effect. |
|
228 |
|
229 |
|
230 .. opcode:: BINARY_MODULO () |
|
231 |
|
232 Implements ``TOS = TOS1 % TOS``. |
|
233 |
|
234 |
|
235 .. opcode:: BINARY_ADD () |
|
236 |
|
237 Implements ``TOS = TOS1 + TOS``. |
|
238 |
|
239 |
|
240 .. opcode:: BINARY_SUBTRACT () |
|
241 |
|
242 Implements ``TOS = TOS1 - TOS``. |
|
243 |
|
244 |
|
245 .. opcode:: BINARY_SUBSCR () |
|
246 |
|
247 Implements ``TOS = TOS1[TOS]``. |
|
248 |
|
249 |
|
250 .. opcode:: BINARY_LSHIFT () |
|
251 |
|
252 Implements ``TOS = TOS1 << TOS``. |
|
253 |
|
254 |
|
255 .. opcode:: BINARY_RSHIFT () |
|
256 |
|
257 Implements ``TOS = TOS1 >> TOS``. |
|
258 |
|
259 |
|
260 .. opcode:: BINARY_AND () |
|
261 |
|
262 Implements ``TOS = TOS1 & TOS``. |
|
263 |
|
264 |
|
265 .. opcode:: BINARY_XOR () |
|
266 |
|
267 Implements ``TOS = TOS1 ^ TOS``. |
|
268 |
|
269 |
|
270 .. opcode:: BINARY_OR () |
|
271 |
|
272 Implements ``TOS = TOS1 | TOS``. |
|
273 |
|
274 In-place operations are like binary operations, in that they remove TOS and |
|
275 TOS1, and push the result back on the stack, but the operation is done in-place |
|
276 when TOS1 supports it, and the resulting TOS may be (but does not have to be) |
|
277 the original TOS1. |
|
278 |
|
279 |
|
280 .. opcode:: INPLACE_POWER () |
|
281 |
|
282 Implements in-place ``TOS = TOS1 ** TOS``. |
|
283 |
|
284 |
|
285 .. opcode:: INPLACE_MULTIPLY () |
|
286 |
|
287 Implements in-place ``TOS = TOS1 * TOS``. |
|
288 |
|
289 |
|
290 .. opcode:: INPLACE_DIVIDE () |
|
291 |
|
292 Implements in-place ``TOS = TOS1 / TOS`` when ``from __future__ import |
|
293 division`` is not in effect. |
|
294 |
|
295 |
|
296 .. opcode:: INPLACE_FLOOR_DIVIDE () |
|
297 |
|
298 Implements in-place ``TOS = TOS1 // TOS``. |
|
299 |
|
300 |
|
301 .. opcode:: INPLACE_TRUE_DIVIDE () |
|
302 |
|
303 Implements in-place ``TOS = TOS1 / TOS`` when ``from __future__ import |
|
304 division`` is in effect. |
|
305 |
|
306 |
|
307 .. opcode:: INPLACE_MODULO () |
|
308 |
|
309 Implements in-place ``TOS = TOS1 % TOS``. |
|
310 |
|
311 |
|
312 .. opcode:: INPLACE_ADD () |
|
313 |
|
314 Implements in-place ``TOS = TOS1 + TOS``. |
|
315 |
|
316 |
|
317 .. opcode:: INPLACE_SUBTRACT () |
|
318 |
|
319 Implements in-place ``TOS = TOS1 - TOS``. |
|
320 |
|
321 |
|
322 .. opcode:: INPLACE_LSHIFT () |
|
323 |
|
324 Implements in-place ``TOS = TOS1 << TOS``. |
|
325 |
|
326 |
|
327 .. opcode:: INPLACE_RSHIFT () |
|
328 |
|
329 Implements in-place ``TOS = TOS1 >> TOS``. |
|
330 |
|
331 |
|
332 .. opcode:: INPLACE_AND () |
|
333 |
|
334 Implements in-place ``TOS = TOS1 & TOS``. |
|
335 |
|
336 |
|
337 .. opcode:: INPLACE_XOR () |
|
338 |
|
339 Implements in-place ``TOS = TOS1 ^ TOS``. |
|
340 |
|
341 |
|
342 .. opcode:: INPLACE_OR () |
|
343 |
|
344 Implements in-place ``TOS = TOS1 | TOS``. |
|
345 |
|
346 The slice opcodes take up to three parameters. |
|
347 |
|
348 |
|
349 .. opcode:: SLICE+0 () |
|
350 |
|
351 Implements ``TOS = TOS[:]``. |
|
352 |
|
353 |
|
354 .. opcode:: SLICE+1 () |
|
355 |
|
356 Implements ``TOS = TOS1[TOS:]``. |
|
357 |
|
358 |
|
359 .. opcode:: SLICE+2 () |
|
360 |
|
361 Implements ``TOS = TOS1[:TOS]``. |
|
362 |
|
363 |
|
364 .. opcode:: SLICE+3 () |
|
365 |
|
366 Implements ``TOS = TOS2[TOS1:TOS]``. |
|
367 |
|
368 Slice assignment needs even an additional parameter. As any statement, they put |
|
369 nothing on the stack. |
|
370 |
|
371 |
|
372 .. opcode:: STORE_SLICE+0 () |
|
373 |
|
374 Implements ``TOS[:] = TOS1``. |
|
375 |
|
376 |
|
377 .. opcode:: STORE_SLICE+1 () |
|
378 |
|
379 Implements ``TOS1[TOS:] = TOS2``. |
|
380 |
|
381 |
|
382 .. opcode:: STORE_SLICE+2 () |
|
383 |
|
384 Implements ``TOS1[:TOS] = TOS2``. |
|
385 |
|
386 |
|
387 .. opcode:: STORE_SLICE+3 () |
|
388 |
|
389 Implements ``TOS2[TOS1:TOS] = TOS3``. |
|
390 |
|
391 |
|
392 .. opcode:: DELETE_SLICE+0 () |
|
393 |
|
394 Implements ``del TOS[:]``. |
|
395 |
|
396 |
|
397 .. opcode:: DELETE_SLICE+1 () |
|
398 |
|
399 Implements ``del TOS1[TOS:]``. |
|
400 |
|
401 |
|
402 .. opcode:: DELETE_SLICE+2 () |
|
403 |
|
404 Implements ``del TOS1[:TOS]``. |
|
405 |
|
406 |
|
407 .. opcode:: DELETE_SLICE+3 () |
|
408 |
|
409 Implements ``del TOS2[TOS1:TOS]``. |
|
410 |
|
411 |
|
412 .. opcode:: STORE_SUBSCR () |
|
413 |
|
414 Implements ``TOS1[TOS] = TOS2``. |
|
415 |
|
416 |
|
417 .. opcode:: DELETE_SUBSCR () |
|
418 |
|
419 Implements ``del TOS1[TOS]``. |
|
420 |
|
421 Miscellaneous opcodes. |
|
422 |
|
423 |
|
424 .. opcode:: PRINT_EXPR () |
|
425 |
|
426 Implements the expression statement for the interactive mode. TOS is removed |
|
427 from the stack and printed. In non-interactive mode, an expression statement is |
|
428 terminated with ``POP_STACK``. |
|
429 |
|
430 |
|
431 .. opcode:: PRINT_ITEM () |
|
432 |
|
433 Prints TOS to the file-like object bound to ``sys.stdout``. There is one such |
|
434 instruction for each item in the :keyword:`print` statement. |
|
435 |
|
436 |
|
437 .. opcode:: PRINT_ITEM_TO () |
|
438 |
|
439 Like ``PRINT_ITEM``, but prints the item second from TOS to the file-like object |
|
440 at TOS. This is used by the extended print statement. |
|
441 |
|
442 |
|
443 .. opcode:: PRINT_NEWLINE () |
|
444 |
|
445 Prints a new line on ``sys.stdout``. This is generated as the last operation of |
|
446 a :keyword:`print` statement, unless the statement ends with a comma. |
|
447 |
|
448 |
|
449 .. opcode:: PRINT_NEWLINE_TO () |
|
450 |
|
451 Like ``PRINT_NEWLINE``, but prints the new line on the file-like object on the |
|
452 TOS. This is used by the extended print statement. |
|
453 |
|
454 |
|
455 .. opcode:: BREAK_LOOP () |
|
456 |
|
457 Terminates a loop due to a :keyword:`break` statement. |
|
458 |
|
459 |
|
460 .. opcode:: CONTINUE_LOOP (target) |
|
461 |
|
462 Continues a loop due to a :keyword:`continue` statement. *target* is the |
|
463 address to jump to (which should be a ``FOR_ITER`` instruction). |
|
464 |
|
465 |
|
466 .. opcode:: LIST_APPEND () |
|
467 |
|
468 Calls ``list.append(TOS1, TOS)``. Used to implement list comprehensions. |
|
469 |
|
470 |
|
471 .. opcode:: LOAD_LOCALS () |
|
472 |
|
473 Pushes a reference to the locals of the current scope on the stack. This is used |
|
474 in the code for a class definition: After the class body is evaluated, the |
|
475 locals are passed to the class definition. |
|
476 |
|
477 |
|
478 .. opcode:: RETURN_VALUE () |
|
479 |
|
480 Returns with TOS to the caller of the function. |
|
481 |
|
482 |
|
483 .. opcode:: YIELD_VALUE () |
|
484 |
|
485 Pops ``TOS`` and yields it from a :term:`generator`. |
|
486 |
|
487 |
|
488 .. opcode:: IMPORT_STAR () |
|
489 |
|
490 Loads all symbols not starting with ``'_'`` directly from the module TOS to the |
|
491 local namespace. The module is popped after loading all names. This opcode |
|
492 implements ``from module import *``. |
|
493 |
|
494 |
|
495 .. opcode:: EXEC_STMT () |
|
496 |
|
497 Implements ``exec TOS2,TOS1,TOS``. The compiler fills missing optional |
|
498 parameters with ``None``. |
|
499 |
|
500 |
|
501 .. opcode:: POP_BLOCK () |
|
502 |
|
503 Removes one block from the block stack. Per frame, there is a stack of blocks, |
|
504 denoting nested loops, try statements, and such. |
|
505 |
|
506 |
|
507 .. opcode:: END_FINALLY () |
|
508 |
|
509 Terminates a :keyword:`finally` clause. The interpreter recalls whether the |
|
510 exception has to be re-raised, or whether the function returns, and continues |
|
511 with the outer-next block. |
|
512 |
|
513 |
|
514 .. opcode:: BUILD_CLASS () |
|
515 |
|
516 Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of |
|
517 the names of the base classes, and TOS2 the class name. |
|
518 |
|
519 |
|
520 .. opcode:: WITH_CLEANUP () |
|
521 |
|
522 Cleans up the stack when a :keyword:`with` statement block exits. On top of |
|
523 the stack are 1--3 values indicating how/why the finally clause was entered: |
|
524 |
|
525 * TOP = ``None`` |
|
526 * (TOP, SECOND) = (``WHY_{RETURN,CONTINUE}``), retval |
|
527 * TOP = ``WHY_*``; no retval below it |
|
528 * (TOP, SECOND, THIRD) = exc_info() |
|
529 |
|
530 Under them is EXIT, the context manager's :meth:`__exit__` bound method. |
|
531 |
|
532 In the last case, ``EXIT(TOP, SECOND, THIRD)`` is called, otherwise |
|
533 ``EXIT(None, None, None)``. |
|
534 |
|
535 EXIT is removed from the stack, leaving the values above it in the same |
|
536 order. In addition, if the stack represents an exception, *and* the function |
|
537 call returns a 'true' value, this information is "zapped", to prevent |
|
538 ``END_FINALLY`` from re-raising the exception. (But non-local gotos should |
|
539 still be resumed.) |
|
540 |
|
541 .. XXX explain the WHY stuff! |
|
542 |
|
543 |
|
544 All of the following opcodes expect arguments. An argument is two bytes, with |
|
545 the more significant byte last. |
|
546 |
|
547 .. opcode:: STORE_NAME (namei) |
|
548 |
|
549 Implements ``name = TOS``. *namei* is the index of *name* in the attribute |
|
550 :attr:`co_names` of the code object. The compiler tries to use ``STORE_FAST`` |
|
551 or ``STORE_GLOBAL`` if possible. |
|
552 |
|
553 |
|
554 .. opcode:: DELETE_NAME (namei) |
|
555 |
|
556 Implements ``del name``, where *namei* is the index into :attr:`co_names` |
|
557 attribute of the code object. |
|
558 |
|
559 |
|
560 .. opcode:: UNPACK_SEQUENCE (count) |
|
561 |
|
562 Unpacks TOS into *count* individual values, which are put onto the stack |
|
563 right-to-left. |
|
564 |
|
565 |
|
566 .. opcode:: DUP_TOPX (count) |
|
567 |
|
568 Duplicate *count* items, keeping them in the same order. Due to implementation |
|
569 limits, *count* should be between 1 and 5 inclusive. |
|
570 |
|
571 |
|
572 .. opcode:: STORE_ATTR (namei) |
|
573 |
|
574 Implements ``TOS.name = TOS1``, where *namei* is the index of name in |
|
575 :attr:`co_names`. |
|
576 |
|
577 |
|
578 .. opcode:: DELETE_ATTR (namei) |
|
579 |
|
580 Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`. |
|
581 |
|
582 |
|
583 .. opcode:: STORE_GLOBAL (namei) |
|
584 |
|
585 Works as ``STORE_NAME``, but stores the name as a global. |
|
586 |
|
587 |
|
588 .. opcode:: DELETE_GLOBAL (namei) |
|
589 |
|
590 Works as ``DELETE_NAME``, but deletes a global name. |
|
591 |
|
592 |
|
593 .. opcode:: LOAD_CONST (consti) |
|
594 |
|
595 Pushes ``co_consts[consti]`` onto the stack. |
|
596 |
|
597 |
|
598 .. opcode:: LOAD_NAME (namei) |
|
599 |
|
600 Pushes the value associated with ``co_names[namei]`` onto the stack. |
|
601 |
|
602 |
|
603 .. opcode:: BUILD_TUPLE (count) |
|
604 |
|
605 Creates a tuple consuming *count* items from the stack, and pushes the resulting |
|
606 tuple onto the stack. |
|
607 |
|
608 |
|
609 .. opcode:: BUILD_LIST (count) |
|
610 |
|
611 Works as ``BUILD_TUPLE``, but creates a list. |
|
612 |
|
613 |
|
614 .. opcode:: BUILD_MAP (count) |
|
615 |
|
616 Pushes a new dictionary object onto the stack. The dictionary is pre-sized |
|
617 to hold *count* entries. |
|
618 |
|
619 |
|
620 .. opcode:: LOAD_ATTR (namei) |
|
621 |
|
622 Replaces TOS with ``getattr(TOS, co_names[namei])``. |
|
623 |
|
624 |
|
625 .. opcode:: COMPARE_OP (opname) |
|
626 |
|
627 Performs a Boolean operation. The operation name can be found in |
|
628 ``cmp_op[opname]``. |
|
629 |
|
630 |
|
631 .. opcode:: IMPORT_NAME (namei) |
|
632 |
|
633 Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide |
|
634 the *fromlist* and *level* arguments of :func:`__import__`. The module |
|
635 object is pushed onto the stack. The current namespace is not affected: |
|
636 for a proper import statement, a subsequent ``STORE_FAST`` instruction |
|
637 modifies the namespace. |
|
638 |
|
639 |
|
640 .. opcode:: IMPORT_FROM (namei) |
|
641 |
|
642 Loads the attribute ``co_names[namei]`` from the module found in TOS. The |
|
643 resulting object is pushed onto the stack, to be subsequently stored by a |
|
644 ``STORE_FAST`` instruction. |
|
645 |
|
646 |
|
647 .. opcode:: JUMP_FORWARD (delta) |
|
648 |
|
649 Increments bytecode counter by *delta*. |
|
650 |
|
651 |
|
652 .. opcode:: JUMP_IF_TRUE (delta) |
|
653 |
|
654 If TOS is true, increment the bytecode counter by *delta*. TOS is left on the |
|
655 stack. |
|
656 |
|
657 |
|
658 .. opcode:: JUMP_IF_FALSE (delta) |
|
659 |
|
660 If TOS is false, increment the bytecode counter by *delta*. TOS is not |
|
661 changed. |
|
662 |
|
663 |
|
664 .. opcode:: JUMP_ABSOLUTE (target) |
|
665 |
|
666 Set bytecode counter to *target*. |
|
667 |
|
668 |
|
669 .. opcode:: FOR_ITER (delta) |
|
670 |
|
671 ``TOS`` is an :term:`iterator`. Call its :meth:`next` method. If this |
|
672 yields a new value, push it on the stack (leaving the iterator below it). If |
|
673 the iterator indicates it is exhausted ``TOS`` is popped, and the bytecode |
|
674 counter is incremented by *delta*. |
|
675 |
|
676 |
|
677 .. opcode:: LOAD_GLOBAL (namei) |
|
678 |
|
679 Loads the global named ``co_names[namei]`` onto the stack. |
|
680 |
|
681 |
|
682 .. opcode:: SETUP_LOOP (delta) |
|
683 |
|
684 Pushes a block for a loop onto the block stack. The block spans from the |
|
685 current instruction with a size of *delta* bytes. |
|
686 |
|
687 |
|
688 .. opcode:: SETUP_EXCEPT (delta) |
|
689 |
|
690 Pushes a try block from a try-except clause onto the block stack. *delta* points |
|
691 to the first except block. |
|
692 |
|
693 |
|
694 .. opcode:: SETUP_FINALLY (delta) |
|
695 |
|
696 Pushes a try block from a try-except clause onto the block stack. *delta* points |
|
697 to the finally block. |
|
698 |
|
699 .. opcode:: STORE_MAP () |
|
700 |
|
701 Store a key and value pair in a dictionary. Pops the key and value while leaving |
|
702 the dictionary on the stack. |
|
703 |
|
704 .. opcode:: LOAD_FAST (var_num) |
|
705 |
|
706 Pushes a reference to the local ``co_varnames[var_num]`` onto the stack. |
|
707 |
|
708 |
|
709 .. opcode:: STORE_FAST (var_num) |
|
710 |
|
711 Stores TOS into the local ``co_varnames[var_num]``. |
|
712 |
|
713 |
|
714 .. opcode:: DELETE_FAST (var_num) |
|
715 |
|
716 Deletes local ``co_varnames[var_num]``. |
|
717 |
|
718 |
|
719 .. opcode:: LOAD_CLOSURE (i) |
|
720 |
|
721 Pushes a reference to the cell contained in slot *i* of the cell and free |
|
722 variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is |
|
723 less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i - |
|
724 len(co_cellvars)]``. |
|
725 |
|
726 |
|
727 .. opcode:: LOAD_DEREF (i) |
|
728 |
|
729 Loads the cell contained in slot *i* of the cell and free variable storage. |
|
730 Pushes a reference to the object the cell contains on the stack. |
|
731 |
|
732 |
|
733 .. opcode:: STORE_DEREF (i) |
|
734 |
|
735 Stores TOS into the cell contained in slot *i* of the cell and free variable |
|
736 storage. |
|
737 |
|
738 |
|
739 .. opcode:: SET_LINENO (lineno) |
|
740 |
|
741 This opcode is obsolete. |
|
742 |
|
743 |
|
744 .. opcode:: RAISE_VARARGS (argc) |
|
745 |
|
746 Raises an exception. *argc* indicates the number of parameters to the raise |
|
747 statement, ranging from 0 to 3. The handler will find the traceback as TOS2, |
|
748 the parameter as TOS1, and the exception as TOS. |
|
749 |
|
750 |
|
751 .. opcode:: CALL_FUNCTION (argc) |
|
752 |
|
753 Calls a function. The low byte of *argc* indicates the number of positional |
|
754 parameters, the high byte the number of keyword parameters. On the stack, the |
|
755 opcode finds the keyword parameters first. For each keyword argument, the value |
|
756 is on top of the key. Below the keyword parameters, the positional parameters |
|
757 are on the stack, with the right-most parameter on top. Below the parameters, |
|
758 the function object to call is on the stack. Pops all function arguments, and |
|
759 the function itself off the stack, and pushes the return value. |
|
760 |
|
761 |
|
762 .. opcode:: MAKE_FUNCTION (argc) |
|
763 |
|
764 Pushes a new function object on the stack. TOS is the code associated with the |
|
765 function. The function object is defined to have *argc* default parameters, |
|
766 which are found below TOS. |
|
767 |
|
768 |
|
769 .. opcode:: MAKE_CLOSURE (argc) |
|
770 |
|
771 Creates a new function object, sets its *func_closure* slot, and pushes it on |
|
772 the stack. TOS is the code associated with the function, TOS1 the tuple |
|
773 containing cells for the closure's free variables. The function also has |
|
774 *argc* default parameters, which are found below the cells. |
|
775 |
|
776 |
|
777 .. opcode:: BUILD_SLICE (argc) |
|
778 |
|
779 .. index:: builtin: slice |
|
780 |
|
781 Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2, |
|
782 ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is |
|
783 pushed. See the :func:`slice` built-in function for more information. |
|
784 |
|
785 |
|
786 .. opcode:: EXTENDED_ARG (ext) |
|
787 |
|
788 Prefixes any opcode which has an argument too big to fit into the default two |
|
789 bytes. *ext* holds two additional bytes which, taken together with the |
|
790 subsequent opcode's argument, comprise a four-byte argument, *ext* being the two |
|
791 most-significant bytes. |
|
792 |
|
793 |
|
794 .. opcode:: CALL_FUNCTION_VAR (argc) |
|
795 |
|
796 Calls a function. *argc* is interpreted as in ``CALL_FUNCTION``. The top element |
|
797 on the stack contains the variable argument list, followed by keyword and |
|
798 positional arguments. |
|
799 |
|
800 |
|
801 .. opcode:: CALL_FUNCTION_KW (argc) |
|
802 |
|
803 Calls a function. *argc* is interpreted as in ``CALL_FUNCTION``. The top element |
|
804 on the stack contains the keyword arguments dictionary, followed by explicit |
|
805 keyword and positional arguments. |
|
806 |
|
807 |
|
808 .. opcode:: CALL_FUNCTION_VAR_KW (argc) |
|
809 |
|
810 Calls a function. *argc* is interpreted as in ``CALL_FUNCTION``. The top |
|
811 element on the stack contains the keyword arguments dictionary, followed by the |
|
812 variable-arguments tuple, followed by explicit keyword and positional arguments. |
|
813 |
|
814 |
|
815 .. opcode:: HAVE_ARGUMENT () |
|
816 |
|
817 This is not really an opcode. It identifies the dividing line between opcodes |
|
818 which don't take arguments ``< HAVE_ARGUMENT`` and those which do ``>= |
|
819 HAVE_ARGUMENT``. |
|
820 |