| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,7 +97,8 @@ PyAPI_FUNC(PyObject*) _PyCompile_CodeGen( | |||
| 97 | 97 | PyObject *ast, | |
| 98 | 98 | PyObject *filename, | |
| 99 | 99 | PyCompilerFlags *flags, | |
| 100 | - int optimize); | ||
| 100 | + int optimize, | ||
| 101 | + int compile_mode); | ||
| 101 | 102 | ||
| 102 | 103 | PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg( | |
| 103 | 104 | PyObject *instructions, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,6 +335,7 @@ struct _Py_global_strings { | |||
| 335 | 335 | STRUCT_FOR_ID(code) | |
| 336 | 336 | STRUCT_FOR_ID(command) | |
| 337 | 337 | STRUCT_FOR_ID(comment_factory) | |
| 338 | + STRUCT_FOR_ID(compile_mode) | ||
| 338 | 339 | STRUCT_FOR_ID(consts) | |
| 339 | 340 | STRUCT_FOR_ID(context) | |
| 340 | 341 | STRUCT_FOR_ID(cookie) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,8 @@ def test_if_expression(self): | |||
| 25 | 25 | ('LOAD_CONST', 2, 1), | |
| 26 | 26 | exit_lbl, | |
| 27 | 27 | ('POP_TOP', None), | |
| 28 | + ('LOAD_CONST', 3), | ||
| 29 | + ('RETURN_VALUE', None), | ||
| 28 | 30 | ] | |
| 29 | 31 | self.codegen_test(snippet, expected) | |
| 30 | 32 | ||
@@ -46,5 +48,7 @@ def test_for_loop(self): | |||
| 46 | 48 | ('JUMP', loop_lbl), | |
| 47 | 49 | exit_lbl, | |
| 48 | 50 | ('END_FOR', None), | |
| 51 | + ('LOAD_CONST', 0), | ||
| 52 | + ('RETURN_VALUE', None), | ||
| 49 | 53 | ] | |
| 50 | 54 | self.codegen_test(snippet, expected) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -593,17 +593,19 @@ _testinternalcapi.compiler_codegen -> object | |||
| 593 | 593 | ast: object | |
| 594 | 594 | filename: object | |
| 595 | 595 | optimize: int | |
| 596 | + compile_mode: int = 0 | ||
| 596 | 597 | ||
| 597 | 598 | Apply compiler code generation to an AST. | |
| 598 | 599 | [clinic start generated code]*/ | |
| 599 | 600 | ||
| 600 | 601 | static PyObject * | |
| 601 | 602 | _testinternalcapi_compiler_codegen_impl(PyObject *module, PyObject *ast, | |
| 602 | - PyObject *filename, int optimize) | ||
| 603 | - /*[clinic end generated code: output=fbbbbfb34700c804 input=e9fbe6562f7f75e4]*/ | ||
| 603 | + PyObject *filename, int optimize, | ||
| 604 | + int compile_mode) | ||
| 605 | + /*[clinic end generated code: output=40a68f6e13951cc8 input=a0e00784f1517cd7]*/ | ||
| 604 | 606 | { | |
| 605 | 607 | PyCompilerFlags *flags = NULL; | |
| 606 | - return _PyCompile_CodeGen(ast, filename, flags, optimize); | ||
| 608 | + return _PyCompile_CodeGen(ast, filename, flags, optimize, compile_mode); | ||
| 607 | 609 | } | |
| 608 | 610 | ||
| 609 | 611 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7258,7 +7258,7 @@ cfg_to_instructions(cfg_builder *g) | |||
| 7258 | 7258 | ||
| 7259 | 7259 | PyObject * | |
| 7260 | 7260 | _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, | |
| 7261 | - int optimize) | ||
| 7261 | + int optimize, int compile_mode) | ||
| 7262 | 7262 | { | |
| 7263 | 7263 | PyObject *res = NULL; | |
| 7264 | 7264 | ||
@@ -7272,7 +7272,7 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, | |||
| 7272 | 7272 | return NULL; | |
| 7273 | 7273 | } | |
| 7274 | 7274 | ||
| 7275 | - mod_ty mod = PyAST_obj2mod(ast, arena, 0 /* exec */); | ||
| 7275 | + mod_ty mod = PyAST_obj2mod(ast, arena, compile_mode); | ||
| 7276 | 7276 | if (mod == NULL || !_PyAST_Validate(mod)) { | |
| 7277 | 7277 | _PyArena_Free(arena); | |
| 7278 | 7278 | return NULL; | |
@@ -7287,6 +7287,10 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, | |||
| 7287 | 7287 | if (compiler_codegen(c, mod) < 0) { | |
| 7288 | 7288 | goto finally; | |
| 7289 | 7289 | } | |
| 7290 | + int addNone = mod->kind != Expression_kind; | ||
| 7291 | + if (add_return_at_end(c, addNone) < 0) { | ||
| 7292 | + return NULL; | ||
| 7293 | + } | ||
| 7290 | 7294 | ||
| 7291 | 7295 | res = instr_sequence_to_instructions(INSTR_SEQUENCE(c)); | |
| 7292 | 7296 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments