Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ int _PyCompile_IsNestedScope(struct _PyCompiler *c);
int _PyCompile_IsInInlinedComp(struct _PyCompiler *c);
int _PyCompile_ScopeType(struct _PyCompiler *c);
int _PyCompile_OptimizationLevel(struct _PyCompiler *c);
PyArena *_PyCompile_Arena(struct _PyCompiler *c);
int _PyCompile_LookupArg(struct _PyCompiler *c, PyCodeObject *co, PyObject *name);
PyObject *_PyCompile_Qualname(struct _PyCompiler *c);
_PyCompile_CodeUnitMetadata *_PyCompile_Metadata(struct _PyCompiler *c);
Expand Down
54 changes: 26 additions & 28 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ typedef struct _PyCompiler compiler;
#define SCOPE_TYPE(C) _PyCompile_ScopeType(C)
#define QUALNAME(C) _PyCompile_Qualname(C)
#define METADATA(C) _PyCompile_Metadata(C)
#define ARENA(C) _PyCompile_Arena(C)

typedef _PyInstruction instruction;
typedef _PyInstructionSequence instr_sequence;
Expand Down Expand Up @@ -209,6 +208,11 @@ static int codegen_call_simple_kw_helper(compiler *c,
location loc,
asdl_keyword_seq *keywords,
Py_ssize_t nkwelts);
static int codegen_call_helper_impl(compiler *c, location loc,
int n, /* Args already pushed */
asdl_expr_seq *args,
PyObject *injected_arg,
asdl_keyword_seq *keywords);
static int codegen_call_helper(compiler *c, location loc,
int n, asdl_expr_seq *args,
asdl_keyword_seq *keywords);
Expand Down Expand Up @@ -1549,28 +1553,10 @@ codegen_class(compiler *c, stmt_ty s)
ADDOP_I_IN_SCOPE(c, loc, CALL_INTRINSIC_1, INTRINSIC_SUBSCRIPT_GENERIC);
RETURN_IF_ERROR_IN_SCOPE(c, codegen_nameop(c, loc, &_Py_STR(generic_base), Store));

Py_ssize_t original_len = asdl_seq_LEN(s->v.ClassDef.bases);
asdl_expr_seq *bases = _Py_asdl_expr_seq_new(
original_len + 1, ARENA(c));
if (bases == NULL) {
_PyCompile_ExitScope(c);
return ERROR;
}
for (Py_ssize_t i = 0; i < original_len; i++) {
asdl_seq_SET(bases, i, asdl_seq_GET(s->v.ClassDef.bases, i));
}
expr_ty name_node = _PyAST_Name(
&_Py_STR(generic_base), Load,
loc.lineno, loc.col_offset, loc.end_lineno, loc.end_col_offset, ARENA(c)
);
if (name_node == NULL) {
_PyCompile_ExitScope(c);
return ERROR;
}
asdl_seq_SET(bases, original_len, name_node);
RETURN_IF_ERROR_IN_SCOPE(c, codegen_call_helper(c, loc, 2,
bases,
s->v.ClassDef.keywords));
RETURN_IF_ERROR_IN_SCOPE(c, codegen_call_helper_impl(c, loc, 2,
s->v.ClassDef.bases,
&_Py_STR(generic_base),
s->v.ClassDef.keywords));

PyCodeObject *co = _PyCompile_OptimizeAndAssemble(c, 0);

Expand Down Expand Up @@ -3973,13 +3959,13 @@ codegen_call_simple_kw_helper(compiler *c, location loc,
return SUCCESS;
}


/* shared code between codegen_call and codegen_class */
static int
codegen_call_helper(compiler *c, location loc,
int n, /* Args already pushed */
asdl_expr_seq *args,
asdl_keyword_seq *keywords)
codegen_call_helper_impl(compiler *c, location loc,
int n, /* Args already pushed */
asdl_expr_seq *args,
PyObject *injected_arg,
asdl_keyword_seq *keywords)
{
Py_ssize_t i, nseen, nelts, nkwelts;

Expand Down Expand Up @@ -4010,6 +3996,10 @@ codegen_call_helper(compiler *c, location loc,
assert(elt->kind != Starred_kind);
VISIT(c, expr, elt);
}
if (injected_arg) {
RETURN_IF_ERROR(codegen_nameop(c, loc, injected_arg, Load));
nelts++;
}
if (nkwelts) {
VISIT_SEQ(c, keyword, keywords);
RETURN_IF_ERROR(
Expand Down Expand Up @@ -4074,6 +4064,14 @@ codegen_call_helper(compiler *c, location loc,
return SUCCESS;
}

static int
codegen_call_helper(compiler *c, location loc,
int n, /* Args already pushed */
asdl_expr_seq *args,
asdl_keyword_seq *keywords)
{
return codegen_call_helper_impl(c, loc, n, args, NULL, keywords);
}

/* List and set comprehensions and generator expressions work by creating a
nested function to perform the actual iteration. This means that the
Expand Down
6 changes: 0 additions & 6 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,12 +1244,6 @@ _PyCompile_Metadata(compiler *c)
return &c->u->u_metadata;
}

PyArena *
_PyCompile_Arena(compiler *c)
{
return c->c_arena;
}

#ifndef NDEBUG
int
_PyCompile_IsTopLevelAwait(compiler *c)
Expand Down