mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-104240: make _PyCompile_CodeGen support different compilation modes (#104241)
This commit is contained in:
parent
1b19bd1a88
commit
2c2dc61e8d
9 changed files with 43 additions and 15 deletions
|
@ -7258,7 +7258,7 @@ error:
|
|||
|
||||
PyObject *
|
||||
_PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
|
||||
int optimize)
|
||||
int optimize, int compile_mode)
|
||||
{
|
||||
PyObject *res = NULL;
|
||||
|
||||
|
@ -7272,7 +7272,7 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
mod_ty mod = PyAST_obj2mod(ast, arena, 0 /* exec */);
|
||||
mod_ty mod = PyAST_obj2mod(ast, arena, compile_mode);
|
||||
if (mod == NULL || !_PyAST_Validate(mod)) {
|
||||
_PyArena_Free(arena);
|
||||
return NULL;
|
||||
|
@ -7287,6 +7287,10 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
|
|||
if (compiler_codegen(c, mod) < 0) {
|
||||
goto finally;
|
||||
}
|
||||
int addNone = mod->kind != Expression_kind;
|
||||
if (add_return_at_end(c, addNone) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = instr_sequence_to_instructions(INSTR_SEQUENCE(c));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue