Mercurial > cpython-lru_cache-weakref
annotate Python/compile.c @ 62453:e9fb042e46fb legacy-trunk
Fix misindents in compile.c (for Benjamin).
Of course, whoever used the wrong indentation rules needs to be spanked.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Tue, 22 Jun 2010 21:42:05 +0000 |
| parents | fd25030223b0 |
| children | b36cb4602e21 |
| rev | line source |
|---|---|
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1 /* |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2 * This file compiles an abstract syntax tree (AST) into Python bytecode. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3 * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
4 * The primary entry point is PyAST_Compile(), which returns a |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
5 * PyCodeObject. The compiler makes several passes to build the code |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
6 * object: |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
7 * 1. Checks for future statements. See future.c |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
8 * 2. Builds a symbol table. See symtable.c. |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
9 * 3. Generate code for basic blocks. See compiler_mod() in this file. |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
10 * 4. Assemble the basic blocks into final code. See assemble() in |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
11 * this file. |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
12 * 5. Optimize the byte code (peephole optimizations). See peephole.c |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
13 * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
14 * Note that compiler_mod() suggests module, but the module ast type |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
15 * (mod_ty) has cases for expressions and interactive statements. |
|
35881
29420bd3b5cb
Correctly handle identifiers for anonymous scopes and align genexpr name with symtable.c
Nick Coghlan <ncoghlan@gmail.com>
parents:
35863
diff
changeset
|
16 * |
|
36766
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
17 * CAUTION: The VISIT_* macros abort the current function when they |
|
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
18 * encounter a problem. So don't invoke them when there is memory |
|
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
19 * which needs to be released. Code blocks are OK, as the compiler |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
20 * structure takes care of releasing those. Use the arena to manage |
|
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
21 * objects. |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
22 */ |
| 69 | 23 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
24 #include "Python.h" |
| 86 | 25 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
26 #include "Python-ast.h" |
| 69 | 27 #include "node.h" |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
35993
diff
changeset
|
28 #include "pyarena.h" |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
29 #include "ast.h" |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
30 #include "code.h" |
| 69 | 31 #include "compile.h" |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
32 #include "symtable.h" |
| 69 | 33 #include "opcode.h" |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
34 |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
35 int Py_OptimizeFlag = 0; |
|
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
36 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
37 #define DEFAULT_BLOCK_SIZE 16 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
38 #define DEFAULT_BLOCKS 8 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
39 #define DEFAULT_CODE_SIZE 128 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
40 #define DEFAULT_LNOTAB_SIZE 16 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
41 |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
42 #define COMP_GENEXP 0 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
43 #define COMP_SETCOMP 1 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
44 #define COMP_DICTCOMP 2 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
45 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
46 struct instr { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
47 unsigned i_jabs : 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
48 unsigned i_jrel : 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
49 unsigned i_hasarg : 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
50 unsigned char i_opcode; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
51 int i_oparg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
52 struct basicblock_ *i_target; /* target block (if jump instruction) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
53 int i_lineno; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
54 }; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
55 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
56 typedef struct basicblock_ { |
|
37390
5e1cf21d4ab2
Expand comments on line numbers and blocks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37067
diff
changeset
|
57 /* Each basicblock in a compilation unit is linked via b_list in the |
|
5e1cf21d4ab2
Expand comments on line numbers and blocks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37067
diff
changeset
|
58 reverse order that the block are allocated. b_list points to the next |
|
5e1cf21d4ab2
Expand comments on line numbers and blocks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37067
diff
changeset
|
59 block, not to be confused with b_next, which is next by control flow. */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
60 struct basicblock_ *b_list; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
61 /* number of instructions used */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
62 int b_iused; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
63 /* length of instruction array (b_instr) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
64 int b_ialloc; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
65 /* pointer to an array of instructions, initially NULL */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
66 struct instr *b_instr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
67 /* If b_next is non-NULL, it is a pointer to the next |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
68 block reached by normal control flow. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
69 struct basicblock_ *b_next; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
70 /* b_seen is used to perform a DFS of basicblocks. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
71 unsigned b_seen : 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
72 /* b_return is true if a RETURN_VALUE opcode is inserted. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
73 unsigned b_return : 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
74 /* depth of stack upon entry of block, computed by stackdepth() */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
75 int b_startdepth; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
76 /* instruction offset for block, computed by assemble_jump_offsets() */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
77 int b_offset; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
78 } basicblock; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
79 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
80 /* fblockinfo tracks the current frame block. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
81 |
|
36766
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
82 A frame block is used to handle loops, try/except, and try/finally. |
|
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
83 It's called a frame block to distinguish it from a basic block in the |
|
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
84 compiler IR. |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
85 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
86 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
87 enum fblocktype { LOOP, EXCEPT, FINALLY_TRY, FINALLY_END }; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
88 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
89 struct fblockinfo { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
90 enum fblocktype fb_type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
91 basicblock *fb_block; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
92 }; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
93 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
94 /* The following items change on entry and exit of code blocks. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
95 They must be saved and restored when returning to a block. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
96 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
97 struct compiler_unit { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
98 PySTEntryObject *u_ste; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
99 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
100 PyObject *u_name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
101 /* The following fields are dicts that map objects to |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
102 the index of them in co_XXX. The index is used as |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
103 the argument for opcodes that refer to those collections. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
104 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
105 PyObject *u_consts; /* all constants */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
106 PyObject *u_names; /* all names */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
107 PyObject *u_varnames; /* local variables */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
108 PyObject *u_cellvars; /* cell variables */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
109 PyObject *u_freevars; /* free variables */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
110 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
111 PyObject *u_private; /* for private name mangling */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
112 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
113 int u_argcount; /* number of arguments for block */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
114 /* Pointer to the most recently allocated block. By following b_list |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
115 members, you can reach all early allocated blocks. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
116 basicblock *u_blocks; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
117 basicblock *u_curblock; /* pointer to current block */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
118 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
119 int u_nfblocks; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
120 struct fblockinfo u_fblock[CO_MAXBLOCKS]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
121 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
122 int u_firstlineno; /* the first lineno of the block */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
123 int u_lineno; /* the lineno for the current stmt */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
124 bool u_lineno_set; /* boolean to indicate whether instr |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
125 has been generated with current lineno */ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
126 }; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
127 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
128 /* This struct captures the global state of a compilation. |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
129 |
|
36766
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
130 The u pointer points to the current compilation unit, while units |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
131 for enclosing blocks are stored in c_stack. The u and c_stack are |
|
36766
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
132 managed by compiler_enter_scope() and compiler_exit_scope(). |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
133 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
134 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
135 struct compiler { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
136 const char *c_filename; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
137 struct symtable *c_st; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
138 PyFutureFeatures *c_future; /* pointer to module's __future__ */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
139 PyCompilerFlags *c_flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
140 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
141 int c_interactive; /* true if in interactive mode */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
142 int c_nestlevel; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
143 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
144 struct compiler_unit *u; /* compiler state for current block */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
145 PyObject *c_stack; /* Python list holding compiler_unit ptrs */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
146 PyArena *c_arena; /* pointer to memory allocation arena */ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
147 }; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
148 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
149 static int compiler_enter_scope(struct compiler *, identifier, void *, int); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
150 static void compiler_free(struct compiler *); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
151 static basicblock *compiler_new_block(struct compiler *); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
152 static int compiler_next_instr(struct compiler *, basicblock *); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
153 static int compiler_addop(struct compiler *, int); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
154 static int compiler_addop_o(struct compiler *, int, PyObject *, PyObject *); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
155 static int compiler_addop_i(struct compiler *, int, int); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
156 static int compiler_addop_j(struct compiler *, int, basicblock *, int); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
157 static basicblock *compiler_use_new_block(struct compiler *); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
158 static int compiler_error(struct compiler *, const char *); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
159 static int compiler_nameop(struct compiler *, identifier, expr_context_ty); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
160 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
161 static PyCodeObject *compiler_mod(struct compiler *, mod_ty); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
162 static int compiler_visit_stmt(struct compiler *, stmt_ty); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
163 static int compiler_visit_keyword(struct compiler *, keyword_ty); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
164 static int compiler_visit_expr(struct compiler *, expr_ty); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
165 static int compiler_augassign(struct compiler *, stmt_ty); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
166 static int compiler_visit_slice(struct compiler *, slice_ty, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
167 expr_context_ty); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
168 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
169 static int compiler_push_fblock(struct compiler *, enum fblocktype, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
170 basicblock *); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
171 static void compiler_pop_fblock(struct compiler *, enum fblocktype, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
172 basicblock *); |
|
39983
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
173 /* Returns true if there is a loop on the fblock stack. */ |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
174 static int compiler_in_loop(struct compiler *); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
175 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
176 static int inplace_binop(struct compiler *, operator_ty); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
177 static int expr_constant(expr_ty e); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
178 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
179 static int compiler_with(struct compiler *, stmt_ty); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
180 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
181 static PyCodeObject *assemble(struct compiler *, int addNone); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
182 static PyObject *__doc__; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
183 |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
59672
diff
changeset
|
184 #define COMPILER_CAPSULE_NAME_COMPILER_UNIT "compile.c compiler unit" |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
59672
diff
changeset
|
185 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
186 PyObject * |
|
37606
f448d0075691
more low-hanging fruit to make code compile under a C++ compiler. Not
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37558
diff
changeset
|
187 _Py_Mangle(PyObject *privateobj, PyObject *ident) |
| 33100 | 188 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
189 /* Name mangling: __private becomes _classname__private. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
190 This is independent from how the name is used. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
191 const char *p, *name = PyString_AsString(ident); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
192 char *buffer; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
193 size_t nlen, plen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
194 if (privateobj == NULL || !PyString_Check(privateobj) || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
195 name == NULL || name[0] != '_' || name[1] != '_') { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
196 Py_INCREF(ident); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
197 return ident; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
198 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
199 p = PyString_AsString(privateobj); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
200 nlen = strlen(name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
201 /* Don't mangle __id__ or names with dots. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
202 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
203 The only time a name with a dot can occur is when |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
204 we are compiling an import statement that has a |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
205 package name. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
206 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
207 TODO(jhylton): Decide whether we want to support |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
208 mangling of the module name, e.g. __M.X. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
209 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
210 if ((name[nlen-1] == '_' && name[nlen-2] == '_') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
211 || strchr(name, '.')) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
212 Py_INCREF(ident); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
213 return ident; /* Don't mangle __whatever__ */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
214 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
215 /* Strip leading underscores from class name */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
216 while (*p == '_') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
217 p++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
218 if (*p == '\0') { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
219 Py_INCREF(ident); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
220 return ident; /* Don't mangle if class is just underscores */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
221 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
222 plen = strlen(p); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
223 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
224 assert(1 <= PY_SSIZE_T_MAX - nlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
225 assert(1 + nlen <= PY_SSIZE_T_MAX - plen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
226 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
227 ident = PyString_FromStringAndSize(NULL, 1 + nlen + plen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
228 if (!ident) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
229 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
230 /* ident = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
231 buffer = PyString_AS_STRING(ident); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
232 buffer[0] = '_'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
233 strncpy(buffer+1, p, plen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
234 strcpy(buffer+1+plen, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
235 return ident; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
236 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
237 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
238 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
239 compiler_init(struct compiler *c) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
240 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
241 memset(c, 0, sizeof(struct compiler)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
242 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
243 c->c_stack = PyList_New(0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
244 if (!c->c_stack) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
245 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
246 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
247 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
248 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
249 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
250 PyCodeObject * |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
35993
diff
changeset
|
251 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
252 PyArena *arena) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
253 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
254 struct compiler c; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
255 PyCodeObject *co = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
256 PyCompilerFlags local_flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
257 int merged; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
258 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
259 if (!__doc__) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
260 __doc__ = PyString_InternFromString("__doc__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
261 if (!__doc__) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
262 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
263 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
264 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
265 if (!compiler_init(&c)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
266 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
267 c.c_filename = filename; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
268 c.c_arena = arena; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
269 c.c_future = PyFuture_FromAST(mod, filename); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
270 if (c.c_future == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
271 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
272 if (!flags) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
273 local_flags.cf_flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
274 flags = &local_flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
275 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
276 merged = c.c_future->ff_features | flags->cf_flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
277 c.c_future->ff_features = merged; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
278 flags->cf_flags = merged; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
279 c.c_flags = flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
280 c.c_nestlevel = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
281 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
282 c.c_st = PySymtable_Build(mod, filename, c.c_future); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
283 if (c.c_st == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
284 if (!PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
285 PyErr_SetString(PyExc_SystemError, "no symtable"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
286 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
287 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
288 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
289 co = compiler_mod(&c, mod); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
290 |
|
36697
78de5f6b2f67
Clarify C-style exception handling with proper label name.
Thomas Wouters <thomas@python.org>
parents:
36696
diff
changeset
|
291 finally: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
292 compiler_free(&c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
293 assert(co || PyErr_Occurred()); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
294 return co; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
295 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
296 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
297 PyCodeObject * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
298 PyNode_Compile(struct _node *n, const char *filename) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
299 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
300 PyCodeObject *co = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
301 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
302 PyArena *arena = PyArena_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
303 if (!arena) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
304 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
305 mod = PyAST_FromNode(n, NULL, filename, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
306 if (mod) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
307 co = PyAST_Compile(mod, filename, NULL, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
308 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
309 return co; |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
310 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
311 |
| 69 | 312 static void |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
313 compiler_free(struct compiler *c) |
| 69 | 314 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
315 if (c->c_st) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
316 PySymtable_Free(c->c_st); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
317 if (c->c_future) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
318 PyObject_Free(c->c_future); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
319 Py_DECREF(c->c_stack); |
| 69 | 320 } |
| 321 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
322 static PyObject * |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
323 list2dict(PyObject *list) |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
324 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
325 Py_ssize_t i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
326 PyObject *v, *k; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
327 PyObject *dict = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
328 if (!dict) return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
329 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
330 n = PyList_Size(list); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
331 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
332 v = PyInt_FromLong(i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
333 if (!v) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
334 Py_DECREF(dict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
335 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
336 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
337 k = PyList_GET_ITEM(list, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
338 k = PyTuple_Pack(2, k, k->ob_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
339 if (k == NULL || PyDict_SetItem(dict, k, v) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
340 Py_XDECREF(k); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
341 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
342 Py_DECREF(dict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
343 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
344 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
345 Py_DECREF(k); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
346 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
347 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
348 return dict; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
349 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
350 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
351 /* Return new dict containing names from src that match scope(s). |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
352 |
|
36766
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
353 src is a symbol table dictionary. If the scope of a name matches |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
354 either scope_type or flag is set, insert it into the new dict. The |
|
36766
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
355 values are integers, starting at offset and increasing by one for |
|
1daa199b784b
Tabify and reflow some long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36729
diff
changeset
|
356 each key. |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
357 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
358 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
359 static PyObject * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
360 dictbytype(PyObject *src, int scope_type, int flag, int offset) |
|
16006
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
361 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
362 Py_ssize_t pos = 0, i = offset, scope; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
363 PyObject *k, *v, *dest = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
364 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
365 assert(offset >= 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
366 if (dest == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
367 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
368 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
369 while (PyDict_Next(src, &pos, &k, &v)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
370 /* XXX this should probably be a macro in symtable.h */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
371 assert(PyInt_Check(v)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
372 scope = (PyInt_AS_LONG(v) >> SCOPE_OFF) & SCOPE_MASK; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
373 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
374 if (scope == scope_type || PyInt_AS_LONG(v) & flag) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
375 PyObject *tuple, *item = PyInt_FromLong(i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
376 if (item == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
377 Py_DECREF(dest); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
378 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
379 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
380 i++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
381 tuple = PyTuple_Pack(2, k, k->ob_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
382 if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
383 Py_DECREF(item); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
384 Py_DECREF(dest); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
385 Py_XDECREF(tuple); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
386 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
387 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
388 Py_DECREF(item); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
389 Py_DECREF(tuple); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
390 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
391 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
392 return dest; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
393 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
394 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
395 static void |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
396 compiler_unit_check(struct compiler_unit *u) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
397 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
398 basicblock *block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
399 for (block = u->u_blocks; block != NULL; block = block->b_list) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
400 assert((void *)block != (void *)0xcbcbcbcb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
401 assert((void *)block != (void *)0xfbfbfbfb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
402 assert((void *)block != (void *)0xdbdbdbdb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
403 if (block->b_instr != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
404 assert(block->b_ialloc > 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
405 assert(block->b_iused > 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
406 assert(block->b_ialloc >= block->b_iused); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
407 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
408 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
409 assert (block->b_iused == 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
410 assert (block->b_ialloc == 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
411 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
412 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
413 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
414 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
415 static void |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
416 compiler_unit_free(struct compiler_unit *u) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
417 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
418 basicblock *b, *next; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
419 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
420 compiler_unit_check(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
421 b = u->u_blocks; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
422 while (b != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
423 if (b->b_instr) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
424 PyObject_Free((void *)b->b_instr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
425 next = b->b_list; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
426 PyObject_Free((void *)b); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
427 b = next; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
428 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
429 Py_CLEAR(u->u_ste); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
430 Py_CLEAR(u->u_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
431 Py_CLEAR(u->u_consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
432 Py_CLEAR(u->u_names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
433 Py_CLEAR(u->u_varnames); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
434 Py_CLEAR(u->u_freevars); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
435 Py_CLEAR(u->u_cellvars); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
436 Py_CLEAR(u->u_private); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
437 PyObject_Free(u); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
438 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
439 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
440 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
441 compiler_enter_scope(struct compiler *c, identifier name, void *key, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
442 int lineno) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
443 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
444 struct compiler_unit *u; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
445 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
446 u = (struct compiler_unit *)PyObject_Malloc(sizeof( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
447 struct compiler_unit)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
448 if (!u) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
449 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
450 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
451 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
452 memset(u, 0, sizeof(struct compiler_unit)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
453 u->u_argcount = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
454 u->u_ste = PySymtable_Lookup(c->c_st, key); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
455 if (!u->u_ste) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
456 compiler_unit_free(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
457 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
458 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
459 Py_INCREF(name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
460 u->u_name = name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
461 u->u_varnames = list2dict(u->u_ste->ste_varnames); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
462 u->u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, 0, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
463 if (!u->u_varnames || !u->u_cellvars) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
464 compiler_unit_free(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
465 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
466 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
467 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
468 u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE, DEF_FREE_CLASS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
469 PyDict_Size(u->u_cellvars)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
470 if (!u->u_freevars) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
471 compiler_unit_free(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
472 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
473 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
474 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
475 u->u_blocks = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
476 u->u_nfblocks = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
477 u->u_firstlineno = lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
478 u->u_lineno = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
479 u->u_lineno_set = false; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
480 u->u_consts = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
481 if (!u->u_consts) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
482 compiler_unit_free(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
483 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
484 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
485 u->u_names = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
486 if (!u->u_names) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
487 compiler_unit_free(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
488 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
489 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
490 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
491 u->u_private = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
492 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
493 /* Push the old compiler_unit on the stack. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
494 if (c->u) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
495 PyObject *capsule = PyCapsule_New(c->u, COMPILER_CAPSULE_NAME_COMPILER_UNIT, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
496 if (!capsule || PyList_Append(c->c_stack, capsule) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
497 Py_XDECREF(capsule); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
498 compiler_unit_free(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
499 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
500 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
501 Py_DECREF(capsule); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
502 u->u_private = c->u->u_private; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
503 Py_XINCREF(u->u_private); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
504 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
505 c->u = u; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
506 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
507 c->c_nestlevel++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
508 if (compiler_use_new_block(c) == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
509 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
510 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
511 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
512 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
513 |
|
35797
3778083fe2c8
Ensure that compiler_exit_scope() is called as necessary to free memory
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
35790
diff
changeset
|
514 static void |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
515 compiler_exit_scope(struct compiler *c) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
516 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
517 int n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
518 PyObject *capsule; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
519 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
520 c->c_nestlevel--; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
521 compiler_unit_free(c->u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
522 /* Restore c->u to the parent unit. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
523 n = PyList_GET_SIZE(c->c_stack) - 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
524 if (n >= 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
525 capsule = PyList_GET_ITEM(c->c_stack, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
526 c->u = (struct compiler_unit *)PyCapsule_GetPointer(capsule, COMPILER_CAPSULE_NAME_COMPILER_UNIT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
527 assert(c->u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
528 /* we are deleting from a list so this really shouldn't fail */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
529 if (PySequence_DelItem(c->c_stack, n) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
530 Py_FatalError("compiler_exit_scope()"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
531 compiler_unit_check(c->u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
532 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
533 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
534 c->u = NULL; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
535 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
536 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
537 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
538 /* Allocate a new block and return a pointer to it. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
539 Returns NULL on error. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
540 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
541 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
542 static basicblock * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
543 compiler_new_block(struct compiler *c) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
544 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
545 basicblock *b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
546 struct compiler_unit *u; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
547 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
548 u = c->u; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
549 b = (basicblock *)PyObject_Malloc(sizeof(basicblock)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
550 if (b == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
551 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
552 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
553 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
554 memset((void *)b, 0, sizeof(basicblock)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
555 /* Extend the singly linked list of blocks with new block. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
556 b->b_list = u->u_blocks; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
557 u->u_blocks = b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
558 return b; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
559 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
560 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
561 static basicblock * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
562 compiler_use_new_block(struct compiler *c) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
563 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
564 basicblock *block = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
565 if (block == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
566 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
567 c->u->u_curblock = block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
568 return block; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
569 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
570 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
571 static basicblock * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
572 compiler_next_block(struct compiler *c) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
573 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
574 basicblock *block = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
575 if (block == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
576 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
577 c->u->u_curblock->b_next = block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
578 c->u->u_curblock = block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
579 return block; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
580 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
581 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
582 static basicblock * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
583 compiler_use_next_block(struct compiler *c, basicblock *block) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
584 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
585 assert(block != NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
586 c->u->u_curblock->b_next = block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
587 c->u->u_curblock = block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
588 return block; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
589 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
590 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
591 /* Returns the offset of the next instruction in the current block's |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
592 b_instr array. Resizes the b_instr as necessary. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
593 Returns -1 on failure. |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
594 */ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
595 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
596 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
597 compiler_next_instr(struct compiler *c, basicblock *b) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
598 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
599 assert(b != NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
600 if (b->b_instr == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
601 b->b_instr = (struct instr *)PyObject_Malloc( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
602 sizeof(struct instr) * DEFAULT_BLOCK_SIZE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
603 if (b->b_instr == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
604 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
605 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
606 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
607 b->b_ialloc = DEFAULT_BLOCK_SIZE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
608 memset((char *)b->b_instr, 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
609 sizeof(struct instr) * DEFAULT_BLOCK_SIZE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
610 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
611 else if (b->b_iused == b->b_ialloc) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
612 struct instr *tmp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
613 size_t oldsize, newsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
614 oldsize = b->b_ialloc * sizeof(struct instr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
615 newsize = oldsize << 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
616 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
617 if (oldsize > (PY_SIZE_MAX >> 1)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
618 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
619 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
620 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
621 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
622 if (newsize == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
623 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
624 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
625 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
626 b->b_ialloc <<= 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
627 tmp = (struct instr *)PyObject_Realloc( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
628 (void *)b->b_instr, newsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
629 if (tmp == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
630 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
631 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
632 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
633 b->b_instr = tmp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
634 memset((char *)b->b_instr + oldsize, 0, newsize - oldsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
635 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
636 return b->b_iused++; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
637 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
638 |
|
45151
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
639 /* Set the i_lineno member of the instruction at offset off if the |
|
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
640 line number for the current expression/statement has not |
|
37390
5e1cf21d4ab2
Expand comments on line numbers and blocks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37067
diff
changeset
|
641 already been set. If it has been set, the call has no effect. |
|
5e1cf21d4ab2
Expand comments on line numbers and blocks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37067
diff
changeset
|
642 |
|
45151
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
643 The line number is reset in the following cases: |
|
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
644 - when entering a new scope |
|
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
645 - on each statement |
|
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
646 - on each expression that start a new line |
|
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
647 - before the "except" clause |
|
643c1397f954
#1750076: Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45076
diff
changeset
|
648 - before the "for" and "while" expressions |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
649 */ |
|
37390
5e1cf21d4ab2
Expand comments on line numbers and blocks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37067
diff
changeset
|
650 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
651 static void |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
652 compiler_set_lineno(struct compiler *c, int off) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
653 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
654 basicblock *b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
655 if (c->u->u_lineno_set) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
656 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
657 c->u->u_lineno_set = true; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
658 b = c->u->u_curblock; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
659 b->b_instr[off].i_lineno = c->u->u_lineno; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
660 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
661 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
662 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
663 opcode_stack_effect(int opcode, int oparg) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
664 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
665 switch (opcode) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
666 case POP_TOP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
667 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
668 case ROT_TWO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
669 case ROT_THREE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
670 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
671 case DUP_TOP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
672 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
673 case ROT_FOUR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
674 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
675 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
676 case UNARY_POSITIVE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
677 case UNARY_NEGATIVE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
678 case UNARY_NOT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
679 case UNARY_CONVERT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
680 case UNARY_INVERT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
681 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
682 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
683 case SET_ADD: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
684 case LIST_APPEND: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
685 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
686 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
687 case MAP_ADD: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
688 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
689 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
690 case BINARY_POWER: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
691 case BINARY_MULTIPLY: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
692 case BINARY_DIVIDE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
693 case BINARY_MODULO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
694 case BINARY_ADD: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
695 case BINARY_SUBTRACT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
696 case BINARY_SUBSCR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
697 case BINARY_FLOOR_DIVIDE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
698 case BINARY_TRUE_DIVIDE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
699 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
700 case INPLACE_FLOOR_DIVIDE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
701 case INPLACE_TRUE_DIVIDE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
702 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
703 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
704 case SLICE+0: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
705 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
706 case SLICE+1: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
707 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
708 case SLICE+2: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
709 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
710 case SLICE+3: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
711 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
712 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
713 case STORE_SLICE+0: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
714 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
715 case STORE_SLICE+1: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
716 return -3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
717 case STORE_SLICE+2: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
718 return -3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
719 case STORE_SLICE+3: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
720 return -4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
721 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
722 case DELETE_SLICE+0: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
723 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
724 case DELETE_SLICE+1: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
725 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
726 case DELETE_SLICE+2: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
727 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
728 case DELETE_SLICE+3: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
729 return -3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
730 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
731 case INPLACE_ADD: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
732 case INPLACE_SUBTRACT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
733 case INPLACE_MULTIPLY: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
734 case INPLACE_DIVIDE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
735 case INPLACE_MODULO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
736 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
737 case STORE_SUBSCR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
738 return -3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
739 case STORE_MAP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
740 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
741 case DELETE_SUBSCR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
742 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
743 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
744 case BINARY_LSHIFT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
745 case BINARY_RSHIFT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
746 case BINARY_AND: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
747 case BINARY_XOR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
748 case BINARY_OR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
749 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
750 case INPLACE_POWER: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
751 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
752 case GET_ITER: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
753 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
754 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
755 case PRINT_EXPR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
756 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
757 case PRINT_ITEM: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
758 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
759 case PRINT_NEWLINE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
760 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
761 case PRINT_ITEM_TO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
762 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
763 case PRINT_NEWLINE_TO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
764 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
765 case INPLACE_LSHIFT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
766 case INPLACE_RSHIFT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
767 case INPLACE_AND: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
768 case INPLACE_XOR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
769 case INPLACE_OR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
770 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
771 case BREAK_LOOP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
772 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
773 case SETUP_WITH: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
774 return 4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
775 case WITH_CLEANUP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
776 return -1; /* XXX Sometimes more */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
777 case LOAD_LOCALS: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
778 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
779 case RETURN_VALUE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
780 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
781 case IMPORT_STAR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
782 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
783 case EXEC_STMT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
784 return -3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
785 case YIELD_VALUE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
786 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
787 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
788 case POP_BLOCK: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
789 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
790 case END_FINALLY: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
791 return -3; /* or -1 or -2 if no exception occurred or |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
792 return/break/continue */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
793 case BUILD_CLASS: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
794 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
795 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
796 case STORE_NAME: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
797 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
798 case DELETE_NAME: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
799 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
800 case UNPACK_SEQUENCE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
801 return oparg-1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
802 case FOR_ITER: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
803 return 1; /* or -1, at end of iterator */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
804 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
805 case STORE_ATTR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
806 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
807 case DELETE_ATTR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
808 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
809 case STORE_GLOBAL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
810 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
811 case DELETE_GLOBAL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
812 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
813 case DUP_TOPX: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
814 return oparg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
815 case LOAD_CONST: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
816 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
817 case LOAD_NAME: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
818 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
819 case BUILD_TUPLE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
820 case BUILD_LIST: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
821 case BUILD_SET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
822 return 1-oparg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
823 case BUILD_MAP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
824 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
825 case LOAD_ATTR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
826 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
827 case COMPARE_OP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
828 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
829 case IMPORT_NAME: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
830 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
831 case IMPORT_FROM: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
832 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
833 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
834 case JUMP_FORWARD: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
835 case JUMP_IF_TRUE_OR_POP: /* -1 if jump not taken */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
836 case JUMP_IF_FALSE_OR_POP: /* "" */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
837 case JUMP_ABSOLUTE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
838 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
839 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
840 case POP_JUMP_IF_FALSE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
841 case POP_JUMP_IF_TRUE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
842 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
843 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
844 case LOAD_GLOBAL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
845 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
846 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
847 case CONTINUE_LOOP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
848 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
849 case SETUP_LOOP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
850 case SETUP_EXCEPT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
851 case SETUP_FINALLY: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
852 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
853 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
854 case LOAD_FAST: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
855 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
856 case STORE_FAST: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
857 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
858 case DELETE_FAST: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
859 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
860 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
861 case RAISE_VARARGS: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
862 return -oparg; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
863 #define NARGS(o) (((o) % 256) + 2*((o) / 256)) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
864 case CALL_FUNCTION: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
865 return -NARGS(oparg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
866 case CALL_FUNCTION_VAR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
867 case CALL_FUNCTION_KW: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
868 return -NARGS(oparg)-1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
869 case CALL_FUNCTION_VAR_KW: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
870 return -NARGS(oparg)-2; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
871 #undef NARGS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
872 case MAKE_FUNCTION: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
873 return -oparg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
874 case BUILD_SLICE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
875 if (oparg == 3) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
876 return -2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
877 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
878 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
879 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
880 case MAKE_CLOSURE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
881 return -oparg-1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
882 case LOAD_CLOSURE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
883 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
884 case LOAD_DEREF: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
885 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
886 case STORE_DEREF: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
887 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
888 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
889 fprintf(stderr, "opcode = %d\n", opcode); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
890 Py_FatalError("opcode_stack_effect()"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
891 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
892 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
893 return 0; /* not reachable */ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
894 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
895 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
896 /* Add an opcode with no argument. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
897 Returns 0 on failure, 1 on success. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
898 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
899 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
900 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
901 compiler_addop(struct compiler *c, int opcode) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
902 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
903 basicblock *b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
904 struct instr *i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
905 int off; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
906 off = compiler_next_instr(c, c->u->u_curblock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
907 if (off < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
908 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
909 b = c->u->u_curblock; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
910 i = &b->b_instr[off]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
911 i->i_opcode = opcode; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
912 i->i_hasarg = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
913 if (opcode == RETURN_VALUE) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
914 b->b_return = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
915 compiler_set_lineno(c, off); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
916 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
917 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
918 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
919 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
920 compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
921 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
922 PyObject *t, *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
923 Py_ssize_t arg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
924 double d; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
925 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
926 /* necessary to make sure types aren't coerced (e.g., int and long) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
927 /* _and_ to distinguish 0.0 from -0.0 e.g. on IEEE platforms */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
928 if (PyFloat_Check(o)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
929 d = PyFloat_AS_DOUBLE(o); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
930 /* all we need is to make the tuple different in either the 0.0 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
931 * or -0.0 case from all others, just to avoid the "coercion". |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
932 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
933 if (d == 0.0 && copysign(1.0, d) < 0.0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
934 t = PyTuple_Pack(3, o, o->ob_type, Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
935 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
936 t = PyTuple_Pack(2, o, o->ob_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
937 } |
|
56545
2754d64180d1
Allow core Python build to succeed under WITHOUT_COMPLEX. The module build stage still fails.
Mark Dickinson <dickinsm@gmail.com>
parents:
56514
diff
changeset
|
938 #ifndef WITHOUT_COMPLEX |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
939 else if (PyComplex_Check(o)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
940 Py_complex z; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
941 int real_negzero, imag_negzero; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
942 /* For the complex case we must make complex(x, 0.) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
943 different from complex(x, -0.) and complex(0., y) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
944 different from complex(-0., y), for any x and y. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
945 All four complex zeros must be distinguished.*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
946 z = PyComplex_AsCComplex(o); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
947 real_negzero = z.real == 0.0 && copysign(1.0, z.real) < 0.0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
948 imag_negzero = z.imag == 0.0 && copysign(1.0, z.imag) < 0.0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
949 if (real_negzero && imag_negzero) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
950 t = PyTuple_Pack(5, o, o->ob_type, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
951 Py_None, Py_None, Py_None); |
|
45076
3f16ac915214
Issue #1678380. Fix a bug that identifies 0j and -0j when they appear
Mark Dickinson <dickinsm@gmail.com>
parents:
45028
diff
changeset
|
952 } |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
953 else if (imag_negzero) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
954 t = PyTuple_Pack(4, o, o->ob_type, Py_None, Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
955 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
956 else if (real_negzero) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
957 t = PyTuple_Pack(3, o, o->ob_type, Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
958 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
959 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
960 t = PyTuple_Pack(2, o, o->ob_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
961 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
962 } |
|
56545
2754d64180d1
Allow core Python build to succeed under WITHOUT_COMPLEX. The module build stage still fails.
Mark Dickinson <dickinsm@gmail.com>
parents:
56514
diff
changeset
|
963 #endif /* WITHOUT_COMPLEX */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
964 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
965 t = PyTuple_Pack(2, o, o->ob_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
966 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
967 if (t == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
968 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
969 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
970 v = PyDict_GetItem(dict, t); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
971 if (!v) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
972 arg = PyDict_Size(dict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
973 v = PyInt_FromLong(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
974 if (!v) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
975 Py_DECREF(t); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
976 return -1; |
|
42704
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
41930
diff
changeset
|
977 } |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
978 if (PyDict_SetItem(dict, t, v) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
979 Py_DECREF(t); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
980 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
981 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
982 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
983 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
984 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
985 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
986 arg = PyInt_AsLong(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
987 Py_DECREF(t); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
988 return arg; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
989 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
990 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
991 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
992 compiler_addop_o(struct compiler *c, int opcode, PyObject *dict, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
993 PyObject *o) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
994 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
995 int arg = compiler_add_o(c, dict, o); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
996 if (arg < 0) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
997 return 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
998 return compiler_addop_i(c, opcode, arg); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
999 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1000 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1001 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1002 compiler_addop_name(struct compiler *c, int opcode, PyObject *dict, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1003 PyObject *o) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1004 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1005 int arg; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1006 PyObject *mangled = _Py_Mangle(c->u->u_private, o); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1007 if (!mangled) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
1008 return 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1009 arg = compiler_add_o(c, dict, mangled); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1010 Py_DECREF(mangled); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1011 if (arg < 0) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
1012 return 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1013 return compiler_addop_i(c, opcode, arg); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1014 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1015 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1016 /* Add an opcode with an integer argument. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1017 Returns 0 on failure, 1 on success. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1018 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1019 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1020 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1021 compiler_addop_i(struct compiler *c, int opcode, int oparg) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1022 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1023 struct instr *i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1024 int off; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1025 off = compiler_next_instr(c, c->u->u_curblock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1026 if (off < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1027 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1028 i = &c->u->u_curblock->b_instr[off]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1029 i->i_opcode = opcode; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1030 i->i_oparg = oparg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1031 i->i_hasarg = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1032 compiler_set_lineno(c, off); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1033 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1034 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1035 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1036 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1037 compiler_addop_j(struct compiler *c, int opcode, basicblock *b, int absolute) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1038 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1039 struct instr *i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1040 int off; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1041 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1042 assert(b != NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1043 off = compiler_next_instr(c, c->u->u_curblock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1044 if (off < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1045 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1046 i = &c->u->u_curblock->b_instr[off]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1047 i->i_opcode = opcode; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1048 i->i_target = b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1049 i->i_hasarg = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1050 if (absolute) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1051 i->i_jabs = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1052 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1053 i->i_jrel = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1054 compiler_set_lineno(c, off); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1055 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1056 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1057 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1058 /* The distinction between NEW_BLOCK and NEXT_BLOCK is subtle. (I'd |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1059 like to find better names.) NEW_BLOCK() creates a new block and sets |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1060 it as the current block. NEXT_BLOCK() also creates an implicit jump |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1061 from the current block to the new block. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1062 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1063 |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
1064 /* The returns inside these macros make it impossible to decref objects |
|
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
1065 created in the local function. Local objects should use the arena. |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1066 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1067 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1068 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1069 #define NEW_BLOCK(C) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1070 if (compiler_use_new_block((C)) == NULL) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1071 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1072 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1073 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1074 #define NEXT_BLOCK(C) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1075 if (compiler_next_block((C)) == NULL) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1076 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1077 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1078 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1079 #define ADDOP(C, OP) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1080 if (!compiler_addop((C), (OP))) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1081 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1082 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1083 |
|
35863
79f2ce320192
Fix a lot of memory and ref leaks in error paths.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35860
diff
changeset
|
1084 #define ADDOP_IN_SCOPE(C, OP) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1085 if (!compiler_addop((C), (OP))) { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1086 compiler_exit_scope(c); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1087 return 0; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1088 } \ |
|
35863
79f2ce320192
Fix a lot of memory and ref leaks in error paths.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35860
diff
changeset
|
1089 } |
|
79f2ce320192
Fix a lot of memory and ref leaks in error paths.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35860
diff
changeset
|
1090 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1091 #define ADDOP_O(C, OP, O, TYPE) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1092 if (!compiler_addop_o((C), (OP), (C)->u->u_ ## TYPE, (O))) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1093 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1094 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1095 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1096 #define ADDOP_NAME(C, OP, O, TYPE) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1097 if (!compiler_addop_name((C), (OP), (C)->u->u_ ## TYPE, (O))) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1098 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1099 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1100 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1101 #define ADDOP_I(C, OP, O) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1102 if (!compiler_addop_i((C), (OP), (O))) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1103 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1104 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1105 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1106 #define ADDOP_JABS(C, OP, O) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1107 if (!compiler_addop_j((C), (OP), (O), 1)) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1108 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1109 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1110 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1111 #define ADDOP_JREL(C, OP, O) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1112 if (!compiler_addop_j((C), (OP), (O), 0)) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1113 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1114 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1115 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1116 /* VISIT and VISIT_SEQ takes an ASDL type as their second argument. They use |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1117 the ASDL name to synthesize the name of the C type and the visit function. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1118 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1119 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1120 #define VISIT(C, TYPE, V) {\ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1121 if (!compiler_visit_ ## TYPE((C), (V))) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1122 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1123 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1124 |
|
35863
79f2ce320192
Fix a lot of memory and ref leaks in error paths.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35860
diff
changeset
|
1125 #define VISIT_IN_SCOPE(C, TYPE, V) {\ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1126 if (!compiler_visit_ ## TYPE((C), (V))) { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1127 compiler_exit_scope(c); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1128 return 0; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1129 } \ |
|
35863
79f2ce320192
Fix a lot of memory and ref leaks in error paths.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35860
diff
changeset
|
1130 } |
|
79f2ce320192
Fix a lot of memory and ref leaks in error paths.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35860
diff
changeset
|
1131 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1132 #define VISIT_SLICE(C, V, CTX) {\ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1133 if (!compiler_visit_slice((C), (V), (CTX))) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1134 return 0; \ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1135 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1136 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1137 #define VISIT_SEQ(C, TYPE, SEQ) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1138 int _i; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1139 asdl_seq *seq = (SEQ); /* avoid variable capture */ \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1140 for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1141 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1142 if (!compiler_visit_ ## TYPE((C), elt)) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1143 return 0; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1144 } \ |
|
37606
f448d0075691
more low-hanging fruit to make code compile under a C++ compiler. Not
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37558
diff
changeset
|
1145 } |
|
f448d0075691
more low-hanging fruit to make code compile under a C++ compiler. Not
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37558
diff
changeset
|
1146 |
|
35863
79f2ce320192
Fix a lot of memory and ref leaks in error paths.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35860
diff
changeset
|
1147 #define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1148 int _i; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1149 asdl_seq *seq = (SEQ); /* avoid variable capture */ \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1150 for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1151 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1152 if (!compiler_visit_ ## TYPE((C), elt)) { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1153 compiler_exit_scope(c); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1154 return 0; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1155 } \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1156 } \ |
|
37606
f448d0075691
more low-hanging fruit to make code compile under a C++ compiler. Not
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37558
diff
changeset
|
1157 } |
|
f448d0075691
more low-hanging fruit to make code compile under a C++ compiler. Not
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37558
diff
changeset
|
1158 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1159 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1160 compiler_isdocstring(stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1161 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1162 if (s->kind != Expr_kind) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
1163 return 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1164 return s->v.Expr.value->kind == Str_kind; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1165 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1166 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1167 /* Compile a sequence of statements, checking for a docstring. */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1168 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1169 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1170 compiler_body(struct compiler *c, asdl_seq *stmts) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1171 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1172 int i = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1173 stmt_ty st; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1174 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1175 if (!asdl_seq_LEN(stmts)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1176 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1177 st = (stmt_ty)asdl_seq_GET(stmts, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1178 if (compiler_isdocstring(st) && Py_OptimizeFlag < 2) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1179 /* don't generate docstrings if -OO */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1180 i = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1181 VISIT(c, expr, st->v.Expr.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1182 if (!compiler_nameop(c, __doc__, Store)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1183 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1184 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1185 for (; i < asdl_seq_LEN(stmts); i++) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1186 VISIT(c, stmt, (stmt_ty)asdl_seq_GET(stmts, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1187 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1188 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1189 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1190 static PyCodeObject * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1191 compiler_mod(struct compiler *c, mod_ty mod) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1192 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1193 PyCodeObject *co; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1194 int addNone = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1195 static PyObject *module; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1196 if (!module) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1197 module = PyString_InternFromString("<module>"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1198 if (!module) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1199 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1200 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1201 /* Use 0 for firstlineno initially, will fixup in assemble(). */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1202 if (!compiler_enter_scope(c, module, mod, 0)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1203 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1204 switch (mod->kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1205 case Module_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1206 if (!compiler_body(c, mod->v.Module.body)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1207 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1208 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1209 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1210 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1211 case Interactive_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1212 c->c_interactive = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1213 VISIT_SEQ_IN_SCOPE(c, stmt, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1214 mod->v.Interactive.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1215 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1216 case Expression_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1217 VISIT_IN_SCOPE(c, expr, mod->v.Expression.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1218 addNone = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1219 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1220 case Suite_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1221 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1222 "suite should not be possible"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1223 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1224 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1225 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1226 "module kind %d should not be possible", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1227 mod->kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1228 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1229 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1230 co = assemble(c, addNone); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1231 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1232 return co; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1233 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1234 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1235 /* The test for LOCAL must come before the test for FREE in order to |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1236 handle classes where name is both local and free. The local var is |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1237 a method and the free var is a free var referenced within a method. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1238 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1239 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1240 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1241 get_ref_type(struct compiler *c, PyObject *name) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1242 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1243 int scope = PyST_GetScope(c->u->u_ste, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1244 if (scope == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1245 char buf[350]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1246 PyOS_snprintf(buf, sizeof(buf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1247 "unknown scope for %.100s in %.100s(%s) in %s\n" |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1248 "symbols: %s\nlocals: %s\nglobals: %s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1249 PyString_AS_STRING(name), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1250 PyString_AS_STRING(c->u->u_name), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1251 PyObject_REPR(c->u->u_ste->ste_id), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1252 c->c_filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1253 PyObject_REPR(c->u->u_ste->ste_symbols), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1254 PyObject_REPR(c->u->u_varnames), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1255 PyObject_REPR(c->u->u_names) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1256 ); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1257 Py_FatalError(buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1258 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1259 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1260 return scope; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1261 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1262 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1263 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1264 compiler_lookup_arg(PyObject *dict, PyObject *name) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1265 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1266 PyObject *k, *v; |
|
38406
8f7c7aeac3a5
Replace Py_BuildValue("OO") by PyTuple_Pack.
Georg Brandl <georg@python.org>
parents:
38084
diff
changeset
|
1267 k = PyTuple_Pack(2, name, name->ob_type); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1268 if (k == NULL) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
1269 return -1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1270 v = PyDict_GetItem(dict, k); |
|
35939
79374eb6db51
Fix a few more ref leaks. Backport candidate
Neal Norwitz <nnorwitz@gmail.com>
parents:
35895
diff
changeset
|
1271 Py_DECREF(k); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1272 if (v == NULL) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
1273 return -1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1274 return PyInt_AS_LONG(v); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1275 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1276 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1277 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1278 compiler_make_closure(struct compiler *c, PyCodeObject *co, int args) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1279 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1280 int i, free = PyCode_GetNumFree(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1281 if (free == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1282 ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1283 ADDOP_I(c, MAKE_FUNCTION, args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1284 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1285 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1286 for (i = 0; i < free; ++i) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1287 /* Bypass com_addop_varname because it will generate |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1288 LOAD_DEREF but LOAD_CLOSURE is needed. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1289 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1290 PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1291 int arg, reftype; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1292 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1293 /* Special case: If a class contains a method with a |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1294 free variable that has the same name as a method, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1295 the name will be considered free *and* local in the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1296 class. It should be handled by the closure, as |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1297 well as by the normal name loookup logic. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1298 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1299 reftype = get_ref_type(c, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1300 if (reftype == CELL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1301 arg = compiler_lookup_arg(c->u->u_cellvars, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1302 else /* (reftype == FREE) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1303 arg = compiler_lookup_arg(c->u->u_freevars, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1304 if (arg == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1305 printf("lookup %s in %s %d %d\n" |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1306 "freevars of %s: %s\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1307 PyObject_REPR(name), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1308 PyString_AS_STRING(c->u->u_name), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1309 reftype, arg, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1310 PyString_AS_STRING(co->co_name), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1311 PyObject_REPR(co->co_freevars)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1312 Py_FatalError("compiler_make_closure()"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1313 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1314 ADDOP_I(c, LOAD_CLOSURE, arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1315 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1316 ADDOP_I(c, BUILD_TUPLE, free); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1317 ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1318 ADDOP_I(c, MAKE_CLOSURE, args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1319 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1320 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1321 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1322 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1323 compiler_decorators(struct compiler *c, asdl_seq* decos) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1324 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1325 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1326 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1327 if (!decos) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1328 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1329 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1330 for (i = 0; i < asdl_seq_LEN(decos); i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1331 VISIT(c, expr, (expr_ty)asdl_seq_GET(decos, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1332 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1333 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1334 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1335 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1336 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1337 compiler_arguments(struct compiler *c, arguments_ty args) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1338 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1339 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1340 int n = asdl_seq_LEN(args->args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1341 /* Correctly handle nested argument lists */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1342 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1343 expr_ty arg = (expr_ty)asdl_seq_GET(args->args, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1344 if (arg->kind == Tuple_kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1345 PyObject *id = PyString_FromFormat(".%d", i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1346 if (id == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1347 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1348 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1349 if (!compiler_nameop(c, id, Load)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1350 Py_DECREF(id); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1351 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1352 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1353 Py_DECREF(id); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1354 VISIT(c, expr, arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1355 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1356 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1357 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1358 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1359 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1360 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1361 compiler_function(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1362 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1363 PyCodeObject *co; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1364 PyObject *first_const = Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1365 arguments_ty args = s->v.FunctionDef.args; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1366 asdl_seq* decos = s->v.FunctionDef.decorator_list; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1367 stmt_ty st; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1368 int i, n, docstring; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1369 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1370 assert(s->kind == FunctionDef_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1371 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1372 if (!compiler_decorators(c, decos)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1373 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1374 if (args->defaults) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1375 VISIT_SEQ(c, expr, args->defaults); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1376 if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1377 s->lineno)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1378 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1379 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1380 st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1381 docstring = compiler_isdocstring(st); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1382 if (docstring && Py_OptimizeFlag < 2) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1383 first_const = st->v.Expr.value->v.Str.s; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1384 if (compiler_add_o(c, c->u->u_consts, first_const) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1385 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1386 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1387 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1388 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1389 /* unpack nested arguments */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1390 compiler_arguments(c, args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1391 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1392 c->u->u_argcount = asdl_seq_LEN(args->args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1393 n = asdl_seq_LEN(s->v.FunctionDef.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1394 /* if there was a docstring, we need to skip the first statement */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1395 for (i = docstring; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1396 st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1397 VISIT_IN_SCOPE(c, stmt, st); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1398 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1399 co = assemble(c, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1400 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1401 if (co == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1402 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1403 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1404 compiler_make_closure(c, co, asdl_seq_LEN(args->defaults)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1405 Py_DECREF(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1406 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1407 for (i = 0; i < asdl_seq_LEN(decos); i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1408 ADDOP_I(c, CALL_FUNCTION, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1409 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1410 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1411 return compiler_nameop(c, s->v.FunctionDef.name, Store); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1412 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1413 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1414 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1415 compiler_class(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1416 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1417 int n, i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1418 PyCodeObject *co; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1419 PyObject *str; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1420 asdl_seq* decos = s->v.ClassDef.decorator_list; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1421 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1422 if (!compiler_decorators(c, decos)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1423 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1424 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1425 /* push class name on stack, needed by BUILD_CLASS */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1426 ADDOP_O(c, LOAD_CONST, s->v.ClassDef.name, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1427 /* push the tuple of base classes on the stack */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1428 n = asdl_seq_LEN(s->v.ClassDef.bases); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1429 if (n > 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1430 VISIT_SEQ(c, expr, s->v.ClassDef.bases); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1431 ADDOP_I(c, BUILD_TUPLE, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1432 if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1433 s->lineno)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1434 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1435 Py_XDECREF(c->u->u_private); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1436 c->u->u_private = s->v.ClassDef.name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1437 Py_INCREF(c->u->u_private); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1438 str = PyString_InternFromString("__name__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1439 if (!str || !compiler_nameop(c, str, Load)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1440 Py_XDECREF(str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1441 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1442 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1443 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1444 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1445 Py_DECREF(str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1446 str = PyString_InternFromString("__module__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1447 if (!str || !compiler_nameop(c, str, Store)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1448 Py_XDECREF(str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1449 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1450 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1451 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1452 Py_DECREF(str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1453 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1454 if (!compiler_body(c, s->v.ClassDef.body)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1455 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1456 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1457 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1458 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1459 ADDOP_IN_SCOPE(c, LOAD_LOCALS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1460 ADDOP_IN_SCOPE(c, RETURN_VALUE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1461 co = assemble(c, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1462 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1463 if (co == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1464 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1465 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1466 compiler_make_closure(c, co, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1467 Py_DECREF(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1468 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1469 ADDOP_I(c, CALL_FUNCTION, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1470 ADDOP(c, BUILD_CLASS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1471 /* apply decorators */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1472 for (i = 0; i < asdl_seq_LEN(decos); i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1473 ADDOP_I(c, CALL_FUNCTION, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1474 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1475 if (!compiler_nameop(c, s->v.ClassDef.name, Store)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1476 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1477 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1478 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1479 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1480 static int |
|
36666
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
1481 compiler_ifexp(struct compiler *c, expr_ty e) |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
1482 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1483 basicblock *end, *next; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1484 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1485 assert(e->kind == IfExp_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1486 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1487 if (end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1488 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1489 next = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1490 if (next == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1491 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1492 VISIT(c, expr, e->v.IfExp.test); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1493 ADDOP_JABS(c, POP_JUMP_IF_FALSE, next); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1494 VISIT(c, expr, e->v.IfExp.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1495 ADDOP_JREL(c, JUMP_FORWARD, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1496 compiler_use_next_block(c, next); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1497 VISIT(c, expr, e->v.IfExp.orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1498 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1499 return 1; |
|
36666
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
1500 } |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
1501 |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
1502 static int |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1503 compiler_lambda(struct compiler *c, expr_ty e) |
| 69 | 1504 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1505 PyCodeObject *co; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1506 static identifier name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1507 arguments_ty args = e->v.Lambda.args; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1508 assert(e->kind == Lambda_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1509 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1510 if (!name) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1511 name = PyString_InternFromString("<lambda>"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1512 if (!name) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1513 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1514 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1515 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1516 if (args->defaults) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1517 VISIT_SEQ(c, expr, args->defaults); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1518 if (!compiler_enter_scope(c, name, (void *)e, e->lineno)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1519 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1520 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1521 /* unpack nested arguments */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1522 compiler_arguments(c, args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1523 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1524 /* Make None the first constant, so the lambda can't have a |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1525 docstring. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1526 if (compiler_add_o(c, c->u->u_consts, Py_None) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1527 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1528 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1529 c->u->u_argcount = asdl_seq_LEN(args->args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1530 VISIT_IN_SCOPE(c, expr, e->v.Lambda.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1531 if (c->u->u_ste->ste_generator) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1532 ADDOP_IN_SCOPE(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1533 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1534 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1535 ADDOP_IN_SCOPE(c, RETURN_VALUE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1536 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1537 co = assemble(c, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1538 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1539 if (co == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1540 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1541 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1542 compiler_make_closure(c, co, asdl_seq_LEN(args->defaults)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1543 Py_DECREF(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1544 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1545 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1546 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1547 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1548 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1549 compiler_print(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1550 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1551 int i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1552 bool dest; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1553 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1554 assert(s->kind == Print_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1555 n = asdl_seq_LEN(s->v.Print.values); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1556 dest = false; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1557 if (s->v.Print.dest) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1558 VISIT(c, expr, s->v.Print.dest); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1559 dest = true; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1560 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1561 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1562 expr_ty e = (expr_ty)asdl_seq_GET(s->v.Print.values, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1563 if (dest) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1564 ADDOP(c, DUP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1565 VISIT(c, expr, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1566 ADDOP(c, ROT_TWO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1567 ADDOP(c, PRINT_ITEM_TO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1568 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1569 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1570 VISIT(c, expr, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1571 ADDOP(c, PRINT_ITEM); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1572 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1573 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1574 if (s->v.Print.nl) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1575 if (dest) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1576 ADDOP(c, PRINT_NEWLINE_TO) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1577 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1578 ADDOP(c, PRINT_NEWLINE) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1579 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1580 else if (dest) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1581 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1582 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1583 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1584 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1585 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1586 compiler_if(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1587 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1588 basicblock *end, *next; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1589 int constant; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1590 assert(s->kind == If_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1591 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1592 if (end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1593 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1594 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1595 constant = expr_constant(s->v.If.test); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1596 /* constant = 0: "if 0" |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1597 * constant = 1: "if 1", "if 2", ... |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1598 * constant = -1: rest */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1599 if (constant == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1600 if (s->v.If.orelse) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1601 VISIT_SEQ(c, stmt, s->v.If.orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1602 } else if (constant == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1603 VISIT_SEQ(c, stmt, s->v.If.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1604 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1605 if (s->v.If.orelse) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1606 next = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1607 if (next == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1608 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1609 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1610 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1611 next = end; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1612 VISIT(c, expr, s->v.If.test); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1613 ADDOP_JABS(c, POP_JUMP_IF_FALSE, next); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1614 VISIT_SEQ(c, stmt, s->v.If.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1615 ADDOP_JREL(c, JUMP_FORWARD, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1616 if (s->v.If.orelse) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1617 compiler_use_next_block(c, next); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1618 VISIT_SEQ(c, stmt, s->v.If.orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1619 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1620 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1621 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1622 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1623 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1624 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1625 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1626 compiler_for(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1627 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1628 basicblock *start, *cleanup, *end; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1629 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1630 start = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1631 cleanup = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1632 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1633 if (start == NULL || end == NULL || cleanup == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1634 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1635 ADDOP_JREL(c, SETUP_LOOP, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1636 if (!compiler_push_fblock(c, LOOP, start)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1637 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1638 VISIT(c, expr, s->v.For.iter); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1639 ADDOP(c, GET_ITER); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1640 compiler_use_next_block(c, start); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1641 ADDOP_JREL(c, FOR_ITER, cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1642 VISIT(c, expr, s->v.For.target); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1643 VISIT_SEQ(c, stmt, s->v.For.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1644 ADDOP_JABS(c, JUMP_ABSOLUTE, start); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1645 compiler_use_next_block(c, cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1646 ADDOP(c, POP_BLOCK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1647 compiler_pop_fblock(c, LOOP, start); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1648 VISIT_SEQ(c, stmt, s->v.For.orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1649 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1650 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1651 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1652 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1653 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1654 compiler_while(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1655 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1656 basicblock *loop, *orelse, *end, *anchor = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1657 int constant = expr_constant(s->v.While.test); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1658 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1659 if (constant == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1660 if (s->v.While.orelse) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1661 VISIT_SEQ(c, stmt, s->v.While.orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1662 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1663 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1664 loop = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1665 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1666 if (constant == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1667 anchor = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1668 if (anchor == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1669 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1670 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1671 if (loop == NULL || end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1672 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1673 if (s->v.While.orelse) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1674 orelse = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1675 if (orelse == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1676 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1677 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1678 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1679 orelse = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1680 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1681 ADDOP_JREL(c, SETUP_LOOP, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1682 compiler_use_next_block(c, loop); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1683 if (!compiler_push_fblock(c, LOOP, loop)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1684 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1685 if (constant == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1686 VISIT(c, expr, s->v.While.test); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1687 ADDOP_JABS(c, POP_JUMP_IF_FALSE, anchor); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1688 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1689 VISIT_SEQ(c, stmt, s->v.While.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1690 ADDOP_JABS(c, JUMP_ABSOLUTE, loop); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1691 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1692 /* XXX should the two POP instructions be in a separate block |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1693 if there is no else clause ? |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1694 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1695 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1696 if (constant == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1697 compiler_use_next_block(c, anchor); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1698 ADDOP(c, POP_BLOCK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1699 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1700 compiler_pop_fblock(c, LOOP, loop); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1701 if (orelse != NULL) /* what if orelse is just pass? */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1702 VISIT_SEQ(c, stmt, s->v.While.orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1703 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1704 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1705 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1706 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1707 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1708 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1709 compiler_continue(struct compiler *c) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1710 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1711 static const char LOOP_ERROR_MSG[] = "'continue' not properly in loop"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1712 static const char IN_FINALLY_ERROR_MSG[] = |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1713 "'continue' not supported inside 'finally' clause"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1714 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1715 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1716 if (!c->u->u_nfblocks) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1717 return compiler_error(c, LOOP_ERROR_MSG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1718 i = c->u->u_nfblocks - 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1719 switch (c->u->u_fblock[i].fb_type) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1720 case LOOP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1721 ADDOP_JABS(c, JUMP_ABSOLUTE, c->u->u_fblock[i].fb_block); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1722 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1723 case EXCEPT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1724 case FINALLY_TRY: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1725 while (--i >= 0 && c->u->u_fblock[i].fb_type != LOOP) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1726 /* Prevent continue anywhere under a finally |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1727 even if hidden in a sub-try or except. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1728 if (c->u->u_fblock[i].fb_type == FINALLY_END) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1729 return compiler_error(c, IN_FINALLY_ERROR_MSG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1730 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1731 if (i == -1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1732 return compiler_error(c, LOOP_ERROR_MSG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1733 ADDOP_JABS(c, CONTINUE_LOOP, c->u->u_fblock[i].fb_block); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1734 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1735 case FINALLY_END: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1736 return compiler_error(c, IN_FINALLY_ERROR_MSG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1737 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1738 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1739 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1740 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1741 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1742 /* Code generated for "try: <body> finally: <finalbody>" is as follows: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1743 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1744 SETUP_FINALLY L |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1745 <code for body> |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1746 POP_BLOCK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1747 LOAD_CONST <None> |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1748 L: <code for finalbody> |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1749 END_FINALLY |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1750 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1751 The special instructions use the block stack. Each block |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1752 stack entry contains the instruction that created it (here |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1753 SETUP_FINALLY), the level of the value stack at the time the |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1754 block stack entry was created, and a label (here L). |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1755 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1756 SETUP_FINALLY: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1757 Pushes the current value stack level and the label |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1758 onto the block stack. |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1759 POP_BLOCK: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1760 Pops en entry from the block stack, and pops the value |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1761 stack until its level is the same as indicated on the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1762 block stack. (The label is ignored.) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1763 END_FINALLY: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1764 Pops a variable number of entries from the *value* stack |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1765 and re-raises the exception they specify. The number of |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1766 entries popped depends on the (pseudo) exception type. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1767 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1768 The block stack is unwound when an exception is raised: |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1769 when a SETUP_FINALLY entry is found, the exception is pushed |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1770 onto the value stack (and the exception condition is cleared), |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1771 and the interpreter jumps to the label gotten from the block |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1772 stack. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1773 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1774 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1775 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1776 compiler_try_finally(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1777 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1778 basicblock *body, *end; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1779 body = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1780 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1781 if (body == NULL || end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1782 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1783 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1784 ADDOP_JREL(c, SETUP_FINALLY, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1785 compiler_use_next_block(c, body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1786 if (!compiler_push_fblock(c, FINALLY_TRY, body)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1787 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1788 VISIT_SEQ(c, stmt, s->v.TryFinally.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1789 ADDOP(c, POP_BLOCK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1790 compiler_pop_fblock(c, FINALLY_TRY, body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1791 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1792 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1793 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1794 if (!compiler_push_fblock(c, FINALLY_END, end)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1795 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1796 VISIT_SEQ(c, stmt, s->v.TryFinally.finalbody); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1797 ADDOP(c, END_FINALLY); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1798 compiler_pop_fblock(c, FINALLY_END, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1799 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1800 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1801 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1802 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1803 /* |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1804 Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...": |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1805 (The contents of the value stack is shown in [], with the top |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1806 at the right; 'tb' is trace-back info, 'val' the exception's |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1807 associated value, and 'exc' the exception.) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1808 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1809 Value stack Label Instruction Argument |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1810 [] SETUP_EXCEPT L1 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1811 [] <code for S> |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1812 [] POP_BLOCK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1813 [] JUMP_FORWARD L0 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1814 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1815 [tb, val, exc] L1: DUP ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1816 [tb, val, exc, exc] <evaluate E1> ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1817 [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1818 [tb, val, exc, 1-or-0] POP_JUMP_IF_FALSE L2 ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1819 [tb, val, exc] POP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1820 [tb, val] <assign to V1> (or POP if no V1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1821 [tb] POP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1822 [] <code for S1> |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1823 JUMP_FORWARD L0 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1824 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1825 [tb, val, exc] L2: DUP |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1826 .............................etc....................... |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1827 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1828 [tb, val, exc] Ln+1: END_FINALLY # re-raise exception |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1829 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1830 [] L0: <next statement> |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1831 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1832 Of course, parts are not generated if Vi or Ei is not present. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1833 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1834 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1835 compiler_try_except(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1836 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1837 basicblock *body, *orelse, *except, *end; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1838 int i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1839 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1840 body = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1841 except = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1842 orelse = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1843 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1844 if (body == NULL || except == NULL || orelse == NULL || end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1845 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1846 ADDOP_JREL(c, SETUP_EXCEPT, except); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1847 compiler_use_next_block(c, body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1848 if (!compiler_push_fblock(c, EXCEPT, body)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1849 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1850 VISIT_SEQ(c, stmt, s->v.TryExcept.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1851 ADDOP(c, POP_BLOCK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1852 compiler_pop_fblock(c, EXCEPT, body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1853 ADDOP_JREL(c, JUMP_FORWARD, orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1854 n = asdl_seq_LEN(s->v.TryExcept.handlers); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1855 compiler_use_next_block(c, except); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1856 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1857 excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1858 s->v.TryExcept.handlers, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1859 if (!handler->v.ExceptHandler.type && i < n-1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1860 return compiler_error(c, "default 'except:' must be last"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1861 c->u->u_lineno_set = false; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1862 c->u->u_lineno = handler->lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1863 except = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1864 if (except == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1865 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1866 if (handler->v.ExceptHandler.type) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1867 ADDOP(c, DUP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1868 VISIT(c, expr, handler->v.ExceptHandler.type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1869 ADDOP_I(c, COMPARE_OP, PyCmp_EXC_MATCH); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1870 ADDOP_JABS(c, POP_JUMP_IF_FALSE, except); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1871 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1872 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1873 if (handler->v.ExceptHandler.name) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1874 VISIT(c, expr, handler->v.ExceptHandler.name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1875 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1876 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1877 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1878 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1879 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1880 VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1881 ADDOP_JREL(c, JUMP_FORWARD, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1882 compiler_use_next_block(c, except); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1883 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1884 ADDOP(c, END_FINALLY); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1885 compiler_use_next_block(c, orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1886 VISIT_SEQ(c, stmt, s->v.TryExcept.orelse); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1887 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1888 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1889 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1890 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1891 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1892 compiler_import_as(struct compiler *c, identifier name, identifier asname) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1893 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1894 /* The IMPORT_NAME opcode was already generated. This function |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1895 merely needs to bind the result to a name. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1896 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1897 If there is a dot in name, we need to split it and emit a |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1898 LOAD_ATTR for each name. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1899 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1900 const char *src = PyString_AS_STRING(name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1901 const char *dot = strchr(src, '.'); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1902 if (dot) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1903 /* Consume the base module name to get the first attribute */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1904 src = dot + 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1905 while (dot) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1906 /* NB src is only defined when dot != NULL */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1907 PyObject *attr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1908 dot = strchr(src, '.'); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1909 attr = PyString_FromStringAndSize(src, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1910 dot ? dot - src : strlen(src)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1911 if (!attr) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1912 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1913 ADDOP_O(c, LOAD_ATTR, attr, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1914 Py_DECREF(attr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1915 src = dot + 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1916 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1917 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1918 return compiler_nameop(c, asname, Store); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1919 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1920 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1921 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1922 compiler_import(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1923 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1924 /* The Import node stores a module name like a.b.c as a single |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1925 string. This is convenient for all cases except |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1926 import a.b.c as d |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1927 where we need to parse that string to extract the individual |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1928 module names. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1929 XXX Perhaps change the representation to make this case simpler? |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1930 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1931 int i, n = asdl_seq_LEN(s->v.Import.names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1932 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1933 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1934 alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1935 int r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1936 PyObject *level; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1937 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1938 if (c->c_flags && (c->c_flags->cf_flags & CO_FUTURE_ABSOLUTE_IMPORT)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1939 level = PyInt_FromLong(0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1940 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1941 level = PyInt_FromLong(-1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1942 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1943 if (level == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1944 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1945 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1946 ADDOP_O(c, LOAD_CONST, level, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1947 Py_DECREF(level); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1948 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1949 ADDOP_NAME(c, IMPORT_NAME, alias->name, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1950 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1951 if (alias->asname) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1952 r = compiler_import_as(c, alias->name, alias->asname); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1953 if (!r) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1954 return r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1955 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1956 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1957 identifier tmp = alias->name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1958 const char *base = PyString_AS_STRING(alias->name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1959 char *dot = strchr(base, '.'); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1960 if (dot) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1961 tmp = PyString_FromStringAndSize(base, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1962 dot - base); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1963 r = compiler_nameop(c, tmp, Store); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1964 if (dot) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1965 Py_DECREF(tmp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1966 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1967 if (!r) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1968 return r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1969 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1970 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1971 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1972 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1973 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1974 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1975 compiler_from_import(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
1976 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1977 int i, n = asdl_seq_LEN(s->v.ImportFrom.names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1978 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1979 PyObject *names = PyTuple_New(n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1980 PyObject *level; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1981 static PyObject *empty_string; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1982 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1983 if (!empty_string) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1984 empty_string = PyString_FromString(""); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1985 if (!empty_string) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1986 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1987 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1988 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1989 if (!names) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1990 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1991 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1992 if (s->v.ImportFrom.level == 0 && c->c_flags && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1993 !(c->c_flags->cf_flags & CO_FUTURE_ABSOLUTE_IMPORT)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1994 level = PyInt_FromLong(-1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1995 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1996 level = PyInt_FromLong(s->v.ImportFrom.level); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1997 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1998 if (!level) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
1999 Py_DECREF(names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2000 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2001 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2002 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2003 /* build up the names */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2004 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2005 alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2006 Py_INCREF(alias->name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2007 PyTuple_SET_ITEM(names, i, alias->name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2008 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2009 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2010 if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2011 !strcmp(PyString_AS_STRING(s->v.ImportFrom.module), "__future__")) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2012 Py_DECREF(level); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2013 Py_DECREF(names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2014 return compiler_error(c, "from __future__ imports must occur " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2015 "at the beginning of the file"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2016 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2017 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2018 ADDOP_O(c, LOAD_CONST, level, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2019 Py_DECREF(level); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2020 ADDOP_O(c, LOAD_CONST, names, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2021 Py_DECREF(names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2022 if (s->v.ImportFrom.module) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2023 ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2024 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2025 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2026 ADDOP_NAME(c, IMPORT_NAME, empty_string, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2027 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2028 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2029 alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2030 identifier store_name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2031 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2032 if (i == 0 && *PyString_AS_STRING(alias->name) == '*') { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2033 assert(n == 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2034 ADDOP(c, IMPORT_STAR); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2035 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2036 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2037 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2038 ADDOP_NAME(c, IMPORT_FROM, alias->name, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2039 store_name = alias->name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2040 if (alias->asname) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2041 store_name = alias->asname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2042 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2043 if (!compiler_nameop(c, store_name, Store)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2044 Py_DECREF(names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2045 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2046 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2047 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2048 /* remove imported module */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2049 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2050 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2051 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2052 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2053 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2054 compiler_assert(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2055 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2056 static PyObject *assertion_error = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2057 basicblock *end; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2058 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2059 if (Py_OptimizeFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2060 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2061 if (assertion_error == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2062 assertion_error = PyString_InternFromString("AssertionError"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2063 if (assertion_error == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2064 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2065 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2066 if (s->v.Assert.test->kind == Tuple_kind && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2067 asdl_seq_LEN(s->v.Assert.test->v.Tuple.elts) > 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2068 const char* msg = |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2069 "assertion is always true, perhaps remove parentheses?"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2070 if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, c->c_filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2071 c->u->u_lineno, NULL, NULL) == -1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2072 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2073 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2074 VISIT(c, expr, s->v.Assert.test); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2075 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2076 if (end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2077 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2078 ADDOP_JABS(c, POP_JUMP_IF_TRUE, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2079 ADDOP_O(c, LOAD_GLOBAL, assertion_error, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2080 if (s->v.Assert.msg) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2081 VISIT(c, expr, s->v.Assert.msg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2082 ADDOP_I(c, RAISE_VARARGS, 2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2083 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2084 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2085 ADDOP_I(c, RAISE_VARARGS, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2086 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2087 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2088 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2089 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2090 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2091 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2092 compiler_visit_stmt(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2093 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2094 int i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2095 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2096 /* Always assign a lineno to the next instruction for a stmt. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2097 c->u->u_lineno = s->lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2098 c->u->u_lineno_set = false; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2099 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2100 switch (s->kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2101 case FunctionDef_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2102 return compiler_function(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2103 case ClassDef_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2104 return compiler_class(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2105 case Return_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2106 if (c->u->u_ste->ste_type != FunctionBlock) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2107 return compiler_error(c, "'return' outside function"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2108 if (s->v.Return.value) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2109 VISIT(c, expr, s->v.Return.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2110 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2111 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2112 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2113 ADDOP(c, RETURN_VALUE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2114 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2115 case Delete_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2116 VISIT_SEQ(c, expr, s->v.Delete.targets) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2117 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2118 case Assign_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2119 n = asdl_seq_LEN(s->v.Assign.targets); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2120 VISIT(c, expr, s->v.Assign.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2121 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2122 if (i < n - 1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2123 ADDOP(c, DUP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2124 VISIT(c, expr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2125 (expr_ty)asdl_seq_GET(s->v.Assign.targets, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2126 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2127 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2128 case AugAssign_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2129 return compiler_augassign(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2130 case Print_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2131 return compiler_print(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2132 case For_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2133 return compiler_for(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2134 case While_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2135 return compiler_while(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2136 case If_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2137 return compiler_if(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2138 case Raise_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2139 n = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2140 if (s->v.Raise.type) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2141 VISIT(c, expr, s->v.Raise.type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2142 n++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2143 if (s->v.Raise.inst) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2144 VISIT(c, expr, s->v.Raise.inst); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2145 n++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2146 if (s->v.Raise.tback) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2147 VISIT(c, expr, s->v.Raise.tback); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2148 n++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2149 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2150 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2151 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2152 ADDOP_I(c, RAISE_VARARGS, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2153 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2154 case TryExcept_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2155 return compiler_try_except(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2156 case TryFinally_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2157 return compiler_try_finally(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2158 case Assert_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2159 return compiler_assert(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2160 case Import_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2161 return compiler_import(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2162 case ImportFrom_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2163 return compiler_from_import(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2164 case Exec_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2165 VISIT(c, expr, s->v.Exec.body); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2166 if (s->v.Exec.globals) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2167 VISIT(c, expr, s->v.Exec.globals); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2168 if (s->v.Exec.locals) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2169 VISIT(c, expr, s->v.Exec.locals); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2170 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2171 ADDOP(c, DUP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2172 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2173 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2174 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2175 ADDOP(c, DUP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2176 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2177 ADDOP(c, EXEC_STMT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2178 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2179 case Global_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2180 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2181 case Expr_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2182 if (c->c_interactive && c->c_nestlevel <= 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2183 VISIT(c, expr, s->v.Expr.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2184 ADDOP(c, PRINT_EXPR); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2185 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2186 else if (s->v.Expr.value->kind != Str_kind && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2187 s->v.Expr.value->kind != Num_kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2188 VISIT(c, expr, s->v.Expr.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2189 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2190 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2191 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2192 case Pass_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2193 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2194 case Break_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2195 if (!compiler_in_loop(c)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2196 return compiler_error(c, "'break' outside loop"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2197 ADDOP(c, BREAK_LOOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2198 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2199 case Continue_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2200 return compiler_continue(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2201 case With_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2202 return compiler_with(c, s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2203 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2204 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2205 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2206 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2207 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2208 unaryop(unaryop_ty op) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2209 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2210 switch (op) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2211 case Invert: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2212 return UNARY_INVERT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2213 case Not: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2214 return UNARY_NOT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2215 case UAdd: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2216 return UNARY_POSITIVE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2217 case USub: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2218 return UNARY_NEGATIVE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2219 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2220 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2221 "unary op %d should not be possible", op); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2222 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2223 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2224 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2225 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2226 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2227 binop(struct compiler *c, operator_ty op) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2228 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2229 switch (op) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2230 case Add: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2231 return BINARY_ADD; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2232 case Sub: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2233 return BINARY_SUBTRACT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2234 case Mult: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2235 return BINARY_MULTIPLY; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2236 case Div: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2237 if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2238 return BINARY_TRUE_DIVIDE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2239 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2240 return BINARY_DIVIDE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2241 case Mod: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2242 return BINARY_MODULO; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2243 case Pow: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2244 return BINARY_POWER; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2245 case LShift: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2246 return BINARY_LSHIFT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2247 case RShift: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2248 return BINARY_RSHIFT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2249 case BitOr: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2250 return BINARY_OR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2251 case BitXor: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2252 return BINARY_XOR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2253 case BitAnd: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2254 return BINARY_AND; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2255 case FloorDiv: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2256 return BINARY_FLOOR_DIVIDE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2257 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2258 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2259 "binary op %d should not be possible", op); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2260 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2261 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2262 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2263 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2264 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2265 cmpop(cmpop_ty op) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2266 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2267 switch (op) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2268 case Eq: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2269 return PyCmp_EQ; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2270 case NotEq: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2271 return PyCmp_NE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2272 case Lt: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2273 return PyCmp_LT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2274 case LtE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2275 return PyCmp_LE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2276 case Gt: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2277 return PyCmp_GT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2278 case GtE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2279 return PyCmp_GE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2280 case Is: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2281 return PyCmp_IS; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2282 case IsNot: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2283 return PyCmp_IS_NOT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2284 case In: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2285 return PyCmp_IN; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2286 case NotIn: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2287 return PyCmp_NOT_IN; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2288 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2289 return PyCmp_BAD; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2290 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2291 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2292 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2293 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2294 inplace_binop(struct compiler *c, operator_ty op) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2295 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2296 switch (op) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2297 case Add: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2298 return INPLACE_ADD; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2299 case Sub: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2300 return INPLACE_SUBTRACT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2301 case Mult: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2302 return INPLACE_MULTIPLY; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2303 case Div: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2304 if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2305 return INPLACE_TRUE_DIVIDE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2306 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2307 return INPLACE_DIVIDE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2308 case Mod: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2309 return INPLACE_MODULO; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2310 case Pow: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2311 return INPLACE_POWER; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2312 case LShift: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2313 return INPLACE_LSHIFT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2314 case RShift: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2315 return INPLACE_RSHIFT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2316 case BitOr: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2317 return INPLACE_OR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2318 case BitXor: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2319 return INPLACE_XOR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2320 case BitAnd: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2321 return INPLACE_AND; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2322 case FloorDiv: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2323 return INPLACE_FLOOR_DIVIDE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2324 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2325 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2326 "inplace binary op %d should not be possible", op); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2327 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2328 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2329 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2330 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2331 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2332 compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2333 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2334 int op, scope, arg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2335 enum { OP_FAST, OP_GLOBAL, OP_DEREF, OP_NAME } optype; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2336 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2337 PyObject *dict = c->u->u_names; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2338 PyObject *mangled; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2339 /* XXX AugStore isn't used anywhere! */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2340 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2341 mangled = _Py_Mangle(c->u->u_private, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2342 if (!mangled) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2343 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2344 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2345 op = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2346 optype = OP_NAME; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2347 scope = PyST_GetScope(c->u->u_ste, mangled); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2348 switch (scope) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2349 case FREE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2350 dict = c->u->u_freevars; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2351 optype = OP_DEREF; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2352 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2353 case CELL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2354 dict = c->u->u_cellvars; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2355 optype = OP_DEREF; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2356 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2357 case LOCAL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2358 if (c->u->u_ste->ste_type == FunctionBlock) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2359 optype = OP_FAST; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2360 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2361 case GLOBAL_IMPLICIT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2362 if (c->u->u_ste->ste_type == FunctionBlock && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2363 !c->u->u_ste->ste_unoptimized) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2364 optype = OP_GLOBAL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2365 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2366 case GLOBAL_EXPLICIT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2367 optype = OP_GLOBAL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2368 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2369 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2370 /* scope can be 0 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2371 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2372 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2373 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2374 /* XXX Leave assert here, but handle __doc__ and the like better */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2375 assert(scope || PyString_AS_STRING(name)[0] == '_'); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2376 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2377 switch (optype) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2378 case OP_DEREF: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2379 switch (ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2380 case Load: op = LOAD_DEREF; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2381 case Store: op = STORE_DEREF; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2382 case AugLoad: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2383 case AugStore: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2384 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2385 case Del: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2386 PyErr_Format(PyExc_SyntaxError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2387 "can not delete variable '%s' referenced " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2388 "in nested scope", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2389 PyString_AS_STRING(name)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2390 Py_DECREF(mangled); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2391 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2392 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2393 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2394 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2395 "param invalid for deref variable"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2396 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2397 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2398 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2399 case OP_FAST: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2400 switch (ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2401 case Load: op = LOAD_FAST; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2402 case Store: op = STORE_FAST; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2403 case Del: op = DELETE_FAST; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2404 case AugLoad: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2405 case AugStore: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2406 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2407 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2408 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2409 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2410 "param invalid for local variable"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2411 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2412 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2413 ADDOP_O(c, op, mangled, varnames); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2414 Py_DECREF(mangled); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2415 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2416 case OP_GLOBAL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2417 switch (ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2418 case Load: op = LOAD_GLOBAL; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2419 case Store: op = STORE_GLOBAL; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2420 case Del: op = DELETE_GLOBAL; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2421 case AugLoad: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2422 case AugStore: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2423 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2424 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2425 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2426 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2427 "param invalid for global variable"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2428 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2429 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2430 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2431 case OP_NAME: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2432 switch (ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2433 case Load: op = LOAD_NAME; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2434 case Store: op = STORE_NAME; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2435 case Del: op = DELETE_NAME; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2436 case AugLoad: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2437 case AugStore: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2438 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2439 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2440 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2441 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2442 "param invalid for name variable"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2443 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2444 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2445 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2446 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2447 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2448 assert(op); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2449 arg = compiler_add_o(c, dict, mangled); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2450 Py_DECREF(mangled); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2451 if (arg < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2452 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2453 return compiler_addop_i(c, op, arg); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2454 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2455 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2456 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2457 compiler_boolop(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2458 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2459 basicblock *end; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2460 int jumpi, i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2461 asdl_seq *s; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2462 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2463 assert(e->kind == BoolOp_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2464 if (e->v.BoolOp.op == And) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2465 jumpi = JUMP_IF_FALSE_OR_POP; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2466 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2467 jumpi = JUMP_IF_TRUE_OR_POP; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2468 end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2469 if (end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2470 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2471 s = e->v.BoolOp.values; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2472 n = asdl_seq_LEN(s) - 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2473 assert(n >= 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2474 for (i = 0; i < n; ++i) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2475 VISIT(c, expr, (expr_ty)asdl_seq_GET(s, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2476 ADDOP_JABS(c, jumpi, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2477 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2478 VISIT(c, expr, (expr_ty)asdl_seq_GET(s, n)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2479 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2480 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2481 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2482 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2483 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2484 compiler_list(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2485 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2486 int n = asdl_seq_LEN(e->v.List.elts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2487 if (e->v.List.ctx == Store) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2488 ADDOP_I(c, UNPACK_SEQUENCE, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2489 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2490 VISIT_SEQ(c, expr, e->v.List.elts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2491 if (e->v.List.ctx == Load) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2492 ADDOP_I(c, BUILD_LIST, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2493 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2494 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2495 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2496 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2497 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2498 compiler_tuple(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2499 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2500 int n = asdl_seq_LEN(e->v.Tuple.elts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2501 if (e->v.Tuple.ctx == Store) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2502 ADDOP_I(c, UNPACK_SEQUENCE, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2503 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2504 VISIT_SEQ(c, expr, e->v.Tuple.elts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2505 if (e->v.Tuple.ctx == Load) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2506 ADDOP_I(c, BUILD_TUPLE, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2507 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2508 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2509 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2510 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2511 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2512 compiler_compare(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2513 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2514 int i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2515 basicblock *cleanup = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2516 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2517 /* XXX the logic can be cleaned up for 1 or multiple comparisons */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2518 VISIT(c, expr, e->v.Compare.left); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2519 n = asdl_seq_LEN(e->v.Compare.ops); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2520 assert(n > 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2521 if (n > 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2522 cleanup = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2523 if (cleanup == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2524 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2525 VISIT(c, expr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2526 (expr_ty)asdl_seq_GET(e->v.Compare.comparators, 0)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2527 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2528 for (i = 1; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2529 ADDOP(c, DUP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2530 ADDOP(c, ROT_THREE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2531 ADDOP_I(c, COMPARE_OP, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2532 cmpop((cmpop_ty)(asdl_seq_GET( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2533 e->v.Compare.ops, i - 1)))); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2534 ADDOP_JABS(c, JUMP_IF_FALSE_OR_POP, cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2535 NEXT_BLOCK(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2536 if (i < (n - 1)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2537 VISIT(c, expr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2538 (expr_ty)asdl_seq_GET(e->v.Compare.comparators, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2539 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2540 VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, n - 1)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2541 ADDOP_I(c, COMPARE_OP, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2542 cmpop((cmpop_ty)(asdl_seq_GET(e->v.Compare.ops, n - 1)))); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2543 if (n > 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2544 basicblock *end = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2545 if (end == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2546 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2547 ADDOP_JREL(c, JUMP_FORWARD, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2548 compiler_use_next_block(c, cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2549 ADDOP(c, ROT_TWO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2550 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2551 compiler_use_next_block(c, end); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2552 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2553 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2554 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2555 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2556 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2557 compiler_call(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2558 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2559 int n, code = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2560 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2561 VISIT(c, expr, e->v.Call.func); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2562 n = asdl_seq_LEN(e->v.Call.args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2563 VISIT_SEQ(c, expr, e->v.Call.args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2564 if (e->v.Call.keywords) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2565 VISIT_SEQ(c, keyword, e->v.Call.keywords); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2566 n |= asdl_seq_LEN(e->v.Call.keywords) << 8; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2567 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2568 if (e->v.Call.starargs) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2569 VISIT(c, expr, e->v.Call.starargs); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2570 code |= 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2571 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2572 if (e->v.Call.kwargs) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2573 VISIT(c, expr, e->v.Call.kwargs); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2574 code |= 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2575 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2576 switch (code) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2577 case 0: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2578 ADDOP_I(c, CALL_FUNCTION, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2579 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2580 case 1: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2581 ADDOP_I(c, CALL_FUNCTION_VAR, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2582 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2583 case 2: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2584 ADDOP_I(c, CALL_FUNCTION_KW, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2585 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2586 case 3: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2587 ADDOP_I(c, CALL_FUNCTION_VAR_KW, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2588 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2589 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2590 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2591 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2592 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2593 static int |
|
50204
94e79d78dff0
Issue #2183: Simplify and optimize bytecode for list comprehensions.
Antoine Pitrou <solipsis@pitrou.net>
parents:
49696
diff
changeset
|
2594 compiler_listcomp_generator(struct compiler *c, asdl_seq *generators, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2595 int gen_index, expr_ty elt) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2596 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2597 /* generate code for the iterator, then each of the ifs, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2598 and then write to the element */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2599 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2600 comprehension_ty l; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2601 basicblock *start, *anchor, *skip, *if_cleanup; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2602 int i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2603 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2604 start = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2605 skip = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2606 if_cleanup = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2607 anchor = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2608 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2609 if (start == NULL || skip == NULL || if_cleanup == NULL || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2610 anchor == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2611 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2612 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2613 l = (comprehension_ty)asdl_seq_GET(generators, gen_index); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2614 VISIT(c, expr, l->iter); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2615 ADDOP(c, GET_ITER); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2616 compiler_use_next_block(c, start); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2617 ADDOP_JREL(c, FOR_ITER, anchor); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2618 NEXT_BLOCK(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2619 VISIT(c, expr, l->target); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2620 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2621 /* XXX this needs to be cleaned up...a lot! */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2622 n = asdl_seq_LEN(l->ifs); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2623 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2624 expr_ty e = (expr_ty)asdl_seq_GET(l->ifs, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2625 VISIT(c, expr, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2626 ADDOP_JABS(c, POP_JUMP_IF_FALSE, if_cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2627 NEXT_BLOCK(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2628 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2629 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2630 if (++gen_index < asdl_seq_LEN(generators)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2631 if (!compiler_listcomp_generator(c, generators, gen_index, elt)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2632 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2633 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2634 /* only append after the last for generator */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2635 if (gen_index >= asdl_seq_LEN(generators)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2636 VISIT(c, expr, elt); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2637 ADDOP_I(c, LIST_APPEND, gen_index+1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2638 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2639 compiler_use_next_block(c, skip); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2640 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2641 compiler_use_next_block(c, if_cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2642 ADDOP_JABS(c, JUMP_ABSOLUTE, start); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2643 compiler_use_next_block(c, anchor); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2644 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2645 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2646 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2647 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2648 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2649 compiler_listcomp(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2650 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2651 assert(e->kind == ListComp_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2652 ADDOP_I(c, BUILD_LIST, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2653 return compiler_listcomp_generator(c, e->v.ListComp.generators, 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2654 e->v.ListComp.elt); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2655 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2656 |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2657 /* Dict and set comprehensions and generator expressions work by creating a |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2658 nested function to perform the actual iteration. This means that the |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2659 iteration variables don't leak into the current scope. |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2660 The defined function is called immediately following its definition, with the |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2661 result of that call being the result of the expression. |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2662 The LC/SC version returns the populated container, while the GE version is |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2663 flagged in symtable.c as a generator, so it returns the generator object |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2664 when the function is called. |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2665 This code *knows* that the loop cannot contain break, continue, or return, |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2666 so it cheats and skips the SETUP_LOOP/POP_BLOCK steps used in normal loops. |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2667 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2668 Possible cleanups: |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2669 - iterate over the generator sequence instead of using recursion |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2670 */ |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2671 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2672 static int |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2673 compiler_comprehension_generator(struct compiler *c, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2674 asdl_seq *generators, int gen_index, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2675 expr_ty elt, expr_ty val, int type) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2676 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2677 /* generate code for the iterator, then each of the ifs, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2678 and then write to the element */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2679 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2680 comprehension_ty gen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2681 basicblock *start, *anchor, *skip, *if_cleanup; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2682 int i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2683 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2684 start = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2685 skip = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2686 if_cleanup = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2687 anchor = compiler_new_block(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2688 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2689 if (start == NULL || skip == NULL || if_cleanup == NULL || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2690 anchor == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2691 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2692 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2693 gen = (comprehension_ty)asdl_seq_GET(generators, gen_index); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2694 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2695 if (gen_index == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2696 /* Receive outermost iter as an implicit argument */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2697 c->u->u_argcount = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2698 ADDOP_I(c, LOAD_FAST, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2699 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2700 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2701 /* Sub-iter - calculate on the fly */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2702 VISIT(c, expr, gen->iter); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2703 ADDOP(c, GET_ITER); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2704 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2705 compiler_use_next_block(c, start); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2706 ADDOP_JREL(c, FOR_ITER, anchor); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2707 NEXT_BLOCK(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2708 VISIT(c, expr, gen->target); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2709 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2710 /* XXX this needs to be cleaned up...a lot! */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2711 n = asdl_seq_LEN(gen->ifs); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2712 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2713 expr_ty e = (expr_ty)asdl_seq_GET(gen->ifs, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2714 VISIT(c, expr, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2715 ADDOP_JABS(c, POP_JUMP_IF_FALSE, if_cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2716 NEXT_BLOCK(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2717 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2718 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2719 if (++gen_index < asdl_seq_LEN(generators)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2720 if (!compiler_comprehension_generator(c, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2721 generators, gen_index, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2722 elt, val, type)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2723 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2724 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2725 /* only append after the last for generator */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2726 if (gen_index >= asdl_seq_LEN(generators)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2727 /* comprehension specific code */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2728 switch (type) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2729 case COMP_GENEXP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2730 VISIT(c, expr, elt); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2731 ADDOP(c, YIELD_VALUE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2732 ADDOP(c, POP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2733 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2734 case COMP_SETCOMP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2735 VISIT(c, expr, elt); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2736 ADDOP_I(c, SET_ADD, gen_index + 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2737 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2738 case COMP_DICTCOMP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2739 /* With 'd[k] = v', v is evaluated before k, so we do |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2740 the same. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2741 VISIT(c, expr, val); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2742 VISIT(c, expr, elt); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2743 ADDOP_I(c, MAP_ADD, gen_index + 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2744 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2745 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2746 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2747 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2748 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2749 compiler_use_next_block(c, skip); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2750 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2751 compiler_use_next_block(c, if_cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2752 ADDOP_JABS(c, JUMP_ABSOLUTE, start); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2753 compiler_use_next_block(c, anchor); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2754 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2755 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2756 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2757 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2758 static int |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2759 compiler_comprehension(struct compiler *c, expr_ty e, int type, identifier name, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2760 asdl_seq *generators, expr_ty elt, expr_ty val) |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2761 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2762 PyCodeObject *co = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2763 expr_ty outermost_iter; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2764 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2765 outermost_iter = ((comprehension_ty) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2766 asdl_seq_GET(generators, 0))->iter; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2767 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2768 if (!compiler_enter_scope(c, name, (void *)e, e->lineno)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2769 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2770 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2771 if (type != COMP_GENEXP) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2772 int op; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2773 switch (type) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2774 case COMP_SETCOMP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2775 op = BUILD_SET; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2776 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2777 case COMP_DICTCOMP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2778 op = BUILD_MAP; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2779 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2780 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2781 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2782 "unknown comprehension type %d", type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2783 goto error_in_scope; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2784 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2785 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2786 ADDOP_I(c, op, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2787 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2788 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2789 if (!compiler_comprehension_generator(c, generators, 0, elt, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2790 val, type)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2791 goto error_in_scope; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2792 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2793 if (type != COMP_GENEXP) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2794 ADDOP(c, RETURN_VALUE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2795 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2796 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2797 co = assemble(c, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2798 compiler_exit_scope(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2799 if (co == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2800 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2801 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2802 if (!compiler_make_closure(c, co, 0)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2803 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2804 Py_DECREF(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2805 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2806 VISIT(c, expr, outermost_iter); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2807 ADDOP(c, GET_ITER); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2808 ADDOP_I(c, CALL_FUNCTION, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2809 return 1; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2810 error_in_scope: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2811 compiler_exit_scope(c); |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2812 error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2813 Py_XDECREF(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2814 return 0; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2815 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2816 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2817 static int |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2818 compiler_genexp(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2819 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2820 static identifier name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2821 if (!name) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2822 name = PyString_FromString("<genexpr>"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2823 if (!name) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2824 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2825 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2826 assert(e->kind == GeneratorExp_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2827 return compiler_comprehension(c, e, COMP_GENEXP, name, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2828 e->v.GeneratorExp.generators, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2829 e->v.GeneratorExp.elt, NULL); |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2830 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2831 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2832 static int |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2833 compiler_setcomp(struct compiler *c, expr_ty e) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2834 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2835 static identifier name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2836 if (!name) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2837 name = PyString_FromString("<setcomp>"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2838 if (!name) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2839 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2840 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2841 assert(e->kind == SetComp_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2842 return compiler_comprehension(c, e, COMP_SETCOMP, name, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2843 e->v.SetComp.generators, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2844 e->v.SetComp.elt, NULL); |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2845 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2846 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2847 static int |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2848 compiler_dictcomp(struct compiler *c, expr_ty e) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2849 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2850 static identifier name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2851 if (!name) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2852 name = PyString_FromString("<dictcomp>"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2853 if (!name) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2854 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2855 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2856 assert(e->kind == DictComp_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2857 return compiler_comprehension(c, e, COMP_DICTCOMP, name, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2858 e->v.DictComp.generators, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2859 e->v.DictComp.key, e->v.DictComp.value); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2860 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2861 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2862 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2863 compiler_visit_keyword(struct compiler *c, keyword_ty k) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2864 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2865 ADDOP_O(c, LOAD_CONST, k->arg, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2866 VISIT(c, expr, k->value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2867 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2868 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2869 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2870 /* Test whether expression is constant. For constants, report |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2871 whether they are true or false. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2872 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2873 Return values: 1 for true, 0 for false, -1 for non-constant. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2874 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2875 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2876 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2877 expr_constant(expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2878 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2879 switch (e->kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2880 case Num_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2881 return PyObject_IsTrue(e->v.Num.n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2882 case Str_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2883 return PyObject_IsTrue(e->v.Str.s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2884 case Name_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2885 /* __debug__ is not assignable, so we can optimize |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2886 * it away in if and while statements */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2887 if (strcmp(PyString_AS_STRING(e->v.Name.id), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2888 "__debug__") == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2889 return ! Py_OptimizeFlag; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2890 /* fall through */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2891 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2892 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2893 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2894 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2895 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2896 /* |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2897 Implements the with statement from PEP 343. |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2898 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2899 The semantics outlined in that PEP are as follows: |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2900 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2901 with EXPR as VAR: |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2902 BLOCK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2903 |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2904 It is implemented roughly as: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2905 |
|
38084
a812d0fae74a
Get rid of __context__, per the latest changes to PEP 343 and python-dev
Guido van Rossum <guido@python.org>
parents:
37685
diff
changeset
|
2906 context = EXPR |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2907 exit = context.__exit__ # not calling it |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2908 value = context.__enter__() |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2909 try: |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2910 VAR = value # if VAR present in the syntax |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2911 BLOCK |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2912 finally: |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2913 if an exception was raised: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2914 exc = copy of (exception, instance, traceback) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2915 else: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2916 exc = (None, None, None) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2917 exit(*exc) |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2918 */ |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2919 static int |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2920 compiler_with(struct compiler *c, stmt_ty s) |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2921 { |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2922 basicblock *block, *finally; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2923 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2924 assert(s->kind == With_kind); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2925 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2926 block = compiler_new_block(c); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2927 finally = compiler_new_block(c); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2928 if (!block || !finally) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2929 return 0; |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2930 |
|
38084
a812d0fae74a
Get rid of __context__, per the latest changes to PEP 343 and python-dev
Guido van Rossum <guido@python.org>
parents:
37685
diff
changeset
|
2931 /* Evaluate EXPR */ |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2932 VISIT(c, expr, s->v.With.context_expr); |
|
54329
145376df3ad7
add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents:
54297
diff
changeset
|
2933 ADDOP_JREL(c, SETUP_WITH, finally); |
|
145376df3ad7
add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents:
54297
diff
changeset
|
2934 |
|
145376df3ad7
add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents:
54297
diff
changeset
|
2935 /* SETUP_WITH pushes a finally block. */ |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2936 compiler_use_next_block(c, block); |
|
58707
76cf60e2d005
normalize exceptions passed to the __exit__ method #7853
Benjamin Peterson <benjamin@python.org>
parents:
58250
diff
changeset
|
2937 /* Note that the block is actually called SETUP_WITH in ceval.c, but |
|
76cf60e2d005
normalize exceptions passed to the __exit__ method #7853
Benjamin Peterson <benjamin@python.org>
parents:
58250
diff
changeset
|
2938 functions the same as SETUP_FINALLY except that exceptions are |
|
76cf60e2d005
normalize exceptions passed to the __exit__ method #7853
Benjamin Peterson <benjamin@python.org>
parents:
58250
diff
changeset
|
2939 normalized. */ |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2940 if (!compiler_push_fblock(c, FINALLY_TRY, block)) { |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2941 return 0; |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2942 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2943 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2944 if (s->v.With.optional_vars) { |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2945 VISIT(c, expr, s->v.With.optional_vars); |
|
54329
145376df3ad7
add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents:
54297
diff
changeset
|
2946 } |
|
145376df3ad7
add a SETUP_WITH opcode
Benjamin Peterson <benjamin@python.org>
parents:
54297
diff
changeset
|
2947 else { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2948 /* Discard result from context.__enter__() */ |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2949 ADDOP(c, POP_TOP); |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2950 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2951 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2952 /* BLOCK code */ |
|
37614
72ceb1b30d4b
per Jeremy's email, remove the _WITH_CAST versions of macros. g++
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37606
diff
changeset
|
2953 VISIT_SEQ(c, stmt, s->v.With.body); |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2954 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2955 /* End of try block; start the finally block */ |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2956 ADDOP(c, POP_BLOCK); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2957 compiler_pop_fblock(c, FINALLY_TRY, block); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2958 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2959 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2960 compiler_use_next_block(c, finally); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2961 if (!compiler_push_fblock(c, FINALLY_END, finally)) |
|
62453
e9fb042e46fb
Fix misindents in compile.c (for Benjamin).
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2962 return 0; |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2963 |
|
45703
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45511
diff
changeset
|
2964 /* Finally block starts; context.__exit__ is on the stack under |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45511
diff
changeset
|
2965 the exception or return information. Just issue our magic |
|
343597c7d682
Speed up with statements by storing the __exit__ method on the stack instead of in a temp variable (bumps the magic number for pyc files)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45511
diff
changeset
|
2966 opcode. */ |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2967 ADDOP(c, WITH_CLEANUP); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2968 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2969 /* Finally block ends. */ |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2970 ADDOP(c, END_FINALLY); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2971 compiler_pop_fblock(c, FINALLY_END, finally); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2972 return 1; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2973 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36666
diff
changeset
|
2974 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2975 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2976 compiler_visit_expr(struct compiler *c, expr_ty e) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
2977 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2978 int i, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2979 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2980 /* If expr e has a different line number than the last expr/stmt, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2981 set a new line number for the next instruction. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2982 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2983 if (e->lineno > c->u->u_lineno) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2984 c->u->u_lineno = e->lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2985 c->u->u_lineno_set = false; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2986 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2987 switch (e->kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2988 case BoolOp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2989 return compiler_boolop(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2990 case BinOp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2991 VISIT(c, expr, e->v.BinOp.left); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2992 VISIT(c, expr, e->v.BinOp.right); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2993 ADDOP(c, binop(c, e->v.BinOp.op)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2994 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2995 case UnaryOp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2996 VISIT(c, expr, e->v.UnaryOp.operand); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2997 ADDOP(c, unaryop(e->v.UnaryOp.op)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2998 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
2999 case Lambda_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3000 return compiler_lambda(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3001 case IfExp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3002 return compiler_ifexp(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3003 case Dict_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3004 n = asdl_seq_LEN(e->v.Dict.values); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3005 ADDOP_I(c, BUILD_MAP, (n>0xFFFF ? 0xFFFF : n)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3006 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3007 VISIT(c, expr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3008 (expr_ty)asdl_seq_GET(e->v.Dict.values, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3009 VISIT(c, expr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3010 (expr_ty)asdl_seq_GET(e->v.Dict.keys, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3011 ADDOP(c, STORE_MAP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3012 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3013 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3014 case Set_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3015 n = asdl_seq_LEN(e->v.Set.elts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3016 VISIT_SEQ(c, expr, e->v.Set.elts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3017 ADDOP_I(c, BUILD_SET, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3018 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3019 case ListComp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3020 return compiler_listcomp(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3021 case SetComp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3022 return compiler_setcomp(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3023 case DictComp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3024 return compiler_dictcomp(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3025 case GeneratorExp_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3026 return compiler_genexp(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3027 case Yield_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3028 if (c->u->u_ste->ste_type != FunctionBlock) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3029 return compiler_error(c, "'yield' outside function"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3030 if (e->v.Yield.value) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3031 VISIT(c, expr, e->v.Yield.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3032 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3033 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3034 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3035 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3036 ADDOP(c, YIELD_VALUE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3037 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3038 case Compare_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3039 return compiler_compare(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3040 case Call_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3041 return compiler_call(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3042 case Repr_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3043 VISIT(c, expr, e->v.Repr.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3044 ADDOP(c, UNARY_CONVERT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3045 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3046 case Num_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3047 ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3048 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3049 case Str_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3050 ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3051 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3052 /* The following exprs can be assignment targets. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3053 case Attribute_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3054 if (e->v.Attribute.ctx != AugStore) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3055 VISIT(c, expr, e->v.Attribute.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3056 switch (e->v.Attribute.ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3057 case AugLoad: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3058 ADDOP(c, DUP_TOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3059 /* Fall through to load */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3060 case Load: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3061 ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3062 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3063 case AugStore: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3064 ADDOP(c, ROT_TWO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3065 /* Fall through to save */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3066 case Store: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3067 ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3068 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3069 case Del: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3070 ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3071 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3072 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3073 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3074 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3075 "param invalid in attribute expression"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3076 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3077 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3078 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3079 case Subscript_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3080 switch (e->v.Subscript.ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3081 case AugLoad: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3082 VISIT(c, expr, e->v.Subscript.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3083 VISIT_SLICE(c, e->v.Subscript.slice, AugLoad); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3084 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3085 case Load: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3086 VISIT(c, expr, e->v.Subscript.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3087 VISIT_SLICE(c, e->v.Subscript.slice, Load); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3088 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3089 case AugStore: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3090 VISIT_SLICE(c, e->v.Subscript.slice, AugStore); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3091 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3092 case Store: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3093 VISIT(c, expr, e->v.Subscript.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3094 VISIT_SLICE(c, e->v.Subscript.slice, Store); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3095 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3096 case Del: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3097 VISIT(c, expr, e->v.Subscript.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3098 VISIT_SLICE(c, e->v.Subscript.slice, Del); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3099 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3100 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3101 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3102 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3103 "param invalid in subscript expression"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3104 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3105 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3106 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3107 case Name_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3108 return compiler_nameop(c, e->v.Name.id, e->v.Name.ctx); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3109 /* child nodes of List and Tuple will have expr_context set */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3110 case List_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3111 return compiler_list(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3112 case Tuple_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3113 return compiler_tuple(c, e); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3114 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3115 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3116 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3117 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3118 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3119 compiler_augassign(struct compiler *c, stmt_ty s) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3120 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3121 expr_ty e = s->v.AugAssign.target; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3122 expr_ty auge; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3123 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3124 assert(s->kind == AugAssign_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3125 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3126 switch (e->kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3127 case Attribute_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3128 auge = Attribute(e->v.Attribute.value, e->v.Attribute.attr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3129 AugLoad, e->lineno, e->col_offset, c->c_arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3130 if (auge == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3131 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3132 VISIT(c, expr, auge); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3133 VISIT(c, expr, s->v.AugAssign.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3134 ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3135 auge->v.Attribute.ctx = AugStore; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3136 VISIT(c, expr, auge); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3137 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3138 case Subscript_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3139 auge = Subscript(e->v.Subscript.value, e->v.Subscript.slice, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3140 AugLoad, e->lineno, e->col_offset, c->c_arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3141 if (auge == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3142 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3143 VISIT(c, expr, auge); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3144 VISIT(c, expr, s->v.AugAssign.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3145 ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3146 auge->v.Subscript.ctx = AugStore; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3147 VISIT(c, expr, auge); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3148 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3149 case Name_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3150 if (!compiler_nameop(c, e->v.Name.id, Load)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3151 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3152 VISIT(c, expr, s->v.AugAssign.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3153 ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3154 return compiler_nameop(c, e->v.Name.id, Store); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3155 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3156 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3157 "invalid node type (%d) for augmented assignment", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3158 e->kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3159 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3160 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3161 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3162 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3163 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3164 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3165 compiler_push_fblock(struct compiler *c, enum fblocktype t, basicblock *b) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3166 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3167 struct fblockinfo *f; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3168 if (c->u->u_nfblocks >= CO_MAXBLOCKS) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3169 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3170 "too many statically nested blocks"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3171 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3172 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3173 f = &c->u->u_fblock[c->u->u_nfblocks++]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3174 f->fb_type = t; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3175 f->fb_block = b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3176 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3177 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3178 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3179 static void |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3180 compiler_pop_fblock(struct compiler *c, enum fblocktype t, basicblock *b) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3181 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3182 struct compiler_unit *u = c->u; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3183 assert(u->u_nfblocks > 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3184 u->u_nfblocks--; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3185 assert(u->u_fblock[u->u_nfblocks].fb_type == t); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3186 assert(u->u_fblock[u->u_nfblocks].fb_block == b); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3187 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3188 |
|
39983
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
3189 static int |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
3190 compiler_in_loop(struct compiler *c) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3191 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3192 struct compiler_unit *u = c->u; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3193 for (i = 0; i < u->u_nfblocks; ++i) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3194 if (u->u_fblock[i].fb_type == LOOP) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3195 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3196 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3197 return 0; |
|
39983
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
3198 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3199 /* Raises a SyntaxError and returns 0. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3200 If something goes wrong, a different exception may be raised. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3201 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3202 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3203 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3204 compiler_error(struct compiler *c, const char *errstr) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3205 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3206 PyObject *loc; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3207 PyObject *u = NULL, *v = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3208 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3209 loc = PyErr_ProgramText(c->c_filename, c->u->u_lineno); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3210 if (!loc) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3211 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3212 loc = Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3213 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3214 u = Py_BuildValue("(ziOO)", c->c_filename, c->u->u_lineno, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3215 Py_None, loc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3216 if (!u) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3217 goto exit; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3218 v = Py_BuildValue("(zO)", errstr, u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3219 if (!v) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3220 goto exit; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3221 PyErr_SetObject(PyExc_SyntaxError, v); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3222 exit: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3223 Py_DECREF(loc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3224 Py_XDECREF(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3225 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3226 return 0; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3227 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3228 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3229 static int |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3230 compiler_handle_subscr(struct compiler *c, const char *kind, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3231 expr_context_ty ctx) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3232 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3233 int op = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3234 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3235 /* XXX this code is duplicated */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3236 switch (ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3237 case AugLoad: /* fall through to Load */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3238 case Load: op = BINARY_SUBSCR; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3239 case AugStore:/* fall through to Store */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3240 case Store: op = STORE_SUBSCR; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3241 case Del: op = DELETE_SUBSCR; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3242 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3243 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3244 "invalid %s kind %d in subscript\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3245 kind, ctx); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3246 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3247 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3248 if (ctx == AugLoad) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3249 ADDOP_I(c, DUP_TOPX, 2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3250 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3251 else if (ctx == AugStore) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3252 ADDOP(c, ROT_THREE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3253 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3254 ADDOP(c, op); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3255 return 1; |
| 69 | 3256 } |
| 3257 | |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3258 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3259 compiler_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3260 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3261 int n = 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3262 assert(s->kind == Slice_kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3263 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3264 /* only handles the cases where BUILD_SLICE is emitted */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3265 if (s->v.Slice.lower) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3266 VISIT(c, expr, s->v.Slice.lower); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3267 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3268 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3269 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3270 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3271 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3272 if (s->v.Slice.upper) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3273 VISIT(c, expr, s->v.Slice.upper); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3274 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3275 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3276 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3277 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3278 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3279 if (s->v.Slice.step) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3280 n++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3281 VISIT(c, expr, s->v.Slice.step); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3282 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3283 ADDOP_I(c, BUILD_SLICE, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3284 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3285 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3286 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3287 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3288 compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3289 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3290 int op = 0, slice_offset = 0, stack_count = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3291 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3292 assert(s->v.Slice.step == NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3293 if (s->v.Slice.lower) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3294 slice_offset++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3295 stack_count++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3296 if (ctx != AugStore) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3297 VISIT(c, expr, s->v.Slice.lower); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3298 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3299 if (s->v.Slice.upper) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3300 slice_offset += 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3301 stack_count++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3302 if (ctx != AugStore) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3303 VISIT(c, expr, s->v.Slice.upper); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3304 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3305 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3306 if (ctx == AugLoad) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3307 switch (stack_count) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3308 case 0: ADDOP(c, DUP_TOP); break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3309 case 1: ADDOP_I(c, DUP_TOPX, 2); break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3310 case 2: ADDOP_I(c, DUP_TOPX, 3); break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3311 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3312 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3313 else if (ctx == AugStore) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3314 switch (stack_count) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3315 case 0: ADDOP(c, ROT_TWO); break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3316 case 1: ADDOP(c, ROT_THREE); break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3317 case 2: ADDOP(c, ROT_FOUR); break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3318 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3319 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3320 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3321 switch (ctx) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3322 case AugLoad: /* fall through to Load */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3323 case Load: op = SLICE; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3324 case AugStore:/* fall through to Store */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3325 case Store: op = STORE_SLICE; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3326 case Del: op = DELETE_SLICE; break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3327 case Param: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3328 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3329 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3330 "param invalid in simple slice"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3331 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3332 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3333 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3334 ADDOP(c, op + slice_offset); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3335 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3336 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3337 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3338 static int |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3339 compiler_visit_nested_slice(struct compiler *c, slice_ty s, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3340 expr_context_ty ctx) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3341 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3342 switch (s->kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3343 case Ellipsis_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3344 ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3345 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3346 case Slice_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3347 return compiler_slice(c, s, ctx); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3348 case Index_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3349 VISIT(c, expr, s->v.Index.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3350 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3351 case ExtSlice_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3352 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3353 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3354 "extended slice invalid in nested slice"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3355 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3356 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3357 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3358 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3359 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3360 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3361 compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3362 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3363 char * kindname = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3364 switch (s->kind) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3365 case Index_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3366 kindname = "index"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3367 if (ctx != AugStore) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3368 VISIT(c, expr, s->v.Index.value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3369 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3370 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3371 case Ellipsis_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3372 kindname = "ellipsis"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3373 if (ctx != AugStore) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3374 ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3375 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3376 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3377 case Slice_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3378 kindname = "slice"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3379 if (!s->v.Slice.step) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3380 return compiler_simple_slice(c, s, ctx); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3381 if (ctx != AugStore) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3382 if (!compiler_slice(c, s, ctx)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3383 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3384 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3385 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3386 case ExtSlice_kind: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3387 kindname = "extended slice"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3388 if (ctx != AugStore) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3389 int i, n = asdl_seq_LEN(s->v.ExtSlice.dims); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3390 for (i = 0; i < n; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3391 slice_ty sub = (slice_ty)asdl_seq_GET( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3392 s->v.ExtSlice.dims, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3393 if (!compiler_visit_nested_slice(c, sub, ctx)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3394 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3395 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3396 ADDOP_I(c, BUILD_TUPLE, n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3397 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3398 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3399 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3400 PyErr_Format(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3401 "invalid subscript kind %d", s->kind); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3402 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3403 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3404 return compiler_handle_subscr(c, kindname, ctx); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3405 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3406 |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
3407 |
|
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
3408 /* End of the compiler section, beginning of the assembler section */ |
|
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
3409 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3410 /* do depth-first search of basic block graph, starting with block. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3411 post records the block indices in post-order. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3412 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3413 XXX must handle implicit jumps from one block to next |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3414 */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3415 |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
3416 struct assembler { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3417 PyObject *a_bytecode; /* string containing bytecode */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3418 int a_offset; /* offset into bytecode */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3419 int a_nblocks; /* number of reachable blocks */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3420 basicblock **a_postorder; /* list of blocks in dfs postorder */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3421 PyObject *a_lnotab; /* string containing lnotab */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3422 int a_lnotab_off; /* offset into lnotab */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3423 int a_lineno; /* last lineno of emitted instruction */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3424 int a_lineno_off; /* bytecode offset of last lineno */ |
|
40256
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
3425 }; |
|
c6774eb3a067
Update comments, remove commented out code.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40241
diff
changeset
|
3426 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3427 static void |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3428 dfs(struct compiler *c, basicblock *b, struct assembler *a) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3429 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3430 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3431 struct instr *instr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3432 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3433 if (b->b_seen) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3434 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3435 b->b_seen = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3436 if (b->b_next != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3437 dfs(c, b->b_next, a); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3438 for (i = 0; i < b->b_iused; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3439 instr = &b->b_instr[i]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3440 if (instr->i_jrel || instr->i_jabs) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3441 dfs(c, instr->i_target, a); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3442 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3443 a->a_postorder[a->a_nblocks++] = b; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3444 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3445 |
|
35860
9b885c934144
make internal method static
Neal Norwitz <nnorwitz@gmail.com>
parents:
35797
diff
changeset
|
3446 static int |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3447 stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3448 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3449 int i, target_depth; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3450 struct instr *instr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3451 if (b->b_seen || b->b_startdepth >= depth) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3452 return maxdepth; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3453 b->b_seen = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3454 b->b_startdepth = depth; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3455 for (i = 0; i < b->b_iused; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3456 instr = &b->b_instr[i]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3457 depth += opcode_stack_effect(instr->i_opcode, instr->i_oparg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3458 if (depth > maxdepth) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3459 maxdepth = depth; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3460 assert(depth >= 0); /* invalid code or bug in stackdepth() */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3461 if (instr->i_jrel || instr->i_jabs) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3462 target_depth = depth; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3463 if (instr->i_opcode == FOR_ITER) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3464 target_depth = depth-2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3465 } else if (instr->i_opcode == SETUP_FINALLY || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3466 instr->i_opcode == SETUP_EXCEPT) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3467 target_depth = depth+3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3468 if (target_depth > maxdepth) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3469 maxdepth = target_depth; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3470 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3471 maxdepth = stackdepth_walk(c, instr->i_target, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3472 target_depth, maxdepth); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3473 if (instr->i_opcode == JUMP_ABSOLUTE || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3474 instr->i_opcode == JUMP_FORWARD) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3475 goto out; /* remaining code is dead */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3476 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3477 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3478 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3479 if (b->b_next) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3480 maxdepth = stackdepth_walk(c, b->b_next, depth, maxdepth); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3481 out: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3482 b->b_seen = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3483 return maxdepth; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3484 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3485 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3486 /* Find the flow path that needs the largest stack. We assume that |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3487 * cycles in the flow graph have no net effect on the stack depth. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3488 */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3489 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3490 stackdepth(struct compiler *c) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3491 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3492 basicblock *b, *entryblock; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3493 entryblock = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3494 for (b = c->u->u_blocks; b != NULL; b = b->b_list) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3495 b->b_seen = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3496 b->b_startdepth = INT_MIN; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3497 entryblock = b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3498 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3499 if (!entryblock) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3500 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3501 return stackdepth_walk(c, entryblock, 0, 0); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3502 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3503 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3504 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3505 assemble_init(struct assembler *a, int nblocks, int firstlineno) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3506 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3507 memset(a, 0, sizeof(struct assembler)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3508 a->a_lineno = firstlineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3509 a->a_bytecode = PyString_FromStringAndSize(NULL, DEFAULT_CODE_SIZE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3510 if (!a->a_bytecode) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3511 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3512 a->a_lnotab = PyString_FromStringAndSize(NULL, DEFAULT_LNOTAB_SIZE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3513 if (!a->a_lnotab) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3514 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3515 if (nblocks > PY_SIZE_MAX / sizeof(basicblock *)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3516 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3517 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3518 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3519 a->a_postorder = (basicblock **)PyObject_Malloc( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3520 sizeof(basicblock *) * nblocks); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3521 if (!a->a_postorder) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3522 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3523 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3524 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3525 return 1; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3526 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3527 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3528 static void |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3529 assemble_free(struct assembler *a) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3530 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3531 Py_XDECREF(a->a_bytecode); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3532 Py_XDECREF(a->a_lnotab); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3533 if (a->a_postorder) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3534 PyObject_Free(a->a_postorder); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3535 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3536 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3537 /* Return the size of a basic block in bytes. */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3538 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3539 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3540 instrsize(struct instr *instr) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3541 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3542 if (!instr->i_hasarg) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3543 return 1; /* 1 byte for the opcode*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3544 if (instr->i_oparg > 0xffff) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3545 return 6; /* 1 (opcode) + 1 (EXTENDED_ARG opcode) + 2 (oparg) + 2(oparg extended) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3546 return 3; /* 1 (opcode) + 2 (oparg) */ |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3547 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3548 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3549 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3550 blocksize(basicblock *b) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3551 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3552 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3553 int size = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3554 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3555 for (i = 0; i < b->b_iused; i++) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3556 size += instrsize(&b->b_instr[i]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3557 return size; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3558 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3559 |
| 54297 | 3560 /* Appends a pair to the end of the line number table, a_lnotab, representing |
| 3561 the instruction's bytecode offset and line number. See | |
| 3562 Objects/lnotab_notes.txt for the description of the line number table. */ | |
|
18065
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
3563 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
17355
diff
changeset
|
3564 static int |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3565 assemble_lnotab(struct assembler *a, struct instr *i) |
| 69 | 3566 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3567 int d_bytecode, d_lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3568 int len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3569 unsigned char *lnotab; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3570 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3571 d_bytecode = a->a_offset - a->a_lineno_off; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3572 d_lineno = i->i_lineno - a->a_lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3573 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3574 assert(d_bytecode >= 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3575 assert(d_lineno >= 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3576 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3577 if(d_bytecode == 0 && d_lineno == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3578 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3579 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3580 if (d_bytecode > 255) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3581 int j, nbytes, ncodes = d_bytecode / 255; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3582 nbytes = a->a_lnotab_off + 2 * ncodes; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3583 len = PyString_GET_SIZE(a->a_lnotab); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3584 if (nbytes >= len) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3585 if ((len <= INT_MAX / 2) && (len * 2 < nbytes)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3586 len = nbytes; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3587 else if (len <= INT_MAX / 2) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3588 len *= 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3589 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3590 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3591 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3592 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3593 if (_PyString_Resize(&a->a_lnotab, len) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3594 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3595 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3596 lnotab = (unsigned char *) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3597 PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3598 for (j = 0; j < ncodes; j++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3599 *lnotab++ = 255; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3600 *lnotab++ = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3601 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3602 d_bytecode -= ncodes * 255; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3603 a->a_lnotab_off += ncodes * 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3604 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3605 assert(d_bytecode <= 255); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3606 if (d_lineno > 255) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3607 int j, nbytes, ncodes = d_lineno / 255; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3608 nbytes = a->a_lnotab_off + 2 * ncodes; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3609 len = PyString_GET_SIZE(a->a_lnotab); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3610 if (nbytes >= len) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3611 if ((len <= INT_MAX / 2) && len * 2 < nbytes) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3612 len = nbytes; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3613 else if (len <= INT_MAX / 2) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3614 len *= 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3615 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3616 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3617 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3618 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3619 if (_PyString_Resize(&a->a_lnotab, len) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3620 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3621 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3622 lnotab = (unsigned char *) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3623 PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3624 *lnotab++ = d_bytecode; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3625 *lnotab++ = 255; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3626 d_bytecode = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3627 for (j = 1; j < ncodes; j++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3628 *lnotab++ = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3629 *lnotab++ = 255; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3630 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3631 d_lineno -= ncodes * 255; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3632 a->a_lnotab_off += ncodes * 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3633 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3634 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3635 len = PyString_GET_SIZE(a->a_lnotab); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3636 if (a->a_lnotab_off + 2 >= len) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3637 if (_PyString_Resize(&a->a_lnotab, len * 2) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3638 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3639 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3640 lnotab = (unsigned char *) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3641 PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3642 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3643 a->a_lnotab_off += 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3644 if (d_bytecode) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3645 *lnotab++ = d_bytecode; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3646 *lnotab++ = d_lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3647 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3648 else { /* First line of a block; def stmt, etc. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3649 *lnotab++ = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3650 *lnotab++ = d_lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3651 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3652 a->a_lineno = i->i_lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3653 a->a_lineno_off = a->a_offset; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3654 return 1; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3655 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3656 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3657 /* assemble_emit() |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3658 Extend the bytecode with a new instruction. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3659 Update lnotab if necessary. |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3660 */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3661 |
|
24855
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
3662 static int |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3663 assemble_emit(struct assembler *a, struct instr *i) |
| 69 | 3664 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3665 int size, arg = 0, ext = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3666 Py_ssize_t len = PyString_GET_SIZE(a->a_bytecode); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3667 char *code; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3668 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3669 size = instrsize(i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3670 if (i->i_hasarg) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3671 arg = i->i_oparg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3672 ext = arg >> 16; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3673 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3674 if (i->i_lineno && !assemble_lnotab(a, i)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3675 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3676 if (a->a_offset + size >= len) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3677 if (len > PY_SSIZE_T_MAX / 2) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3678 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3679 if (_PyString_Resize(&a->a_bytecode, len * 2) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3680 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3681 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3682 code = PyString_AS_STRING(a->a_bytecode) + a->a_offset; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3683 a->a_offset += size; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3684 if (size == 6) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3685 assert(i->i_hasarg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3686 *code++ = (char)EXTENDED_ARG; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3687 *code++ = ext & 0xff; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3688 *code++ = ext >> 8; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3689 arg &= 0xffff; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3690 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3691 *code++ = i->i_opcode; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3692 if (i->i_hasarg) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3693 assert(size == 3 || size == 6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3694 *code++ = arg & 0xff; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3695 *code++ = arg >> 8; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3696 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3697 return 1; |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
3698 } |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
3699 |
|
35789
19a37a9f4ef9
cleanup a bit and reuse instrsize (instruction size). working towards fixing problems with EXTENDED_ARG
Neal Norwitz <nnorwitz@gmail.com>
parents:
35781
diff
changeset
|
3700 static void |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3701 assemble_jump_offsets(struct assembler *a, struct compiler *c) |
| 69 | 3702 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3703 basicblock *b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3704 int bsize, totsize, extended_arg_count = 0, last_extended_arg_count; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3705 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3706 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3707 /* Compute the size of each block and fixup jump args. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3708 Replace block pointer with position in bytecode. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3709 do { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3710 totsize = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3711 for (i = a->a_nblocks - 1; i >= 0; i--) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3712 b = a->a_postorder[i]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3713 bsize = blocksize(b); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3714 b->b_offset = totsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3715 totsize += bsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3716 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3717 last_extended_arg_count = extended_arg_count; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3718 extended_arg_count = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3719 for (b = c->u->u_blocks; b != NULL; b = b->b_list) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3720 bsize = b->b_offset; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3721 for (i = 0; i < b->b_iused; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3722 struct instr *instr = &b->b_instr[i]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3723 /* Relative jumps are computed relative to |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3724 the instruction pointer after fetching |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3725 the jump instruction. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3726 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3727 bsize += instrsize(instr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3728 if (instr->i_jabs) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3729 instr->i_oparg = instr->i_target->b_offset; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3730 else if (instr->i_jrel) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3731 int delta = instr->i_target->b_offset - bsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3732 instr->i_oparg = delta; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3733 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3734 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3735 continue; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3736 if (instr->i_oparg > 0xffff) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3737 extended_arg_count++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3738 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3739 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3740 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3741 /* XXX: This is an awful hack that could hurt performance, but |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3742 on the bright side it should work until we come up |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3743 with a better solution. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3744 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3745 The issue is that in the first loop blocksize() is called |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3746 which calls instrsize() which requires i_oparg be set |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3747 appropriately. There is a bootstrap problem because |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3748 i_oparg is calculated in the second loop above. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3749 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3750 So we loop until we stop seeing new EXTENDED_ARGs. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3751 The only EXTENDED_ARGs that could be popping up are |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3752 ones in jump instructions. So this should converge |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3753 fairly quickly. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3754 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3755 } while (last_extended_arg_count != extended_arg_count); |
| 69 | 3756 } |
| 3757 | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3758 static PyObject * |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3759 dict_keys_inorder(PyObject *dict, int offset) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3760 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3761 PyObject *tuple, *k, *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3762 Py_ssize_t i, pos = 0, size = PyDict_Size(dict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3763 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3764 tuple = PyTuple_New(size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3765 if (tuple == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3766 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3767 while (PyDict_Next(dict, &pos, &k, &v)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3768 i = PyInt_AS_LONG(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3769 /* The keys of the dictionary are tuples. (see compiler_add_o) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3770 The object we want is always first, though. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3771 k = PyTuple_GET_ITEM(k, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3772 Py_INCREF(k); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3773 assert((i - offset) < size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3774 assert((i - offset) >= 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3775 PyTuple_SET_ITEM(tuple, i - offset, k); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3776 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3777 return tuple; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3778 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3779 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3780 static int |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3781 compute_code_flags(struct compiler *c) |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3782 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3783 PySTEntryObject *ste = c->u->u_ste; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3784 int flags = 0, n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3785 if (ste->ste_type != ModuleBlock) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3786 flags |= CO_NEWLOCALS; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3787 if (ste->ste_type == FunctionBlock) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3788 if (!ste->ste_unoptimized) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3789 flags |= CO_OPTIMIZED; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3790 if (ste->ste_nested) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3791 flags |= CO_NESTED; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3792 if (ste->ste_generator) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3793 flags |= CO_GENERATOR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3794 if (ste->ste_varargs) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3795 flags |= CO_VARARGS; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3796 if (ste->ste_varkeywords) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3797 flags |= CO_VARKEYWORDS; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3798 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3799 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3800 /* (Only) inherit compilerflags in PyCF_MASK */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3801 flags |= (c->c_flags->cf_flags & PyCF_MASK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3802 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3803 n = PyDict_Size(c->u->u_freevars); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3804 if (n < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3805 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3806 if (n == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3807 n = PyDict_Size(c->u->u_cellvars); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3808 if (n < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3809 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3810 if (n == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3811 flags |= CO_NOFREE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3812 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3813 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3814 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3815 return flags; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3816 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3817 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3818 static PyCodeObject * |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3819 makecode(struct compiler *c, struct assembler *a) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3820 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3821 PyObject *tmp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3822 PyCodeObject *co = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3823 PyObject *consts = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3824 PyObject *names = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3825 PyObject *varnames = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3826 PyObject *filename = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3827 PyObject *name = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3828 PyObject *freevars = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3829 PyObject *cellvars = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3830 PyObject *bytecode = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3831 int nlocals, flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3832 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3833 tmp = dict_keys_inorder(c->u->u_consts, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3834 if (!tmp) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3835 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3836 consts = PySequence_List(tmp); /* optimize_code requires a list */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3837 Py_DECREF(tmp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3838 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3839 names = dict_keys_inorder(c->u->u_names, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3840 varnames = dict_keys_inorder(c->u->u_varnames, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3841 if (!consts || !names || !varnames) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3842 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3843 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3844 cellvars = dict_keys_inorder(c->u->u_cellvars, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3845 if (!cellvars) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3846 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3847 freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_Size(cellvars)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3848 if (!freevars) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3849 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3850 filename = PyString_FromString(c->c_filename); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3851 if (!filename) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3852 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3853 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3854 nlocals = PyDict_Size(c->u->u_varnames); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3855 flags = compute_code_flags(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3856 if (flags < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3857 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3858 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3859 bytecode = PyCode_Optimize(a->a_bytecode, consts, names, a->a_lnotab); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3860 if (!bytecode) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3861 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3862 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3863 tmp = PyList_AsTuple(consts); /* PyCode_New requires a tuple */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3864 if (!tmp) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3865 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3866 Py_DECREF(consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3867 consts = tmp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3868 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3869 co = PyCode_New(c->u->u_argcount, nlocals, stackdepth(c), flags, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3870 bytecode, consts, names, varnames, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3871 freevars, cellvars, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3872 filename, c->u->u_name, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3873 c->u->u_firstlineno, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3874 a->a_lnotab); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3875 error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3876 Py_XDECREF(consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3877 Py_XDECREF(names); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3878 Py_XDECREF(varnames); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3879 Py_XDECREF(filename); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3880 Py_XDECREF(name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3881 Py_XDECREF(freevars); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3882 Py_XDECREF(cellvars); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3883 Py_XDECREF(bytecode); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3884 return co; |
| 69 | 3885 } |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3886 |
|
39363
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3887 |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3888 /* For debugging purposes only */ |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3889 #if 0 |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3890 static void |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3891 dump_instr(const struct instr *i) |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3892 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3893 const char *jrel = i->i_jrel ? "jrel " : ""; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3894 const char *jabs = i->i_jabs ? "jabs " : ""; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3895 char arg[128]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3896 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3897 *arg = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3898 if (i->i_hasarg) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3899 sprintf(arg, "arg: %d ", i->i_oparg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3900 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3901 fprintf(stderr, "line: %d, opcode: %d %s%s%s\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3902 i->i_lineno, i->i_opcode, arg, jabs, jrel); |
|
39363
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3903 } |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3904 |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3905 static void |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3906 dump_basicblock(const basicblock *b) |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3907 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3908 const char *seen = b->b_seen ? "seen " : ""; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3909 const char *b_return = b->b_return ? "return " : ""; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3910 fprintf(stderr, "used: %d, depth: %d, offset: %d %s%s\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3911 b->b_iused, b->b_startdepth, b->b_offset, seen, b_return); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3912 if (b->b_instr) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3913 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3914 for (i = 0; i < b->b_iused; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3915 fprintf(stderr, " [%02d] ", i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3916 dump_instr(b->b_instr + i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3917 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3918 } |
|
39363
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3919 } |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3920 #endif |
|
b90a8b0395bd
Bug #1191458: tracing over for loops now produces a line event
Neal Norwitz <nnorwitz@gmail.com>
parents:
39317
diff
changeset
|
3921 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3922 static PyCodeObject * |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3923 assemble(struct compiler *c, int addNone) |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3924 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3925 basicblock *b, *entryblock; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3926 struct assembler a; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3927 int i, j, nblocks; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3928 PyCodeObject *co = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3929 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3930 /* Make sure every block that falls off the end returns None. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3931 XXX NEXT_BLOCK() isn't quite right, because if the last |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3932 block ends with a jump or return b_next shouldn't set. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3933 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3934 if (!c->u->u_curblock->b_return) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3935 NEXT_BLOCK(c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3936 if (addNone) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3937 ADDOP_O(c, LOAD_CONST, Py_None, consts); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3938 ADDOP(c, RETURN_VALUE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3939 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3940 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3941 nblocks = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3942 entryblock = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3943 for (b = c->u->u_blocks; b != NULL; b = b->b_list) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3944 nblocks++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3945 entryblock = b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3946 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3947 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3948 /* Set firstlineno if it wasn't explicitly set. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3949 if (!c->u->u_firstlineno) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3950 if (entryblock && entryblock->b_instr) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3951 c->u->u_firstlineno = entryblock->b_instr->i_lineno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3952 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3953 c->u->u_firstlineno = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3954 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3955 if (!assemble_init(&a, nblocks, c->u->u_firstlineno)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3956 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3957 dfs(c, entryblock, &a); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3958 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3959 /* Can't modify the bytecode after computing jump offsets. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3960 assemble_jump_offsets(&a, c); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3961 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3962 /* Emit code in reverse postorder from dfs. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3963 for (i = a.a_nblocks - 1; i >= 0; i--) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3964 b = a.a_postorder[i]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3965 for (j = 0; j < b->b_iused; j++) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3966 if (!assemble_emit(&a, &b->b_instr[j])) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3967 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3968 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3969 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3970 if (_PyString_Resize(&a.a_lnotab, a.a_lnotab_off) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3971 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3972 if (_PyString_Resize(&a.a_bytecode, a.a_offset) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3973 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3974 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3975 co = makecode(c, &a); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35310
diff
changeset
|
3976 error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3977 assemble_free(&a); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59998
diff
changeset
|
3978 return co; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3979 } |
