Skip to content

Commit

Permalink
bpo-46329: Change calling sequence (again) (GH-31373)
Browse files Browse the repository at this point in the history
* Change calling sequence: Add PUSH_NULL. Merge PRECALL_FUNCTION and PRECALL_METHOD into PRECALL.
  • Loading branch information
markshannon authored Feb 18, 2022
1 parent e2c2861 commit cf345e9
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 344 deletions.
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ CPython bytecode changes

* Replaced the three call instructions: :opcode:`CALL_FUNCTION`,
:opcode:`CALL_FUNCTION_KW` and :opcode:`CALL_METHOD` with
:opcode:`PRECALL_FUNCTION`, :opcode:`PRECALL_METHOD`, :opcode:`CALL`,
:opcode:`PUSH_NULL`, :opcode:`PRECALL`, :opcode:`CALL`,
and :opcode:`KW_NAMES`.
This decouples the argument shifting for methods from the handling of
keyword arguments and allows better specialization of calls.
Expand Down
134 changes: 67 additions & 67 deletions Include/opcode.h

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

3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a5 3477 (Replace DUP_TOP/DUP_TOP_TWO with COPY and
# ROT_TWO/ROT_THREE/ROT_FOUR/ROT_N with SWAP)
# Python 3.11a5 3478 (New CALL opcodes)
# Python 3.11a5 3479 (Add PUSH_NULL opcode)

# Python 3.12 will start with magic number 3500

Expand All @@ -402,7 +403,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3478).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3479).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
5 changes: 2 additions & 3 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def jabs_op(name, op):
# Blank lines correspond to available opcodes

def_op('POP_TOP', 1)
def_op('PUSH_NULL', 2)

def_op('NOP', 9)
def_op('UNARY_POSITIVE', 10)
Expand Down Expand Up @@ -187,9 +188,7 @@ def jabs_op(name, op):
def_op('SET_UPDATE', 163)
def_op('DICT_MERGE', 164)
def_op('DICT_UPDATE', 165)

def_op('PRECALL_FUNCTION', 167)
def_op('PRECALL_METHOD', 168)
def_op('PRECALL', 166)

def_op('CALL', 171)
def_op('KW_NAMES', 172)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def foo(x):
instructions = [opcode.opname for opcode in opcodes]
self.assertNotIn('LOAD_METHOD', instructions)
self.assertIn('LOAD_ATTR', instructions)
self.assertIn('PRECALL_FUNCTION', instructions)
self.assertIn('PRECALL', instructions)

def test_lineno_procedure_call(self):
def call():
Expand Down
Loading

0 comments on commit cf345e9

Please sign in to comment.