Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7439)

Side by Side Diff: Python/compile.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file compiles an abstract syntax tree (AST) into Python bytecode. 2 * This file compiles an abstract syntax tree (AST) into Python bytecode.
3 * 3 *
4 * The primary entry point is PyAST_Compile(), which returns a 4 * The primary entry point is PyAST_Compile(), which returns a
5 * PyCodeObject. The compiler makes several passes to build the code 5 * PyCodeObject. The compiler makes several passes to build the code
6 * object: 6 * object:
7 * 1. Checks for future statements. See future.c 7 * 1. Checks for future statements. See future.c
8 * 2. Builds a symbol table. See symtable.c. 8 * 2. Builds a symbol table. See symtable.c.
9 * 3. Generate code for basic blocks. See compiler_mod() in this file. 9 * 3. Generate code for basic blocks. See compiler_mod() in this file.
10 * 4. Assemble the basic blocks into final code. See assemble() in 10 * 4. Assemble the basic blocks into final code. See assemble() in
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 return 7; 833 return 7;
834 case WITH_CLEANUP: 834 case WITH_CLEANUP:
835 return -1; /* XXX Sometimes more */ 835 return -1; /* XXX Sometimes more */
836 case STORE_LOCALS: 836 case STORE_LOCALS:
837 return -1; 837 return -1;
838 case RETURN_VALUE: 838 case RETURN_VALUE:
839 return -1; 839 return -1;
840 case IMPORT_STAR: 840 case IMPORT_STAR:
841 return -1; 841 return -1;
842 case YIELD_VALUE: 842 case YIELD_VALUE:
843 case YIELD_FROM:
843 return 0; 844 return 0;
844 845
845 case POP_BLOCK: 846 case POP_BLOCK:
846 return 0; 847 return 0;
847 case POP_EXCEPT: 848 case POP_EXCEPT:
848 return 0; /* -3 except if bad bytecode */ 849 return 0; /* -3 except if bad bytecode */
849 case END_FINALLY: 850 case END_FINALLY:
850 return -1; /* or -2 or -3 if exception occurred */ 851 return -1; /* or -2 or -3 if exception occurred */
851 852
852 case STORE_NAME: 853 case STORE_NAME:
(...skipping 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after
3311 return compiler_dictcomp(c, e); 3312 return compiler_dictcomp(c, e);
3312 case Yield_kind: 3313 case Yield_kind:
3313 if (c->u->u_ste->ste_type != FunctionBlock) 3314 if (c->u->u_ste->ste_type != FunctionBlock)
3314 return compiler_error(c, "'yield' outside function"); 3315 return compiler_error(c, "'yield' outside function");
3315 if (e->v.Yield.value) { 3316 if (e->v.Yield.value) {
3316 VISIT(c, expr, e->v.Yield.value); 3317 VISIT(c, expr, e->v.Yield.value);
3317 } 3318 }
3318 else { 3319 else {
3319 ADDOP_O(c, LOAD_CONST, Py_None, consts); 3320 ADDOP_O(c, LOAD_CONST, Py_None, consts);
3320 } 3321 }
3321 ADDOP(c, YIELD_VALUE); 3322 if (e->v.Yield.is_from) {
3323 ADDOP(c, YIELD_FROM);
3324 }
3325 else {
3326 ADDOP(c, YIELD_VALUE);
3327 }
3322 break; 3328 break;
3323 case Compare_kind: 3329 case Compare_kind:
3324 return compiler_compare(c, e); 3330 return compiler_compare(c, e);
3325 case Call_kind: 3331 case Call_kind:
3326 return compiler_call(c, e); 3332 return compiler_call(c, e);
3327 case Num_kind: 3333 case Num_kind:
3328 ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts); 3334 ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts);
3329 break; 3335 break;
3330 case Str_kind: 3336 case Str_kind:
3331 ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts); 3337 ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts);
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
4211 4217
4212 #undef PyAST_Compile 4218 #undef PyAST_Compile
4213 PyAPI_FUNC(PyCodeObject *) 4219 PyAPI_FUNC(PyCodeObject *)
4214 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, 4220 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags,
4215 PyArena *arena) 4221 PyArena *arena)
4216 { 4222 {
4217 return PyAST_CompileEx(mod, filename, flags, -1, arena); 4223 return PyAST_CompileEx(mod, filename, flags, -1, arena);
4218 } 4224 }
4219 4225
4220 4226
OLDNEW
« Objects/exceptions.c ('K') | « Python/ceval.c ('k') | Python/graminit.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+