gh-121404: remove redundant c_nestlevel. more compiler abstractions. more macro usage consistency (#123225)

This commit is contained in:
Irit Katriel 2024-08-22 15:08:16 +01:00 committed by GitHub
parent 31acc4d243
commit 4abc1c1456
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -92,11 +92,18 @@ static PySTEntryObject *compiler_symtable_entry(struct compiler *c);
#define FUTURE_FEATURES(C) compiler_future_features(C) #define FUTURE_FEATURES(C) compiler_future_features(C)
#define SYMTABLE(C) compiler_symtable(C) #define SYMTABLE(C) compiler_symtable(C)
#define SYMTABLE_ENTRY(C) compiler_symtable_entry(C) #define SYMTABLE_ENTRY(C) compiler_symtable_entry(C)
#define OPTIMIZATION_LEVEL(C) compiler_optimization_level(C)
#define IS_INTERACTIVE(C) compiler_is_interactive(C)
#define IS_NESTED_SCOPE(C) compiler_is_nested_scope(C)
typedef _Py_SourceLocation location; typedef _Py_SourceLocation location;
typedef struct _PyCfgBuilder cfg_builder; typedef struct _PyCfgBuilder cfg_builder;
static PyObject *compiler_mangle(struct compiler *c, PyObject *name);
static PyObject *compiler_maybe_mangle(struct compiler *c, PyObject *name); static PyObject *compiler_maybe_mangle(struct compiler *c, PyObject *name);
static int compiler_optimization_level(struct compiler *c);
static int compiler_is_interactive(struct compiler *c);
static int compiler_is_nested_scope(struct compiler *c);
#define LOCATION(LNO, END_LNO, COL, END_COL) \ #define LOCATION(LNO, END_LNO, COL, END_COL) \
((const _Py_SourceLocation){(LNO), (END_LNO), (COL), (END_COL)}) ((const _Py_SourceLocation){(LNO), (END_LNO), (COL), (END_COL)})
@ -260,7 +267,6 @@ struct compiler {
int c_optimize; /* optimization level */ int c_optimize; /* optimization level */
int c_interactive; /* true if in interactive mode */ int c_interactive; /* true if in interactive mode */
int c_nestlevel;
PyObject *c_const_cache; /* Python dict holding all constants, PyObject *c_const_cache; /* Python dict holding all constants,
including names tuple */ including names tuple */
struct compiler_unit *u; /* compiler state for current block */ struct compiler_unit *u; /* compiler state for current block */
@ -383,7 +389,6 @@ compiler_setup(struct compiler *c, mod_ty mod, PyObject *filename,
flags->cf_flags = merged; flags->cf_flags = merged;
c->c_flags = *flags; c->c_flags = *flags;
c->c_optimize = (optimize == -1) ? _Py_GetConfig()->optimization_level : optimize; c->c_optimize = (optimize == -1) ? _Py_GetConfig()->optimization_level : optimize;
c->c_nestlevel = 0;
c->c_save_nested_seqs = false; c->c_save_nested_seqs = false;
if (!_PyAST_Optimize(mod, arena, c->c_optimize, merged)) { if (!_PyAST_Optimize(mod, arena, c->c_optimize, merged)) {
@ -1178,8 +1183,6 @@ compiler_enter_scope(struct compiler *c, identifier name, int scope_type,
c->u = u; c->u = u;
c->c_nestlevel++;
if (u->u_scope_type == COMPILER_SCOPE_MODULE) { if (u->u_scope_type == COMPILER_SCOPE_MODULE) {
loc.lineno = 0; loc.lineno = 0;
} }
@ -1202,7 +1205,6 @@ compiler_exit_scope(struct compiler *c)
nested_seq = c->u->u_instr_sequence; nested_seq = c->u->u_instr_sequence;
Py_INCREF(nested_seq); Py_INCREF(nested_seq);
} }
c->c_nestlevel--;
compiler_unit_free(c->u); compiler_unit_free(c->u);
/* Restore c->u to the parent unit. */ /* Restore c->u to the parent unit. */
Py_ssize_t n = PyList_GET_SIZE(c->c_stack) - 1; Py_ssize_t n = PyList_GET_SIZE(c->c_stack) - 1;
@ -1493,12 +1495,10 @@ codegen_leave_annotations_scope(struct compiler *c, location loc,
if (co == NULL) { if (co == NULL) {
return ERROR; return ERROR;
} }
if (codegen_make_closure(c, loc, co, 0) < 0) { int ret = codegen_make_closure(c, loc, co, 0);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
return 0; RETURN_IF_ERROR(ret);
return SUCCESS;
} }
/* Compile a sequence of statements, checking for a docstring /* Compile a sequence of statements, checking for a docstring
@ -1517,12 +1517,12 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
return SUCCESS; return SUCCESS;
} }
Py_ssize_t first_instr = 0; Py_ssize_t first_instr = 0;
if (!c->c_interactive) { if (!IS_INTERACTIVE(c)) {
PyObject *docstring = _PyAST_GetDocString(stmts); PyObject *docstring = _PyAST_GetDocString(stmts);
if (docstring) { if (docstring) {
first_instr = 1; first_instr = 1;
/* if not -OO mode, set docstring */ /* if not -OO mode, set docstring */
if (c->c_optimize < 2) { if (OPTIMIZATION_LEVEL(c) < 2) {
PyObject *cleandoc = _PyCompile_CleanDoc(docstring); PyObject *cleandoc = _PyCompile_CleanDoc(docstring);
if (cleandoc == NULL) { if (cleandoc == NULL) {
return ERROR; return ERROR;
@ -1568,7 +1568,7 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
Py_DECREF(deferred_anno); Py_DECREF(deferred_anno);
return ERROR; return ERROR;
} }
PyObject *mangled = _Py_Mangle(c->u->u_private, st->v.AnnAssign.target->v.Name.id); PyObject *mangled = compiler_mangle(c, st->v.AnnAssign.target->v.Name.id);
ADDOP_LOAD_CONST_NEW(c, LOC(st), mangled); ADDOP_LOAD_CONST_NEW(c, LOC(st), mangled);
VISIT(c, expr, st->v.AnnAssign.annotation); VISIT(c, expr, st->v.AnnAssign.annotation);
} }
@ -1606,17 +1606,13 @@ compiler_codegen(struct compiler *c, mod_ty mod)
switch (mod->kind) { switch (mod->kind) {
case Module_kind: { case Module_kind: {
asdl_stmt_seq *stmts = mod->v.Module.body; asdl_stmt_seq *stmts = mod->v.Module.body;
if (compiler_body(c, start_location(stmts), stmts) < 0) { RETURN_IF_ERROR(compiler_body(c, start_location(stmts), stmts));
return ERROR;
}
break; break;
} }
case Interactive_kind: { case Interactive_kind: {
c->c_interactive = 1; c->c_interactive = 1;
asdl_stmt_seq *stmts = mod->v.Interactive.body; asdl_stmt_seq *stmts = mod->v.Interactive.body;
if (compiler_body(c, start_location(stmts), stmts) < 0) { RETURN_IF_ERROR(compiler_body(c, start_location(stmts), stmts));
return ERROR;
}
break; break;
} }
case Expression_kind: { case Expression_kind: {
@ -1943,20 +1939,14 @@ codegen_annotations(struct compiler *c, location loc,
Py_ssize_t annotations_len = 0; Py_ssize_t annotations_len = 0;
PySTEntryObject *ste; PySTEntryObject *ste;
if (_PySymtable_LookupOptional(SYMTABLE(c), args, &ste) < 0) { RETURN_IF_ERROR(_PySymtable_LookupOptional(SYMTABLE(c), args, &ste));
return ERROR;
}
assert(ste != NULL); assert(ste != NULL);
bool annotations_used = ste->ste_annotations_used; bool annotations_used = ste->ste_annotations_used;
if (annotations_used) { int err = annotations_used ?
if (codegen_setup_annotations_scope(c, loc, (void *)args, codegen_setup_annotations_scope(c, loc, (void *)args, ste->ste_name) : SUCCESS;
ste->ste_name) < 0) {
Py_DECREF(ste);
return ERROR;
}
}
Py_DECREF(ste); Py_DECREF(ste);
RETURN_IF_ERROR(err);
if (codegen_annotations_in_scope(c, loc, args, returns, &annotations_len) < 0) { if (codegen_annotations_in_scope(c, loc, args, returns, &annotations_len) < 0) {
if (annotations_used) { if (annotations_used) {
@ -2031,9 +2021,7 @@ codegen_type_param_bound_or_default(struct compiler *c, expr_ty e,
{ {
PyObject *defaults = PyTuple_Pack(1, _PyLong_GetOne()); PyObject *defaults = PyTuple_Pack(1, _PyLong_GetOne());
ADDOP_LOAD_CONST_NEW(c, LOC(e), defaults); ADDOP_LOAD_CONST_NEW(c, LOC(e), defaults);
if (codegen_setup_annotations_scope(c, LOC(e), key, name) == -1) { RETURN_IF_ERROR(codegen_setup_annotations_scope(c, LOC(e), key, name));
return ERROR;
}
if (allow_starred && e->kind == Starred_kind) { if (allow_starred && e->kind == Starred_kind) {
VISIT(c, expr, e->v.Starred.value); VISIT(c, expr, e->v.Starred.value);
ADDOP_I(c, LOC(e), UNPACK_SEQUENCE, (Py_ssize_t)1); ADDOP_I(c, LOC(e), UNPACK_SEQUENCE, (Py_ssize_t)1);
@ -2047,11 +2035,9 @@ codegen_type_param_bound_or_default(struct compiler *c, expr_ty e,
if (co == NULL) { if (co == NULL) {
return ERROR; return ERROR;
} }
if (codegen_make_closure(c, LOC(e), co, MAKE_FUNCTION_DEFAULTS) < 0) { int ret = codegen_make_closure(c, LOC(e), co, MAKE_FUNCTION_DEFAULTS);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
RETURN_IF_ERROR(ret);
return SUCCESS; return SUCCESS;
} }
@ -2145,8 +2131,8 @@ codegen_type_params(struct compiler *c, asdl_type_param_seq *type_params)
} }
static int static int
compiler_function_body(struct compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags, codegen_function_body(struct compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags,
int firstlineno) int firstlineno)
{ {
arguments_ty args; arguments_ty args;
identifier name; identifier name;
@ -2184,7 +2170,7 @@ compiler_function_body(struct compiler *c, stmt_ty s, int is_async, Py_ssize_t f
if (docstring) { if (docstring) {
first_instr = 1; first_instr = 1;
/* if not -OO mode, add docstring */ /* if not -OO mode, add docstring */
if (c->c_optimize < 2) { if (OPTIMIZATION_LEVEL(c) < 2) {
docstring = _PyCompile_CleanDoc(docstring); docstring = _PyCompile_CleanDoc(docstring);
if (docstring == NULL) { if (docstring == NULL) {
compiler_exit_scope(c); compiler_exit_scope(c);
@ -2273,9 +2259,7 @@ codegen_function(struct compiler *c, stmt_ty s, int is_async)
int is_generic = asdl_seq_LEN(type_params) > 0; int is_generic = asdl_seq_LEN(type_params) > 0;
funcflags = codegen_default_arguments(c, loc, args); funcflags = codegen_default_arguments(c, loc, args);
if (funcflags == -1) { RETURN_IF_ERROR(funcflags);
return ERROR;
}
int num_typeparam_args = 0; int num_typeparam_args = 0;
@ -2296,12 +2280,10 @@ codegen_function(struct compiler *c, stmt_ty s, int is_async)
_PyCompile_CodeUnitMetadata umd = { _PyCompile_CodeUnitMetadata umd = {
.u_argcount = num_typeparam_args, .u_argcount = num_typeparam_args,
}; };
if (compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_ANNOTATIONS, int ret = compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_ANNOTATIONS,
(void *)type_params, firstlineno, NULL, &umd) == -1) { (void *)type_params, firstlineno, NULL, &umd);
Py_DECREF(type_params_name);
return ERROR;
}
Py_DECREF(type_params_name); Py_DECREF(type_params_name);
RETURN_IF_ERROR(ret);
RETURN_IF_ERROR_IN_SCOPE(c, codegen_type_params(c, type_params)); RETURN_IF_ERROR_IN_SCOPE(c, codegen_type_params(c, type_params));
for (int i = 0; i < num_typeparam_args; i++) { for (int i = 0; i < num_typeparam_args; i++) {
ADDOP_I_IN_SCOPE(c, loc, LOAD_FAST, i); ADDOP_I_IN_SCOPE(c, loc, LOAD_FAST, i);
@ -2317,11 +2299,12 @@ codegen_function(struct compiler *c, stmt_ty s, int is_async)
} }
funcflags |= annotations_flag; funcflags |= annotations_flag;
if (compiler_function_body(c, s, is_async, funcflags, firstlineno) < 0) { int ret = codegen_function_body(c, s, is_async, funcflags, firstlineno);
if (is_generic) { if (is_generic) {
compiler_exit_scope(c); RETURN_IF_ERROR_IN_SCOPE(c, ret);
} }
return ERROR; else {
RETURN_IF_ERROR(ret);
} }
if (is_generic) { if (is_generic) {
@ -2334,11 +2317,9 @@ codegen_function(struct compiler *c, stmt_ty s, int is_async)
if (co == NULL) { if (co == NULL) {
return ERROR; return ERROR;
} }
if (codegen_make_closure(c, loc, co, 0) < 0) { int ret = codegen_make_closure(c, loc, co, 0);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
RETURN_IF_ERROR(ret);
if (num_typeparam_args > 0) { if (num_typeparam_args > 0) {
ADDOP_I(c, loc, SWAP, num_typeparam_args + 1); ADDOP_I(c, loc, SWAP, num_typeparam_args + 1);
ADDOP_I(c, loc, CALL, num_typeparam_args - 1); ADDOP_I(c, loc, CALL, num_typeparam_args - 1);
@ -2458,11 +2439,9 @@ compiler_class_body(struct compiler *c, stmt_ty s, int firstlineno)
ADDOP(c, loc, PUSH_NULL); ADDOP(c, loc, PUSH_NULL);
/* 3. load a function (or closure) made from the code object */ /* 3. load a function (or closure) made from the code object */
if (codegen_make_closure(c, loc, co, 0) < 0) { int ret = codegen_make_closure(c, loc, co, 0);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
RETURN_IF_ERROR(ret);
/* 4. load class name */ /* 4. load class name */
ADDOP_LOAD_CONST(c, loc, s->v.ClassDef.name); ADDOP_LOAD_CONST(c, loc, s->v.ClassDef.name);
@ -2491,22 +2470,21 @@ codegen_class(struct compiler *c, stmt_ty s)
if (!type_params_name) { if (!type_params_name) {
return ERROR; return ERROR;
} }
if (compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_ANNOTATIONS, int ret = compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_ANNOTATIONS,
(void *)type_params, firstlineno, s->v.ClassDef.name, NULL) == -1) { (void *)type_params, firstlineno, s->v.ClassDef.name, NULL);
Py_DECREF(type_params_name);
return ERROR;
}
Py_DECREF(type_params_name); Py_DECREF(type_params_name);
RETURN_IF_ERROR(ret);
RETURN_IF_ERROR_IN_SCOPE(c, codegen_type_params(c, type_params)); RETURN_IF_ERROR_IN_SCOPE(c, codegen_type_params(c, type_params));
_Py_DECLARE_STR(type_params, ".type_params"); _Py_DECLARE_STR(type_params, ".type_params");
RETURN_IF_ERROR_IN_SCOPE(c, compiler_nameop(c, loc, &_Py_STR(type_params), Store)); RETURN_IF_ERROR_IN_SCOPE(c, compiler_nameop(c, loc, &_Py_STR(type_params), Store));
} }
if (compiler_class_body(c, s, firstlineno) < 0) { int ret = compiler_class_body(c, s, firstlineno);
if (is_generic) { if (is_generic) {
compiler_exit_scope(c); RETURN_IF_ERROR_IN_SCOPE(c, ret);
} }
return ERROR; else {
RETURN_IF_ERROR(ret);
} }
/* generate the rest of the code for the call */ /* generate the rest of the code for the call */
@ -2547,11 +2525,9 @@ codegen_class(struct compiler *c, stmt_ty s)
if (co == NULL) { if (co == NULL) {
return ERROR; return ERROR;
} }
if (codegen_make_closure(c, loc, co, 0) < 0) { int ret = codegen_make_closure(c, loc, co, 0);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
RETURN_IF_ERROR(ret);
ADDOP(c, loc, PUSH_NULL); ADDOP(c, loc, PUSH_NULL);
ADDOP_I(c, loc, CALL, 0); ADDOP_I(c, loc, CALL, 0);
} else { } else {
@ -2587,11 +2563,10 @@ codegen_typealias_body(struct compiler *c, stmt_ty s)
if (co == NULL) { if (co == NULL) {
return ERROR; return ERROR;
} }
if (codegen_make_closure(c, loc, co, MAKE_FUNCTION_DEFAULTS) < 0) { int ret = codegen_make_closure(c, loc, co, MAKE_FUNCTION_DEFAULTS);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
RETURN_IF_ERROR(ret);
ADDOP_I(c, loc, BUILD_TUPLE, 3); ADDOP_I(c, loc, BUILD_TUPLE, 3);
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_TYPEALIAS); ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_TYPEALIAS);
return SUCCESS; return SUCCESS;
@ -2610,12 +2585,10 @@ codegen_typealias(struct compiler *c, stmt_ty s)
if (!type_params_name) { if (!type_params_name) {
return ERROR; return ERROR;
} }
if (compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_ANNOTATIONS, int ret = compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_ANNOTATIONS,
(void *)type_params, loc.lineno, NULL, NULL) == -1) { (void *)type_params, loc.lineno, NULL, NULL);
Py_DECREF(type_params_name);
return ERROR;
}
Py_DECREF(type_params_name); Py_DECREF(type_params_name);
RETURN_IF_ERROR(ret);
ADDOP_LOAD_CONST_IN_SCOPE(c, loc, name); ADDOP_LOAD_CONST_IN_SCOPE(c, loc, name);
RETURN_IF_ERROR_IN_SCOPE(c, codegen_type_params(c, type_params)); RETURN_IF_ERROR_IN_SCOPE(c, codegen_type_params(c, type_params));
} }
@ -2624,11 +2597,12 @@ codegen_typealias(struct compiler *c, stmt_ty s)
ADDOP_LOAD_CONST(c, loc, Py_None); ADDOP_LOAD_CONST(c, loc, Py_None);
} }
if (codegen_typealias_body(c, s) < 0) { int ret = codegen_typealias_body(c, s);
if (is_generic) { if (is_generic) {
compiler_exit_scope(c); RETURN_IF_ERROR_IN_SCOPE(c, ret);
} }
return ERROR; else {
RETURN_IF_ERROR(ret);
} }
if (is_generic) { if (is_generic) {
@ -2637,11 +2611,9 @@ codegen_typealias(struct compiler *c, stmt_ty s)
if (co == NULL) { if (co == NULL) {
return ERROR; return ERROR;
} }
if (codegen_make_closure(c, loc, co, 0) < 0) { int ret = codegen_make_closure(c, loc, co, 0);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
RETURN_IF_ERROR(ret);
ADDOP(c, loc, PUSH_NULL); ADDOP(c, loc, PUSH_NULL);
ADDOP_I(c, loc, CALL, 0); ADDOP_I(c, loc, CALL, 0);
} }
@ -2867,9 +2839,7 @@ codegen_lambda(struct compiler *c, expr_ty e)
location loc = LOC(e); location loc = LOC(e);
funcflags = codegen_default_arguments(c, loc, args); funcflags = codegen_default_arguments(c, loc, args);
if (funcflags == -1) { RETURN_IF_ERROR(funcflags);
return ERROR;
}
_PyCompile_CodeUnitMetadata umd = { _PyCompile_CodeUnitMetadata umd = {
.u_argcount = asdl_seq_LEN(args->args), .u_argcount = asdl_seq_LEN(args->args),
@ -2902,12 +2872,9 @@ codegen_lambda(struct compiler *c, expr_ty e)
return ERROR; return ERROR;
} }
if (codegen_make_closure(c, loc, co, funcflags) < 0) { int ret = codegen_make_closure(c, loc, co, funcflags);
Py_DECREF(co);
return ERROR;
}
Py_DECREF(co); Py_DECREF(co);
RETURN_IF_ERROR(ret);
return SUCCESS; return SUCCESS;
} }
@ -3798,7 +3765,7 @@ codegen_from_import(struct compiler *c, stmt_ty s)
} }
static int static int
compiler_assert(struct compiler *c, stmt_ty s) codegen_assert(struct compiler *c, stmt_ty s)
{ {
/* Always emit a warning if the test is a non-zero length tuple */ /* Always emit a warning if the test is a non-zero length tuple */
if ((s->v.Assert.test->kind == Tuple_kind && if ((s->v.Assert.test->kind == Tuple_kind &&
@ -3811,7 +3778,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
compiler_warn(c, LOC(s), "assertion is always true, " compiler_warn(c, LOC(s), "assertion is always true, "
"perhaps remove parentheses?")); "perhaps remove parentheses?"));
} }
if (c->c_optimize) { if (OPTIMIZATION_LEVEL(c)) {
return SUCCESS; return SUCCESS;
} }
NEW_JUMP_TARGET_LABEL(c, end); NEW_JUMP_TARGET_LABEL(c, end);
@ -3828,9 +3795,9 @@ compiler_assert(struct compiler *c, stmt_ty s)
} }
static int static int
compiler_stmt_expr(struct compiler *c, location loc, expr_ty value) codegen_stmt_expr(struct compiler *c, location loc, expr_ty value)
{ {
if (c->c_interactive && c->c_nestlevel <= 1) { if (IS_INTERACTIVE(c) && !IS_NESTED_SCOPE(c)) {
VISIT(c, expr, value); VISIT(c, expr, value);
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT); ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT);
ADDOP(c, NO_LOCATION, POP_TOP); ADDOP(c, NO_LOCATION, POP_TOP);
@ -3908,7 +3875,7 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
case TryStar_kind: case TryStar_kind:
return codegen_try_star(c, s); return codegen_try_star(c, s);
case Assert_kind: case Assert_kind:
return compiler_assert(c, s); return codegen_assert(c, s);
case Import_kind: case Import_kind:
return codegen_import(c, s); return codegen_import(c, s);
case ImportFrom_kind: case ImportFrom_kind:
@ -3918,7 +3885,7 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
break; break;
case Expr_kind: case Expr_kind:
{ {
return compiler_stmt_expr(c, LOC(s), s->v.Expr.value); return codegen_stmt_expr(c, LOC(s), s->v.Expr.value);
} }
case Pass_kind: case Pass_kind:
{ {
@ -5617,8 +5584,8 @@ pop_inlined_comprehension_state(struct compiler *c, location loc,
} }
static inline int static inline int
compiler_comprehension_iter(struct compiler *c, location loc, codegen_comprehension_iter(struct compiler *c, location loc,
comprehension_ty comp) comprehension_ty comp)
{ {
VISIT(c, expr, comp->iter); VISIT(c, expr, comp->iter);
if (comp->is_async) { if (comp->is_async) {
@ -5653,7 +5620,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
outermost = (comprehension_ty) asdl_seq_GET(generators, 0); outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
if (is_inlined) { if (is_inlined) {
if (compiler_comprehension_iter(c, loc, outermost)) { if (codegen_comprehension_iter(c, loc, outermost)) {
goto error; goto error;
} }
if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) { if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) {
@ -5731,7 +5698,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
} }
Py_CLEAR(co); Py_CLEAR(co);
if (compiler_comprehension_iter(c, loc, outermost)) { if (codegen_comprehension_iter(c, loc, outermost)) {
goto error; goto error;
} }
@ -5758,7 +5725,7 @@ error:
} }
static int static int
compiler_genexp(struct compiler *c, expr_ty e) codegen_genexp(struct compiler *c, expr_ty e)
{ {
assert(e->kind == GeneratorExp_kind); assert(e->kind == GeneratorExp_kind);
_Py_DECLARE_STR(anon_genexpr, "<genexpr>"); _Py_DECLARE_STR(anon_genexpr, "<genexpr>");
@ -5768,7 +5735,7 @@ compiler_genexp(struct compiler *c, expr_ty e)
} }
static int static int
compiler_listcomp(struct compiler *c, expr_ty e) codegen_listcomp(struct compiler *c, expr_ty e)
{ {
assert(e->kind == ListComp_kind); assert(e->kind == ListComp_kind);
_Py_DECLARE_STR(anon_listcomp, "<listcomp>"); _Py_DECLARE_STR(anon_listcomp, "<listcomp>");
@ -5778,7 +5745,7 @@ compiler_listcomp(struct compiler *c, expr_ty e)
} }
static int static int
compiler_setcomp(struct compiler *c, expr_ty e) codegen_setcomp(struct compiler *c, expr_ty e)
{ {
assert(e->kind == SetComp_kind); assert(e->kind == SetComp_kind);
_Py_DECLARE_STR(anon_setcomp, "<setcomp>"); _Py_DECLARE_STR(anon_setcomp, "<setcomp>");
@ -5789,7 +5756,7 @@ compiler_setcomp(struct compiler *c, expr_ty e)
static int static int
compiler_dictcomp(struct compiler *c, expr_ty e) codegen_dictcomp(struct compiler *c, expr_ty e)
{ {
assert(e->kind == DictComp_kind); assert(e->kind == DictComp_kind);
_Py_DECLARE_STR(anon_dictcomp, "<dictcomp>"); _Py_DECLARE_STR(anon_dictcomp, "<dictcomp>");
@ -6066,13 +6033,13 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
case Set_kind: case Set_kind:
return codegen_set(c, e); return codegen_set(c, e);
case GeneratorExp_kind: case GeneratorExp_kind:
return compiler_genexp(c, e); return codegen_genexp(c, e);
case ListComp_kind: case ListComp_kind:
return compiler_listcomp(c, e); return codegen_listcomp(c, e);
case SetComp_kind: case SetComp_kind:
return compiler_setcomp(c, e); return codegen_setcomp(c, e);
case DictComp_kind: case DictComp_kind:
return compiler_dictcomp(c, e); return codegen_dictcomp(c, e);
case Yield_kind: case Yield_kind:
if (!_PyST_IsFunctionLike(SYMTABLE_ENTRY(c))) { if (!_PyST_IsFunctionLike(SYMTABLE_ENTRY(c))) {
return compiler_error(c, loc, "'yield' outside function"); return compiler_error(c, loc, "'yield' outside function");
@ -7376,6 +7343,12 @@ consts_dict_keys_inorder(PyObject *dict)
return consts; return consts;
} }
static PyObject *
compiler_mangle(struct compiler *c, PyObject *name)
{
return _Py_Mangle(c->u->u_private, name);
}
static PyObject * static PyObject *
compiler_maybe_mangle(struct compiler *c, PyObject *name) compiler_maybe_mangle(struct compiler *c, PyObject *name)
{ {
@ -7406,6 +7379,26 @@ compiler_symtable_entry(struct compiler *c)
return c->u->u_ste; return c->u->u_ste;
} }
static int
compiler_optimization_level(struct compiler *c)
{
return c->c_optimize;
}
static int
compiler_is_interactive(struct compiler *c)
{
return c->c_interactive;
}
static int
compiler_is_nested_scope(struct compiler *c)
{
assert(c->c_stack != NULL);
assert(PyList_CheckExact(c->c_stack));
return PyList_GET_SIZE(c->c_stack) > 0;
}
static int static int
compute_code_flags(struct compiler *c) compute_code_flags(struct compiler *c)
{ {