bpo-39320: Handle unpacking of *values in compiler (GH-17984)

* Add three new bytecodes: LIST_TO_TUPLE, LIST_EXTEND, SET_UPDATE. Use them to implement star unpacking expressions.

* Remove four bytecodes BUILD_LIST_UNPACK, BUILD_TUPLE_UNPACK, BUILD_SET_UNPACK and  BUILD_TUPLE_UNPACK_WITH_CALL opcodes as they are now unused.

* Update magic number and dis.rst for new bytecodes.
This commit is contained in:
Mark Shannon 2020-01-23 09:25:17 +00:00 committed by GitHub
parent f9e07e116c
commit 13bc13960c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 2349 additions and 2360 deletions

View file

@ -859,40 +859,25 @@ All of the following opcodes use their arguments.
.. versionadded:: 3.6
.. opcode:: BUILD_TUPLE_UNPACK (count)
.. opcode:: LIST_TO_TUPLE
Pops *count* iterables from the stack, joins them in a single tuple,
and pushes the result. Implements iterable unpacking in tuple
displays ``(*x, *y, *z)``.
Pops a list from the stack and pushes a tuple containing the same values.
.. versionadded:: 3.5
.. versionadded:: 3.9
.. opcode:: BUILD_TUPLE_UNPACK_WITH_CALL (count)
.. opcode:: LIST_EXTEND (i)
This is similar to :opcode:`BUILD_TUPLE_UNPACK`,
but is used for ``f(*x, *y, *z)`` call syntax. The stack item at position
``count + 1`` should be the corresponding callable ``f``.
Calls ``list.extend(TOS1[-i], TOS)``. Used to build lists.
.. versionadded:: 3.6
.. versionadded:: 3.9
.. opcode:: BUILD_LIST_UNPACK (count)
.. opcode:: SET_UPDATE
This is similar to :opcode:`BUILD_TUPLE_UNPACK`, but pushes a list
instead of tuple. Implements iterable unpacking in list
displays ``[*x, *y, *z]``.
Calls ``set.update(TOS1[-i], TOS)``. Used to build sets.
.. versionadded:: 3.5
.. opcode:: BUILD_SET_UNPACK (count)
This is similar to :opcode:`BUILD_TUPLE_UNPACK`, but pushes a set
instead of tuple. Implements iterable unpacking in set
displays ``{*x, *y, *z}``.
.. versionadded:: 3.5
.. versionadded:: 3.9
.. opcode:: BUILD_MAP_UNPACK (count)
@ -1124,10 +1109,6 @@ All of the following opcodes use their arguments.
Calls a callable object with variable set of positional and keyword
arguments. If the lowest bit of *flags* is set, the top of the stack
contains a mapping object containing additional keyword arguments.
Below that is an iterable object containing positional arguments and
a callable object to call. :opcode:`BUILD_MAP_UNPACK_WITH_CALL` and
:opcode:`BUILD_TUPLE_UNPACK_WITH_CALL` can be used for merging multiple
mapping objects and iterables containing arguments.
Before the callable is called, the mapping object and iterable object
are each "unpacked" and their contents passed in as keyword and
positional arguments respectively.