Skip to content

Commit 8de7276

Browse files
committed
add CONSTANT_BUILTIN_ALL/ANY/TUPLE oparg for LOAD_COMMON_CONST
1 parent 49234c0 commit 8de7276

File tree

7 files changed

+72
-10
lines changed

7 files changed

+72
-10
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_opcode_utils.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ extern "C" {
6767
/* Values used as the oparg for LOAD_COMMON_CONSTANT */
6868
#define CONSTANT_ASSERTIONERROR 0
6969
#define CONSTANT_NOTIMPLEMENTEDERROR 1
70-
#define NUM_COMMON_CONSTANTS 2
70+
#define CONSTANT_BUILTIN_TUPLE 2
71+
#define CONSTANT_BUILTIN_ALL 3
72+
#define CONSTANT_BUILTIN_ANY 4
73+
#define NUM_COMMON_CONSTANTS 5
7174

7275
/* Values used in the oparg for RESUME */
7376
#define RESUME_AT_FUNC_START 0

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/opcode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"HAVE_ARGUMENT", "EXTENDED_ARG", "hasarg", "hasconst", "hasname",
1010
"hasjump", "hasjrel", "hasjabs", "hasfree", "haslocal", "hasexc"]
1111

12+
import builtins
1213
import _opcode
1314
from _opcode import stack_effect
1415

@@ -38,7 +39,8 @@
3839
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
3940
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
4041
_special_method_names = _opcode.get_special_method_names()
41-
_common_constants = [AssertionError, NotImplementedError]
42+
_common_constants = [AssertionError, NotImplementedError,
43+
builtins.tuple, builtins.all, builtins.any]
4244
_nb_ops = _opcode.get_nb_ops()
4345

4446
hascompare = [opmap["COMPARE_OP"]]

Python/bytecodes.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,10 +1409,21 @@ dummy_func(
14091409
if (oparg == CONSTANT_ASSERTIONERROR) {
14101410
val = PyExc_AssertionError;
14111411
}
1412-
else {
1413-
assert(oparg == CONSTANT_NOTIMPLEMENTEDERROR);
1412+
else if (oparg == CONSTANT_NOTIMPLEMENTEDERROR) {
14141413
val = PyExc_NotImplementedError;
14151414
}
1415+
else if (oparg == CONSTANT_BUILTIN_TUPLE) {
1416+
val = (PyObject*)&PyTuple_Type;
1417+
}
1418+
else if (oparg == CONSTANT_BUILTIN_ALL) {
1419+
val = PyDict_GetItemWithError(builtins_dict, &_Py_ID(all));
1420+
}
1421+
else if (oparg == CONSTANT_BUILTIN_ANY) {
1422+
val = PyDict_GetItemWithError(builtins_dict, &_Py_ID(any));
1423+
}
1424+
else {
1425+
Py_UNREACHABLE();
1426+
}
14161427
value = PyStackRef_FromPyObjectImmortal(val);
14171428
}
14181429

Python/executor_cases.c.h

Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)