diff options
Diffstat (limited to 'Doc/library/dis.rst')
-rw-r--r-- | Doc/library/dis.rst | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index d2c3c1a..9173c1b 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -1351,13 +1351,74 @@ iterations of the loop. .. opcode:: HAVE_ARGUMENT This is not really an opcode. It identifies the dividing line between - opcodes which don't use their argument and those that do - (``< HAVE_ARGUMENT`` and ``>= HAVE_ARGUMENT``, respectively). + opcodes in the range [0,255] which don't use their argument and those + that do (``< HAVE_ARGUMENT`` and ``>= HAVE_ARGUMENT``, respectively). + + If your application uses pseudo instructions, use the :data:`hasarg` + collection instead. .. versionchanged:: 3.6 Now every instruction has an argument, but opcodes ``< HAVE_ARGUMENT`` ignore it. Before, only opcodes ``>= HAVE_ARGUMENT`` had an argument. + .. versionchanged:: 3.12 + Pseudo instructions were added to the :mod:`dis` module, and for them + it is not true that comparison with ``HAVE_ARGUMENT`` indicates whether + they use their arg. + + +**Pseudo-instructions** + +These opcodes do not appear in python bytecode, they are used by the compiler +but are replaced by real opcodes or removed before bytecode is generated. + +.. opcode:: SETUP_FINALLY (target) + + Set up an exception handler for the following code block. If an exception + occurs, the value stack level is restored to its current state and control + is transferred to the exception handler at ``target``. + + +.. opcode:: SETUP_CLEANUP (target) + + Like ``SETUP_FINALLY``, but in case of exception also pushes the last + instruction (``lasti``) to the stack so that ``RERAISE`` can restore it. + If an exception occurs, the value stack level and the last instruction on + the frame are restored to their current state, and control is transferred + to the exception handler at ``target``. + + +.. opcode:: SETUP_WITH (target) + + Like ``SETUP_CLEANUP``, but in case of exception one more item is popped + from the stack before control is transferred to the exception handler at + ``target``. + + This variant is used in :keyword:`with` and :keyword:`async with` + constructs, which push the return value of the context manager's + :meth:`~object.__enter__` or :meth:`~object.__aenter__` to the stack. + + +.. opcode:: POP_BLOCK + + Marks the end of the code block associated with the last ``SETUP_FINALLY``, + ``SETUP_CLEANUP`` or ``SETUP_WITH``. + +.. opcode:: JUMP +.. opcode:: JUMP_NO_INTERRUPT +.. opcode:: POP_JUMP_IF_FALSE +.. opcode:: POP_JUMP_IF_TRUE +.. opcode:: POP_JUMP_IF_NONE +.. opcode:: POP_JUMP_IF_NOT_NONE + + Undirected relative jump instructions which are replaced by their + directed (forward/backward) counterparts by the assembler. + +.. opcode:: LOAD_METHOD + + Optimized unbound method lookup. Emitted as a ``LOAD_ATTR`` opcode + with a flag set in the arg. + .. _opcode_collections: @@ -1367,6 +1428,10 @@ Opcode collections These collections are provided for automatic introspection of bytecode instructions: + .. versionchanged:: 3.12 + The collections now contain pseudo instructions as well. These are + opcodes with values ``>= MIN_PSEUDO_OPCODE``. + .. data:: opname Sequence of operation names, indexable using the bytecode. @@ -1382,6 +1447,13 @@ instructions: Sequence of all compare operation names. +.. data:: hasarg + + Sequence of bytecodes that use their argument. + + .. versionadded:: 3.12 + + .. data:: hasconst Sequence of bytecodes that access a constant. @@ -1418,3 +1490,9 @@ instructions: .. data:: hascompare Sequence of bytecodes of Boolean operations. + +.. data:: hasexc + + Sequence of bytecodes that set an exception handler. + + .. versionadded:: 3.12 |