Various small fixes to dis docs (#103923)

- Fix description of MAKE_CELL, which appeared to be inverted from the
  actual behavior
- Fix stray ".:" (sphinx-contrib/sphinx-lint#63)
- Fix inconsistent indentation
- Add some missing code blocks
- Slight style improvements
This commit is contained in:
Jelle Zijlstra 2023-04-29 00:02:21 -07:00 committed by GitHub
parent 738c226786
commit ed29f524cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -402,7 +402,7 @@ The Python compiler currently generates the following bytecode instructions.
**General instructions** **General instructions**
In the following, We will refer to the interpreter stack as STACK and describe In the following, We will refer to the interpreter stack as ``STACK`` and describe
operations on it as if it was a Python list. The top of the stack corresponds to operations on it as if it was a Python list. The top of the stack corresponds to
``STACK[-1]`` in this language. ``STACK[-1]`` in this language.
@ -414,7 +414,7 @@ operations on it as if it was a Python list. The top of the stack corresponds to
.. opcode:: POP_TOP .. opcode:: POP_TOP
Removes the top-of-stack item.:: Removes the top-of-stack item::
STACK.pop() STACK.pop()
@ -422,7 +422,7 @@ operations on it as if it was a Python list. The top of the stack corresponds to
.. opcode:: END_FOR .. opcode:: END_FOR
Removes the top two values from the stack. Removes the top two values from the stack.
Equivalent to POP_TOP; POP_TOP. Equivalent to ``POP_TOP``; ``POP_TOP``.
Used to clean up at the end of loops, hence the name. Used to clean up at the end of loops, hence the name.
.. versionadded:: 3.12 .. versionadded:: 3.12
@ -431,7 +431,7 @@ operations on it as if it was a Python list. The top of the stack corresponds to
.. opcode:: COPY (i) .. opcode:: COPY (i)
Push the i-th item to the top of the stack without removing it from its original Push the i-th item to the top of the stack without removing it from its original
location.:: location::
assert i > 0 assert i > 0
STACK.append(STACK[-i]) STACK.append(STACK[-i])
@ -441,7 +441,7 @@ operations on it as if it was a Python list. The top of the stack corresponds to
.. opcode:: SWAP (i) .. opcode:: SWAP (i)
Swap the top of the stack with the i-th element.:: Swap the top of the stack with the i-th element::
STACK[-i], STACK[-1] = stack[-1], STACK[-i] STACK[-i], STACK[-1] = stack[-1], STACK[-i]
@ -513,7 +513,7 @@ not have to be) the original ``STACK[-2]``.
.. opcode:: BINARY_OP (op) .. opcode:: BINARY_OP (op)
Implements the binary and in-place operators (depending on the value of Implements the binary and in-place operators (depending on the value of
*op*).:: *op*)::
rhs = STACK.pop() rhs = STACK.pop()
lhs = STACK.pop() lhs = STACK.pop()
@ -580,14 +580,14 @@ not have to be) the original ``STACK[-2]``.
Implements ``STACK[-1] = get_awaitable(STACK[-1])``, where ``get_awaitable(o)`` Implements ``STACK[-1] = get_awaitable(STACK[-1])``, where ``get_awaitable(o)``
returns ``o`` if ``o`` is a coroutine object or a generator object with returns ``o`` if ``o`` is a coroutine object or a generator object with
the CO_ITERABLE_COROUTINE flag, or resolves the :data:`~inspect.CO_ITERABLE_COROUTINE` flag, or resolves
``o.__await__``. ``o.__await__``.
If the ``where`` operand is nonzero, it indicates where the instruction If the ``where`` operand is nonzero, it indicates where the instruction
occurs: occurs:
* ``1`` After a call to ``__aenter__`` * ``1``: After a call to ``__aenter__``
* ``2`` After a call to ``__aexit__`` * ``2``: After a call to ``__aexit__``
.. versionadded:: 3.5 .. versionadded:: 3.5
@ -652,6 +652,7 @@ not have to be) the original ``STACK[-2]``.
.. opcode:: SET_ADD (i) .. opcode:: SET_ADD (i)
Implements:: Implements::
item = STACK.pop() item = STACK.pop()
set.add(STACK[-i], item) set.add(STACK[-i], item)
@ -751,7 +752,7 @@ iterations of the loop.
.. opcode:: CHECK_EXC_MATCH .. opcode:: CHECK_EXC_MATCH
Performs exception matching for ``except``. Tests whether the ``STACK[-2]`` Performs exception matching for ``except``. Tests whether the ``STACK[-2]``
is an exception matching ``STACK[-1]``. Pops STACK[-1] and pushes the boolean is an exception matching ``STACK[-1]``. Pops ``STACK[-1]`` and pushes the boolean
result of the test. result of the test.
.. versionadded:: 3.11 .. versionadded:: 3.11
@ -863,7 +864,7 @@ iterations of the loop.
.. opcode:: UNPACK_SEQUENCE (count) .. opcode:: UNPACK_SEQUENCE (count)
Unpacks ``STACK[-1]`` into *count* individual values, which are put onto the stack Unpacks ``STACK[-1]`` into *count* individual values, which are put onto the stack
right-to-left.:: right-to-left::
STACK.extend(STACK.pop()[:count:-1]) STACK.extend(STACK.pop()[:count:-1])
@ -1028,7 +1029,7 @@ iterations of the loop.
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
correct name, the bytecode pushes the unbound method and ``STACK[-1]``. correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL` ``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
when calling the unbound method. Otherwise, ``NULL`` and the object return by when calling the unbound method. Otherwise, ``NULL`` and the object returned by
the attribute lookup are pushed. the attribute lookup are pushed.
.. versionchanged:: 3.12 .. versionchanged:: 3.12
@ -1207,7 +1208,7 @@ iterations of the loop.
.. opcode:: MAKE_CELL (i) .. opcode:: MAKE_CELL (i)
Creates a new cell in slot ``i``. If that slot is empty then Creates a new cell in slot ``i``. If that slot is nonempty then
that value is stored into the new cell. that value is stored into the new cell.
.. versionadded:: 3.11 .. versionadded:: 3.11
@ -1521,7 +1522,7 @@ iterations of the loop.
**Pseudo-instructions** **Pseudo-instructions**
These opcodes do not appear in python bytecode, they are used by the compiler 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. but are replaced by real opcodes or removed before bytecode is generated.
.. opcode:: SETUP_FINALLY (target) .. opcode:: SETUP_FINALLY (target)
@ -1533,7 +1534,7 @@ but are replaced by real opcodes or removed before bytecode is generated.
.. opcode:: SETUP_CLEANUP (target) .. opcode:: SETUP_CLEANUP (target)
Like ``SETUP_FINALLY``, but in case of exception also pushes the last Like ``SETUP_FINALLY``, but in case of an exception also pushes the last
instruction (``lasti``) to the stack so that ``RERAISE`` can restore it. instruction (``lasti``) to the stack so that ``RERAISE`` can restore it.
If an exception occurs, the value stack level and the last instruction on 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 the frame are restored to their current state, and control is transferred
@ -1542,7 +1543,7 @@ but are replaced by real opcodes or removed before bytecode is generated.
.. opcode:: SETUP_WITH (target) .. opcode:: SETUP_WITH (target)
Like ``SETUP_CLEANUP``, but in case of exception one more item is popped Like ``SETUP_CLEANUP``, but in case of an exception one more item is popped
from the stack before control is transferred to the exception handler at from the stack before control is transferred to the exception handler at
``target``. ``target``.
@ -1576,7 +1577,7 @@ Opcode collections
These collections are provided for automatic introspection of bytecode These collections are provided for automatic introspection of bytecode
instructions: instructions:
.. versionchanged:: 3.12 .. versionchanged:: 3.12
The collections now contain pseudo instructions as well. These are The collections now contain pseudo instructions as well. These are
opcodes with values ``>= MIN_PSEUDO_OPCODE``. opcodes with values ``>= MIN_PSEUDO_OPCODE``.
@ -1609,10 +1610,10 @@ instructions:
.. data:: hasfree .. data:: hasfree
Sequence of bytecodes that access a free variable (note that 'free' in this Sequence of bytecodes that access a free variable. 'free' in this
context refers to names in the current scope that are referenced by inner context refers to names in the current scope that are referenced by inner
scopes or names in outer scopes that are referenced from this scope. It does scopes or names in outer scopes that are referenced from this scope. It does
*not* include references to global or builtin scopes). *not* include references to global or builtin scopes.
.. data:: hasname .. data:: hasname