summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2023-08-09 18:19:39 (GMT)
committerGitHub <noreply@github.com>2023-08-09 18:19:39 (GMT)
commita9caf9cf9041d6d0b69f8be0fd778dd1f9b50e74 (patch)
tree5e325bac9eda1b264d3e5fd32991eed91d243f16 /Python/compile.c
parent0a7f48b9a8d54809f1e9272337aefe2444158e64 (diff)
downloadcpython-a9caf9cf9041d6d0b69f8be0fd778dd1f9b50e74.zip
cpython-a9caf9cf9041d6d0b69f8be0fd778dd1f9b50e74.tar.gz
cpython-a9caf9cf9041d6d0b69f8be0fd778dd1f9b50e74.tar.bz2
GH-105848: Simplify the arrangement of CALL's stack (GH-107788)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/Python/compile.c b/Python/compile.c
index b673e3a..68af5d6 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2361,11 +2361,6 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
int is_generic = asdl_seq_LEN(type_params) > 0;
- if (is_generic) {
- // Used by the CALL to the type parameters function.
- ADDOP(c, loc, PUSH_NULL);
- }
-
funcflags = compiler_default_arguments(c, loc, args);
if (funcflags == -1) {
return ERROR;
@@ -2436,8 +2431,12 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
Py_DECREF(co);
if (num_typeparam_args > 0) {
ADDOP_I(c, loc, SWAP, num_typeparam_args + 1);
+ ADDOP_I(c, loc, CALL, num_typeparam_args - 1);
+ }
+ else {
+ ADDOP(c, loc, PUSH_NULL);
+ ADDOP_I(c, loc, CALL, 0);
}
- ADDOP_I(c, loc, CALL, num_typeparam_args);
}
RETURN_IF_ERROR(compiler_apply_decorators(c, decos));
@@ -2565,8 +2564,8 @@ compiler_class_body(struct compiler *c, stmt_ty s, int firstlineno)
// these instructions should be attributed to the class line,
// not a decorator line
loc = LOC(s);
- ADDOP(c, loc, PUSH_NULL);
ADDOP(c, loc, LOAD_BUILD_CLASS);
+ ADDOP(c, loc, PUSH_NULL);
/* 3. load a function (or closure) made from the code object */
if (compiler_make_closure(c, loc, co, 0) < 0) {
@@ -2598,7 +2597,6 @@ compiler_class(struct compiler *c, stmt_ty s)
int is_generic = asdl_seq_LEN(type_params) > 0;
if (is_generic) {
Py_XSETREF(c->u->u_private, Py_NewRef(s->v.ClassDef.name));
- ADDOP(c, loc, PUSH_NULL);
PyObject *type_params_name = PyUnicode_FromFormat("<generic parameters of %U>",
s->v.ClassDef.name);
if (!type_params_name) {
@@ -2666,6 +2664,7 @@ compiler_class(struct compiler *c, stmt_ty s)
return ERROR;
}
Py_DECREF(co);
+ ADDOP(c, loc, PUSH_NULL);
ADDOP_I(c, loc, CALL, 0);
} else {
RETURN_IF_ERROR(compiler_call_helper(c, loc, 2,
@@ -2716,7 +2715,6 @@ compiler_typealias(struct compiler *c, stmt_ty s)
int is_generic = asdl_seq_LEN(type_params) > 0;
PyObject *name = s->v.TypeAlias.name->v.Name.id;
if (is_generic) {
- ADDOP(c, loc, PUSH_NULL);
PyObject *type_params_name = PyUnicode_FromFormat("<generic parameters of %U>",
name);
if (!type_params_name) {
@@ -2756,6 +2754,7 @@ compiler_typealias(struct compiler *c, stmt_ty s)
return ERROR;
}
Py_DECREF(co);
+ ADDOP(c, loc, PUSH_NULL);
ADDOP_I(c, loc, CALL, 0);
}
RETURN_IF_ERROR(compiler_nameop(c, loc, name, Store));
@@ -4994,9 +4993,9 @@ compiler_call(struct compiler *c, expr_ty e)
return SUCCESS;
}
RETURN_IF_ERROR(check_caller(c, e->v.Call.func));
+ VISIT(c, expr, e->v.Call.func);
location loc = LOC(e->v.Call.func);
ADDOP(c, loc, PUSH_NULL);
- VISIT(c, expr, e->v.Call.func);
loc = LOC(e);
return compiler_call_helper(c, loc, 0,
e->v.Call.args,