summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorMatthieu Dartiailh <m.dartiailh@gmail.com>2023-10-17 12:59:34 (GMT)
committerGitHub <noreply@github.com>2023-10-17 12:59:34 (GMT)
commit198aa67d4ceb5298c3c60f7a77524f5ba084c121 (patch)
treedb00933f29e7d941dad8ac6ab266ce2db9b7e0b7 /Doc/library
parent24e4ec7766fd471deb5b7e5087f0e7dba8576cfb (diff)
downloadcpython-198aa67d4ceb5298c3c60f7a77524f5ba084c121.zip
cpython-198aa67d4ceb5298c3c60f7a77524f5ba084c121.tar.gz
cpython-198aa67d4ceb5298c3c60f7a77524f5ba084c121.tar.bz2
gh-107457: update dis documentation with changes in 3.12 (#108900)
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/dis.rst59
1 files changed, 43 insertions, 16 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 1f773b7..7c92360 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -42,6 +42,14 @@ interpreter.
bytecode to specialize it for different runtime conditions. The
adaptive bytecode can be shown by passing ``adaptive=True``.
+ .. versionchanged:: 3.12
+ The argument of a jump is the offset of the target instruction relative
+ to the instruction that appears immediately after the jump instruction's
+ :opcode:`CACHE` entries.
+
+ As a consequence, the presence of the :opcode:`CACHE` instructions is
+ transparent for forward jumps but needs to be taken into account when
+ reasoning about backward jumps.
Example: Given the function :func:`!myfunc`::
@@ -513,6 +521,14 @@ operations on it as if it was a Python list. The top of the stack corresponds to
.. versionadded:: 3.12
+.. opcode:: END_SEND
+
+ Implements ``del STACK[-2]``.
+ Used to clean up when a generator exits.
+
+ .. versionadded:: 3.12
+
+
.. opcode:: COPY (i)
Push the i-th item to the top of the stack without removing it from its original
@@ -1159,15 +1175,21 @@ iterations of the loop.
.. opcode:: LOAD_SUPER_ATTR (namei)
- This opcode implements :func:`super` (e.g. ``super().method()`` and
- ``super().attr``). It works the same as :opcode:`LOAD_ATTR`, except that
- ``namei`` is shifted left by 2 bits instead of 1, and instead of expecting a
- single receiver on the stack, it expects three objects (from top of stack
- down): ``self`` (the first argument to the current method), ``cls`` (the
- class within which the current method was defined), and the global ``super``.
+ This opcode implements :func:`super`, both in its zero-argument and
+ two-argument forms (e.g. ``super().method()``, ``super().attr`` and
+ ``super(cls, self).method()``, ``super(cls, self).attr``).
+
+ It pops three values from the stack (from top of stack down):
+ - ``self``: the first argument to the current method
+ - ``cls``: the class within which the current method was defined
+ - the global ``super``
+
+ With respect to its argument, it works similarly to :opcode:`LOAD_ATTR`,
+ except that ``namei`` is shifted left by 2 bits instead of 1.
The low bit of ``namei`` signals to attempt a method load, as with
- :opcode:`LOAD_ATTR`.
+ :opcode:`LOAD_ATTR`, which results in pushing ``None`` and the loaded method.
+ When it is unset a single value is pushed to the stack.
The second-low bit of ``namei``, if set, means that this was a two-argument
call to :func:`super` (unset means zero-argument).
@@ -1632,9 +1654,9 @@ iterations of the loop.
Equivalent to ``STACK[-1] = STACK[-2].send(STACK[-1])``. Used in ``yield from``
and ``await`` statements.
- If the call raises :exc:`StopIteration`, pop both items, push the
- exception's ``value`` attribute, and increment the bytecode counter by
- *delta*.
+ If the call raises :exc:`StopIteration`, pop the top value from the stack,
+ push the exception's ``value`` attribute, and increment the bytecode counter
+ by *delta*.
.. versionadded:: 3.11
@@ -1664,7 +1686,7 @@ iterations of the loop.
Calls an intrinsic function with one argument. Passes ``STACK[-1]`` as the
argument and sets ``STACK[-1]`` to the result. Used to implement
- functionality that is necessary but not performance critical.
+ functionality that is not performance critical.
The operand determines which intrinsic function is called:
@@ -1712,9 +1734,13 @@ iterations of the loop.
.. opcode:: CALL_INTRINSIC_2
- Calls an intrinsic function with two arguments. Passes ``STACK[-2]``, ``STACK[-1]`` as the
- arguments and sets ``STACK[-1]`` to the result. Used to implement functionality that is
- necessary but not performance critical.
+ Calls an intrinsic function with two arguments. Used to implement functionality
+ that is not performance critical::
+
+ arg2 = STACK.pop()
+ arg1 = STACK.pop()
+ result = intrinsic2(arg1, arg2)
+ STACK.push(result)
The operand determines which intrinsic function is called:
@@ -1810,8 +1836,9 @@ 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``.
+ The collections now contain pseudo instructions and instrumented
+ instructions as well. These are opcodes with values ``>= MIN_PSEUDO_OPCODE``
+ and ``>= MIN_INSTRUMENTED_OPCODE``.
.. data:: opname