Skip to content
Next Next commit
Split things up (sorta)
  • Loading branch information
brandtbucher committed Aug 11, 2023
commit 5e435449bccdd61882c7ea329dade478673dc473
50 changes: 35 additions & 15 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1390,10 +1390,38 @@ iterations of the loop.

.. opcode:: CALL (argc)

Calls a callable object with the number of arguments specified by ``argc``.
On the stack are (in ascending order):

* NULL
* The callable
* The positional arguments
* The named arguments

or:

* The callable
* ``self`` (or ``NULL``)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ``self`` (or ``NULL``)
* ``self`` or ``NULL``

* The remaining positional arguments

``argc`` is the total of the positional arguments, excluding
``self`` when a ``NULL`` is not present.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's clearer to just say "excluding self":

Suggested change
``argc`` is the total of the positional arguments, excluding
``self`` when a ``NULL`` is not present.
``argc`` is the total of the positional arguments, excluding ``self``.


``CALL`` pops all arguments and the callable object off the stack,
calls the callable object with those arguments, and pushes the return value
returned by the callable object.

.. versionadded:: 3.11

.. versionchanged:: 3.13
Calls with keyword arguments are now handled by :opcode:`CALL_KW`.


.. opcode:: CALL_KW (argc)

Calls a callable object with the number of arguments specified by ``argc``,
including the named arguments specified by the preceding
:opcode:`KW_NAMES`, if any.
On the stack are (in ascending order), either:
including one or more named arguments.
On the stack are (in ascending order):

* NULL
* The callable
Expand All @@ -1403,18 +1431,19 @@ iterations of the loop.
or:

* The callable
* ``self``
* ``self`` (or ``NULL``)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ``self`` (or ``NULL``)
* ``self`` or ``NULL``

* The remaining positional arguments
* The named arguments
* A :class:`tuple` of keyword argument names

``argc`` is the total of the positional and named arguments, excluding
``self`` when a ``NULL`` is not present.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same thing about whether "not" should be removed.)

Make explicit that if there are N positional and M keyword arguments, oparg is N+M, and len(tuple) must be == M.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``argc`` is the total of the positional and named arguments, excluding
``self`` when a ``NULL`` is not present.
``argc`` is the total of the positional and named arguments, excluding ``self``.


``CALL`` pops all arguments and the callable object off the stack,
``CALL`` pops all arguments, the keyword names, and the callable object off the stack,
calls the callable object with those arguments, and pushes the return value
returned by the callable object.

.. versionadded:: 3.11
.. versionadded:: 3.13


.. opcode:: CALL_FUNCTION_EX (flags)
Expand All @@ -1441,15 +1470,6 @@ iterations of the loop.
.. versionadded:: 3.11


.. opcode:: KW_NAMES (consti)

Prefixes :opcode:`CALL`.
Stores a reference to ``co_consts[consti]`` into an internal variable
for use by :opcode:`CALL`. ``co_consts[consti]`` must be a tuple of strings.

.. versionadded:: 3.11


.. opcode:: MAKE_FUNCTION

Pushes a new function object on the stack built from the code object at ``STACK[1]``.
Expand Down
4 changes: 3 additions & 1 deletion Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ extern void _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container,
extern void _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub,
_Py_CODEUNIT *instr);
extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
int nargs, PyObject *kwnames);
int nargs);
extern void _Py_Specialize_CallKw(PyObject *callable, _Py_CODEUNIT *instr,
int nargs, PyObject *kwnames);
extern void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
int oparg, PyObject **locals);
extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
Expand Down
35 changes: 21 additions & 14 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 56 additions & 55 deletions Include/opcode_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading