gh-119180: Add LOAD_COMMON_CONSTANT opcode (#119321)

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.

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Jelle Zijlstra 2024-05-21 20:46:39 -04:00 committed by GitHub
parent 506b1a3ff6
commit 98e855fcc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 337 additions and 288 deletions

View file

@ -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