mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
GH-125837: Split LOAD_CONST
into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
This commit is contained in:
parent
67f5c5bd6f
commit
faa3272fb8
33 changed files with 706 additions and 538 deletions
|
@ -280,6 +280,14 @@ codegen_addop_noarg(instr_sequence *seq, int opcode, location loc)
|
|||
static int
|
||||
codegen_addop_load_const(compiler *c, location loc, PyObject *o)
|
||||
{
|
||||
if (PyLong_CheckExact(o)) {
|
||||
int overflow;
|
||||
long val = PyLong_AsLongAndOverflow(o, &overflow);
|
||||
if (!overflow && val >= 0 && val < 256 && val < _PY_NSMALLPOSINTS) {
|
||||
ADDOP_I(c, loc, LOAD_SMALL_INT, val);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
Py_ssize_t arg = _PyCompile_AddConst(c, o);
|
||||
if (arg < 0) {
|
||||
return ERROR;
|
||||
|
@ -656,6 +664,9 @@ codegen_setup_annotations_scope(compiler *c, location loc,
|
|||
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
|
||||
key, loc.lineno, NULL, &umd));
|
||||
|
||||
// Insert None into consts to prevent an annotation
|
||||
// appearing to be a docstring
|
||||
_PyCompile_AddConst(c, Py_None);
|
||||
// if .format != 1: raise NotImplementedError
|
||||
_Py_DECLARE_STR(format, ".format");
|
||||
ADDOP_I(c, loc, LOAD_FAST, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue