summaryrefslogtreecommitdiffstats
path: root/Python/codegen.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-10-29 11:15:42 (GMT)
committerGitHub <noreply@github.com>2024-10-29 11:15:42 (GMT)
commitfaa3272fb8d63d481a136cc0467a0cba6ed7b264 (patch)
tree474ac9edbff637a8edb280846a1d3d9b113915c4 /Python/codegen.c
parent67f5c5bd6fcc956a785edef3be67e8cbe470cd31 (diff)
downloadcpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.zip
cpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.tar.gz
cpython-faa3272fb8d63d481a136cc0467a0cba6ed7b264.tar.bz2
GH-125837: Split `LOAD_CONST` into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
Diffstat (limited to 'Python/codegen.c')
-rw-r--r--Python/codegen.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/codegen.c b/Python/codegen.c
index bfacc6f..976c942 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -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);