Skip to content
Merged
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
Next Next commit
extract compiler_codegen from compiler_mod
  • Loading branch information
iritkatriel committed Nov 4, 2022
commit d5f14fcc97cc3ba37e0b1a327413bffecc9ced05
21 changes: 14 additions & 7 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2145,15 +2145,13 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
return 1;
}

static PyCodeObject *
compiler_mod(struct compiler *c, mod_ty mod)
static int
compiler_codegen(struct compiler *c, mod_ty mod)
{
PyCodeObject *co;
int addNone = 1;
_Py_DECLARE_STR(anon_module, "<module>");
if (!compiler_enter_scope(c, &_Py_STR(anon_module), COMPILER_SCOPE_MODULE,
mod, 1)) {
return NULL;
return 0;
}
location loc = LOCATION(1, 1, 0, 0);
switch (mod->kind) {
Expand All @@ -2172,15 +2170,24 @@ compiler_mod(struct compiler *c, mod_ty mod)
break;
case Expression_kind:
VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
addNone = 0;
break;
default:
PyErr_Format(PyExc_SystemError,
"module kind %d should not be possible",
mod->kind);
return 0;
}
co = assemble(c, addNone);
return 1;
}

static PyCodeObject *
compiler_mod(struct compiler *c, mod_ty mod)
{
int addNone = mod->kind != Expression_kind;
if (!compiler_codegen(c, mod)) {
return NULL;
}
PyCodeObject *co = assemble(c, addNone);
compiler_exit_scope(c);
return co;
}
Expand Down