Skip to content

Commit cebdf71

Browse files
committed
pythongh-124058: remove c_interactive from the compiler struct
1 parent 3961210 commit cebdf71

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

Include/internal/pycore_compile.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ int _PyCompile_LookupCellvar(struct _PyCompiler *c, PyObject *name);
133133
int _PyCompile_ResolveNameop(struct _PyCompiler *c, PyObject *mangled, int scope,
134134
_PyCompile_optype *optype, Py_ssize_t *arg);
135135

136-
int _PyCompile_IsInteractive(struct _PyCompiler *c);
137-
int _PyCompile_IsNestedScope(struct _PyCompiler *c);
138136
int _PyCompile_IsInInlinedComp(struct _PyCompiler *c);
139137
int _PyCompile_ScopeType(struct _PyCompiler *c);
140138
int _PyCompile_OptimizationLevel(struct _PyCompiler *c);

Python/codegen.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,17 @@ _PyCodegen_Expression(compiler *c, expr_ty e)
742742
return SUCCESS;
743743
}
744744

745+
static int
746+
codegen_interactive(compiler *c, location loc, asdl_stmt_seq *stmts)
747+
{
748+
assert(asdl_seq_LEN(stmts) == 1);
749+
stmt_ty s = (stmt_ty)asdl_seq_GET(stmts, 0);
750+
VISIT(c, expr, s->v.Expr.value);
751+
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT);
752+
ADDOP(c, NO_LOCATION, POP_TOP);
753+
return SUCCESS;
754+
}
755+
745756
/* Compile a sequence of statements, checking for a docstring
746757
and for annotations. */
747758

@@ -775,9 +786,12 @@ _PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts, bool is_interac
775786
Py_DECREF(cleandoc);
776787
RETURN_IF_ERROR(codegen_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store));
777788
}
789+
for (Py_ssize_t i = first_instr; i < asdl_seq_LEN(stmts); i++) {
790+
VISIT(c, stmt, (stmt_ty)asdl_seq_GET(stmts, i));
791+
}
778792
}
779-
for (Py_ssize_t i = first_instr; i < asdl_seq_LEN(stmts); i++) {
780-
VISIT(c, stmt, (stmt_ty)asdl_seq_GET(stmts, i));
793+
else {
794+
RETURN_IF_ERROR(codegen_interactive(c, loc, stmts));
781795
}
782796
// If there are annotations and the future import is not on, we
783797
// collect the annotations in a separate pass and generate an
@@ -2823,13 +2837,6 @@ codegen_assert(compiler *c, stmt_ty s)
28232837
static int
28242838
codegen_stmt_expr(compiler *c, location loc, expr_ty value)
28252839
{
2826-
if (IS_INTERACTIVE(c) && !IS_NESTED_SCOPE(c)) {
2827-
VISIT(c, expr, value);
2828-
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT);
2829-
ADDOP(c, NO_LOCATION, POP_TOP);
2830-
return SUCCESS;
2831-
}
2832-
28332840
if (value->kind == Constant_kind) {
28342841
/* ignore constant statement */
28352842
ADDOP(c, loc, NOP);

Python/compile.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ typedef struct _PyCompiler {
8383
PyCompilerFlags c_flags;
8484

8585
int c_optimize; /* optimization level */
86-
int c_interactive; /* true if in interactive mode */
8786
PyObject *c_const_cache; /* Python dict holding all constants,
8887
including names tuple */
8988
struct compiler_unit *u; /* compiler state for current block */
@@ -794,7 +793,6 @@ compiler_codegen(compiler *c, mod_ty mod)
794793
break;
795794
}
796795
case Interactive_kind: {
797-
c->c_interactive = 1;
798796
asdl_stmt_seq *stmts = mod->v.Interactive.body;
799797
RETURN_IF_ERROR(_PyCodegen_Body(c, start_location(stmts), stmts, true));
800798
break;
@@ -1203,20 +1201,6 @@ _PyCompile_OptimizationLevel(compiler *c)
12031201
return c->c_optimize;
12041202
}
12051203

1206-
int
1207-
_PyCompile_IsInteractive(compiler *c)
1208-
{
1209-
return c->c_interactive;
1210-
}
1211-
1212-
int
1213-
_PyCompile_IsNestedScope(compiler *c)
1214-
{
1215-
assert(c->c_stack != NULL);
1216-
assert(PyList_CheckExact(c->c_stack));
1217-
return PyList_GET_SIZE(c->c_stack) > 0;
1218-
}
1219-
12201204
int
12211205
_PyCompile_ScopeType(compiler *c)
12221206
{

0 commit comments

Comments
 (0)