Skip to content

Commit

Permalink
pythongh-119180: Add LOAD_COMMON_CONSTANT opcode
Browse files Browse the repository at this point in the history
The PEP 649 implementation will require a way to load NotImplementedError
from the bytecode. @markshannon suggested implementing this by converting
LOAD_ASSERTION_ERROR into a more general mechanism for loading constants.

This PR adds this new opcode. I will work on the rest of the implementation
of the PEP separately.
  • Loading branch information
JelleZijlstra committed May 21, 2024
1 parent c4722cd commit 00d6eeb
Show file tree
Hide file tree
Showing 26 changed files with 359 additions and 289 deletions.
9 changes: 5 additions & 4 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,13 @@ iterations of the loop.
Exception representation on the stack now consist of one, not three, items.


.. opcode:: LOAD_ASSERTION_ERROR
.. opcode:: LOAD_COMMON_CONSTANT

Pushes :exc:`AssertionError` onto the stack. Used by the :keyword:`assert`
statement.
Pushes a common constant onto the stack. The interpreter contains a hardcoded
list of constants supported by this instruction. Used by the :keyword:`assert`
statement to load :exc:`AssertionError`.

.. versionadded:: 3.9
.. versionadded:: 3.14


.. opcode:: LOAD_BUILD_CLASS
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode);

PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index);
PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index);
PyAPI_FUNC(PyObject *) _PyCompile_GetCommonConstantsList(void);

/* Access compiler internals for unit testing */

Expand Down
16 changes: 8 additions & 8 deletions Include/internal/pycore_opcode_metadata.h

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

5 changes: 5 additions & 0 deletions Include/internal/pycore_opcode_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ extern "C" {
#define MAKE_FUNCTION_ANNOTATIONS 0x04
#define MAKE_FUNCTION_CLOSURE 0x08

/* Values used as the oparg for LOAD_COMMON_CONSTANT */
#define CONSTANT_ASSERTIONERROR 0
#define CONSTANT_NOTIMPLEMENTEDERROR 1
#define NUM_COMMON_CONSTANTS 2

/* Values used in the oparg for RESUME */
#define RESUME_AT_FUNC_START 0
#define RESUME_AFTER_YIELD 1
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_ids.h

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

6 changes: 3 additions & 3 deletions Include/internal/pycore_uop_metadata.h

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

122 changes: 61 additions & 61 deletions Include/opcode_ids.h

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

Loading

0 comments on commit 00d6eeb

Please sign in to comment.