@@ -42,6 +42,14 @@ interpreter.
42
42
bytecode to specialize it for different runtime conditions. The
43
43
adaptive bytecode can be shown by passing ``adaptive=True ``.
44
44
45
+ .. versionchanged :: 3.12
46
+ The argument of a jump is the offset of the target instruction relative
47
+ to the instruction that appears immediately after the jump instruction's
48
+ :opcode: `CACHE ` entries.
49
+
50
+ As a consequence, the presence of the :opcode: `CACHE ` instructions is
51
+ transparent for forward jumps but needs to be taken into account when
52
+ reasoning about backward jumps.
45
53
46
54
Example: Given the function :func: `!myfunc `::
47
55
@@ -513,6 +521,14 @@ operations on it as if it was a Python list. The top of the stack corresponds to
513
521
.. versionadded :: 3.12
514
522
515
523
524
+ .. opcode :: END_SEND
525
+
526
+ Implements ``del STACK[-2] ``.
527
+ Used to clean up when a generator exits.
528
+
529
+ .. versionadded :: 3.12
530
+
531
+
516
532
.. opcode :: COPY (i)
517
533
518
534
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.
1159
1175
1160
1176
.. opcode :: LOAD_SUPER_ATTR (namei)
1161
1177
1162
- This opcode implements :func: `super ` (e.g. ``super().method() `` and
1163
- ``super().attr ``). It works the same as :opcode: `LOAD_ATTR `, except that
1164
- ``namei `` is shifted left by 2 bits instead of 1, and instead of expecting a
1165
- single receiver on the stack, it expects three objects (from top of stack
1166
- down): ``self `` (the first argument to the current method), ``cls `` (the
1167
- class within which the current method was defined), and the global ``super ``.
1178
+ This opcode implements :func: `super `, both in its zero-argument and
1179
+ two-argument forms (e.g. ``super().method() ``, ``super().attr `` and
1180
+ ``super(cls, self).method() ``, ``super(cls, self).attr ``).
1181
+
1182
+ It pops three values from the stack (from top of stack down):
1183
+ - ``self ``: the first argument to the current method
1184
+ - ``cls ``: the class within which the current method was defined
1185
+ - the global ``super ``
1186
+
1187
+ With respect to its argument, it works similarly to :opcode: `LOAD_ATTR `,
1188
+ except that ``namei `` is shifted left by 2 bits instead of 1.
1168
1189
1169
1190
The low bit of ``namei `` signals to attempt a method load, as with
1170
- :opcode: `LOAD_ATTR `.
1191
+ :opcode: `LOAD_ATTR `, which results in pushing ``None `` and the loaded method.
1192
+ When it is unset a single value is pushed to the stack.
1171
1193
1172
1194
The second-low bit of ``namei ``, if set, means that this was a two-argument
1173
1195
call to :func: `super ` (unset means zero-argument).
@@ -1632,9 +1654,9 @@ iterations of the loop.
1632
1654
Equivalent to ``STACK[-1] = STACK[-2].send(STACK[-1]) ``. Used in ``yield from ``
1633
1655
and ``await `` statements.
1634
1656
1635
- If the call raises :exc: `StopIteration `, pop both items, push the
1636
- exception's ``value `` attribute, and increment the bytecode counter by
1637
- *delta *.
1657
+ If the call raises :exc: `StopIteration `, pop the top value from the stack,
1658
+ push the exception's ``value `` attribute, and increment the bytecode counter
1659
+ by *delta *.
1638
1660
1639
1661
.. versionadded :: 3.11
1640
1662
@@ -1664,7 +1686,7 @@ iterations of the loop.
1664
1686
1665
1687
Calls an intrinsic function with one argument. Passes ``STACK[-1] `` as the
1666
1688
argument and sets ``STACK[-1] `` to the result. Used to implement
1667
- functionality that is necessary but not performance critical.
1689
+ functionality that is not performance critical.
1668
1690
1669
1691
The operand determines which intrinsic function is called:
1670
1692
@@ -1712,9 +1734,13 @@ iterations of the loop.
1712
1734
1713
1735
.. opcode :: CALL_INTRINSIC_2
1714
1736
1715
- Calls an intrinsic function with two arguments. Passes ``STACK[-2] ``, ``STACK[-1] `` as the
1716
- arguments and sets ``STACK[-1] `` to the result. Used to implement functionality that is
1717
- necessary but not performance critical.
1737
+ Calls an intrinsic function with two arguments. Used to implement functionality
1738
+ that is not performance critical::
1739
+
1740
+ arg2 = STACK.pop()
1741
+ arg1 = STACK.pop()
1742
+ result = intrinsic2(arg1, arg2)
1743
+ STACK.push(result)
1718
1744
1719
1745
The operand determines which intrinsic function is called:
1720
1746
@@ -1810,8 +1836,9 @@ These collections are provided for automatic introspection of bytecode
1810
1836
instructions:
1811
1837
1812
1838
.. versionchanged :: 3.12
1813
- The collections now contain pseudo instructions as well. These are
1814
- opcodes with values ``>= MIN_PSEUDO_OPCODE ``.
1839
+ The collections now contain pseudo instructions and instrumented
1840
+ instructions as well. These are opcodes with values ``>= MIN_PSEUDO_OPCODE ``
1841
+ and ``>= MIN_INSTRUMENTED_OPCODE ``.
1815
1842
1816
1843
.. data :: opname
1817
1844
0 commit comments