@@ -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
@@ -450,6 +458,14 @@ operations on it as if it was a Python list. The top of the stack corresponds to
450
458
.. versionadded :: 3.12
451
459
452
460
461
+ .. opcode :: END_SEND
462
+
463
+ Implements ``del STACK[-2] ``.
464
+ Used to clean up when a generator exits.
465
+
466
+ .. versionadded :: 3.12
467
+
468
+
453
469
.. opcode :: COPY (i)
454
470
455
471
Push the i-th item to the top of the stack without removing it from its original
@@ -1085,15 +1101,21 @@ iterations of the loop.
1085
1101
1086
1102
.. opcode :: LOAD_SUPER_ATTR (namei)
1087
1103
1088
- This opcode implements :func: `super ` (e.g. ``super().method() `` and
1089
- ``super().attr ``). It works the same as :opcode: `LOAD_ATTR `, except that
1090
- ``namei `` is shifted left by 2 bits instead of 1, and instead of expecting a
1091
- single receiver on the stack, it expects three objects (from top of stack
1092
- down): ``self `` (the first argument to the current method), ``cls `` (the
1093
- class within which the current method was defined), and the global ``super ``.
1104
+ This opcode implements :func: `super `, both in its zero-argument and
1105
+ two-argument forms (e.g. ``super().method() ``, ``super().attr `` and
1106
+ ``super(cls, self).method() ``, ``super(cls, self).attr ``).
1107
+
1108
+ It pops three values from the stack (from top of stack down):
1109
+ - ``self ``: the first argument to the current method
1110
+ - ``cls ``: the class within which the current method was defined
1111
+ - the global ``super ``
1112
+
1113
+ With respect to its argument, it works similarly to :opcode: `LOAD_ATTR `,
1114
+ except that ``namei `` is shifted left by 2 bits instead of 1.
1094
1115
1095
1116
The low bit of ``namei `` signals to attempt a method load, as with
1096
- :opcode: `LOAD_ATTR `.
1117
+ :opcode: `LOAD_ATTR `, which results in pushing ``None `` and the loaded method.
1118
+ When it is unset a single value is pushed to the stack.
1097
1119
1098
1120
The second-low bit of ``namei ``, if set, means that this was a two-argument
1099
1121
call to :func: `super ` (unset means zero-argument).
@@ -1520,9 +1542,9 @@ iterations of the loop.
1520
1542
Equivalent to ``STACK[-1] = STACK[-2].send(STACK[-1]) ``. Used in ``yield from ``
1521
1543
and ``await `` statements.
1522
1544
1523
- If the call raises :exc: `StopIteration `, pop both items, push the
1524
- exception's ``value `` attribute, and increment the bytecode counter by
1525
- *delta *.
1545
+ If the call raises :exc: `StopIteration `, pop the top value from the stack,
1546
+ push the exception's ``value `` attribute, and increment the bytecode counter
1547
+ by *delta *.
1526
1548
1527
1549
.. versionadded :: 3.11
1528
1550
@@ -1550,7 +1572,7 @@ iterations of the loop.
1550
1572
1551
1573
Calls an intrinsic function with one argument. Passes ``STACK[-1] `` as the
1552
1574
argument and sets ``STACK[-1] `` to the result. Used to implement
1553
- functionality that is necessary but not performance critical.
1575
+ functionality that is not performance critical.
1554
1576
1555
1577
The operand determines which intrinsic function is called:
1556
1578
@@ -1598,9 +1620,13 @@ iterations of the loop.
1598
1620
1599
1621
.. opcode :: CALL_INTRINSIC_2
1600
1622
1601
- Calls an intrinsic function with two arguments. Passes ``STACK[-2] ``, ``STACK[-1] `` as the
1602
- arguments and sets ``STACK[-1] `` to the result. Used to implement functionality that is
1603
- necessary but not performance critical.
1623
+ Calls an intrinsic function with two arguments. Used to implement functionality
1624
+ that is not performance critical::
1625
+
1626
+ arg2 = STACK.pop()
1627
+ arg1 = STACK.pop()
1628
+ result = intrinsic2(arg1, arg2)
1629
+ STACK.push(result)
1604
1630
1605
1631
The operand determines which intrinsic function is called:
1606
1632
@@ -1685,8 +1711,9 @@ These collections are provided for automatic introspection of bytecode
1685
1711
instructions:
1686
1712
1687
1713
.. versionchanged :: 3.12
1688
- The collections now contain pseudo instructions as well. These are
1689
- opcodes with values ``>= MIN_PSEUDO_OPCODE ``.
1714
+ The collections now contain pseudo instructions and instrumented
1715
+ instructions as well. These are opcodes with values ``>= MIN_PSEUDO_OPCODE ``
1716
+ and ``>= MIN_INSTRUMENTED_OPCODE ``.
1690
1717
1691
1718
.. data :: opname
1692
1719
0 commit comments