Mercurial > cpython-lru_cache-weakref
annotate Python/compile.c @ 28887:e4eabe5b3da1 legacy-trunk
Use Tim's suggestion to fix
[ 708901 ] Lineno calculation sometimes broken
A one line patch to compile.c and a rather-more-than-one-line patch
to test_dis. Hey ho.
Possibly a backport candidate -- tho' lnotab is less used in 2.2...
| author | Michael W. Hudson <mwh@python.net> |
|---|---|
| date | Tue, 29 Apr 2003 17:07:36 +0000 |
| parents | 3df0cf16defc |
| children | 1763d9d3fd9d |
| rev | line source |
|---|---|
| 69 | 1 /* Compile an expression node to intermediate code */ |
| 2 | |
| 86 | 3 /* XXX TO DO: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4 XXX add __doc__ attribute == co_doc to code object attributes? |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
5 XXX (it's currently the first item of the co_const tuple) |
| 86 | 6 XXX Generate simple jump for break/return outside 'try...finally' |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
7 XXX Allow 'continue' inside finally clause of try-finally |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
8 XXX New opcode for loading the initial index for a for loop |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
9 XXX other JAR tricks? |
| 86 | 10 */ |
| 69 | 11 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
12 #include "Python.h" |
| 86 | 13 |
| 69 | 14 #include "node.h" |
| 15 #include "token.h" | |
| 16 #include "graminit.h" | |
| 17 #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
|
18 #include "symtable.h" |
| 69 | 19 #include "opcode.h" |
| 86 | 20 #include "structmember.h" |
| 21 | |
| 22 #include <ctype.h> | |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
23 |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
24 /* Three symbols from graminit.h are also defined in Python.h, with |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
25 Py_ prefixes to their names. Python.h can't include graminit.h |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
26 (which defines too many confusing symbols), but we can check here |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
27 that they haven't changed (which is very unlikely, but possible). */ |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
28 #if Py_single_input != single_input |
|
5566
19d4a2874645
Indent the #error directives so a classic K&R cpp doesn't see them.
Guido van Rossum <guido@python.org>
parents:
5453
diff
changeset
|
29 #error "single_input has changed -- update Py_single_input in Python.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
|
30 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
31 #if Py_file_input != file_input |
|
5566
19d4a2874645
Indent the #error directives so a classic K&R cpp doesn't see them.
Guido van Rossum <guido@python.org>
parents:
5453
diff
changeset
|
32 #error "file_input has changed -- update Py_file_input in Python.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
|
33 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
34 #if Py_eval_input != eval_input |
|
5566
19d4a2874645
Indent the #error directives so a classic K&R cpp doesn't see them.
Guido van Rossum <guido@python.org>
parents:
5453
diff
changeset
|
35 #error "eval_input has changed -- update Py_eval_input in Python.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
|
36 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
37 |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
38 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
|
39 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
40 #define OP_DELETE 0 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
41 #define OP_ASSIGN 1 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
42 #define OP_APPLY 2 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
43 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
44 #define VAR_LOAD 0 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
45 #define VAR_STORE 1 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
46 #define VAR_DELETE 2 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
47 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
48 #define DEL_CLOSURE_ERROR \ |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
49 "can not delete variable '%.400s' referenced in nested scope" |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
50 |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
51 #define DUPLICATE_ARGUMENT \ |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
52 "duplicate argument '%s' in function definition" |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
53 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
54 #define ILLEGAL_DYNAMIC_SCOPE \ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
55 "%.100s: exec or 'import *' makes names ambiguous in nested scope" |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
56 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
57 #define GLOBAL_AFTER_ASSIGN \ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
58 "name '%.400s' is assigned to before global declaration" |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
59 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
60 #define GLOBAL_AFTER_USE \ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
61 "name '%.400s' is used prior to global declaration" |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
62 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
63 #define LOCAL_GLOBAL \ |
|
21833
070d392042e3
Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21725
diff
changeset
|
64 "name '%.400s' is a function parameter and declared global" |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
65 |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
66 #define LATE_FUTURE \ |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
67 "from __future__ imports must occur at the beginning of the file" |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
68 |
|
17185
f9a30015e8b0
Make it illegal to assign to __debug__ as per Guido's request.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17132
diff
changeset
|
69 #define ASSIGN_DEBUG \ |
|
f9a30015e8b0
Make it illegal to assign to __debug__ as per Guido's request.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17132
diff
changeset
|
70 "can not assign to __debug__" |
|
f9a30015e8b0
Make it illegal to assign to __debug__ as per Guido's request.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17132
diff
changeset
|
71 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
72 #define MANGLE_LEN 256 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
73 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
74 #define OFF(x) offsetof(PyCodeObject, x) |
| 86 | 75 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19915
diff
changeset
|
76 static PyMemberDef code_memberlist[] = { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
77 {"co_argcount", T_INT, OFF(co_argcount), READONLY}, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
78 {"co_nlocals", T_INT, OFF(co_nlocals), READONLY}, |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
79 {"co_stacksize",T_INT, OFF(co_stacksize), READONLY}, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
80 {"co_flags", T_INT, OFF(co_flags), READONLY}, |
|
568
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
81 {"co_code", T_OBJECT, OFF(co_code), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
82 {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
83 {"co_names", T_OBJECT, OFF(co_names), READONLY}, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
84 {"co_varnames", T_OBJECT, OFF(co_varnames), READONLY}, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
85 {"co_freevars", T_OBJECT, OFF(co_freevars), READONLY}, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
86 {"co_cellvars", T_OBJECT, OFF(co_cellvars), READONLY}, |
|
568
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
87 {"co_filename", T_OBJECT, OFF(co_filename), READONLY}, |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
88 {"co_name", T_OBJECT, OFF(co_name), READONLY}, |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
89 {"co_firstlineno", T_INT, OFF(co_firstlineno), READONLY}, |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
90 {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY}, |
| 86 | 91 {NULL} /* Sentinel */ |
| 92 }; | |
| 93 | |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
94 PyDoc_STRVAR(code_doc, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
95 "code(argcount, nlocals, stacksize, flags, codestring, constants, names,\n\ |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
96 varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]])\n\ |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
97 \n\ |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
98 Create a code object. Not for the faint of heart."); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
99 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
100 static PyObject * |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
101 code_new(PyTypeObject *type, PyObject *args, PyObject *kw) |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
102 { |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
103 int argcount; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
104 int nlocals; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
105 int stacksize; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
106 int flags; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
107 PyObject *code; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
108 PyObject *consts; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
109 PyObject *names; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
110 PyObject *varnames; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
111 PyObject *freevars = NULL; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
112 PyObject *cellvars = NULL; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
113 PyObject *filename; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
114 PyObject *name; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
115 int firstlineno; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
116 PyObject *lnotab; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
117 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
118 if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS|O!O!:code", |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
119 &argcount, &nlocals, &stacksize, &flags, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
120 &code, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
121 &PyTuple_Type, &consts, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
122 &PyTuple_Type, &names, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
123 &PyTuple_Type, &varnames, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
124 &filename, &name, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
125 &firstlineno, &lnotab, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
126 &PyTuple_Type, &freevars, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
127 &PyTuple_Type, &cellvars)) |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
128 return NULL; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
129 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
130 if (freevars == NULL || cellvars == NULL) { |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
131 PyObject *empty = PyTuple_New(0); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
132 if (empty == NULL) |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
133 return NULL; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
134 if (freevars == NULL) { |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
135 freevars = empty; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
136 Py_INCREF(freevars); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
137 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
138 if (cellvars == NULL) { |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
139 cellvars = empty; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
140 Py_INCREF(cellvars); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
141 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
142 Py_DECREF(empty); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
143 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
144 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
145 if (!PyObject_CheckReadBuffer(code)) { |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
146 PyErr_SetString(PyExc_TypeError, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
147 "bytecode object must be a single-segment read-only buffer"); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
148 return NULL; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
149 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
150 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
151 return (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
152 code, consts, names, varnames, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
153 freevars, cellvars, filename, name, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
154 firstlineno, lnotab); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
155 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
156 |
| 69 | 157 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
158 code_dealloc(PyCodeObject *co) |
| 69 | 159 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
160 Py_XDECREF(co->co_code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
161 Py_XDECREF(co->co_consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
162 Py_XDECREF(co->co_names); |
|
5901
ba49a6ef7214
Plug a leak in code_dealloc() (and reordered the deallocs to match the
Guido van Rossum <guido@python.org>
parents:
5754
diff
changeset
|
163 Py_XDECREF(co->co_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
164 Py_XDECREF(co->co_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
165 Py_XDECREF(co->co_cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
166 Py_XDECREF(co->co_filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
167 Py_XDECREF(co->co_name); |
|
5901
ba49a6ef7214
Plug a leak in code_dealloc() (and reordered the deallocs to match the
Guido van Rossum <guido@python.org>
parents:
5754
diff
changeset
|
168 Py_XDECREF(co->co_lnotab); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12538
diff
changeset
|
169 PyObject_DEL(co); |
| 69 | 170 } |
| 171 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
172 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
173 code_repr(PyCodeObject *co) |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
174 { |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
175 char buf[500]; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
176 int lineno = -1; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
177 char *filename = "???"; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
178 char *name = "???"; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
179 |
|
12278
647bf71912f0
Vladimir Marangozov: This fixes the line number in the string
Guido van Rossum <guido@python.org>
parents:
12086
diff
changeset
|
180 if (co->co_firstlineno != 0) |
|
647bf71912f0
Vladimir Marangozov: This fixes the line number in the string
Guido van Rossum <guido@python.org>
parents:
12086
diff
changeset
|
181 lineno = co->co_firstlineno; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
182 if (co->co_filename && PyString_Check(co->co_filename)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
183 filename = PyString_AS_STRING(co->co_filename); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
184 if (co->co_name && PyString_Check(co->co_name)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
185 name = PyString_AS_STRING(co->co_name); |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
186 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
187 "<code object %.100s at %p, file \"%.300s\", line %d>", |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
188 name, co, filename, lineno); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
189 return PyString_FromString(buf); |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
190 } |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
191 |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
192 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
193 code_compare(PyCodeObject *co, PyCodeObject *cp) |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
194 { |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
195 int cmp; |
|
12333
525b2358721e
Patch by Vladimir Marangozov to include the function name when
Guido van Rossum <guido@python.org>
parents:
12278
diff
changeset
|
196 cmp = PyObject_Compare(co->co_name, cp->co_name); |
|
525b2358721e
Patch by Vladimir Marangozov to include the function name when
Guido van Rossum <guido@python.org>
parents:
12278
diff
changeset
|
197 if (cmp) return cmp; |
|
6186
2e755d1ff661
Cprrect stuoid tyops -- was comparing variabes with themselves because
Guido van Rossum <guido@python.org>
parents:
5901
diff
changeset
|
198 cmp = co->co_argcount - cp->co_argcount; |
|
25538
2c0e0f0dca6f
Clamp code objects' tp_compare result to [-1, 1].
Michael W. Hudson <mwh@python.net>
parents:
25078
diff
changeset
|
199 if (cmp) return (cmp<0)?-1:1; |
|
6186
2e755d1ff661
Cprrect stuoid tyops -- was comparing variabes with themselves because
Guido van Rossum <guido@python.org>
parents:
5901
diff
changeset
|
200 cmp = co->co_nlocals - cp->co_nlocals; |
|
25538
2c0e0f0dca6f
Clamp code objects' tp_compare result to [-1, 1].
Michael W. Hudson <mwh@python.net>
parents:
25078
diff
changeset
|
201 if (cmp) return (cmp<0)?-1:1; |
|
6186
2e755d1ff661
Cprrect stuoid tyops -- was comparing variabes with themselves because
Guido van Rossum <guido@python.org>
parents:
5901
diff
changeset
|
202 cmp = co->co_flags - cp->co_flags; |
|
25538
2c0e0f0dca6f
Clamp code objects' tp_compare result to [-1, 1].
Michael W. Hudson <mwh@python.net>
parents:
25078
diff
changeset
|
203 if (cmp) return (cmp<0)?-1:1; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
204 cmp = PyObject_Compare(co->co_code, cp->co_code); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
205 if (cmp) return cmp; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
206 cmp = PyObject_Compare(co->co_consts, cp->co_consts); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
207 if (cmp) return cmp; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
208 cmp = PyObject_Compare(co->co_names, cp->co_names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
209 if (cmp) return cmp; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
210 cmp = PyObject_Compare(co->co_varnames, cp->co_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
211 if (cmp) return cmp; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
212 cmp = PyObject_Compare(co->co_freevars, cp->co_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
213 if (cmp) return cmp; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
214 cmp = PyObject_Compare(co->co_cellvars, cp->co_cellvars); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
215 return cmp; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
216 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
217 |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
218 static long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
219 code_hash(PyCodeObject *co) |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
220 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
221 long h, h0, h1, h2, h3, h4, h5, h6; |
|
12333
525b2358721e
Patch by Vladimir Marangozov to include the function name when
Guido van Rossum <guido@python.org>
parents:
12278
diff
changeset
|
222 h0 = PyObject_Hash(co->co_name); |
|
525b2358721e
Patch by Vladimir Marangozov to include the function name when
Guido van Rossum <guido@python.org>
parents:
12278
diff
changeset
|
223 if (h0 == -1) return -1; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
224 h1 = PyObject_Hash(co->co_code); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
225 if (h1 == -1) return -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
226 h2 = PyObject_Hash(co->co_consts); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
227 if (h2 == -1) return -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
228 h3 = PyObject_Hash(co->co_names); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
229 if (h3 == -1) return -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
230 h4 = PyObject_Hash(co->co_varnames); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
231 if (h4 == -1) return -1; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
232 h5 = PyObject_Hash(co->co_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
233 if (h5 == -1) return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
234 h6 = PyObject_Hash(co->co_cellvars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
235 if (h6 == -1) return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
236 h = h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5 ^ h6 ^ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
237 co->co_argcount ^ co->co_nlocals ^ co->co_flags; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
238 if (h == -1) h = -2; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
239 return h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
240 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
241 |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
242 /* XXX code objects need to participate in GC? */ |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
243 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
244 PyTypeObject PyCode_Type = { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
245 PyObject_HEAD_INIT(&PyType_Type) |
| 69 | 246 0, |
| 247 "code", | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
248 sizeof(PyCodeObject), |
| 69 | 249 0, |
|
19915
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
250 (destructor)code_dealloc, /* tp_dealloc */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
251 0, /* tp_print */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
252 0, /* tp_getattr */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
253 0, /* tp_setattr */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
254 (cmpfunc)code_compare, /* tp_compare */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
255 (reprfunc)code_repr, /* tp_repr */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
256 0, /* tp_as_number */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
257 0, /* tp_as_sequence */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
258 0, /* tp_as_mapping */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
259 (hashfunc)code_hash, /* tp_hash */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
260 0, /* tp_call */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
261 0, /* tp_str */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
262 PyObject_GenericGetAttr, /* tp_getattro */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
263 0, /* tp_setattro */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
264 0, /* tp_as_buffer */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
265 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
266 code_doc, /* tp_doc */ |
|
19915
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
267 0, /* tp_traverse */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
268 0, /* tp_clear */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
269 0, /* tp_richcompare */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
270 0, /* tp_weaklistoffset */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
271 0, /* tp_iter */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
272 0, /* tp_iternext */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
273 0, /* tp_methods */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
274 code_memberlist, /* tp_members */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
275 0, /* tp_getset */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
276 0, /* tp_base */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
277 0, /* tp_dict */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
278 0, /* tp_descr_get */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
279 0, /* tp_descr_set */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
280 0, /* tp_dictoffset */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
281 0, /* tp_init */ |
|
2263cb43eaab
Supply code objects a new-style tp_members slot and tp_getattr impl.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19793
diff
changeset
|
282 0, /* tp_alloc */ |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23589
diff
changeset
|
283 code_new, /* tp_new */ |
| 69 | 284 }; |
| 285 | |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
286 #define NAME_CHARS \ |
|
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
287 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" |
|
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
288 |
|
16006
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
289 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
290 |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
291 static int |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
292 all_name_chars(unsigned char *s) |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
293 { |
|
16523
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
294 static char ok_name_char[256]; |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
295 static unsigned char *name_chars = (unsigned char *)NAME_CHARS; |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
296 |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
297 if (ok_name_char[*name_chars] == 0) { |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
298 unsigned char *p; |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
299 for (p = name_chars; *p; p++) |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
300 ok_name_char[*p] = 1; |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
301 } |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
302 while (*s) { |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
303 if (ok_name_char[*s++] == 0) |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
304 return 0; |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
305 } |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
306 return 1; |
|
16006
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
307 } |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
308 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
309 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
310 intern_strings(PyObject *tuple) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
311 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
312 int i; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
313 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
314 for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
315 PyObject *v = PyTuple_GET_ITEM(tuple, i); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
316 if (v == NULL || !PyString_Check(v)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
317 Py_FatalError("non-string found in code slot"); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
318 PyErr_BadInternalCall(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
319 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
320 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
321 PyString_InternInPlace(&PyTuple_GET_ITEM(tuple, i)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
322 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
323 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
324 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
325 |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
326 #define GETARG(arr, i) ((int)((arr[i+2]<<8) + arr[i+1])) |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
327 #define UNCONDITIONAL_JUMP(op) (op==JUMP_ABSOLUTE || op==JUMP_FORWARD) |
|
28417
1a2fd109f6b6
Factored out test for absolute jumps.
Raymond Hettinger <python@rcn.com>
parents:
28406
diff
changeset
|
328 #define ABSOLUTE_JUMP(op) (op==JUMP_ABSOLUTE || op==CONTINUE_LOOP) |
|
1a2fd109f6b6
Factored out test for absolute jumps.
Raymond Hettinger <python@rcn.com>
parents:
28406
diff
changeset
|
329 #define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3)) |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
330 #define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255 |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
331 |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
332 static PyObject * |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
333 optimize_code(PyObject *code, PyObject* consts) |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
334 { |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
335 int i, j, codelen; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
336 int tgt, tgttgt, opcode; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
337 unsigned char *codestr; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
338 |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
339 /* Make a modifiable copy of the code string */ |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
340 if (!PyString_Check(code)) |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
341 goto exitUnchanged; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
342 codelen = PyString_Size(code); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
343 codestr = PyMem_Malloc(codelen); |
|
28759
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
344 if (codestr == NULL) |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
345 goto exitUnchanged; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
346 codestr = memcpy(codestr, PyString_AS_STRING(code), codelen); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
347 assert(PyTuple_Check(consts)); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
348 |
|
28759
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
349 for (i=0 ; i<codelen-7 ; i += HAS_ARG(codestr[i]) ? 3 : 1) { |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
350 opcode = codestr[i]; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
351 switch (opcode) { |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
352 |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
353 /* Skip over LOAD_CONST trueconst JUMP_IF_FALSE xx POP_TOP. |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
354 Note, only the first opcode is changed, the others still |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
355 perform normally if they happen to be jump targets. */ |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
356 case LOAD_CONST: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
357 j = GETARG(codestr, i); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
358 if (codestr[i+3] != JUMP_IF_FALSE || |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
359 codestr[i+6] != POP_TOP || |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
360 !PyObject_IsTrue(PyTuple_GET_ITEM(consts, j))) |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
361 continue; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
362 codestr[i] = JUMP_FORWARD; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
363 SETARG(codestr, i, 4); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
364 break; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
365 |
|
28759
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
366 /* Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2 JMP+2. |
|
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
367 Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2 JMP+1. |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
368 Note, these opcodes occur together only in assignment |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
369 statements. Accordingly, the unpack opcode is never |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
370 a jump target. */ |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
371 case BUILD_TUPLE: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
372 case BUILD_LIST: |
|
28610
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
373 if (codestr[i+3] != UNPACK_SEQUENCE) |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
374 continue; |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
375 if (GETARG(codestr, i) == 2 && \ |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
376 GETARG(codestr, i+3) == 2) { |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
377 codestr[i] = ROT_TWO; |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
378 codestr[i+1] = JUMP_FORWARD; |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
379 SETARG(codestr, i+1, 2); |
|
28759
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
380 codestr[i+4] = DUP_TOP; /* Filler codes used as NOPs */ |
|
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
381 codestr[i+5] = POP_TOP; |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
382 continue; |
|
28610
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
383 } |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
384 if (GETARG(codestr, i) == 3 && \ |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
385 GETARG(codestr, i+3) == 3) { |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
386 codestr[i] = ROT_THREE; |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
387 codestr[i+1] = ROT_TWO; |
|
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
388 codestr[i+2] = JUMP_FORWARD; |
|
28759
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
389 SETARG(codestr, i+2, 1); |
|
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
390 codestr[i+5] = DUP_TOP; |
|
28610
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
391 } |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
392 break; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
393 |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
394 /* Replace jumps to unconditional jumps */ |
|
28610
67d36f4dfea1
Extend SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28417
diff
changeset
|
395 case FOR_ITER: |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
396 case JUMP_FORWARD: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
397 case JUMP_IF_FALSE: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
398 case JUMP_IF_TRUE: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
399 case JUMP_ABSOLUTE: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
400 case CONTINUE_LOOP: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
401 case SETUP_LOOP: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
402 case SETUP_EXCEPT: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
403 case SETUP_FINALLY: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
404 tgt = GETJUMPTGT(codestr, i); |
|
28759
3df0cf16defc
Revert the previous enhancement to the bytecode optimizer.
Raymond Hettinger <python@rcn.com>
parents:
28716
diff
changeset
|
405 if (!UNCONDITIONAL_JUMP(codestr[tgt])) |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
406 continue; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
407 tgttgt = GETJUMPTGT(codestr, tgt); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
408 if (opcode == JUMP_FORWARD) /* JMP_ABS can go backwards */ |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
409 opcode = JUMP_ABSOLUTE; |
|
28417
1a2fd109f6b6
Factored out test for absolute jumps.
Raymond Hettinger <python@rcn.com>
parents:
28406
diff
changeset
|
410 if (!ABSOLUTE_JUMP(opcode)) |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
411 tgttgt -= i + 3; /* Calc relative jump addr */ |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
412 if (tgttgt < 0) /* No backward relative jumps */ |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
413 continue; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
414 codestr[i] = opcode; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
415 SETARG(codestr, i, tgttgt); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
416 break; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
417 |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
418 case EXTENDED_ARG: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
419 PyMem_Free(codestr); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
420 goto exitUnchanged; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
421 } |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
422 } |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
423 code = PyString_FromStringAndSize(codestr, codelen); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
424 PyMem_Free(codestr); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
425 return code; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
426 |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
427 exitUnchanged: |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
428 Py_INCREF(code); |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
429 return code; |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
430 } |
|
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
431 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
432 PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
433 PyCode_New(int argcount, int nlocals, int stacksize, int flags, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
434 PyObject *code, PyObject *consts, PyObject *names, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
435 PyObject *varnames, PyObject *freevars, PyObject *cellvars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
436 PyObject *filename, PyObject *name, int firstlineno, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
437 PyObject *lnotab) |
| 69 | 438 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
439 PyCodeObject *co; |
| 69 | 440 int i; |
| 441 /* Check argument types */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
442 if (argcount < 0 || nlocals < 0 || |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
443 code == NULL || |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
444 consts == NULL || !PyTuple_Check(consts) || |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
445 names == NULL || !PyTuple_Check(names) || |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
446 varnames == NULL || !PyTuple_Check(varnames) || |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
447 freevars == NULL || !PyTuple_Check(freevars) || |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
448 cellvars == NULL || !PyTuple_Check(cellvars) || |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
449 name == NULL || !PyString_Check(name) || |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
450 filename == NULL || !PyString_Check(filename) || |
|
20947
c555f1e7c4be
Use PyObject_CheckReadBuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20939
diff
changeset
|
451 lnotab == NULL || !PyString_Check(lnotab) || |
|
c555f1e7c4be
Use PyObject_CheckReadBuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20939
diff
changeset
|
452 !PyObject_CheckReadBuffer(code)) { |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
453 PyErr_BadInternalCall(); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
454 return NULL; |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
455 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
456 intern_strings(names); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
457 intern_strings(varnames); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
458 intern_strings(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
459 intern_strings(cellvars); |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
460 /* Intern selected string constants */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
461 for (i = PyTuple_Size(consts); --i >= 0; ) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
462 PyObject *v = PyTuple_GetItem(consts, i); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
463 if (!PyString_Check(v)) |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
464 continue; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
465 if (!all_name_chars((unsigned char *)PyString_AS_STRING(v))) |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
466 continue; |
|
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
467 PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i)); |
| 69 | 468 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
469 co = PyObject_NEW(PyCodeObject, &PyCode_Type); |
| 69 | 470 if (co != NULL) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
471 co->co_argcount = argcount; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
472 co->co_nlocals = nlocals; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
473 co->co_stacksize = stacksize; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
474 co->co_flags = flags; |
|
28406
733729261c41
SF patch #707257: Improve code generation
Raymond Hettinger <python@rcn.com>
parents:
28402
diff
changeset
|
475 co->co_code = optimize_code(code, consts); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
476 Py_INCREF(consts); |
| 69 | 477 co->co_consts = consts; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
478 Py_INCREF(names); |
| 69 | 479 co->co_names = names; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
480 Py_INCREF(varnames); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
481 co->co_varnames = varnames; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
482 Py_INCREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
483 co->co_freevars = freevars; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
484 Py_INCREF(cellvars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
485 co->co_cellvars = cellvars; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
486 Py_INCREF(filename); |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
487 co->co_filename = filename; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
488 Py_INCREF(name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
489 co->co_name = name; |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
490 co->co_firstlineno = firstlineno; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
491 Py_INCREF(lnotab); |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
492 co->co_lnotab = lnotab; |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27270
diff
changeset
|
493 if (PyTuple_GET_SIZE(freevars) == 0 && |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27270
diff
changeset
|
494 PyTuple_GET_SIZE(cellvars) == 0) |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27270
diff
changeset
|
495 co->co_flags |= CO_NOFREE; |
| 69 | 496 } |
| 497 return co; | |
| 498 } | |
| 499 | |
| 500 | |
| 501 /* Data structure used internally */ | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
502 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
503 /* The compiler uses two passes to generate bytecodes. The first pass |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
504 builds the symbol table. The second pass generates the bytecode. |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
505 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
506 The first pass uses a single symtable struct. The second pass uses |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
507 a compiling struct for each code block. The compiling structs |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
508 share a reference to the symtable. |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
509 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
510 The two passes communicate via symtable_load_symbols() and via |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
511 is_local() and is_global(). The former initializes several slots |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
512 in the compiling struct: c_varnames, c_locals, c_nlocals, |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
513 c_argcount, c_globals, and c_flags. |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
514 */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
515 |
|
18065
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
516 /* All about c_lnotab. |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
517 |
| 24844 | 518 c_lnotab is an array of unsigned bytes disguised as a Python string. Since |
| 519 version 2.3, SET_LINENO opcodes are never generated and bytecode offsets are | |
| 520 mapped to source code line #s via c_lnotab instead. | |
| 521 | |
|
18065
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
522 The array is conceptually a list of |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
523 (bytecode offset increment, line number increment) |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
524 pairs. The details are important and delicate, best illustrated by example: |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
525 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
526 byte code offset source code line number |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
527 0 1 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
528 6 2 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
529 50 7 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
530 350 307 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
531 361 308 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
532 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
533 The first trick is that these numbers aren't stored, only the increments |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
534 from one row to the next (this doesn't really work, but it's a start): |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
535 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
536 0, 1, 6, 1, 44, 5, 300, 300, 11, 1 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
537 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
538 The second trick is that an unsigned byte can't hold negative values, or |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
539 values larger than 255, so (a) there's a deep assumption that byte code |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
540 offsets and their corresponding line #s both increase monotonically, and (b) |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
541 if at least one column jumps by more than 255 from one row to the next, more |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
542 than one pair is written to the table. In case #b, there's no way to know |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
543 from looking at the table later how many were written. That's the delicate |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
544 part. A user of c_lnotab desiring to find the source line number |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
545 corresponding to a bytecode address A should do something like this |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
546 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
547 lineno = addr = 0 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
548 for addr_incr, line_incr in c_lnotab: |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
549 addr += addr_incr |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
550 if addr > A: |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
551 return lineno |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
552 lineno += line_incr |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
553 |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
554 In order for this to work, when the addr field increments by more than 255, |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
555 the line # increment in each pair generated must be 0 until the remaining addr |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
556 increment is < 256. So, in the example above, com_set_lineno should not (as |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
557 was actually done until 2.2) expand 300, 300 to 255, 255, 45, 45, but to |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
558 255, 0, 45, 255, 0, 45. |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
559 */ |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
560 |
| 69 | 561 struct compiling { |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
562 PyObject *c_code; /* string */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
563 PyObject *c_consts; /* list of objects */ |
| 12522 | 564 PyObject *c_const_dict; /* inverse of c_consts */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
565 PyObject *c_names; /* list of strings (names) */ |
| 12522 | 566 PyObject *c_name_dict; /* inverse of c_names */ |
|
26701
45ab31127bf9
SF # 654960, remove unnecessary static variable
Neal Norwitz <nnorwitz@gmail.com>
parents:
26670
diff
changeset
|
567 PyObject *c_globals; /* dictionary (value=None or True) */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
568 PyObject *c_locals; /* dictionary (value=localID) */ |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
569 PyObject *c_varnames; /* list (inverse of c_locals) */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
570 PyObject *c_freevars; /* dictionary (value=None) */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
571 PyObject *c_cellvars; /* list */ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
572 int c_nlocals; /* index of next local */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
573 int c_argcount; /* number of top-level arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
574 int c_flags; /* same as co_flags */ |
| 69 | 575 int c_nexti; /* index into c_code */ |
| 576 int c_errors; /* counts errors occurred */ | |
| 86 | 577 int c_infunction; /* set when compiling a function */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
578 int c_interactive; /* generating code for interactive command */ |
| 86 | 579 int c_loops; /* counts nested loops */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
580 int c_begin; /* begin of current loop, for 'continue' */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
581 int c_block[CO_MAXBLOCKS]; /* stack of block types */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
582 int c_nblocks; /* current block stack level */ |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
583 const char *c_filename; /* filename of current node */ |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
584 char *c_name; /* name of object (e.g. function) */ |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
585 int c_lineno; /* Current line number */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
586 int c_stacklevel; /* Current stack level */ |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
587 int c_maxstacklevel; /* Maximum stack level */ |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
588 int c_firstlineno; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
589 PyObject *c_lnotab; /* Table mapping address to line number */ |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
590 int c_last_addr, c_last_line, c_lnotab_next; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
591 char *c_private; /* for private name mangling */ |
| 13936 | 592 int c_tmpname; /* temporary local name counter */ |
|
16523
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
593 int c_nested; /* Is block nested funcdef or lamdef? */ |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
594 int c_closure; /* Is nested w/freevars? */ |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
595 struct symtable *c_symtable; /* pointer to module symbol table */ |
|
16799
08d937107fe6
Improved __future__ parser; still more to do
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16783
diff
changeset
|
596 PyFutureFeatures *c_future; /* pointer to module's __future__ */ |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
597 char *c_encoding; /* source encoding (a borrowed reference) */ |
| 69 | 598 }; |
| 599 | |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
17355
diff
changeset
|
600 static int |
|
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
17355
diff
changeset
|
601 is_free(int v) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
602 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
603 if ((v & (USE | DEF_FREE)) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
604 && !(v & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL))) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
605 return 1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
606 if (v & DEF_FREE_CLASS) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
607 return 1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
608 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
609 } |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
610 |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
611 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
612 com_error(struct compiling *c, PyObject *exc, char *msg) |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
613 { |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
614 PyObject *t = NULL, *v = NULL, *w = NULL, *line = NULL; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
615 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
616 if (c == NULL) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
617 /* Error occurred via symtable call to |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
618 is_constant_false */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
619 PyErr_SetString(exc, msg); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
620 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
621 } |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
622 c->c_errors++; |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
623 if (c->c_lineno < 1 || c->c_interactive) { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
624 /* Unknown line number or interactive input */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
625 PyErr_SetString(exc, msg); |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
626 return; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
627 } |
|
13993
716e1c4e3f78
When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents:
13956
diff
changeset
|
628 v = PyString_FromString(msg); |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
629 if (v == NULL) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
630 return; /* MemoryError, too bad */ |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
631 |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
632 line = PyErr_ProgramText(c->c_filename, c->c_lineno); |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
633 if (line == NULL) { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
634 Py_INCREF(Py_None); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
635 line = Py_None; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
636 } |
|
22120
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
637 if (exc == PyExc_SyntaxError) { |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
638 t = Py_BuildValue("(ziOO)", c->c_filename, c->c_lineno, |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
639 Py_None, line); |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
640 if (t == NULL) |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
641 goto exit; |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
642 w = Py_BuildValue("(OO)", v, t); |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
643 if (w == NULL) |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
644 goto exit; |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
645 PyErr_SetObject(exc, w); |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
646 } else { |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
647 /* Make sure additional exceptions are printed with |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
648 file and line, also. */ |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
649 PyErr_SetObject(exc, v); |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
650 PyErr_SyntaxLocation(c->c_filename, c->c_lineno); |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
651 } |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
652 exit: |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
653 Py_XDECREF(t); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
654 Py_XDECREF(v); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
655 Py_XDECREF(w); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
656 Py_XDECREF(line); |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
657 } |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
658 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
659 /* Interface to the block stack */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
660 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
661 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
662 block_push(struct compiling *c, int type) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
663 { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
664 if (c->c_nblocks >= CO_MAXBLOCKS) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
665 com_error(c, PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
666 "too many statically nested blocks"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
667 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
668 else { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
669 c->c_block[c->c_nblocks++] = type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
670 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
671 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
672 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
673 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
674 block_pop(struct compiling *c, int type) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
675 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
676 if (c->c_nblocks > 0) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
677 c->c_nblocks--; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
678 if (c->c_block[c->c_nblocks] != type && c->c_errors == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
679 com_error(c, PyExc_SystemError, "bad block pop"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
680 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
681 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
682 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
683 /* Prototype forward declarations */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
684 |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
685 static int issue_warning(const char *, const char *, int); |
|
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
686 static int com_init(struct compiling *, const char *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
687 static void com_free(struct compiling *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
688 static void com_push(struct compiling *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
689 static void com_pop(struct compiling *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
690 static void com_done(struct compiling *); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
691 static void com_node(struct compiling *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
692 static void com_factor(struct compiling *, node *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
693 static void com_addbyte(struct compiling *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
694 static void com_addint(struct compiling *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
695 static void com_addoparg(struct compiling *, int, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
696 static void com_addfwref(struct compiling *, int, int *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
697 static void com_backpatch(struct compiling *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
698 static int com_add(struct compiling *, PyObject *, PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
699 static int com_addconst(struct compiling *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
700 static int com_addname(struct compiling *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
701 static void com_addopname(struct compiling *, int, node *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
702 static void com_list(struct compiling *, node *, int); |
| 13936 | 703 static void com_list_iter(struct compiling *, node *, node *, char *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
704 static int com_argdefs(struct compiling *, node *); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
705 static void com_assign(struct compiling *, node *, int, node *); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
706 static void com_assign_name(struct compiling *, node *, int); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
707 static PyCodeObject *icompile(node *, struct compiling *); |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
708 static PyCodeObject *jcompile(node *, const char *, struct compiling *, |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
709 PyCompilerFlags *); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
710 static PyObject *parsestrplus(struct compiling*, node *); |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
711 static PyObject *parsestr(struct compiling *, char *); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
712 static node *get_rawdocstring(node *); |
| 69 | 713 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
714 static int get_ref_type(struct compiling *, char *); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
715 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
716 /* symtable operations */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
717 static int symtable_build(struct compiling *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
718 static int symtable_load_symbols(struct compiling *); |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
719 static struct symtable *symtable_init(void); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
720 static void symtable_enter_scope(struct symtable *, char *, int, int); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
721 static int symtable_exit_scope(struct symtable *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
722 static int symtable_add_def(struct symtable *, char *, int); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
723 static int symtable_add_def_o(struct symtable *, PyObject *, PyObject *, int); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
724 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
725 static void symtable_node(struct symtable *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
726 static void symtable_funcdef(struct symtable *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
727 static void symtable_default_args(struct symtable *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
728 static void symtable_params(struct symtable *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
729 static void symtable_params_fplist(struct symtable *, node *n); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
730 static void symtable_global(struct symtable *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
731 static void symtable_import(struct symtable *, node *); |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
732 static void symtable_assign(struct symtable *, node *, int); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
733 static void symtable_list_comprehension(struct symtable *, node *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
734 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
735 static int symtable_update_free_vars(struct symtable *); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
736 static int symtable_undo_free(struct symtable *, PyObject *, PyObject *); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
737 static int symtable_check_global(struct symtable *, PyObject *, PyObject *); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
738 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
739 /* helper */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
740 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
741 do_pad(int pad) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
742 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
743 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
744 for (i = 0; i < pad; ++i) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
745 fprintf(stderr, " "); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
746 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
747 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
748 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
749 dump(node *n, int pad, int depth) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
750 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
751 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
752 if (depth == 0) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
753 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
754 do_pad(pad); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
755 fprintf(stderr, "%d: %s\n", TYPE(n), STR(n)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
756 if (depth > 0) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
757 depth--; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
758 for (i = 0; i < NCH(n); ++i) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
759 dump(CHILD(n, i), pad + 1, depth); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
760 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
761 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
762 #define DUMP(N) dump(N, 0, -1) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
763 |
| 69 | 764 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
765 com_init(struct compiling *c, const char *filename) |
| 69 | 766 { |
| 12522 | 767 memset((void *)c, '\0', sizeof(struct compiling)); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
768 if ((c->c_code = PyString_FromStringAndSize((char *)NULL, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
769 1000)) == NULL) |
| 12522 | 770 goto fail; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
771 if ((c->c_consts = PyList_New(0)) == NULL) |
| 12522 | 772 goto fail; |
| 773 if ((c->c_const_dict = PyDict_New()) == NULL) | |
| 774 goto fail; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
775 if ((c->c_names = PyList_New(0)) == NULL) |
| 12522 | 776 goto fail; |
| 777 if ((c->c_name_dict = PyDict_New()) == NULL) | |
| 778 goto fail; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
779 if ((c->c_locals = PyDict_New()) == NULL) |
| 12522 | 780 goto fail; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
781 if ((c->c_lnotab = PyString_FromStringAndSize((char *)NULL, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
782 1000)) == NULL) |
| 12522 | 783 goto fail; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
784 c->c_globals = NULL; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
785 c->c_varnames = NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
786 c->c_freevars = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
787 c->c_cellvars = NULL; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
788 c->c_nlocals = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
789 c->c_argcount = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
790 c->c_flags = 0; |
| 69 | 791 c->c_nexti = 0; |
| 792 c->c_errors = 0; | |
| 86 | 793 c->c_infunction = 0; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
794 c->c_interactive = 0; |
| 86 | 795 c->c_loops = 0; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
796 c->c_begin = 0; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
797 c->c_nblocks = 0; |
| 86 | 798 c->c_filename = filename; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
799 c->c_name = "?"; |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
800 c->c_lineno = 0; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
801 c->c_stacklevel = 0; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
802 c->c_maxstacklevel = 0; |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
803 c->c_firstlineno = 0; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
804 c->c_last_addr = 0; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
805 c->c_last_line = 0; |
|
16096
fb67122e5c1e
com_init(): My entry into the smallest patch possible category.
Barry Warsaw <barry@python.org>
parents:
16060
diff
changeset
|
806 c->c_lnotab_next = 0; |
| 13936 | 807 c->c_tmpname = 0; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
808 c->c_nested = 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
809 c->c_closure = 0; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
810 c->c_symtable = NULL; |
| 69 | 811 return 1; |
| 812 | |
| 12522 | 813 fail: |
| 814 com_free(c); | |
| 69 | 815 return 0; |
| 816 } | |
| 817 | |
| 818 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
819 com_free(struct compiling *c) |
| 69 | 820 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
821 Py_XDECREF(c->c_code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
822 Py_XDECREF(c->c_consts); |
| 12522 | 823 Py_XDECREF(c->c_const_dict); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
824 Py_XDECREF(c->c_names); |
| 12522 | 825 Py_XDECREF(c->c_name_dict); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
826 Py_XDECREF(c->c_globals); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
827 Py_XDECREF(c->c_locals); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
828 Py_XDECREF(c->c_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
829 Py_XDECREF(c->c_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
830 Py_XDECREF(c->c_cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
831 Py_XDECREF(c->c_lnotab); |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
832 if (c->c_future) |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24373
diff
changeset
|
833 PyObject_FREE((void *)c->c_future); |
| 69 | 834 } |
| 835 | |
| 836 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
837 com_push(struct compiling *c, int n) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
838 { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
839 c->c_stacklevel += n; |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
840 if (c->c_stacklevel > c->c_maxstacklevel) { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
841 c->c_maxstacklevel = c->c_stacklevel; |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
842 /* |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
843 fprintf(stderr, "%s:%s:%d max stack nexti=%d level=%d n=%d\n", |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
844 c->c_filename, c->c_name, c->c_lineno, |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
845 c->c_nexti, c->c_stacklevel, n); |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
846 */ |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
847 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
848 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
849 |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
850 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
851 com_pop(struct compiling *c, int n) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
852 { |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
853 if (c->c_stacklevel < n) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
854 c->c_stacklevel = 0; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
855 else |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
856 c->c_stacklevel -= n; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
857 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
858 |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
859 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
860 com_done(struct compiling *c) |
| 69 | 861 { |
| 862 if (c->c_code != NULL) | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
863 _PyString_Resize(&c->c_code, c->c_nexti); |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
864 if (c->c_lnotab != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
865 _PyString_Resize(&c->c_lnotab, c->c_lnotab_next); |
| 69 | 866 } |
| 867 | |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
868 static int |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
869 com_check_size(PyObject **s, int offset) |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
870 { |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
871 int len = PyString_GET_SIZE(*s); |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
872 if (offset >= len) |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
873 return _PyString_Resize(s, len * 2); |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
874 return 0; |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
875 } |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
876 |
| 69 | 877 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
878 com_addbyte(struct compiling *c, int byte) |
| 69 | 879 { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
880 /*fprintf(stderr, "%3d: %3d\n", c->c_nexti, byte);*/ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
881 assert(byte >= 0 && byte <= 255); |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
882 assert(c->c_code != 0); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
883 if (com_check_size(&c->c_code, c->c_nexti)) { |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
884 c->c_errors++; |
| 69 | 885 return; |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
886 } |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
887 PyString_AS_STRING(c->c_code)[c->c_nexti++] = byte; |
| 69 | 888 } |
| 889 | |
| 890 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
891 com_addint(struct compiling *c, int x) |
| 69 | 892 { |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
893 com_addbyte(c, x & 0xff); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
894 com_addbyte(c, x >> 8); /* XXX x should be positive */ |
| 69 | 895 } |
| 896 | |
| 897 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
898 com_add_lnotab(struct compiling *c, int addr, int line) |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
899 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
900 char *p; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
901 if (c->c_lnotab == NULL) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
902 return; |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
903 if (com_check_size(&c->c_lnotab, c->c_lnotab_next + 2)) { |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
904 c->c_errors++; |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
905 return; |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
906 } |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
907 p = PyString_AS_STRING(c->c_lnotab) + c->c_lnotab_next; |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
908 *p++ = addr; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
909 *p++ = line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
910 c->c_lnotab_next += 2; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
911 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
912 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
913 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
914 com_set_lineno(struct compiling *c, int lineno) |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
915 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
916 c->c_lineno = lineno; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
917 if (c->c_firstlineno == 0) { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
918 c->c_firstlineno = c->c_last_line = lineno; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
919 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
920 else { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
921 int incr_addr = c->c_nexti - c->c_last_addr; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
922 int incr_line = lineno - c->c_last_line; |
|
18065
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
923 while (incr_addr > 255) { |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
924 com_add_lnotab(c, 255, 0); |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
925 incr_addr -= 255; |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
926 } |
|
18065
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
927 while (incr_line > 255) { |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
928 com_add_lnotab(c, incr_addr, 255); |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
929 incr_line -=255; |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
930 incr_addr = 0; |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
931 } |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
932 if (incr_addr > 0 || incr_line > 0) |
|
889db6d55506
SF bug 430991: wrong co_lnotab
Tim Peters <tim.peters@gmail.com>
parents:
17736
diff
changeset
|
933 com_add_lnotab(c, incr_addr, incr_line); |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
934 c->c_last_addr = c->c_nexti; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
935 c->c_last_line = lineno; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
936 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
937 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
938 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
939 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
940 com_addoparg(struct compiling *c, int op, int arg) |
| 69 | 941 { |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
942 int extended_arg = arg >> 16; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
943 if (extended_arg){ |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
944 com_addbyte(c, EXTENDED_ARG); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
945 com_addint(c, extended_arg); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
946 arg &= 0xffff; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
947 } |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
948 com_addbyte(c, op); |
|
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
949 com_addint(c, arg); |
| 69 | 950 } |
| 951 | |
| 952 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
953 com_addfwref(struct compiling *c, int op, int *p_anchor) |
| 69 | 954 { |
| 955 /* Compile a forward reference for backpatching */ | |
| 956 int here; | |
| 957 int anchor; | |
| 958 com_addbyte(c, op); | |
| 959 here = c->c_nexti; | |
| 960 anchor = *p_anchor; | |
| 961 *p_anchor = here; | |
| 962 com_addint(c, anchor == 0 ? 0 : here - anchor); | |
| 963 } | |
| 964 | |
| 965 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
966 com_backpatch(struct compiling *c, int anchor) |
| 69 | 967 { |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
968 unsigned char *code = (unsigned char *) PyString_AS_STRING(c->c_code); |
| 69 | 969 int target = c->c_nexti; |
| 970 int dist; | |
| 971 int prev; | |
| 972 for (;;) { | |
| 973 /* Make the JUMP instruction at anchor point to target */ | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
974 prev = code[anchor] + (code[anchor+1] << 8); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
975 dist = target - (anchor+2); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
976 code[anchor] = dist & 0xff; |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
977 dist >>= 8; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
978 code[anchor+1] = dist; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
979 dist >>= 8; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
980 if (dist) { |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
981 com_error(c, PyExc_SystemError, |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
982 "com_backpatch: offset too large"); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
983 break; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
984 } |
| 69 | 985 if (!prev) |
| 986 break; | |
| 987 anchor -= prev; | |
| 988 } | |
| 989 } | |
| 990 | |
| 544 | 991 /* Handle literals and names uniformly */ |
| 69 | 992 |
| 993 static int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
994 com_add(struct compiling *c, PyObject *list, PyObject *dict, PyObject *v) |
| 69 | 995 { |
| 12522 | 996 PyObject *w, *t, *np=NULL; |
| 997 long n; | |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
998 |
| 12522 | 999 t = Py_BuildValue("(OO)", v, v->ob_type); |
| 1000 if (t == NULL) | |
| 1001 goto fail; | |
| 1002 w = PyDict_GetItem(dict, t); | |
| 1003 if (w != NULL) { | |
| 1004 n = PyInt_AsLong(w); | |
| 1005 } else { | |
| 1006 n = PyList_Size(list); | |
| 1007 np = PyInt_FromLong(n); | |
| 1008 if (np == NULL) | |
| 1009 goto fail; | |
| 1010 if (PyList_Append(list, v) != 0) | |
| 1011 goto fail; | |
| 1012 if (PyDict_SetItem(dict, t, np) != 0) | |
| 1013 goto fail; | |
| 1014 Py_DECREF(np); | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1015 } |
| 12522 | 1016 Py_DECREF(t); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1017 return n; |
| 12522 | 1018 fail: |
| 1019 Py_XDECREF(np); | |
| 1020 Py_XDECREF(t); | |
| 1021 c->c_errors++; | |
| 1022 return 0; | |
| 69 | 1023 } |
| 1024 | |
| 1025 static int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1026 com_addconst(struct compiling *c, PyObject *v) |
| 69 | 1027 { |
| 12522 | 1028 return com_add(c, c->c_consts, c->c_const_dict, v); |
| 69 | 1029 } |
| 1030 | |
| 1031 static int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1032 com_addname(struct compiling *c, PyObject *v) |
| 69 | 1033 { |
| 12522 | 1034 return com_add(c, c->c_names, c->c_name_dict, v); |
| 69 | 1035 } |
| 1036 | |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23868
diff
changeset
|
1037 int |
|
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23868
diff
changeset
|
1038 _Py_Mangle(char *p, char *name, char *buffer, size_t maxlen) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1039 { |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
1040 /* Name mangling: __private becomes _classname__private. |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1041 This is independent from how the name is used. */ |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1042 size_t nlen, plen; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1043 if (p == NULL || name == NULL || name[0] != '_' || name[1] != '_') |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1044 return 0; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1045 nlen = strlen(name); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
1046 if (nlen+2 >= maxlen) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1047 return 0; /* Don't mangle __extremely_long_names */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1048 if (name[nlen-1] == '_' && name[nlen-2] == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1049 return 0; /* Don't mangle __whatever__ */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1050 /* Strip leading underscores from class name */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1051 while (*p == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1052 p++; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1053 if (*p == '\0') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1054 return 0; /* Don't mangle if class is just underscores */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1055 plen = strlen(p); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1056 if (plen + nlen >= maxlen) |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
1057 plen = maxlen-nlen-2; /* Truncate class name if too long */ |
|
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
1058 /* buffer = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */ |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1059 buffer[0] = '_'; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1060 strncpy(buffer+1, p, plen); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
1061 strcpy(buffer+1+plen, name); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1062 return 1; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1063 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1064 |
| 69 | 1065 static void |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1066 com_addop_name(struct compiling *c, int op, char *name) |
| 69 | 1067 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1068 PyObject *v; |
| 69 | 1069 int i; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1070 char buffer[MANGLE_LEN]; |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
1071 |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23868
diff
changeset
|
1072 if (_Py_Mangle(c->c_private, name, buffer, sizeof(buffer))) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1073 name = buffer; |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
1074 if (name == NULL || (v = PyString_InternFromString(name)) == NULL) { |
| 69 | 1075 c->c_errors++; |
| 1076 i = 255; | |
| 1077 } | |
| 1078 else { | |
| 1079 i = com_addname(c, v); | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1080 Py_DECREF(v); |
| 69 | 1081 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1082 com_addoparg(c, op, i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1083 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1084 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1085 #define NAME_LOCAL 0 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1086 #define NAME_GLOBAL 1 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1087 #define NAME_DEFAULT 2 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1088 #define NAME_CLOSURE 3 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1089 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1090 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1091 com_lookup_arg(PyObject *dict, PyObject *name) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1092 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1093 PyObject *v = PyDict_GetItem(dict, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1094 if (v == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1095 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1096 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1097 return PyInt_AS_LONG(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1098 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1099 |
|
24855
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1100 static int |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1101 none_assignment_check(struct compiling *c, char *name, int assigning) |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1102 { |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1103 if (name[0] == 'N' && strcmp(name, "None") == 0) { |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1104 char *msg; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1105 if (assigning) |
|
27270
392feecd2f1c
A. Lloyd Flanagan pointed out a spelling error on c.l.py.
Michael W. Hudson <mwh@python.net>
parents:
26979
diff
changeset
|
1106 msg = "assignment to None"; |
|
24855
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1107 else |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1108 msg = "deleting None"; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1109 if (issue_warning(msg, c->c_filename, c->c_lineno) < 0) { |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1110 c->c_errors++; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1111 return -1; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1112 } |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1113 } |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1114 return 0; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1115 } |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1116 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1117 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1118 com_addop_varname(struct compiling *c, int kind, char *name) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1119 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1120 PyObject *v; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1121 int i, reftype; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1122 int scope = NAME_DEFAULT; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1123 int op = STOP_CODE; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1124 char buffer[MANGLE_LEN]; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1125 |
|
24855
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1126 if (kind != VAR_LOAD && |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1127 none_assignment_check(c, name, kind == VAR_STORE)) |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1128 { |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1129 c->c_errors++; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1130 i = 255; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1131 goto done; |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
1132 } |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23868
diff
changeset
|
1133 if (_Py_Mangle(c->c_private, name, buffer, sizeof(buffer))) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1134 name = buffer; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1135 if (name == NULL || (v = PyString_InternFromString(name)) == NULL) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1136 c->c_errors++; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1137 i = 255; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1138 goto done; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1139 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1140 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1141 reftype = get_ref_type(c, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1142 switch (reftype) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1143 case LOCAL: |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
1144 if (c->c_symtable->st_cur->ste_type == TYPE_FUNCTION) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1145 scope = NAME_LOCAL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1146 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1147 case GLOBAL_EXPLICIT: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1148 scope = NAME_GLOBAL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1149 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1150 case GLOBAL_IMPLICIT: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1151 if (c->c_flags & CO_OPTIMIZED) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1152 scope = NAME_GLOBAL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1153 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1154 case FREE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1155 case CELL: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1156 scope = NAME_CLOSURE; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1157 break; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1158 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1159 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1160 i = com_addname(c, v); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1161 if (scope == NAME_LOCAL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1162 i = com_lookup_arg(c->c_locals, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1163 else if (reftype == FREE) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1164 i = com_lookup_arg(c->c_freevars, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1165 else if (reftype == CELL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1166 i = com_lookup_arg(c->c_cellvars, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1167 if (i == -1) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1168 c->c_errors++; /* XXX no exception set */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1169 i = 255; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1170 goto done; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1171 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1172 Py_DECREF(v); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1173 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1174 switch (kind) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1175 case VAR_LOAD: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1176 switch (scope) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1177 case NAME_LOCAL: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1178 op = LOAD_FAST; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1179 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1180 case NAME_GLOBAL: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1181 op = LOAD_GLOBAL; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1182 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1183 case NAME_DEFAULT: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1184 op = LOAD_NAME; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1185 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1186 case NAME_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1187 op = LOAD_DEREF; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1188 break; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1189 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1190 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1191 case VAR_STORE: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1192 switch (scope) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1193 case NAME_LOCAL: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1194 op = STORE_FAST; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1195 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1196 case NAME_GLOBAL: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1197 op = STORE_GLOBAL; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1198 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1199 case NAME_DEFAULT: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1200 op = STORE_NAME; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1201 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1202 case NAME_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1203 op = STORE_DEREF; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1204 break; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1205 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1206 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1207 case VAR_DELETE: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1208 switch (scope) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1209 case NAME_LOCAL: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1210 op = DELETE_FAST; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1211 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1212 case NAME_GLOBAL: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1213 op = DELETE_GLOBAL; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1214 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1215 case NAME_DEFAULT: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1216 op = DELETE_NAME; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1217 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1218 case NAME_CLOSURE: { |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
1219 char buf[500]; |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
1220 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
1221 DEL_CLOSURE_ERROR, name); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1222 com_error(c, PyExc_SyntaxError, buf); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1223 i = 255; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1224 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
1225 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1226 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1227 break; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1228 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1229 done: |
| 69 | 1230 com_addoparg(c, op, i); |
| 1231 } | |
| 1232 | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1233 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1234 com_addopname(struct compiling *c, int op, node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1235 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1236 char *name; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1237 char buffer[1000]; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1238 /* XXX it is possible to write this code without the 1000 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1239 chars on the total length of dotted names, I just can't be |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1240 bothered right now */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1241 if (TYPE(n) == STAR) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1242 name = "*"; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1243 else if (TYPE(n) == dotted_name) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1244 char *p = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1245 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1246 name = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1247 for (i = 0; i < NCH(n); i += 2) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1248 char *s = STR(CHILD(n, i)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1249 if (p + strlen(s) > buffer + (sizeof buffer) - 2) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1250 com_error(c, PyExc_MemoryError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1251 "dotted_name too long"); |
|
2367
915fabec64a3
fix typo (== for =) in assignment
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
1252 name = NULL; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1253 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1254 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1255 if (p != buffer) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1256 *p++ = '.'; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1257 strcpy(p, s); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1258 p = strchr(p, '\0'); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1259 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1260 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1261 else { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1262 REQ(n, NAME); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1263 name = STR(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1264 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1265 com_addop_name(c, op, name); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1266 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1267 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1268 static PyObject * |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1269 parsenumber(struct compiling *c, char *s) |
| 69 | 1270 { |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1271 char *end; |
| 69 | 1272 long x; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1273 double dx; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1274 #ifndef WITHOUT_COMPLEX |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1275 int imflag; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1276 #endif |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1277 |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
1278 errno = 0; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1279 end = s + strlen(s) - 1; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1280 #ifndef WITHOUT_COMPLEX |
|
3366
c25865884649
only use 'j' for imaginary constants
Guido van Rossum <guido@python.org>
parents:
3349
diff
changeset
|
1281 imflag = *end == 'j' || *end == 'J'; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1282 #endif |
| 744 | 1283 if (*end == 'l' || *end == 'L') |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1284 return PyLong_FromString(s, (char **)0, 0); |
|
24736
ff05eef3a6d1
Implement stage B0 of PEP 237: add warnings for operations that
Guido van Rossum <guido@python.org>
parents:
24630
diff
changeset
|
1285 if (s[0] == '0') { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1286 x = (long) PyOS_strtoul(s, &end, 0); |
|
24736
ff05eef3a6d1
Implement stage B0 of PEP 237: add warnings for operations that
Guido van Rossum <guido@python.org>
parents:
24630
diff
changeset
|
1287 if (x < 0 && errno == 0) { |
|
24770
d75bd9e5c4d9
Use PyErr_WarnExplicit() to warn about hex/oct constants, so the
Guido van Rossum <guido@python.org>
parents:
24739
diff
changeset
|
1288 if (PyErr_WarnExplicit( |
|
24818
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24808
diff
changeset
|
1289 PyExc_FutureWarning, |
|
24770
d75bd9e5c4d9
Use PyErr_WarnExplicit() to warn about hex/oct constants, so the
Guido van Rossum <guido@python.org>
parents:
24739
diff
changeset
|
1290 "hex/oct constants > sys.maxint " |
|
d75bd9e5c4d9
Use PyErr_WarnExplicit() to warn about hex/oct constants, so the
Guido van Rossum <guido@python.org>
parents:
24739
diff
changeset
|
1291 "will return positive values " |
|
d75bd9e5c4d9
Use PyErr_WarnExplicit() to warn about hex/oct constants, so the
Guido van Rossum <guido@python.org>
parents:
24739
diff
changeset
|
1292 "in Python 2.4 and up", |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
1293 /* XXX: Give WarnExplicit |
|
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
1294 a const char* argument. */ |
|
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
1295 (char*)c->c_filename, |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1296 c->c_lineno, |
|
24770
d75bd9e5c4d9
Use PyErr_WarnExplicit() to warn about hex/oct constants, so the
Guido van Rossum <guido@python.org>
parents:
24739
diff
changeset
|
1297 NULL, |
|
d75bd9e5c4d9
Use PyErr_WarnExplicit() to warn about hex/oct constants, so the
Guido van Rossum <guido@python.org>
parents:
24739
diff
changeset
|
1298 NULL) < 0) |
|
24736
ff05eef3a6d1
Implement stage B0 of PEP 237: add warnings for operations that
Guido van Rossum <guido@python.org>
parents:
24630
diff
changeset
|
1299 return NULL; |
|
24739
eec6832818a3
Reset errno to zero after calling PyErr_Warn(). It can potentially do
Guido van Rossum <guido@python.org>
parents:
24736
diff
changeset
|
1300 errno = 0; /* Might be changed by PyErr_Warn() */ |
|
24736
ff05eef3a6d1
Implement stage B0 of PEP 237: add warnings for operations that
Guido van Rossum <guido@python.org>
parents:
24630
diff
changeset
|
1301 } |
|
ff05eef3a6d1
Implement stage B0 of PEP 237: add warnings for operations that
Guido van Rossum <guido@python.org>
parents:
24630
diff
changeset
|
1302 } |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
1303 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1304 x = PyOS_strtol(s, &end, 0); |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
1305 if (*end == '\0') { |
|
19502
62bf9401a1ac
If an integer constant can't be generated from an integer literal
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19343
diff
changeset
|
1306 if (errno != 0) |
|
62bf9401a1ac
If an integer constant can't be generated from an integer literal
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19343
diff
changeset
|
1307 return PyLong_FromString(s, (char **)0, 0); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1308 return PyInt_FromLong(x); |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
1309 } |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1310 /* XXX Huge floats may silently fail */ |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1311 #ifndef WITHOUT_COMPLEX |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1312 if (imflag) { |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1313 Py_complex z; |
|
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1314 z.real = 0.; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1315 PyFPE_START_PROTECT("atof", return 0) |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1316 z.imag = atof(s); |
|
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1317 PyFPE_END_PROTECT(z) |
|
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1318 return PyComplex_FromCComplex(z); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1319 } |
|
6453
c9b139b9c5ff
Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents:
6186
diff
changeset
|
1320 else |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1321 #endif |
|
6453
c9b139b9c5ff
Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents:
6186
diff
changeset
|
1322 { |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1323 PyFPE_START_PROTECT("atof", return 0) |
|
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1324 dx = atof(s); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5183
diff
changeset
|
1325 PyFPE_END_PROTECT(dx) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1326 return PyFloat_FromDouble(dx); |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1327 } |
| 69 | 1328 } |
| 1329 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1330 static PyObject * |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1331 decode_utf8(char **sPtr, char *end, char* encoding) |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1332 { |
|
24624
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1333 #ifndef Py_USING_UNICODE |
|
24630
43caa212b959
Use Py_FatalError instead of abort.
Martin v. Löwis <martin@v.loewis.de>
parents:
24624
diff
changeset
|
1334 Py_FatalError("decode_utf8 should not be called in this build."); |
|
43caa212b959
Use Py_FatalError instead of abort.
Martin v. Löwis <martin@v.loewis.de>
parents:
24624
diff
changeset
|
1335 return NULL; |
|
24624
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1336 #else |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1337 PyObject *u, *v; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1338 char *s, *t; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1339 t = s = *sPtr; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1340 /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */ |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1341 while (s < end && (*s & 0x80)) s++; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1342 *sPtr = s; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1343 u = PyUnicode_DecodeUTF8(t, s - t, NULL); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1344 if (u == NULL) |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1345 return NULL; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1346 v = PyUnicode_AsEncodedString(u, encoding, NULL); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1347 Py_DECREF(u); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1348 return v; |
|
24624
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1349 #endif |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1350 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1351 |
|
26979
784e7fdf8c52
SF patch [ 597919 ] compiler package and SET_LINENO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26756
diff
changeset
|
1352 /* compiler.transformer.Transformer.decode_literal depends on what |
|
784e7fdf8c52
SF patch [ 597919 ] compiler package and SET_LINENO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26756
diff
changeset
|
1353 might seem like minor details of this function -- changes here |
|
784e7fdf8c52
SF patch [ 597919 ] compiler package and SET_LINENO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26756
diff
changeset
|
1354 must be reflected there. */ |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1355 static PyObject * |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1356 parsestr(struct compiling *c, char *s) |
| 69 | 1357 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1358 PyObject *v; |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1359 size_t len; |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24770
diff
changeset
|
1360 int quote = *s; |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1361 int rawmode = 0; |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1362 char* encoding = ((c == NULL) ? NULL : c->c_encoding); |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1363 int need_encoding; |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1364 int unicode = 0; |
|
23555
c4fa37f89783
Accept u"..." literals even when Unicode is disabled. But these
Guido van Rossum <guido@python.org>
parents:
23538
diff
changeset
|
1365 |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1366 if (isalpha(quote) || quote == '_') { |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1367 if (quote == 'u' || quote == 'U') { |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1368 quote = *++s; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1369 unicode = 1; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1370 } |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1371 if (quote == 'r' || quote == 'R') { |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1372 quote = *++s; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1373 rawmode = 1; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1374 } |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1375 } |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
1376 if (quote != '\'' && quote != '\"') { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1377 PyErr_BadInternalCall(); |
| 69 | 1378 return NULL; |
| 1379 } | |
| 1380 s++; | |
| 1381 len = strlen(s); | |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1382 if (len > INT_MAX) { |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1383 com_error(c, PyExc_OverflowError, |
|
22120
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
1384 "string to parse is too long"); |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1385 return NULL; |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1386 } |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
1387 if (s[--len] != quote) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1388 PyErr_BadInternalCall(); |
| 69 | 1389 return NULL; |
| 1390 } | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1391 if (len >= 4 && s[0] == quote && s[1] == quote) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1392 s += 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1393 len -= 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1394 if (s[--len] != quote || s[--len] != quote) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1395 PyErr_BadInternalCall(); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1396 return NULL; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1397 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1398 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1399 #ifdef Py_USING_UNICODE |
| 12538 | 1400 if (unicode || Py_UnicodeFlag) { |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1401 PyObject *u, *w; |
|
26319
90e9a3ecda44
Move three variables that are only used inside an if block into the block,
Walter Dörwald <walter@livinglogic.de>
parents:
25538
diff
changeset
|
1402 char *buf; |
|
90e9a3ecda44
Move three variables that are only used inside an if block into the block,
Walter Dörwald <walter@livinglogic.de>
parents:
25538
diff
changeset
|
1403 char *p; |
|
90e9a3ecda44
Move three variables that are only used inside an if block into the block,
Walter Dörwald <walter@livinglogic.de>
parents:
25538
diff
changeset
|
1404 char *end; |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1405 if (encoding == NULL) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1406 buf = s; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1407 u = NULL; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1408 } else if (strcmp(encoding, "iso-8859-1") == 0) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1409 buf = s; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1410 u = NULL; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1411 } else { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1412 /* "\XX" may become "\u005c\uHHLL" (12 bytes) */ |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1413 u = PyString_FromStringAndSize((char *)NULL, len * 4); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1414 if (u == NULL) |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1415 return NULL; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1416 p = buf = PyString_AsString(u); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1417 end = s + len; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1418 while (s < end) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1419 if (*s == '\\') { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1420 *p++ = *s++; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1421 if (*s & 0x80) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1422 strcpy(p, "u005c"); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1423 p += 5; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1424 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1425 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1426 if (*s & 0x80) { /* XXX inefficient */ |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1427 char *r; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1428 int rn, i; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1429 w = decode_utf8(&s, end, "utf-16-be"); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1430 if (w == NULL) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1431 Py_DECREF(u); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1432 return NULL; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1433 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1434 r = PyString_AsString(w); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1435 rn = PyString_Size(w); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1436 assert(rn % 2 == 0); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1437 for (i = 0; i < rn; i += 2) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1438 sprintf(p, "\\u%02x%02x", |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1439 r[i + 0] & 0xFF, |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1440 r[i + 1] & 0xFF); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1441 p += 6; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1442 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1443 Py_DECREF(w); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1444 } else { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1445 *p++ = *s++; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1446 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1447 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1448 len = p - buf; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1449 } |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1450 if (rawmode) |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1451 v = PyUnicode_DecodeRawUnicodeEscape(buf, len, NULL); |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1452 else |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1453 v = PyUnicode_DecodeUnicodeEscape(buf, len, NULL); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1454 Py_XDECREF(u); |
|
22120
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
1455 if (v == NULL) |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1456 PyErr_SyntaxLocation(c->c_filename, c->c_lineno); |
|
22120
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
1457 return v; |
|
b2a2cc0c2a63
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21834
diff
changeset
|
1458 |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1459 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1460 #endif |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1461 need_encoding = (encoding != NULL && |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1462 strcmp(encoding, "utf-8") != 0 && |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1463 strcmp(encoding, "iso-8859-1") != 0); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1464 if (rawmode || strchr(s, '\\') == NULL) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1465 if (need_encoding) { |
|
24624
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1466 #ifndef Py_USING_UNICODE |
|
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1467 /* This should not happen - we never see any other |
|
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1468 encoding. */ |
|
24630
43caa212b959
Use Py_FatalError instead of abort.
Martin v. Löwis <martin@v.loewis.de>
parents:
24624
diff
changeset
|
1469 Py_FatalError("cannot deal with encodings in this build."); |
|
24624
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1470 #else |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1471 PyObject* u = PyUnicode_DecodeUTF8(s, len, NULL); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1472 if (u == NULL) |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1473 return NULL; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1474 v = PyUnicode_AsEncodedString(u, encoding, NULL); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1475 Py_DECREF(u); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1476 return v; |
|
24624
6445e44fcb78
Fix PEP 263 code --without-unicode. Fixes #591943.
Martin v. Löwis <martin@v.loewis.de>
parents:
24539
diff
changeset
|
1477 #endif |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1478 } else { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1479 return PyString_FromStringAndSize(s, len); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1480 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
1481 } |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24770
diff
changeset
|
1482 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24770
diff
changeset
|
1483 v = PyString_DecodeEscape(s, len, NULL, unicode, |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24770
diff
changeset
|
1484 need_encoding ? encoding : NULL); |
|
14382
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1485 if (v == NULL) |
|
24854
136b853622cc
Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
Guido van Rossum <guido@python.org>
parents:
24844
diff
changeset
|
1486 PyErr_SyntaxLocation(c->c_filename, c->c_lineno); |
| 69 | 1487 return v; |
| 1488 } | |
| 1489 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1490 static PyObject * |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1491 parsestrplus(struct compiling* c, node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1492 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1493 PyObject *v; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1494 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1495 REQ(CHILD(n, 0), STRING); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1496 if ((v = parsestr(c, STR(CHILD(n, 0)))) != NULL) { |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1497 /* String literal concatenation */ |
|
12388
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1498 for (i = 1; i < NCH(n); i++) { |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1499 PyObject *s; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1500 s = parsestr(c, STR(CHILD(n, i))); |
|
12388
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1501 if (s == NULL) |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1502 goto onError; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1503 if (PyString_Check(v) && PyString_Check(s)) { |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1504 PyString_ConcatAndDel(&v, s); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1505 if (v == NULL) |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1506 goto onError; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1507 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1508 #ifdef Py_USING_UNICODE |
|
12388
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1509 else { |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1510 PyObject *temp; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1511 temp = PyUnicode_Concat(v, s); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1512 Py_DECREF(s); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1513 if (temp == NULL) |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1514 goto onError; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1515 Py_DECREF(v); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1516 v = temp; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1517 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1518 #endif |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1519 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1520 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1521 return v; |
|
12388
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1522 |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1523 onError: |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1524 Py_XDECREF(v); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1525 return NULL; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1526 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1527 |
| 69 | 1528 static void |
| 13936 | 1529 com_list_for(struct compiling *c, node *n, node *e, char *t) |
| 1530 { | |
| 1531 int anchor = 0; | |
| 1532 int save_begin = c->c_begin; | |
| 1533 | |
| 1534 /* list_iter: for v in expr [list_iter] */ | |
| 1535 com_node(c, CHILD(n, 3)); /* expr */ | |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
1536 com_addbyte(c, GET_ITER); |
| 13936 | 1537 c->c_begin = c->c_nexti; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
1538 com_addfwref(c, FOR_ITER, &anchor); |
| 13936 | 1539 com_push(c, 1); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1540 com_assign(c, CHILD(n, 1), OP_ASSIGN, NULL); |
| 13936 | 1541 c->c_loops++; |
| 1542 com_list_iter(c, n, e, t); | |
| 1543 c->c_loops--; | |
| 1544 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); | |
| 1545 c->c_begin = save_begin; | |
| 1546 com_backpatch(c, anchor); | |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
1547 com_pop(c, 1); /* FOR_ITER has popped this */ |
| 13936 | 1548 } |
| 1549 | |
| 1550 static void | |
| 1551 com_list_if(struct compiling *c, node *n, node *e, char *t) | |
| 1552 { | |
| 1553 int anchor = 0; | |
| 1554 int a = 0; | |
| 1555 /* list_iter: 'if' test [list_iter] */ | |
| 1556 com_node(c, CHILD(n, 1)); | |
| 1557 com_addfwref(c, JUMP_IF_FALSE, &a); | |
| 1558 com_addbyte(c, POP_TOP); | |
| 1559 com_pop(c, 1); | |
| 1560 com_list_iter(c, n, e, t); | |
| 1561 com_addfwref(c, JUMP_FORWARD, &anchor); | |
| 1562 com_backpatch(c, a); | |
| 1563 /* We jump here with an extra entry which we now pop */ | |
| 1564 com_addbyte(c, POP_TOP); | |
| 1565 com_backpatch(c, anchor); | |
| 1566 } | |
| 1567 | |
| 1568 static void | |
| 1569 com_list_iter(struct compiling *c, | |
| 1570 node *p, /* parent of list_iter node */ | |
| 1571 node *e, /* element expression node */ | |
| 1572 char *t /* name of result list temp local */) | |
| 69 | 1573 { |
| 13936 | 1574 /* list_iter is the last child in a listmaker, list_for, or list_if */ |
| 1575 node *n = CHILD(p, NCH(p)-1); | |
| 1576 if (TYPE(n) == list_iter) { | |
| 1577 n = CHILD(n, 0); | |
| 1578 switch (TYPE(n)) { | |
| 1579 case list_for: | |
| 1580 com_list_for(c, n, e, t); | |
| 1581 break; | |
| 1582 case list_if: | |
| 1583 com_list_if(c, n, e, t); | |
| 1584 break; | |
| 1585 default: | |
| 1586 com_error(c, PyExc_SystemError, | |
| 1587 "invalid list_iter node type"); | |
| 1588 } | |
| 1589 } | |
| 1590 else { | |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1591 com_addop_varname(c, VAR_LOAD, t); |
| 13936 | 1592 com_push(c, 1); |
| 1593 com_node(c, e); | |
| 1594 com_addoparg(c, CALL_FUNCTION, 1); | |
| 1595 com_addbyte(c, POP_TOP); | |
| 1596 com_pop(c, 2); | |
| 1597 } | |
| 1598 } | |
| 1599 | |
| 1600 static void | |
| 1601 com_list_comprehension(struct compiling *c, node *n) | |
| 1602 { | |
|
14117
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1603 /* listmaker: test list_for */ |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
1604 char tmpname[30]; |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
1605 PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", ++c->c_tmpname); |
| 13936 | 1606 com_addoparg(c, BUILD_LIST, 0); |
| 1607 com_addbyte(c, DUP_TOP); /* leave the result on the stack */ | |
| 1608 com_push(c, 2); | |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1609 com_addop_name(c, LOAD_ATTR, "append"); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1610 com_addop_varname(c, VAR_STORE, tmpname); |
| 13936 | 1611 com_pop(c, 1); |
|
14117
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1612 com_list_for(c, CHILD(n, 1), CHILD(n, 0), tmpname); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1613 com_addop_varname(c, VAR_DELETE, tmpname); |
| 13936 | 1614 --c->c_tmpname; |
| 1615 } | |
| 1616 | |
| 1617 static void | |
| 1618 com_listmaker(struct compiling *c, node *n) | |
| 1619 { | |
|
14117
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1620 /* listmaker: test ( list_for | (',' test)* [','] ) */ |
|
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1621 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) |
| 13936 | 1622 com_list_comprehension(c, n); |
| 1623 else { | |
| 1624 int len = 0; | |
| 1625 int i; | |
| 1626 for (i = 0; i < NCH(n); i += 2, len++) | |
| 1627 com_node(c, CHILD(n, i)); | |
| 1628 com_addoparg(c, BUILD_LIST, len); | |
| 1629 com_pop(c, len-1); | |
| 1630 } | |
| 69 | 1631 } |
| 1632 | |
| 1633 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1634 com_dictmaker(struct compiling *c, node *n) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1635 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1636 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1637 /* dictmaker: test ':' test (',' test ':' value)* [','] */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1638 for (i = 0; i+2 < NCH(n); i += 4) { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1639 /* We must arrange things just right for STORE_SUBSCR. |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1640 It wants the stack to look like (value) (dict) (key) */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1641 com_addbyte(c, DUP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1642 com_push(c, 1); |
| 26670 | 1643 com_node(c, CHILD(n, i)); /* key */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1644 com_node(c, CHILD(n, i+2)); /* value */ |
| 26670 | 1645 com_addbyte(c, ROT_THREE); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1646 com_addbyte(c, STORE_SUBSCR); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1647 com_pop(c, 3); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1648 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1649 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1650 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1651 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1652 com_atom(struct compiling *c, node *n) |
| 69 | 1653 { |
| 1654 node *ch; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1655 PyObject *v; |
| 69 | 1656 int i; |
| 1657 REQ(n, atom); | |
| 1658 ch = CHILD(n, 0); | |
| 1659 switch (TYPE(ch)) { | |
| 1660 case LPAR: | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1661 if (TYPE(CHILD(n, 1)) == RPAR) { |
| 69 | 1662 com_addoparg(c, BUILD_TUPLE, 0); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1663 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1664 } |
| 69 | 1665 else |
| 1666 com_node(c, CHILD(n, 1)); | |
| 1667 break; | |
| 13936 | 1668 case LSQB: /* '[' [listmaker] ']' */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1669 if (TYPE(CHILD(n, 1)) == RSQB) { |
| 69 | 1670 com_addoparg(c, BUILD_LIST, 0); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1671 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1672 } |
| 69 | 1673 else |
| 13936 | 1674 com_listmaker(c, CHILD(n, 1)); |
| 69 | 1675 break; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1676 case LBRACE: /* '{' [dictmaker] '}' */ |
| 69 | 1677 com_addoparg(c, BUILD_MAP, 0); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1678 com_push(c, 1); |
| 13936 | 1679 if (TYPE(CHILD(n, 1)) == dictmaker) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1680 com_dictmaker(c, CHILD(n, 1)); |
| 69 | 1681 break; |
| 1682 case BACKQUOTE: | |
| 1683 com_node(c, CHILD(n, 1)); | |
| 1684 com_addbyte(c, UNARY_CONVERT); | |
| 1685 break; | |
| 1686 case NUMBER: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1687 if ((v = parsenumber(c, STR(ch))) == NULL) { |
| 69 | 1688 i = 255; |
| 1689 } | |
| 1690 else { | |
| 1691 i = com_addconst(c, v); | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1692 Py_DECREF(v); |
| 69 | 1693 } |
| 1694 com_addoparg(c, LOAD_CONST, i); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1695 com_push(c, 1); |
| 69 | 1696 break; |
| 1697 case STRING: | |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
1698 v = parsestrplus(c, n); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1699 if (v == NULL) { |
| 69 | 1700 c->c_errors++; |
| 1701 i = 255; | |
| 1702 } | |
| 1703 else { | |
| 1704 i = com_addconst(c, v); | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1705 Py_DECREF(v); |
| 69 | 1706 } |
| 1707 com_addoparg(c, LOAD_CONST, i); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1708 com_push(c, 1); |
| 69 | 1709 break; |
| 1710 case NAME: | |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1711 com_addop_varname(c, VAR_LOAD, STR(ch)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1712 com_push(c, 1); |
| 69 | 1713 break; |
| 1714 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1715 com_error(c, PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1716 "com_atom: unexpected node type"); |
| 69 | 1717 } |
| 1718 } | |
| 1719 | |
| 1720 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1721 com_slice(struct compiling *c, node *n, int op) |
| 69 | 1722 { |
| 1723 if (NCH(n) == 1) { | |
| 1724 com_addbyte(c, op); | |
| 1725 } | |
| 1726 else if (NCH(n) == 2) { | |
| 1727 if (TYPE(CHILD(n, 0)) != COLON) { | |
| 1728 com_node(c, CHILD(n, 0)); | |
| 1729 com_addbyte(c, op+1); | |
| 1730 } | |
| 1731 else { | |
| 1732 com_node(c, CHILD(n, 1)); | |
| 1733 com_addbyte(c, op+2); | |
| 1734 } | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1735 com_pop(c, 1); |
| 69 | 1736 } |
| 1737 else { | |
| 1738 com_node(c, CHILD(n, 0)); | |
| 1739 com_node(c, CHILD(n, 2)); | |
| 1740 com_addbyte(c, op+3); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1741 com_pop(c, 2); |
| 69 | 1742 } |
| 1743 } | |
| 1744 | |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1745 static void |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1746 com_augassign_slice(struct compiling *c, node *n, int opcode, node *augn) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1747 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1748 if (NCH(n) == 1) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1749 com_addbyte(c, DUP_TOP); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1750 com_push(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1751 com_addbyte(c, SLICE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1752 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1753 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1754 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1755 com_addbyte(c, ROT_TWO); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1756 com_addbyte(c, STORE_SLICE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1757 com_pop(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1758 } else if (NCH(n) == 2 && TYPE(CHILD(n, 0)) != COLON) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1759 com_node(c, CHILD(n, 0)); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1760 com_addoparg(c, DUP_TOPX, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1761 com_push(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1762 com_addbyte(c, SLICE+1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1763 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1764 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1765 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1766 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1767 com_addbyte(c, ROT_THREE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1768 com_addbyte(c, STORE_SLICE+1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1769 com_pop(c, 3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1770 } else if (NCH(n) == 2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1771 com_node(c, CHILD(n, 1)); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1772 com_addoparg(c, DUP_TOPX, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1773 com_push(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1774 com_addbyte(c, SLICE+2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1775 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1776 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1777 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1778 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1779 com_addbyte(c, ROT_THREE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1780 com_addbyte(c, STORE_SLICE+2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1781 com_pop(c, 3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1782 } else { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1783 com_node(c, CHILD(n, 0)); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1784 com_node(c, CHILD(n, 2)); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1785 com_addoparg(c, DUP_TOPX, 3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1786 com_push(c, 3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1787 com_addbyte(c, SLICE+3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1788 com_pop(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1789 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1790 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1791 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1792 com_addbyte(c, ROT_FOUR); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1793 com_addbyte(c, STORE_SLICE+3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1794 com_pop(c, 4); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1795 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1796 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1797 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1798 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1799 com_argument(struct compiling *c, node *n, PyObject **pkeywords) |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1800 { |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1801 node *m; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1802 REQ(n, argument); /* [test '='] test; really [keyword '='] test */ |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1803 if (NCH(n) == 1) { |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1804 if (*pkeywords != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1805 com_error(c, PyExc_SyntaxError, |
|
13993
716e1c4e3f78
When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents:
13956
diff
changeset
|
1806 "non-keyword arg after keyword arg"); |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1807 } |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1808 else { |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1809 com_node(c, CHILD(n, 0)); |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1810 } |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1811 return; |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1812 } |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1813 m = n; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1814 do { |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1815 m = CHILD(m, 0); |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1816 } while (NCH(m) == 1); |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1817 if (TYPE(m) != NAME) { |
|
16658
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1818 /* f(lambda x: x[0] = 3) ends up getting parsed with |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1819 * LHS test = lambda x: x[0], and RHS test = 3. |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1820 * SF bug 132313 points out that complaining about a keyword |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1821 * then is very confusing. |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1822 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1823 com_error(c, PyExc_SyntaxError, |
|
16658
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1824 TYPE(m) == lambdef ? |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1825 "lambda cannot contain assignment" : |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1826 "keyword can't be an expression"); |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1827 } |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1828 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1829 PyObject *v = PyString_InternFromString(STR(m)); |
|
24856
87448a228cca
Add warning for None used as keyword argument name in function call.
Guido van Rossum <guido@python.org>
parents:
24855
diff
changeset
|
1830 (void) none_assignment_check(c, STR(m), 1); |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1831 if (v != NULL && *pkeywords == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1832 *pkeywords = PyDict_New(); |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1833 if (v == NULL) |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1834 c->c_errors++; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1835 else if (*pkeywords == NULL) { |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1836 c->c_errors++; |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1837 Py_DECREF(v); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1838 } else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1839 if (PyDict_GetItem(*pkeywords, v) != NULL) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1840 com_error(c, PyExc_SyntaxError, |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1841 "duplicate keyword argument"); |
|
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1842 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1843 if (PyDict_SetItem(*pkeywords, v, v) != 0) |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1844 c->c_errors++; |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1845 com_addoparg(c, LOAD_CONST, com_addconst(c, v)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1846 com_push(c, 1); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1847 Py_DECREF(v); |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1848 } |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1849 } |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1850 com_node(c, CHILD(n, 2)); |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1851 } |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1852 |
| 69 | 1853 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1854 com_call_function(struct compiling *c, node *n) |
| 69 | 1855 { |
| 1856 if (TYPE(n) == RPAR) { | |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1857 com_addoparg(c, CALL_FUNCTION, 0); |
| 69 | 1858 } |
| 1859 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1860 PyObject *keywords = NULL; |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1861 int i, na, nk; |
|
9625
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1862 int lineno = n->n_lineno; |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1863 int star_flag = 0; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1864 int starstar_flag = 0; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1865 int opcode; |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1866 REQ(n, arglist); |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1867 na = 0; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1868 nk = 0; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1869 for (i = 0; i < NCH(n); i += 2) { |
|
9625
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1870 node *ch = CHILD(n, i); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1871 if (TYPE(ch) == STAR || |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1872 TYPE(ch) == DOUBLESTAR) |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1873 break; |
|
9625
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1874 if (ch->n_lineno != lineno) { |
|
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1875 lineno = ch->n_lineno; |
| 24844 | 1876 com_set_lineno(c, lineno); |
|
9625
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1877 } |
|
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1878 com_argument(c, ch, &keywords); |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1879 if (keywords == NULL) |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1880 na++; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1881 else |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1882 nk++; |
|
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1883 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1884 Py_XDECREF(keywords); |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1885 while (i < NCH(n)) { |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1886 node *tok = CHILD(n, i); |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1887 node *ch = CHILD(n, i+1); |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1888 i += 3; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1889 switch (TYPE(tok)) { |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1890 case STAR: star_flag = 1; break; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1891 case DOUBLESTAR: starstar_flag = 1; break; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1892 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1893 com_node(c, ch); |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1894 } |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1895 if (na > 255 || nk > 255) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1896 com_error(c, PyExc_SyntaxError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1897 "more than 255 arguments"); |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
1898 } |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1899 if (star_flag || starstar_flag) |
|
12086
96ea1a800b23
remove reference (vestigal) to CALL_FUNCTION_STAR
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12082
diff
changeset
|
1900 opcode = CALL_FUNCTION_VAR - 1 + |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1901 star_flag + (starstar_flag << 1); |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1902 else |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1903 opcode = CALL_FUNCTION; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1904 com_addoparg(c, opcode, na | (nk << 8)); |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1905 com_pop(c, na + 2*nk + star_flag + starstar_flag); |
| 69 | 1906 } |
| 1907 } | |
| 1908 | |
| 1909 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1910 com_select_member(struct compiling *c, node *n) |
| 69 | 1911 { |
| 1912 com_addopname(c, LOAD_ATTR, n); | |
| 1913 } | |
| 1914 | |
| 1915 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1916 com_sliceobj(struct compiling *c, node *n) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1917 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1918 int i=0; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1919 int ns=2; /* number of slice arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1920 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1921 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1922 /* first argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1923 if (TYPE(CHILD(n,i)) == COLON) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1924 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1925 com_push(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1926 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1927 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1928 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1929 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1930 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1931 REQ(CHILD(n,i),COLON); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1932 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1933 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1934 /* second argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1935 if (i < NCH(n) && TYPE(CHILD(n,i)) == test) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1936 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1937 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1938 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1939 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1940 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1941 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1942 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1943 /* remaining arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1944 for (; i < NCH(n); i++) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1945 ns++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1946 ch=CHILD(n,i); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1947 REQ(ch, sliceop); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1948 if (NCH(ch) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1949 /* right argument of ':' missing */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1950 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1951 com_push(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1952 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1953 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1954 com_node(c, CHILD(ch,1)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1955 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1956 com_addoparg(c, BUILD_SLICE, ns); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1957 com_pop(c, 1 + (ns == 3)); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1958 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1959 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1960 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1961 com_subscript(struct compiling *c, node *n) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1962 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1963 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1964 REQ(n, subscript); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1965 ch = CHILD(n,0); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1966 /* check for rubber index */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1967 if (TYPE(ch) == DOT && TYPE(CHILD(n,1)) == DOT) { |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4315
diff
changeset
|
1968 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_Ellipsis)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1969 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1970 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1971 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1972 /* check for slice */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1973 if ((TYPE(ch) == COLON || NCH(n) > 1)) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1974 com_sliceobj(c, n); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1975 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1976 REQ(ch, test); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1977 com_node(c, ch); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1978 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1979 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1980 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1981 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1982 static void |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1983 com_subscriptlist(struct compiling *c, node *n, int assigning, node *augn) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1984 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1985 int i, op; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1986 REQ(n, subscriptlist); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1987 /* Check to make backward compatible slice behavior for '[i:j]' */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1988 if (NCH(n) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1989 node *sub = CHILD(n, 0); /* subscript */ |
|
13873
d014c8ab6a82
Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
1990 /* 'Basic' slice, should have exactly one colon. */ |
|
d014c8ab6a82
Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
1991 if ((TYPE(CHILD(sub, 0)) == COLON |
|
d014c8ab6a82
Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
1992 || (NCH(sub) > 1 && TYPE(CHILD(sub, 1)) == COLON)) |
|
d014c8ab6a82
Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
1993 && (TYPE(CHILD(sub,NCH(sub)-1)) != sliceop)) |
|
d014c8ab6a82
Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
1994 { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1995 switch (assigning) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1996 case OP_DELETE: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1997 op = DELETE_SLICE; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1998 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1999 case OP_ASSIGN: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2000 op = STORE_SLICE; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2001 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2002 case OP_APPLY: |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2003 op = SLICE; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2004 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2005 default: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2006 com_augassign_slice(c, sub, assigning, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2007 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2008 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2009 com_slice(c, sub, op); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2010 if (op == STORE_SLICE) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2011 com_pop(c, 2); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2012 else if (op == DELETE_SLICE) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2013 com_pop(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2014 return; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2015 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2016 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2017 /* Else normal subscriptlist. Compile each subscript. */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2018 for (i = 0; i < NCH(n); i += 2) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2019 com_subscript(c, CHILD(n, i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2020 /* Put multiple subscripts into a tuple */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2021 if (NCH(n) > 1) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2022 i = (NCH(n)+1) / 2; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2023 com_addoparg(c, BUILD_TUPLE, i); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2024 com_pop(c, i-1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2025 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2026 switch (assigning) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2027 case OP_DELETE: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2028 op = DELETE_SUBSCR; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2029 i = 2; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2030 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2031 default: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2032 case OP_ASSIGN: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2033 op = STORE_SUBSCR; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2034 i = 3; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2035 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2036 case OP_APPLY: |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2037 op = BINARY_SUBSCR; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2038 i = 1; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2039 break; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2040 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2041 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2042 com_addoparg(c, DUP_TOPX, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2043 com_push(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2044 com_addbyte(c, BINARY_SUBSCR); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2045 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2046 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2047 com_addbyte(c, assigning); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2048 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2049 com_addbyte(c, ROT_THREE); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2050 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2051 com_addbyte(c, op); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2052 com_pop(c, i); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2053 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2054 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2055 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2056 com_apply_trailer(struct compiling *c, node *n) |
| 69 | 2057 { |
| 2058 REQ(n, trailer); | |
| 2059 switch (TYPE(CHILD(n, 0))) { | |
| 2060 case LPAR: | |
| 2061 com_call_function(c, CHILD(n, 1)); | |
| 2062 break; | |
| 2063 case DOT: | |
| 2064 com_select_member(c, CHILD(n, 1)); | |
| 2065 break; | |
| 2066 case LSQB: | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2067 com_subscriptlist(c, CHILD(n, 1), OP_APPLY, NULL); |
| 69 | 2068 break; |
| 2069 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2070 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2071 "com_apply_trailer: unknown trailer type"); |
| 69 | 2072 } |
| 2073 } | |
| 2074 | |
| 2075 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2076 com_power(struct compiling *c, node *n) |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2077 { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2078 int i; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2079 REQ(n, power); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2080 com_atom(c, CHILD(n, 0)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2081 for (i = 1; i < NCH(n); i++) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2082 if (TYPE(CHILD(n, i)) == DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2083 com_factor(c, CHILD(n, i+1)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2084 com_addbyte(c, BINARY_POWER); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2085 com_pop(c, 1); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2086 break; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2087 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2088 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2089 com_apply_trailer(c, CHILD(n, i)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2090 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2091 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2092 |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2093 static void |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2094 com_invert_constant(struct compiling *c, node *n) |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2095 { |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2096 /* Compute the inverse of int and longs and use them directly, |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2097 but be prepared to generate code for all other |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2098 possibilities (invalid numbers, floats, complex). |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2099 */ |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2100 PyObject *num, *inv = NULL; |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2101 int i; |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2102 |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2103 REQ(n, NUMBER); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2104 num = parsenumber(c, STR(n)); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2105 if (num == NULL) |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2106 i = 255; |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2107 else { |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2108 inv = PyNumber_Invert(num); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2109 if (inv == NULL) { |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2110 PyErr_Clear(); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2111 i = com_addconst(c, num); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2112 } else { |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2113 i = com_addconst(c, inv); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2114 Py_DECREF(inv); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2115 } |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2116 Py_DECREF(num); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2117 } |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2118 com_addoparg(c, LOAD_CONST, i); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2119 com_push(c, 1); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2120 if (num != NULL && inv == NULL) |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2121 com_addbyte(c, UNARY_INVERT); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2122 } |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2123 |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2124 static int |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2125 is_float_zero(const char *p) |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2126 { |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2127 int found_radix_point = 0; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2128 int ch; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2129 while ((ch = Py_CHARMASK(*p++)) != '\0') { |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2130 switch (ch) { |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2131 case '0': |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2132 /* no reason to believe it's not 0 -- continue */ |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2133 break; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2134 |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2135 case 'e': case 'E': case 'j': case 'J': |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2136 /* If this was a hex constant, we already would have |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2137 returned 0 due to the 'x' or 'X', so 'e' or 'E' |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2138 must be an exponent marker, and we haven't yet |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2139 seen a non-zero digit, and it doesn't matter what |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2140 the exponent is then. For 'j' or 'J' similarly, |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2141 except that this is an imaginary 0 then. */ |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2142 return 1; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2143 |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2144 case '.': |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2145 found_radix_point = 1; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2146 break; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2147 |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2148 default: |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2149 return 0; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2150 } |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2151 } |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2152 return found_radix_point; |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2153 } |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2154 |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2155 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2156 com_factor(struct compiling *c, node *n) |
| 69 | 2157 { |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2158 int childtype = TYPE(CHILD(n, 0)); |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2159 node *pfactor, *ppower, *patom, *pnum; |
| 69 | 2160 REQ(n, factor); |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2161 /* If the unary +, -, or ~ operator is applied to a constant, |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2162 don't generate a UNARY_xxx opcode. Just store the |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2163 approriate value as a constant. If the value is negative, |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2164 extend the string containing the constant and insert a |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2165 negative in the 0th position -- unless we're doing unary minus |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2166 of a floating zero! In that case the sign is significant, but |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2167 the const dict can't distinguish +0.0 from -0.0. |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2168 */ |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2169 if ((childtype == PLUS || childtype == MINUS || childtype == TILDE) |
|
19613
f7cf8961c667
When re-writing a factor containing a unary negation of a literal, only
Fred Drake <fdrake@acm.org>
parents:
19601
diff
changeset
|
2170 && NCH(n) == 2 |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2171 && TYPE((pfactor = CHILD(n, 1))) == factor |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2172 && NCH(pfactor) == 1 |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2173 && TYPE((ppower = CHILD(pfactor, 0))) == power |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2174 && NCH(ppower) == 1 |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2175 && TYPE((patom = CHILD(ppower, 0))) == atom |
|
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2176 && TYPE((pnum = CHILD(patom, 0))) == NUMBER |
|
27846
e9d7102f8278
SF #660455 : patch by NNorwitz.
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
2177 && !(childtype == MINUS && |
|
e9d7102f8278
SF #660455 : patch by NNorwitz.
Guido van Rossum <guido@python.org>
parents:
27781
diff
changeset
|
2178 (STR(pnum)[0] == '0' || is_float_zero(STR(pnum))))) { |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2179 if (childtype == TILDE) { |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2180 com_invert_constant(c, pnum); |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2181 return; |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2182 } |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2183 if (childtype == MINUS) { |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24373
diff
changeset
|
2184 char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2); |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2185 if (s == NULL) { |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2186 com_error(c, PyExc_MemoryError, ""); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2187 com_addbyte(c, 255); |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2188 return; |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2189 } |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2190 s[0] = '-'; |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2191 strcpy(s + 1, STR(pnum)); |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24373
diff
changeset
|
2192 PyObject_FREE(STR(pnum)); |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2193 STR(pnum) = s; |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2194 } |
|
19793
e2e9f1722c4f
SF bug [#458941] Looks like a unary minus bug.
Tim Peters <tim.peters@gmail.com>
parents:
19613
diff
changeset
|
2195 com_atom(c, patom); |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2196 } |
|
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2197 else if (childtype == PLUS) { |
| 69 | 2198 com_factor(c, CHILD(n, 1)); |
| 2199 com_addbyte(c, UNARY_POSITIVE); | |
| 2200 } | |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2201 else if (childtype == MINUS) { |
| 69 | 2202 com_factor(c, CHILD(n, 1)); |
| 2203 com_addbyte(c, UNARY_NEGATIVE); | |
| 2204 } | |
|
19187
30f8b654c2e5
SF Patch [ 429024 ] deal with some unary ops at compile time
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19177
diff
changeset
|
2205 else if (childtype == TILDE) { |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2206 com_factor(c, CHILD(n, 1)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2207 com_addbyte(c, UNARY_INVERT); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2208 } |
| 69 | 2209 else { |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2210 com_power(c, CHILD(n, 0)); |
| 69 | 2211 } |
| 2212 } | |
| 2213 | |
| 2214 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2215 com_term(struct compiling *c, node *n) |
| 69 | 2216 { |
| 2217 int i; | |
| 2218 int op; | |
| 2219 REQ(n, term); | |
| 2220 com_factor(c, CHILD(n, 0)); | |
| 2221 for (i = 2; i < NCH(n); i += 2) { | |
| 2222 com_factor(c, CHILD(n, i)); | |
| 2223 switch (TYPE(CHILD(n, i-1))) { | |
| 2224 case STAR: | |
| 2225 op = BINARY_MULTIPLY; | |
| 2226 break; | |
| 2227 case SLASH: | |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2228 if (c->c_flags & CO_FUTURE_DIVISION) |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2229 op = BINARY_TRUE_DIVIDE; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2230 else |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2231 op = BINARY_DIVIDE; |
| 69 | 2232 break; |
| 2233 case PERCENT: | |
| 2234 op = BINARY_MODULO; | |
| 2235 break; | |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2236 case DOUBLESLASH: |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2237 op = BINARY_FLOOR_DIVIDE; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2238 break; |
| 69 | 2239 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2240 com_error(c, PyExc_SystemError, |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2241 "com_term: operator not *, /, // or %"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2242 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2243 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2244 com_addbyte(c, op); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2245 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2246 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2247 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2248 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2249 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2250 com_arith_expr(struct compiling *c, node *n) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2251 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2252 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2253 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2254 REQ(n, arith_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2255 com_term(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2256 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2257 com_term(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2258 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2259 case PLUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2260 op = BINARY_ADD; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2261 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2262 case MINUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2263 op = BINARY_SUBTRACT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2264 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2265 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2266 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2267 "com_arith_expr: operator not + or -"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2268 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2269 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2270 com_addbyte(c, op); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2271 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2272 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2273 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2274 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2275 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2276 com_shift_expr(struct compiling *c, node *n) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2277 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2278 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2279 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2280 REQ(n, shift_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2281 com_arith_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2282 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2283 com_arith_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2284 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2285 case LEFTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2286 op = BINARY_LSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2287 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2288 case RIGHTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2289 op = BINARY_RSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2290 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2291 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2292 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2293 "com_shift_expr: operator not << or >>"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2294 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2295 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2296 com_addbyte(c, op); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2297 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2298 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2299 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2300 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2301 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2302 com_and_expr(struct compiling *c, node *n) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2303 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2304 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2305 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2306 REQ(n, and_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2307 com_shift_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2308 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2309 com_shift_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2310 if (TYPE(CHILD(n, i-1)) == AMPER) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2311 op = BINARY_AND; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2312 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2313 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2314 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2315 "com_and_expr: operator not &"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2316 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2317 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2318 com_addbyte(c, op); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2319 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2320 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2321 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2322 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2323 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2324 com_xor_expr(struct compiling *c, node *n) |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2325 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2326 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2327 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2328 REQ(n, xor_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2329 com_and_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2330 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2331 com_and_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2332 if (TYPE(CHILD(n, i-1)) == CIRCUMFLEX) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2333 op = BINARY_XOR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2334 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2335 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2336 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2337 "com_xor_expr: operator not ^"); |
| 69 | 2338 op = 255; |
| 2339 } | |
| 2340 com_addbyte(c, op); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2341 com_pop(c, 1); |
| 69 | 2342 } |
| 2343 } | |
| 2344 | |
| 2345 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2346 com_expr(struct compiling *c, node *n) |
| 69 | 2347 { |
| 2348 int i; | |
| 2349 int op; | |
| 2350 REQ(n, expr); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2351 com_xor_expr(c, CHILD(n, 0)); |
| 69 | 2352 for (i = 2; i < NCH(n); i += 2) { |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2353 com_xor_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2354 if (TYPE(CHILD(n, i-1)) == VBAR) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2355 op = BINARY_OR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2356 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2357 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2358 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2359 "com_expr: expr operator not |"); |
| 69 | 2360 op = 255; |
| 2361 } | |
| 2362 com_addbyte(c, op); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2363 com_pop(c, 1); |
| 69 | 2364 } |
| 2365 } | |
| 2366 | |
| 2367 static enum cmp_op | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2368 cmp_type(node *n) |
| 69 | 2369 { |
| 2370 REQ(n, comp_op); | |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
2371 /* comp_op: '<' | '>' | '=' | '>=' | '<=' | '<>' | '!=' | '==' |
| 69 | 2372 | 'in' | 'not' 'in' | 'is' | 'is' not' */ |
| 2373 if (NCH(n) == 1) { | |
| 2374 n = CHILD(n, 0); | |
| 2375 switch (TYPE(n)) { | |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2376 case LESS: return PyCmp_LT; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2377 case GREATER: return PyCmp_GT; |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
2378 case EQEQUAL: /* == */ |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2379 case EQUAL: return PyCmp_EQ; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2380 case LESSEQUAL: return PyCmp_LE; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2381 case GREATEREQUAL: return PyCmp_GE; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2382 case NOTEQUAL: return PyCmp_NE; /* <> or != */ |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2383 case NAME: if (strcmp(STR(n), "in") == 0) return PyCmp_IN; |
|
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2384 if (strcmp(STR(n), "is") == 0) return PyCmp_IS; |
| 69 | 2385 } |
| 2386 } | |
| 2387 else if (NCH(n) == 2) { | |
| 2388 switch (TYPE(CHILD(n, 0))) { | |
| 2389 case NAME: if (strcmp(STR(CHILD(n, 1)), "in") == 0) | |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2390 return PyCmp_NOT_IN; |
| 69 | 2391 if (strcmp(STR(CHILD(n, 0)), "is") == 0) |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2392 return PyCmp_IS_NOT; |
| 69 | 2393 } |
| 2394 } | |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2395 return PyCmp_BAD; |
| 69 | 2396 } |
| 2397 | |
| 2398 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2399 com_comparison(struct compiling *c, node *n) |
| 69 | 2400 { |
| 2401 int i; | |
| 2402 enum cmp_op op; | |
| 2403 int anchor; | |
| 2404 REQ(n, comparison); /* comparison: expr (comp_op expr)* */ | |
| 2405 com_expr(c, CHILD(n, 0)); | |
| 2406 if (NCH(n) == 1) | |
| 2407 return; | |
| 2408 | |
| 2409 /**************************************************************** | |
| 2410 The following code is generated for all but the last | |
| 2411 comparison in a chain: | |
| 2412 | |
| 2413 label: on stack: opcode: jump to: | |
| 2414 | |
| 2415 a <code to load b> | |
| 2416 a, b DUP_TOP | |
| 2417 a, b, b ROT_THREE | |
| 2418 b, a, b COMPARE_OP | |
| 2419 b, 0-or-1 JUMP_IF_FALSE L1 | |
| 2420 b, 1 POP_TOP | |
| 2421 b | |
| 2422 | |
| 2423 We are now ready to repeat this sequence for the next | |
| 2424 comparison in the chain. | |
| 2425 | |
| 2426 For the last we generate: | |
| 2427 | |
| 2428 b <code to load c> | |
| 2429 b, c COMPARE_OP | |
| 2430 0-or-1 | |
| 2431 | |
| 2432 If there were any jumps to L1 (i.e., there was more than one | |
| 2433 comparison), we generate: | |
| 2434 | |
| 2435 0-or-1 JUMP_FORWARD L2 | |
| 2436 L1: b, 0 ROT_TWO | |
| 2437 0, b POP_TOP | |
| 2438 0 | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2439 L2: 0-or-1 |
| 69 | 2440 ****************************************************************/ |
| 2441 | |
| 2442 anchor = 0; | |
| 2443 | |
| 2444 for (i = 2; i < NCH(n); i += 2) { | |
| 2445 com_expr(c, CHILD(n, i)); | |
| 2446 if (i+2 < NCH(n)) { | |
| 2447 com_addbyte(c, DUP_TOP); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2448 com_push(c, 1); |
| 69 | 2449 com_addbyte(c, ROT_THREE); |
| 2450 } | |
| 2451 op = cmp_type(CHILD(n, i-1)); | |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
2452 if (op == PyCmp_BAD) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2453 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2454 "com_comparison: unknown comparison op"); |
| 69 | 2455 } |
| 2456 com_addoparg(c, COMPARE_OP, op); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2457 com_pop(c, 1); |
| 69 | 2458 if (i+2 < NCH(n)) { |
| 2459 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 2460 com_addbyte(c, POP_TOP); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2461 com_pop(c, 1); |
| 69 | 2462 } |
| 2463 } | |
| 2464 | |
| 2465 if (anchor) { | |
| 2466 int anchor2 = 0; | |
| 2467 com_addfwref(c, JUMP_FORWARD, &anchor2); | |
| 2468 com_backpatch(c, anchor); | |
| 2469 com_addbyte(c, ROT_TWO); | |
| 2470 com_addbyte(c, POP_TOP); | |
| 2471 com_backpatch(c, anchor2); | |
| 2472 } | |
| 2473 } | |
| 2474 | |
| 2475 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2476 com_not_test(struct compiling *c, node *n) |
| 69 | 2477 { |
| 2478 REQ(n, not_test); /* 'not' not_test | comparison */ | |
| 2479 if (NCH(n) == 1) { | |
| 2480 com_comparison(c, CHILD(n, 0)); | |
| 2481 } | |
| 2482 else { | |
| 2483 com_not_test(c, CHILD(n, 1)); | |
| 2484 com_addbyte(c, UNARY_NOT); | |
| 2485 } | |
| 2486 } | |
| 2487 | |
| 2488 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2489 com_and_test(struct compiling *c, node *n) |
| 69 | 2490 { |
| 2491 int i; | |
| 2492 int anchor; | |
| 2493 REQ(n, and_test); /* not_test ('and' not_test)* */ | |
| 2494 anchor = 0; | |
| 2495 i = 0; | |
| 2496 for (;;) { | |
| 2497 com_not_test(c, CHILD(n, i)); | |
| 2498 if ((i += 2) >= NCH(n)) | |
| 2499 break; | |
| 2500 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 2501 com_addbyte(c, POP_TOP); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2502 com_pop(c, 1); |
| 69 | 2503 } |
| 2504 if (anchor) | |
| 2505 com_backpatch(c, anchor); | |
| 2506 } | |
| 2507 | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2508 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2509 com_make_closure(struct compiling *c, PyCodeObject *co) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2510 { |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21179
diff
changeset
|
2511 int i, free = PyCode_GetNumFree(co); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2512 if (free == 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2513 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2514 for (i = 0; i < free; ++i) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2515 /* Bypass com_addop_varname because it will generate |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2516 LOAD_DEREF but LOAD_CLOSURE is needed. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2517 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2518 PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2519 int arg, reftype; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2520 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2521 /* Special case: If a class contains a method with a |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2522 free variable that has the same name as a method, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2523 the name will be considered free *and* local in the |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2524 class. It should be handled by the closure, as |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2525 well as by the normal name loookup logic. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2526 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2527 reftype = get_ref_type(c, PyString_AS_STRING(name)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2528 if (reftype == CELL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2529 arg = com_lookup_arg(c->c_cellvars, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2530 else /* (reftype == FREE) */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2531 arg = com_lookup_arg(c->c_freevars, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2532 if (arg == -1) { |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2533 fprintf(stderr, "lookup %s in %s %d %d\n" |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2534 "freevars of %s: %s\n", |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2535 PyObject_REPR(name), |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2536 c->c_name, |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2537 reftype, arg, |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2538 PyString_AS_STRING(co->co_name), |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2539 PyObject_REPR(co->co_freevars)); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2540 Py_FatalError("com_make_closure()"); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2541 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2542 com_addoparg(c, LOAD_CLOSURE, arg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2543 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2544 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2545 com_push(c, free); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2546 return 1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2547 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2548 |
| 69 | 2549 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2550 com_test(struct compiling *c, node *n) |
| 69 | 2551 { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2552 REQ(n, test); /* and_test ('or' and_test)* | lambdef */ |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2553 if (NCH(n) == 1 && TYPE(CHILD(n, 0)) == lambdef) { |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
2554 PyCodeObject *co; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2555 int i, closure; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2556 int ndefs = com_argdefs(c, CHILD(n, 0)); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
2557 symtable_enter_scope(c->c_symtable, "lambda", lambdef, |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
2558 n->n_lineno); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
2559 co = icompile(CHILD(n, 0), c); |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2560 if (co == NULL) { |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2561 c->c_errors++; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2562 return; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2563 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2564 symtable_exit_scope(c->c_symtable); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
2565 i = com_addconst(c, (PyObject *)co); |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
2566 closure = com_make_closure(c, co); |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2567 com_addoparg(c, LOAD_CONST, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2568 com_push(c, 1); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
2569 if (closure) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2570 com_addoparg(c, MAKE_CLOSURE, ndefs); |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21179
diff
changeset
|
2571 com_pop(c, PyCode_GetNumFree(co)); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
2572 } else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2573 com_addoparg(c, MAKE_FUNCTION, ndefs); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
2574 Py_DECREF(co); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2575 com_pop(c, ndefs); |
| 69 | 2576 } |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2577 else { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2578 int anchor = 0; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2579 int i = 0; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2580 for (;;) { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2581 com_and_test(c, CHILD(n, i)); |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2582 if ((i += 2) >= NCH(n)) |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2583 break; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2584 com_addfwref(c, JUMP_IF_TRUE, &anchor); |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2585 com_addbyte(c, POP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2586 com_pop(c, 1); |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2587 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2588 if (anchor) |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2589 com_backpatch(c, anchor); |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2590 } |
| 69 | 2591 } |
| 2592 | |
| 2593 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2594 com_list(struct compiling *c, node *n, int toplevel) |
| 69 | 2595 { |
| 2596 /* exprlist: expr (',' expr)* [',']; likewise for testlist */ | |
| 482 | 2597 if (NCH(n) == 1 && !toplevel) { |
| 69 | 2598 com_node(c, CHILD(n, 0)); |
| 2599 } | |
| 2600 else { | |
| 2601 int i; | |
| 2602 int len; | |
| 2603 len = (NCH(n) + 1) / 2; | |
| 2604 for (i = 0; i < NCH(n); i += 2) | |
| 2605 com_node(c, CHILD(n, i)); | |
| 2606 com_addoparg(c, BUILD_TUPLE, len); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2607 com_pop(c, len-1); |
| 69 | 2608 } |
| 2609 } | |
| 2610 | |
| 2611 | |
| 2612 /* Begin of assignment compilation */ | |
| 2613 | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2614 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2615 static void |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2616 com_augassign_attr(struct compiling *c, node *n, int opcode, node *augn) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2617 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2618 com_addbyte(c, DUP_TOP); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2619 com_push(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2620 com_addopname(c, LOAD_ATTR, n); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2621 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2622 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2623 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2624 com_addbyte(c, ROT_TWO); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2625 com_addopname(c, STORE_ATTR, n); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2626 com_pop(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2627 } |
| 69 | 2628 |
| 2629 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2630 com_assign_attr(struct compiling *c, node *n, int assigning) |
| 69 | 2631 { |
|
24855
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
2632 if (none_assignment_check(c, STR(n), assigning)) |
|
bed5d5e536bc
Add warnings for assignment or deletion of variables and attributes
Guido van Rossum <guido@python.org>
parents:
24854
diff
changeset
|
2633 return; |
| 69 | 2634 com_addopname(c, assigning ? STORE_ATTR : DELETE_ATTR, n); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2635 com_pop(c, assigning ? 2 : 1); |
| 69 | 2636 } |
| 2637 | |
| 2638 static void | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2639 com_assign_trailer(struct compiling *c, node *n, int assigning, node *augn) |
| 69 | 2640 { |
| 2641 REQ(n, trailer); | |
| 2642 switch (TYPE(CHILD(n, 0))) { | |
| 2643 case LPAR: /* '(' [exprlist] ')' */ | |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23555
diff
changeset
|
2644 if (assigning == OP_DELETE) |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23555
diff
changeset
|
2645 com_error(c, PyExc_SyntaxError, |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23555
diff
changeset
|
2646 "can't delete function call"); |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23555
diff
changeset
|
2647 else |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23555
diff
changeset
|
2648 com_error(c, PyExc_SyntaxError, |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23555
diff
changeset
|
2649 "can't assign to function call"); |
| 69 | 2650 break; |
| 2651 case DOT: /* '.' NAME */ | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2652 if (assigning > OP_APPLY) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2653 com_augassign_attr(c, CHILD(n, 1), assigning, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2654 else |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2655 com_assign_attr(c, CHILD(n, 1), assigning); |
| 69 | 2656 break; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2657 case LSQB: /* '[' subscriptlist ']' */ |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2658 com_subscriptlist(c, CHILD(n, 1), assigning, augn); |
| 69 | 2659 break; |
| 2660 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2661 com_error(c, PyExc_SystemError, "unknown trailer type"); |
| 69 | 2662 } |
| 2663 } | |
| 2664 | |
| 2665 static void | |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13884
diff
changeset
|
2666 com_assign_sequence(struct compiling *c, node *n, int assigning) |
| 69 | 2667 { |
| 2668 int i; | |
|
14178
dff22d4a48da
Fix allowable node-types for assignment, need to add 'listmaker'.
Thomas Wouters <thomas@python.org>
parents:
14163
diff
changeset
|
2669 if (TYPE(n) != testlist && TYPE(n) != listmaker) |
| 69 | 2670 REQ(n, exprlist); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2671 if (assigning) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2672 i = (NCH(n)+1)/2; |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13884
diff
changeset
|
2673 com_addoparg(c, UNPACK_SEQUENCE, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2674 com_push(c, i-1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2675 } |
| 69 | 2676 for (i = 0; i < NCH(n); i += 2) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2677 com_assign(c, CHILD(n, i), assigning, NULL); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2678 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2679 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2680 static void |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2681 com_augassign_name(struct compiling *c, node *n, int opcode, node *augn) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2682 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2683 REQ(n, NAME); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2684 com_addop_varname(c, VAR_LOAD, STR(n)); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2685 com_push(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2686 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2687 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2688 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2689 com_assign_name(c, n, OP_ASSIGN); |
| 69 | 2690 } |
| 2691 | |
| 2692 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2693 com_assign_name(struct compiling *c, node *n, int assigning) |
| 69 | 2694 { |
| 2695 REQ(n, NAME); | |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2696 com_addop_varname(c, assigning ? VAR_STORE : VAR_DELETE, STR(n)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2697 if (assigning) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2698 com_pop(c, 1); |
| 69 | 2699 } |
| 2700 | |
| 2701 static void | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2702 com_assign(struct compiling *c, node *n, int assigning, node *augn) |
| 69 | 2703 { |
| 2704 /* Loop to avoid trivial recursion */ | |
| 2705 for (;;) { | |
| 2706 switch (TYPE(n)) { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2707 |
| 69 | 2708 case exprlist: |
| 2709 case testlist: | |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
23280
diff
changeset
|
2710 case testlist1: |
| 69 | 2711 if (NCH(n) > 1) { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2712 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2713 com_error(c, PyExc_SyntaxError, |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
2714 "augmented assign to tuple not possible"); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2715 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2716 } |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13884
diff
changeset
|
2717 com_assign_sequence(c, n, assigning); |
| 69 | 2718 return; |
| 2719 } | |
| 2720 n = CHILD(n, 0); | |
| 2721 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2722 |
| 69 | 2723 case test: |
| 2724 case and_test: | |
| 2725 case not_test: | |
| 2726 case comparison: | |
| 2727 case expr: | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2728 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2729 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2730 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2731 case arith_expr: |
| 69 | 2732 case term: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2733 case factor: |
| 69 | 2734 if (NCH(n) > 1) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2735 com_error(c, PyExc_SyntaxError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2736 "can't assign to operator"); |
| 69 | 2737 return; |
| 2738 } | |
| 2739 n = CHILD(n, 0); | |
| 2740 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2741 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2742 case power: /* atom trailer* ('**' power)* |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2743 ('+'|'-'|'~') factor | atom trailer* */ |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2744 if (TYPE(CHILD(n, 0)) != atom) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2745 com_error(c, PyExc_SyntaxError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2746 "can't assign to operator"); |
| 69 | 2747 return; |
| 2748 } | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2749 if (NCH(n) > 1) { /* trailer or exponent present */ |
| 69 | 2750 int i; |
| 2751 com_node(c, CHILD(n, 0)); | |
| 2752 for (i = 1; i+1 < NCH(n); i++) { | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2753 if (TYPE(CHILD(n, i)) == DOUBLESTAR) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2754 com_error(c, PyExc_SyntaxError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2755 "can't assign to operator"); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2756 return; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2757 } |
| 69 | 2758 com_apply_trailer(c, CHILD(n, i)); |
| 2759 } /* NB i is still alive */ | |
| 2760 com_assign_trailer(c, | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2761 CHILD(n, i), assigning, augn); |
| 69 | 2762 return; |
| 2763 } | |
| 2764 n = CHILD(n, 0); | |
| 2765 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2766 |
| 69 | 2767 case atom: |
| 2768 switch (TYPE(CHILD(n, 0))) { | |
| 2769 case LPAR: | |
| 2770 n = CHILD(n, 1); | |
| 2771 if (TYPE(n) == RPAR) { | |
| 2772 /* XXX Should allow () = () ??? */ | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2773 com_error(c, PyExc_SyntaxError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2774 "can't assign to ()"); |
| 69 | 2775 return; |
| 2776 } | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2777 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2778 com_error(c, PyExc_SyntaxError, |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2779 "augmented assign to tuple not possible"); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2780 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2781 } |
| 69 | 2782 break; |
| 2783 case LSQB: | |
| 2784 n = CHILD(n, 1); | |
| 2785 if (TYPE(n) == RSQB) { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2786 com_error(c, PyExc_SyntaxError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2787 "can't assign to []"); |
| 69 | 2788 return; |
| 2789 } | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2790 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2791 com_error(c, PyExc_SyntaxError, |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2792 "augmented assign to list not possible"); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2793 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2794 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2795 if (NCH(n) > 1 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2796 && TYPE(CHILD(n, 1)) == list_for) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2797 com_error(c, PyExc_SyntaxError, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2798 "can't assign to list comprehension"); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2799 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2800 } |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13884
diff
changeset
|
2801 com_assign_sequence(c, n, assigning); |
| 69 | 2802 return; |
| 2803 case NAME: | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2804 if (assigning > OP_APPLY) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2805 com_augassign_name(c, CHILD(n, 0), |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2806 assigning, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2807 else |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2808 com_assign_name(c, CHILD(n, 0), |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2809 assigning); |
| 69 | 2810 return; |
| 2811 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2812 com_error(c, PyExc_SyntaxError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2813 "can't assign to literal"); |
| 69 | 2814 return; |
| 2815 } | |
| 2816 break; | |
|
3963
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
2817 |
|
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
2818 case lambdef: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2819 com_error(c, PyExc_SyntaxError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2820 "can't assign to lambda"); |
|
3963
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
2821 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2822 |
| 69 | 2823 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2824 com_error(c, PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2825 "com_assign: bad node"); |
| 69 | 2826 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2827 |
| 69 | 2828 } |
| 2829 } | |
| 2830 } | |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2831 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2832 static void |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2833 com_augassign(struct compiling *c, node *n) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2834 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2835 int opcode; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2836 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2837 switch (STR(CHILD(CHILD(n, 1), 0))[0]) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2838 case '+': opcode = INPLACE_ADD; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2839 case '-': opcode = INPLACE_SUBTRACT; break; |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2840 case '/': |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2841 if (STR(CHILD(CHILD(n, 1), 0))[1] == '/') |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2842 opcode = INPLACE_FLOOR_DIVIDE; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2843 else if (c->c_flags & CO_FUTURE_DIVISION) |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2844 opcode = INPLACE_TRUE_DIVIDE; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2845 else |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2846 opcode = INPLACE_DIVIDE; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19021
diff
changeset
|
2847 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2848 case '%': opcode = INPLACE_MODULO; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2849 case '<': opcode = INPLACE_LSHIFT; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2850 case '>': opcode = INPLACE_RSHIFT; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2851 case '&': opcode = INPLACE_AND; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2852 case '^': opcode = INPLACE_XOR; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2853 case '|': opcode = INPLACE_OR; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2854 case '*': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2855 if (STR(CHILD(CHILD(n, 1), 0))[1] == '*') |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2856 opcode = INPLACE_POWER; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2857 else |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2858 opcode = INPLACE_MULTIPLY; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2859 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2860 default: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2861 com_error(c, PyExc_SystemError, "com_augassign: bad operator"); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2862 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2863 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2864 com_assign(c, CHILD(n, 0), opcode, CHILD(n, 2)); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2865 } |
| 69 | 2866 |
| 2867 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2868 com_expr_stmt(struct compiling *c, node *n) |
| 69 | 2869 { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2870 REQ(n, expr_stmt); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2871 /* testlist (('=' testlist)* | augassign testlist) */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2872 /* Forget it if we have just a doc string here */ |
|
5264
38878f1cd4f1
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
5233
diff
changeset
|
2873 if (!c->c_interactive && NCH(n) == 1 && get_rawdocstring(n) != NULL) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2874 return; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2875 if (NCH(n) == 1) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2876 com_node(c, CHILD(n, NCH(n)-1)); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2877 if (c->c_interactive) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2878 com_addbyte(c, PRINT_EXPR); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2879 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2880 com_addbyte(c, POP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2881 com_pop(c, 1); |
| 69 | 2882 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2883 else if (TYPE(CHILD(n,1)) == augassign) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2884 com_augassign(c, n); |
| 69 | 2885 else { |
| 2886 int i; | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2887 com_node(c, CHILD(n, NCH(n)-1)); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2888 for (i = 0; i < NCH(n)-2; i+=2) { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2889 if (i+2 < NCH(n)-2) { |
| 69 | 2890 com_addbyte(c, DUP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2891 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2892 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2893 com_assign(c, CHILD(n, i), OP_ASSIGN, NULL); |
| 69 | 2894 } |
| 2895 } | |
| 2896 } | |
| 2897 | |
| 2898 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2899 com_assert_stmt(struct compiling *c, node *n) |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2900 { |
|
23280
9e22a8702de2
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23211
diff
changeset
|
2901 int a = 0; |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2902 int i; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2903 REQ(n, assert_stmt); /* 'assert' test [',' test] */ |
|
23280
9e22a8702de2
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23211
diff
changeset
|
2904 if (Py_OptimizeFlag) |
|
9e22a8702de2
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23211
diff
changeset
|
2905 return; |
|
9e22a8702de2
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23211
diff
changeset
|
2906 /* Generate code like |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2907 |
|
23280
9e22a8702de2
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23211
diff
changeset
|
2908 if not <test>: |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2909 raise AssertionError [, <message>] |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2910 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2911 where <message> is the second test, if present. |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2912 */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2913 com_node(c, CHILD(n, 1)); |
|
23280
9e22a8702de2
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23211
diff
changeset
|
2914 com_addfwref(c, JUMP_IF_TRUE, &a); |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2915 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2916 com_pop(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2917 /* Raise that exception! */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2918 com_addop_name(c, LOAD_GLOBAL, "AssertionError"); |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2919 com_push(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2920 i = NCH(n)/2; /* Either 2 or 4 */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2921 if (i > 1) |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2922 com_node(c, CHILD(n, 3)); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2923 com_addoparg(c, RAISE_VARARGS, i); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2924 com_pop(c, i); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2925 /* The interpreter does not fall through */ |
|
23280
9e22a8702de2
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
23211
diff
changeset
|
2926 /* Jump ends up here */ |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2927 com_backpatch(c, a); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2928 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2929 } |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2930 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2931 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2932 com_print_stmt(struct compiling *c, node *n) |
| 69 | 2933 { |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2934 int i = 1; |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2935 node* stream = NULL; |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2936 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2937 REQ(n, print_stmt); /* 'print' (test ',')* [test] */ |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2938 |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2939 /* are we using the extended print form? */ |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2940 if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) { |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2941 stream = CHILD(n, 2); |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2942 com_node(c, stream); |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2943 /* stack: [...] => [... stream] */ |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2944 com_push(c, 1); |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2945 if (NCH(n) > 3 && TYPE(CHILD(n, 3)) == COMMA) |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2946 i = 4; |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2947 else |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2948 i = 3; |
| 69 | 2949 } |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2950 for (; i < NCH(n); i += 2) { |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2951 if (stream != NULL) { |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2952 com_addbyte(c, DUP_TOP); |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2953 /* stack: [stream] => [stream stream] */ |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2954 com_push(c, 1); |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2955 com_node(c, CHILD(n, i)); |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2956 /* stack: [stream stream] => [stream stream obj] */ |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2957 com_addbyte(c, ROT_TWO); |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2958 /* stack: [stream stream obj] => [stream obj stream] */ |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2959 com_addbyte(c, PRINT_ITEM_TO); |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2960 /* stack: [stream obj stream] => [stream] */ |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2961 com_pop(c, 2); |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2962 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2963 else { |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2964 com_node(c, CHILD(n, i)); |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2965 /* stack: [...] => [... obj] */ |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2966 com_addbyte(c, PRINT_ITEM); |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2967 com_pop(c, 1); |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2968 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2969 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2970 /* XXX Alternatively, LOAD_CONST '\n' and then PRINT_ITEM */ |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2971 if (TYPE(CHILD(n, NCH(n)-1)) == COMMA) { |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2972 if (stream != NULL) { |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2973 /* must pop the extra stream object off the stack */ |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2974 com_addbyte(c, POP_TOP); |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2975 /* stack: [... stream] => [...] */ |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2976 com_pop(c, 1); |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2977 } |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2978 } |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2979 else { |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2980 if (stream != NULL) { |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2981 /* this consumes the last stream object on stack */ |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2982 com_addbyte(c, PRINT_NEWLINE_TO); |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2983 /* stack: [... stream] => [...] */ |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2984 com_pop(c, 1); |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2985 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2986 else |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2987 com_addbyte(c, PRINT_NEWLINE); |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2988 } |
| 69 | 2989 } |
| 2990 | |
| 2991 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2992 com_return_stmt(struct compiling *c, node *n) |
| 69 | 2993 { |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2994 REQ(n, return_stmt); /* 'return' [testlist] */ |
| 86 | 2995 if (!c->c_infunction) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2996 com_error(c, PyExc_SyntaxError, "'return' outside function"); |
| 86 | 2997 } |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
2998 if (c->c_flags & CO_GENERATOR) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
2999 if (NCH(n) > 1) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3000 com_error(c, PyExc_SyntaxError, |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3001 "'return' with argument inside generator"); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3002 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3003 } |
|
18243
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18228
diff
changeset
|
3004 if (NCH(n) < 2) { |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18228
diff
changeset
|
3005 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18228
diff
changeset
|
3006 com_push(c, 1); |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3007 } |
|
18243
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18228
diff
changeset
|
3008 else |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18228
diff
changeset
|
3009 com_node(c, CHILD(n, 1)); |
|
47717e5667eb
Change the semantics of "return" in generators, as discussed on the
Tim Peters <tim.peters@gmail.com>
parents:
18228
diff
changeset
|
3010 com_addbyte(c, RETURN_VALUE); |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3011 com_pop(c, 1); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3012 } |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3013 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3014 static void |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3015 com_yield_stmt(struct compiling *c, node *n) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3016 { |
|
18228
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3017 int i; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3018 REQ(n, yield_stmt); /* 'yield' testlist */ |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3019 if (!c->c_infunction) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3020 com_error(c, PyExc_SyntaxError, "'yield' outside function"); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3021 } |
|
18228
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3022 |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3023 for (i = 0; i < c->c_nblocks; ++i) { |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3024 if (c->c_block[i] == SETUP_FINALLY) { |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3025 com_error(c, PyExc_SyntaxError, |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3026 "'yield' not allowed in a 'try' block " |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3027 "with a 'finally' clause"); |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3028 return; |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3029 } |
|
4ebd292c975f
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3030 } |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3031 com_node(c, CHILD(n, 1)); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3032 com_addbyte(c, YIELD_VALUE); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3033 com_pop(c, 1); |
| 69 | 3034 } |
| 3035 | |
| 3036 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3037 com_raise_stmt(struct compiling *c, node *n) |
| 69 | 3038 { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3039 int i; |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3040 REQ(n, raise_stmt); /* 'raise' [test [',' test [',' test]]] */ |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3041 if (NCH(n) > 1) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3042 com_node(c, CHILD(n, 1)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3043 if (NCH(n) > 3) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3044 com_node(c, CHILD(n, 3)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3045 if (NCH(n) > 5) |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3046 com_node(c, CHILD(n, 5)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
3047 } |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
3048 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3049 i = NCH(n)/2; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3050 com_addoparg(c, RAISE_VARARGS, i); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3051 com_pop(c, i); |
| 69 | 3052 } |
| 3053 | |
| 3054 static void | |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3055 com_from_import(struct compiling *c, node *n) |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3056 { |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3057 com_addopname(c, IMPORT_FROM, CHILD(n, 0)); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3058 com_push(c, 1); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3059 if (NCH(n) > 1) { |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3060 if (strcmp(STR(CHILD(n, 1)), "as") != 0) { |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3061 com_error(c, PyExc_SyntaxError, "invalid syntax"); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3062 return; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3063 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3064 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 2))); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3065 } else |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3066 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 0))); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3067 com_pop(c, 1); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3068 } |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3069 |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3070 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3071 com_import_stmt(struct compiling *c, node *n) |
| 69 | 3072 { |
| 3073 int i; | |
| 3074 REQ(n, import_stmt); | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3075 /* 'import' dotted_name (',' dotted_name)* | |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3076 'from' dotted_name 'import' ('*' | NAME (',' NAME)*) */ |
| 69 | 3077 if (STR(CHILD(n, 0))[0] == 'f') { |
|
15438
433458651eb4
Plug a memory leak in com_import_stmt(): the tuple created to hold the
Guido van Rossum <guido@python.org>
parents:
15408
diff
changeset
|
3078 PyObject *tup; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3079 /* 'from' dotted_name 'import' ... */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3080 REQ(CHILD(n, 1), dotted_name); |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3081 |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3082 if (TYPE(CHILD(n, 3)) == STAR) { |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3083 tup = Py_BuildValue("(s)", "*"); |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3084 } else { |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3085 tup = PyTuple_New((NCH(n) - 2)/2); |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3086 for (i = 3; i < NCH(n); i += 2) { |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3087 PyTuple_SET_ITEM(tup, (i-3)/2, |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
3088 PyString_FromString(STR( |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
3089 CHILD(CHILD(n, i), 0)))); |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3090 } |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3091 } |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3092 com_addoparg(c, LOAD_CONST, com_addconst(c, tup)); |
|
15438
433458651eb4
Plug a memory leak in com_import_stmt(): the tuple created to hold the
Guido van Rossum <guido@python.org>
parents:
15408
diff
changeset
|
3093 Py_DECREF(tup); |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3094 com_push(c, 1); |
| 69 | 3095 com_addopname(c, IMPORT_NAME, CHILD(n, 1)); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3096 if (TYPE(CHILD(n, 3)) == STAR) |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3097 com_addbyte(c, IMPORT_STAR); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3098 else { |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3099 for (i = 3; i < NCH(n); i += 2) |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3100 com_from_import(c, CHILD(n, i)); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3101 com_addbyte(c, POP_TOP); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3102 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3103 com_pop(c, 1); |
| 69 | 3104 } |
| 3105 else { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3106 /* 'import' ... */ |
| 69 | 3107 for (i = 1; i < NCH(n); i += 2) { |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3108 node *subn = CHILD(n, i); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3109 REQ(subn, dotted_as_name); |
|
14232
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3110 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
3111 com_push(c, 1); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3112 com_addopname(c, IMPORT_NAME, CHILD(subn, 0)); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3113 if (NCH(subn) > 1) { |
|
14230
31925ab46b23
Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents:
14226
diff
changeset
|
3114 int j; |
|
31925ab46b23
Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents:
14226
diff
changeset
|
3115 if (strcmp(STR(CHILD(subn, 1)), "as") != 0) { |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3116 com_error(c, PyExc_SyntaxError, |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3117 "invalid syntax"); |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3118 return; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3119 } |
|
14230
31925ab46b23
Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents:
14226
diff
changeset
|
3120 for (j=2 ; j < NCH(CHILD(subn, 0)); j += 2) |
|
31925ab46b23
Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents:
14226
diff
changeset
|
3121 com_addopname(c, LOAD_ATTR, |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3122 CHILD(CHILD(subn, 0), |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3123 j)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3124 com_addop_varname(c, VAR_STORE, |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3125 STR(CHILD(subn, 2))); |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
3126 } else |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3127 com_addop_varname(c, VAR_STORE, |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3128 STR(CHILD(CHILD(subn, 0), |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3129 0))); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3130 com_pop(c, 1); |
| 69 | 3131 } |
| 3132 } | |
| 3133 } | |
| 3134 | |
| 3135 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3136 com_exec_stmt(struct compiling *c, node *n) |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3137 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3138 REQ(n, exec_stmt); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3139 /* exec_stmt: 'exec' expr ['in' expr [',' expr]] */ |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3140 com_node(c, CHILD(n, 1)); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3141 if (NCH(n) >= 4) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3142 com_node(c, CHILD(n, 3)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3143 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3144 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3145 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3146 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3147 if (NCH(n) >= 6) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3148 com_node(c, CHILD(n, 5)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3149 else { |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3150 com_addbyte(c, DUP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3151 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3152 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3153 com_addbyte(c, EXEC_STMT); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3154 com_pop(c, 3); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3155 } |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3156 |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3157 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3158 is_constant_false(struct compiling *c, node *n) |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3159 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3160 PyObject *v; |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3161 int i; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3162 /* argument c will be NULL when called from symtable_node() */ |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3163 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3164 /* Label to avoid tail recursion */ |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3165 next: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3166 switch (TYPE(n)) { |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3167 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3168 case suite: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3169 if (NCH(n) == 1) { |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3170 n = CHILD(n, 0); |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3171 goto next; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3172 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3173 /* Fall through */ |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3174 case file_input: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3175 for (i = 0; i < NCH(n); i++) { |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3176 node *ch = CHILD(n, i); |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3177 if (TYPE(ch) == stmt) { |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3178 n = ch; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3179 goto next; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3180 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3181 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3182 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3183 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3184 case stmt: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3185 case simple_stmt: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3186 case small_stmt: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3187 n = CHILD(n, 0); |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3188 goto next; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3189 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3190 case expr_stmt: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3191 case testlist: |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
23280
diff
changeset
|
3192 case testlist1: |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3193 case test: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3194 case and_test: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3195 case not_test: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3196 case comparison: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3197 case expr: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3198 case xor_expr: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3199 case and_expr: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3200 case shift_expr: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3201 case arith_expr: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3202 case term: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3203 case factor: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3204 case power: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3205 case atom: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3206 if (NCH(n) == 1) { |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3207 n = CHILD(n, 0); |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3208 goto next; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3209 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3210 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3211 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3212 case NAME: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3213 if (Py_OptimizeFlag && strcmp(STR(n), "__debug__") == 0) |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3214 return 1; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3215 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3216 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3217 case NUMBER: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3218 v = parsenumber(c, STR(n)); |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3219 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3220 PyErr_Clear(); |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3221 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3222 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3223 i = PyObject_IsTrue(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3224 Py_DECREF(v); |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3225 return i == 0; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3226 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3227 case STRING: |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
3228 v = parsestr(c, STR(n)); |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3229 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3230 PyErr_Clear(); |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3231 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3232 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3233 i = PyObject_IsTrue(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3234 Py_DECREF(v); |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3235 return i == 0; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3236 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3237 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3238 return 0; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3239 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3240 |
|
18333
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3241 |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3242 /* Look under n for a return stmt with an expression. |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3243 * This hack is used to find illegal returns under "if 0:" blocks in |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3244 * functions already known to be generators (as determined by the symtable |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3245 * pass). |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3246 * Return the offending return node if found, else NULL. |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3247 */ |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3248 static node * |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3249 look_for_offending_return(node *n) |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3250 { |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3251 int i; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3252 |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3253 for (i = 0; i < NCH(n); ++i) { |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3254 node *kid = CHILD(n, i); |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3255 |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3256 switch (TYPE(kid)) { |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3257 case classdef: |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3258 case funcdef: |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3259 case lambdef: |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3260 /* Stuff in nested functions & classes doesn't |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3261 affect the code block we started in. */ |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3262 return NULL; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3263 |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3264 case return_stmt: |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3265 if (NCH(kid) > 1) |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3266 return kid; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3267 break; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3268 |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3269 default: { |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3270 node *bad = look_for_offending_return(kid); |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3271 if (bad != NULL) |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3272 return bad; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3273 } |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3274 } |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3275 } |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3276 |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3277 return NULL; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3278 } |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3279 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3280 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3281 com_if_stmt(struct compiling *c, node *n) |
| 69 | 3282 { |
| 3283 int i; | |
| 3284 int anchor = 0; | |
| 3285 REQ(n, if_stmt); | |
| 3286 /*'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] */ | |
| 3287 for (i = 0; i+3 < NCH(n); i+=4) { | |
| 3288 int a = 0; | |
| 86 | 3289 node *ch = CHILD(n, i+1); |
|
18333
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3290 if (is_constant_false(c, ch)) { |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3291 /* We're going to skip this block. However, if this |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3292 is a generator, we have to check the dead code |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3293 anyway to make sure there aren't any return stmts |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3294 with expressions, in the same scope. */ |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3295 if (c->c_flags & CO_GENERATOR) { |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3296 node *p = look_for_offending_return(n); |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3297 if (p != NULL) { |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3298 int savelineno = c->c_lineno; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3299 c->c_lineno = p->n_lineno; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3300 com_error(c, PyExc_SyntaxError, |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3301 "'return' with argument " |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3302 "inside generator"); |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3303 c->c_lineno = savelineno; |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3304 } |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3305 } |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3306 continue; |
|
18333
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
3307 } |
| 86 | 3308 if (i > 0) |
| 24844 | 3309 com_set_lineno(c, ch->n_lineno); |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3310 com_node(c, ch); |
| 69 | 3311 com_addfwref(c, JUMP_IF_FALSE, &a); |
| 3312 com_addbyte(c, POP_TOP); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3313 com_pop(c, 1); |
| 69 | 3314 com_node(c, CHILD(n, i+3)); |
| 3315 com_addfwref(c, JUMP_FORWARD, &anchor); | |
| 3316 com_backpatch(c, a); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3317 /* We jump here with an extra entry which we now pop */ |
| 69 | 3318 com_addbyte(c, POP_TOP); |
| 3319 } | |
| 3320 if (i+2 < NCH(n)) | |
| 3321 com_node(c, CHILD(n, i+2)); | |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3322 if (anchor) |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
3323 com_backpatch(c, anchor); |
| 69 | 3324 } |
| 3325 | |
| 3326 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3327 com_while_stmt(struct compiling *c, node *n) |
| 69 | 3328 { |
| 3329 int break_anchor = 0; | |
| 3330 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3331 int save_begin = c->c_begin; |
| 69 | 3332 REQ(n, while_stmt); /* 'while' test ':' suite ['else' ':' suite] */ |
| 3333 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3334 block_push(c, SETUP_LOOP); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3335 c->c_begin = c->c_nexti; |
| 24844 | 3336 com_set_lineno(c, n->n_lineno); |
| 69 | 3337 com_node(c, CHILD(n, 1)); |
| 3338 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 3339 com_addbyte(c, POP_TOP); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3340 com_pop(c, 1); |
| 86 | 3341 c->c_loops++; |
| 69 | 3342 com_node(c, CHILD(n, 3)); |
| 86 | 3343 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3344 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3345 c->c_begin = save_begin; |
| 69 | 3346 com_backpatch(c, anchor); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3347 /* We jump here with one entry more on the stack */ |
| 69 | 3348 com_addbyte(c, POP_TOP); |
| 3349 com_addbyte(c, POP_BLOCK); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3350 block_pop(c, SETUP_LOOP); |
| 69 | 3351 if (NCH(n) > 4) |
| 3352 com_node(c, CHILD(n, 6)); | |
| 3353 com_backpatch(c, break_anchor); | |
| 3354 } | |
| 3355 | |
| 3356 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3357 com_for_stmt(struct compiling *c, node *n) |
| 69 | 3358 { |
| 3359 int break_anchor = 0; | |
| 3360 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3361 int save_begin = c->c_begin; |
| 69 | 3362 REQ(n, for_stmt); |
| 3363 /* 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] */ | |
| 3364 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3365 block_push(c, SETUP_LOOP); |
| 69 | 3366 com_node(c, CHILD(n, 3)); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
3367 com_addbyte(c, GET_ITER); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3368 c->c_begin = c->c_nexti; |
|
28887
e4eabe5b3da1
Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents:
28759
diff
changeset
|
3369 com_set_lineno(c, c->c_last_line); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
3370 com_addfwref(c, FOR_ITER, &anchor); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3371 com_push(c, 1); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
3372 com_assign(c, CHILD(n, 1), OP_ASSIGN, NULL); |
| 86 | 3373 c->c_loops++; |
| 69 | 3374 com_node(c, CHILD(n, 5)); |
| 86 | 3375 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3376 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3377 c->c_begin = save_begin; |
| 69 | 3378 com_backpatch(c, anchor); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
3379 com_pop(c, 1); /* FOR_ITER has popped this */ |
| 69 | 3380 com_addbyte(c, POP_BLOCK); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3381 block_pop(c, SETUP_LOOP); |
| 69 | 3382 if (NCH(n) > 8) |
| 3383 com_node(c, CHILD(n, 8)); | |
| 3384 com_backpatch(c, break_anchor); | |
| 3385 } | |
| 3386 | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3387 /* Code generated for "try: S finally: Sf" is as follows: |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3388 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3389 SETUP_FINALLY L |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3390 <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3391 POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3392 LOAD_CONST <nil> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3393 L: <code for Sf> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3394 END_FINALLY |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3395 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3396 The special instructions use the block stack. Each block |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3397 stack entry contains the instruction that created it (here |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3398 SETUP_FINALLY), the level of the value stack at the time the |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3399 block stack entry was created, and a label (here L). |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3400 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3401 SETUP_FINALLY: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3402 Pushes the current value stack level and the label |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3403 onto the block stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3404 POP_BLOCK: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3405 Pops en entry from the block stack, and pops the value |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3406 stack until its level is the same as indicated on the |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3407 block stack. (The label is ignored.) |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3408 END_FINALLY: |
| 86 | 3409 Pops a variable number of entries from the *value* stack |
| 3410 and re-raises the exception they specify. The number of | |
| 3411 entries popped depends on the (pseudo) exception type. | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3412 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3413 The block stack is unwound when an exception is raised: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3414 when a SETUP_FINALLY entry is found, the exception is pushed |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3415 onto the value stack (and the exception condition is cleared), |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3416 and the interpreter jumps to the label gotten from the block |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3417 stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3418 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3419 Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...": |
| 86 | 3420 (The contents of the value stack is shown in [], with the top |
| 3421 at the right; 'tb' is trace-back info, 'val' the exception's | |
| 3422 associated value, and 'exc' the exception.) | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3423 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3424 Value stack Label Instruction Argument |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3425 [] SETUP_EXCEPT L1 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3426 [] <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3427 [] POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3428 [] JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3429 |
| 86 | 3430 [tb, val, exc] L1: DUP ) |
| 3431 [tb, val, exc, exc] <evaluate E1> ) | |
| 3432 [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1 | |
| 3433 [tb, val, exc, 1-or-0] JUMP_IF_FALSE L2 ) | |
| 3434 [tb, val, exc, 1] POP ) | |
| 3435 [tb, val, exc] POP | |
| 3436 [tb, val] <assign to V1> (or POP if no V1) | |
| 3437 [tb] POP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3438 [] <code for S1> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3439 JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3440 |
| 86 | 3441 [tb, val, exc, 0] L2: POP |
| 3442 [tb, val, exc] DUP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3443 .............................etc....................... |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3444 |
| 86 | 3445 [tb, val, exc, 0] Ln+1: POP |
| 3446 [tb, val, exc] END_FINALLY # re-raise exception | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3447 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3448 [] L0: <next statement> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3449 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3450 Of course, parts are not generated if Vi or Ei is not present. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3451 */ |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3452 |
| 69 | 3453 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3454 com_try_except(struct compiling *c, node *n) |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3455 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3456 int except_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3457 int end_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3458 int else_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3459 int i; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3460 node *ch; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3461 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3462 com_addfwref(c, SETUP_EXCEPT, &except_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3463 block_push(c, SETUP_EXCEPT); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3464 com_node(c, CHILD(n, 2)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3465 com_addbyte(c, POP_BLOCK); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3466 block_pop(c, SETUP_EXCEPT); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3467 com_addfwref(c, JUMP_FORWARD, &else_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3468 com_backpatch(c, except_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3469 for (i = 3; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3470 i < NCH(n) && TYPE(ch = CHILD(n, i)) == except_clause; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3471 i += 3) { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3472 /* except_clause: 'except' [expr [',' var]] */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3473 if (except_anchor == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3474 com_error(c, PyExc_SyntaxError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
3475 "default 'except:' must be last"); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3476 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3477 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3478 except_anchor = 0; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3479 com_push(c, 3); /* tb, val, exc pushed by exception */ |
| 24844 | 3480 com_set_lineno(c, ch->n_lineno); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3481 if (NCH(ch) > 1) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3482 com_addbyte(c, DUP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3483 com_push(c, 1); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3484 com_node(c, CHILD(ch, 1)); |
|
21609
3ba0f1b20320
Patch #494783: Rename cmp_op enumerators.
Martin v. Löwis <martin@v.loewis.de>
parents:
21398
diff
changeset
|
3485 com_addoparg(c, COMPARE_OP, PyCmp_EXC_MATCH); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3486 com_pop(c, 1); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3487 com_addfwref(c, JUMP_IF_FALSE, &except_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3488 com_addbyte(c, POP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3489 com_pop(c, 1); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3490 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3491 com_addbyte(c, POP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3492 com_pop(c, 1); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3493 if (NCH(ch) > 3) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
3494 com_assign(c, CHILD(ch, 3), OP_ASSIGN, NULL); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3495 else { |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3496 com_addbyte(c, POP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3497 com_pop(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3498 } |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3499 com_addbyte(c, POP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3500 com_pop(c, 1); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3501 com_node(c, CHILD(n, i+2)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3502 com_addfwref(c, JUMP_FORWARD, &end_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3503 if (except_anchor) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3504 com_backpatch(c, except_anchor); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3505 /* We come in with [tb, val, exc, 0] on the |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3506 stack; one pop and it's the same as |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3507 expected at the start of the loop */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3508 com_addbyte(c, POP_TOP); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3509 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3510 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3511 /* We actually come in here with [tb, val, exc] but the |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3512 END_FINALLY will zap those and jump around. |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3513 The c_stacklevel does not reflect them so we need not pop |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3514 anything. */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3515 com_addbyte(c, END_FINALLY); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3516 com_backpatch(c, else_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3517 if (i < NCH(n)) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3518 com_node(c, CHILD(n, i+2)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3519 com_backpatch(c, end_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3520 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3521 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3522 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3523 com_try_finally(struct compiling *c, node *n) |
| 69 | 3524 { |
| 3525 int finally_anchor = 0; | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3526 node *ch; |
|
792
dc3b455f7632
Only * can be used for varargs argument lists
Guido van Rossum <guido@python.org>
parents:
744
diff
changeset
|
3527 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3528 com_addfwref(c, SETUP_FINALLY, &finally_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3529 block_push(c, SETUP_FINALLY); |
| 69 | 3530 com_node(c, CHILD(n, 2)); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3531 com_addbyte(c, POP_BLOCK); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3532 block_pop(c, SETUP_FINALLY); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3533 block_push(c, END_FINALLY); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3534 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3535 /* While the generated code pushes only one item, |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3536 the try-finally handling can enter here with |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3537 up to three items. OK, here are the details: |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3538 3 for an exception, 2 for RETURN, 1 for BREAK. */ |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3539 com_push(c, 3); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3540 com_backpatch(c, finally_anchor); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3541 ch = CHILD(n, NCH(n)-1); |
| 24844 | 3542 com_set_lineno(c, ch->n_lineno); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3543 com_node(c, ch); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3544 com_addbyte(c, END_FINALLY); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3545 block_pop(c, END_FINALLY); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3546 com_pop(c, 3); /* Matches the com_push above */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3547 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3548 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3549 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3550 com_try_stmt(struct compiling *c, node *n) |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3551 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3552 REQ(n, try_stmt); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3553 /* 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3554 | 'try' ':' suite 'finally' ':' suite */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3555 if (TYPE(CHILD(n, 3)) != except_clause) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3556 com_try_finally(c, n); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3557 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3558 com_try_except(c, n); |
| 69 | 3559 } |
| 3560 | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3561 static node * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3562 get_rawdocstring(node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3563 { |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3564 int i; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3565 |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3566 /* Label to avoid tail recursion */ |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3567 next: |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3568 switch (TYPE(n)) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3569 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3570 case suite: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3571 if (NCH(n) == 1) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3572 n = CHILD(n, 0); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3573 goto next; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3574 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3575 /* Fall through */ |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3576 case file_input: |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3577 for (i = 0; i < NCH(n); i++) { |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3578 node *ch = CHILD(n, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3579 if (TYPE(ch) == stmt) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3580 n = ch; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3581 goto next; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3582 } |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3583 } |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3584 break; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3585 |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3586 case stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3587 case simple_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3588 case small_stmt: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3589 n = CHILD(n, 0); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3590 goto next; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3591 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3592 case expr_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3593 case testlist: |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
23280
diff
changeset
|
3594 case testlist1: |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3595 case test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3596 case and_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3597 case not_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3598 case comparison: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3599 case expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3600 case xor_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3601 case and_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3602 case shift_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3603 case arith_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3604 case term: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3605 case factor: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3606 case power: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3607 if (NCH(n) == 1) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3608 n = CHILD(n, 0); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3609 goto next; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3610 } |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3611 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3612 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3613 case atom: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3614 if (TYPE(CHILD(n, 0)) == STRING) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3615 return n; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3616 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3617 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3618 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3619 return NULL; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3620 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3621 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3622 static PyObject * |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
3623 get_docstring(struct compiling *c, node *n) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3624 { |
|
9987
b7bcc2cda1b3
Implement -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents:
9626
diff
changeset
|
3625 /* Don't generate doc-strings if run with -OO */ |
|
b7bcc2cda1b3
Implement -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents:
9626
diff
changeset
|
3626 if (Py_OptimizeFlag > 1) |
|
b7bcc2cda1b3
Implement -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents:
9626
diff
changeset
|
3627 return NULL; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3628 n = get_rawdocstring(n); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3629 if (n == NULL) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3630 return NULL; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
3631 return parsestrplus(c, n); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3632 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3633 |
| 69 | 3634 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3635 com_suite(struct compiling *c, node *n) |
| 69 | 3636 { |
| 3637 REQ(n, suite); | |
| 3638 /* simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT */ | |
| 3639 if (NCH(n) == 1) { | |
| 3640 com_node(c, CHILD(n, 0)); | |
| 3641 } | |
| 3642 else { | |
| 3643 int i; | |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
3644 for (i = 0; i < NCH(n) && c->c_errors == 0; i++) { |
| 69 | 3645 node *ch = CHILD(n, i); |
| 3646 if (TYPE(ch) == stmt) | |
| 3647 com_node(c, ch); | |
| 3648 } | |
| 3649 } | |
| 3650 } | |
| 3651 | |
| 744 | 3652 /* ARGSUSED */ |
| 69 | 3653 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3654 com_continue_stmt(struct compiling *c, node *n) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3655 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3656 int i = c->c_nblocks; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3657 if (i-- > 0 && c->c_block[i] == SETUP_LOOP) { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3658 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3659 } |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3660 else if (i <= 0) { |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3661 /* at the outer level */ |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3662 com_error(c, PyExc_SyntaxError, |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3663 "'continue' not properly in loop"); |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3664 } |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3665 else { |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3666 int j; |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3667 for (j = i-1; j >= 0; --j) { |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3668 if (c->c_block[j] == SETUP_LOOP) |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3669 break; |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3670 } |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3671 if (j >= 0) { |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3672 /* there is a loop, but something interferes */ |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3673 for (; i > j; --i) { |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3674 if (c->c_block[i] == SETUP_EXCEPT || |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3675 c->c_block[i] == SETUP_FINALLY) { |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3676 com_addoparg(c, CONTINUE_LOOP, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3677 c->c_begin); |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3678 return; |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3679 } |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3680 if (c->c_block[i] == END_FINALLY) { |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3681 com_error(c, PyExc_SyntaxError, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3682 "'continue' not supported inside 'finally' clause"); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3683 return; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3684 } |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3685 } |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3686 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3687 com_error(c, PyExc_SyntaxError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3688 "'continue' not properly in loop"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3689 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3690 /* XXX Could allow it inside a 'finally' clause |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3691 XXX if we could pop the exception still on the stack */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3692 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3693 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3694 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3695 com_argdefs(struct compiling *c, node *n) |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3696 { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3697 int i, nch, nargs, ndefs; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3698 if (TYPE(n) == lambdef) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3699 /* lambdef: 'lambda' [varargslist] ':' test */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3700 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3701 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3702 else { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3703 REQ(n, funcdef); /* funcdef: 'def' NAME parameters ... */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3704 n = CHILD(n, 2); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3705 REQ(n, parameters); /* parameters: '(' [varargslist] ')' */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3706 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3707 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3708 if (TYPE(n) != varargslist) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3709 return 0; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3710 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3711 (fpdef ['=' test] ',')* '*' ....... | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3712 fpdef ['=' test] (',' fpdef ['=' test])* [','] */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3713 nch = NCH(n); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3714 nargs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3715 ndefs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3716 for (i = 0; i < nch; i++) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3717 int t; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3718 if (TYPE(CHILD(n, i)) == STAR || |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3719 TYPE(CHILD(n, i)) == DOUBLESTAR) |
|
2813
999b5bdc18ce
3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents:
2367
diff
changeset
|
3720 break; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3721 nargs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3722 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3723 if (i >= nch) |
|
3103
e51e17b2d88b
fix bug with missing default for last arg (discovered by Tommy Burnette)
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
3724 t = RPAR; /* Anything except EQUAL or COMMA */ |
|
e51e17b2d88b
fix bug with missing default for last arg (discovered by Tommy Burnette)
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
3725 else |
|
e51e17b2d88b
fix bug with missing default for last arg (discovered by Tommy Burnette)
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
3726 t = TYPE(CHILD(n, i)); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3727 if (t == EQUAL) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3728 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3729 ndefs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3730 com_node(c, CHILD(n, i)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3731 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3732 if (i >= nch) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3733 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3734 t = TYPE(CHILD(n, i)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3735 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3736 else { |
|
9214
c259c3c4d0cc
Treat def f(a, b=1, c): ... as an error (missing default for c)
Guido van Rossum <guido@python.org>
parents:
9049
diff
changeset
|
3737 /* Treat "(a=1, b)" as an error */ |
|
c259c3c4d0cc
Treat def f(a, b=1, c): ... as an error (missing default for c)
Guido van Rossum <guido@python.org>
parents:
9049
diff
changeset
|
3738 if (ndefs) |
|
c259c3c4d0cc
Treat def f(a, b=1, c): ... as an error (missing default for c)
Guido van Rossum <guido@python.org>
parents:
9049
diff
changeset
|
3739 com_error(c, PyExc_SyntaxError, |
|
9215
1995cdbe3384
Eh, better error message for the previous change. It now says
Guido van Rossum <guido@python.org>
parents:
9214
diff
changeset
|
3740 "non-default argument follows default argument"); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3741 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3742 if (t != COMMA) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3743 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3744 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3745 return ndefs; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3746 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3747 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3748 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3749 com_funcdef(struct compiling *c, node *n) |
| 69 | 3750 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3751 PyObject *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
|
3752 int ndefs; |
| 69 | 3753 REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3754 ndefs = com_argdefs(c, n); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3755 symtable_enter_scope(c->c_symtable, STR(CHILD(n, 1)), TYPE(n), |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3756 n->n_lineno); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3757 co = (PyObject *)icompile(n, c); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3758 symtable_exit_scope(c->c_symtable); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3759 if (co == NULL) |
| 69 | 3760 c->c_errors++; |
| 3761 else { | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3762 int closure = com_make_closure(c, (PyCodeObject *)co); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3763 int i = com_addconst(c, co); |
| 69 | 3764 com_addoparg(c, LOAD_CONST, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3765 com_push(c, 1); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3766 if (closure) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3767 com_addoparg(c, MAKE_CLOSURE, ndefs); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3768 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3769 com_addoparg(c, MAKE_FUNCTION, ndefs); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3770 com_pop(c, ndefs); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3771 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 1))); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3772 com_pop(c, 1); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3773 Py_DECREF(co); |
| 69 | 3774 } |
| 3775 } | |
| 3776 | |
| 3777 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3778 com_bases(struct compiling *c, node *n) |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3779 { |
| 744 | 3780 int i; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3781 REQ(n, testlist); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3782 /* testlist: test (',' test)* [','] */ |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3783 for (i = 0; i < NCH(n); i += 2) |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3784 com_node(c, CHILD(n, i)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3785 i = (NCH(n)+1) / 2; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3786 com_addoparg(c, BUILD_TUPLE, i); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3787 com_pop(c, i-1); |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3788 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3789 |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3790 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3791 com_classdef(struct compiling *c, node *n) |
| 69 | 3792 { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3793 int i; |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3794 PyObject *v; |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3795 PyCodeObject *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
|
3796 char *name; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3797 |
| 69 | 3798 REQ(n, classdef); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3799 /* classdef: class NAME ['(' testlist ')'] ':' suite */ |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
3800 if ((v = PyString_InternFromString(STR(CHILD(n, 1)))) == NULL) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3801 c->c_errors++; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3802 return; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3803 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3804 /* Push the class name on the stack */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3805 i = com_addconst(c, v); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3806 com_addoparg(c, LOAD_CONST, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3807 com_push(c, 1); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3808 Py_DECREF(v); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3809 /* Push the tuple of base classes on the stack */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3810 if (TYPE(CHILD(n, 2)) != LPAR) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3811 com_addoparg(c, BUILD_TUPLE, 0); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3812 com_push(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3813 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3814 else |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3815 com_bases(c, CHILD(n, 3)); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3816 name = STR(CHILD(n, 1)); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3817 symtable_enter_scope(c->c_symtable, name, TYPE(n), n->n_lineno); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3818 co = icompile(n, c); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3819 symtable_exit_scope(c->c_symtable); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3820 if (co == NULL) |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3821 c->c_errors++; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3822 else { |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3823 int closure = com_make_closure(c, co); |
|
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3824 i = com_addconst(c, (PyObject *)co); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3825 com_addoparg(c, LOAD_CONST, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3826 com_push(c, 1); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3827 if (closure) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3828 com_addoparg(c, MAKE_CLOSURE, 0); |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21179
diff
changeset
|
3829 com_pop(c, PyCode_GetNumFree(co)); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3830 } else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3831 com_addoparg(c, MAKE_FUNCTION, 0); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3832 com_addoparg(c, CALL_FUNCTION, 0); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3833 com_addbyte(c, BUILD_CLASS); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3834 com_pop(c, 2); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3835 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 1))); |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
3836 com_pop(c, 1); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3837 Py_DECREF(co); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3838 } |
| 69 | 3839 } |
| 3840 | |
| 3841 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3842 com_node(struct compiling *c, node *n) |
| 69 | 3843 { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3844 loop: |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
3845 if (c->c_errors) |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
3846 return; |
| 69 | 3847 switch (TYPE(n)) { |
| 3848 | |
| 3849 /* Definition nodes */ | |
| 3850 | |
| 3851 case funcdef: | |
| 3852 com_funcdef(c, n); | |
| 3853 break; | |
| 3854 case classdef: | |
| 3855 com_classdef(c, n); | |
| 3856 break; | |
| 3857 | |
| 3858 /* Trivial parse tree nodes */ | |
| 3859 | |
| 3860 case stmt: | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3861 case small_stmt: |
| 86 | 3862 case flow_stmt: |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3863 n = CHILD(n, 0); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3864 goto loop; |
| 86 | 3865 |
| 69 | 3866 case simple_stmt: |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3867 /* small_stmt (';' small_stmt)* [';'] NEWLINE */ |
| 24844 | 3868 com_set_lineno(c, n->n_lineno); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3869 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3870 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3871 for (i = 0; i < NCH(n)-1; i += 2) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3872 com_node(c, CHILD(n, i)); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3873 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3874 break; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3875 |
| 69 | 3876 case compound_stmt: |
| 24844 | 3877 com_set_lineno(c, n->n_lineno); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3878 n = CHILD(n, 0); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3879 goto loop; |
| 69 | 3880 |
| 3881 /* Statement nodes */ | |
| 3882 | |
| 3883 case expr_stmt: | |
| 3884 com_expr_stmt(c, n); | |
| 3885 break; | |
| 3886 case print_stmt: | |
| 3887 com_print_stmt(c, n); | |
| 3888 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3889 case del_stmt: /* 'del' exprlist */ |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
3890 com_assign(c, CHILD(n, 1), OP_DELETE, NULL); |
| 69 | 3891 break; |
| 3892 case pass_stmt: | |
| 3893 break; | |
| 3894 case break_stmt: | |
| 86 | 3895 if (c->c_loops == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3896 com_error(c, PyExc_SyntaxError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3897 "'break' outside loop"); |
| 86 | 3898 } |
| 69 | 3899 com_addbyte(c, BREAK_LOOP); |
| 3900 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3901 case continue_stmt: |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3902 com_continue_stmt(c, n); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3903 break; |
| 69 | 3904 case return_stmt: |
| 3905 com_return_stmt(c, n); | |
| 3906 break; | |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3907 case yield_stmt: |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3908 com_yield_stmt(c, n); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
3909 break; |
| 69 | 3910 case raise_stmt: |
| 3911 com_raise_stmt(c, n); | |
| 3912 break; | |
| 3913 case import_stmt: | |
| 3914 com_import_stmt(c, n); | |
| 3915 break; | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3916 case global_stmt: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3917 break; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3918 case exec_stmt: |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3919 com_exec_stmt(c, n); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3920 break; |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3921 case assert_stmt: |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3922 com_assert_stmt(c, n); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3923 break; |
| 69 | 3924 case if_stmt: |
| 3925 com_if_stmt(c, n); | |
| 3926 break; | |
| 3927 case while_stmt: | |
| 3928 com_while_stmt(c, n); | |
| 3929 break; | |
| 3930 case for_stmt: | |
| 3931 com_for_stmt(c, n); | |
| 3932 break; | |
| 3933 case try_stmt: | |
| 3934 com_try_stmt(c, n); | |
| 3935 break; | |
| 3936 case suite: | |
| 3937 com_suite(c, n); | |
| 3938 break; | |
| 3939 | |
| 3940 /* Expression nodes */ | |
| 3941 | |
| 3942 case testlist: | |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
23280
diff
changeset
|
3943 case testlist1: |
|
20432
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
3944 case testlist_safe: |
| 482 | 3945 com_list(c, n, 0); |
| 69 | 3946 break; |
| 3947 case test: | |
| 3948 com_test(c, n); | |
| 3949 break; | |
| 3950 case and_test: | |
| 3951 com_and_test(c, n); | |
| 3952 break; | |
| 3953 case not_test: | |
| 3954 com_not_test(c, n); | |
| 3955 break; | |
| 3956 case comparison: | |
| 3957 com_comparison(c, n); | |
| 3958 break; | |
| 3959 case exprlist: | |
| 482 | 3960 com_list(c, n, 0); |
| 69 | 3961 break; |
| 3962 case expr: | |
| 3963 com_expr(c, n); | |
| 3964 break; | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3965 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3966 com_xor_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3967 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3968 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3969 com_and_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3970 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3971 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3972 com_shift_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3973 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3974 case arith_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3975 com_arith_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3976 break; |
| 69 | 3977 case term: |
| 3978 com_term(c, n); | |
| 3979 break; | |
| 3980 case factor: | |
| 3981 com_factor(c, n); | |
| 3982 break; | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3983 case power: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3984 com_power(c, n); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3985 break; |
| 69 | 3986 case atom: |
| 3987 com_atom(c, n); | |
| 3988 break; | |
| 3989 | |
| 3990 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3991 com_error(c, PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3992 "com_node: unexpected node type"); |
| 69 | 3993 } |
| 3994 } | |
| 3995 | |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
3996 static void com_fplist(struct compiling *, node *); |
| 69 | 3997 |
| 3998 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3999 com_fpdef(struct compiling *c, node *n) |
| 69 | 4000 { |
| 4001 REQ(n, fpdef); /* fpdef: NAME | '(' fplist ')' */ | |
| 4002 if (TYPE(CHILD(n, 0)) == LPAR) | |
| 4003 com_fplist(c, CHILD(n, 1)); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4004 else { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4005 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 0))); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4006 com_pop(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4007 } |
| 69 | 4008 } |
| 4009 | |
| 4010 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4011 com_fplist(struct compiling *c, node *n) |
| 69 | 4012 { |
| 544 | 4013 REQ(n, fplist); /* fplist: fpdef (',' fpdef)* [','] */ |
| 69 | 4014 if (NCH(n) == 1) { |
| 4015 com_fpdef(c, CHILD(n, 0)); | |
| 4016 } | |
| 4017 else { | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4018 int i = (NCH(n)+1)/2; |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13884
diff
changeset
|
4019 com_addoparg(c, UNPACK_SEQUENCE, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4020 com_push(c, i-1); |
| 69 | 4021 for (i = 0; i < NCH(n); i += 2) |
| 4022 com_fpdef(c, CHILD(n, i)); | |
| 4023 } | |
| 4024 } | |
| 4025 | |
| 4026 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4027 com_arglist(struct compiling *c, node *n) |
| 584 | 4028 { |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4029 int nch, i, narg; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4030 int complex = 0; |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4031 char nbuf[30]; |
| 584 | 4032 REQ(n, varargslist); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
4033 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4034 (fpdef ['=' test] ',')* (fpdef ['=' test] | '*' .....) */ |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4035 nch = NCH(n); |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4036 /* Enter all arguments in table of locals */ |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4037 for (i = 0, narg = 0; i < nch; i++) { |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4038 node *ch = CHILD(n, i); |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4039 node *fp; |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4040 if (TYPE(ch) == STAR || TYPE(ch) == DOUBLESTAR) |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4041 break; |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4042 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4043 fp = CHILD(ch, 0); |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4044 if (TYPE(fp) != NAME) { |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4045 PyOS_snprintf(nbuf, sizeof(nbuf), ".%d", i); |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3366
diff
changeset
|
4046 complex = 1; |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4047 } |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4048 narg++; |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4049 /* all name updates handled by symtable */ |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4050 if (++i >= nch) |
|
26754
8c3ef524faa0
Add warning for assignment to None, True and False. This is patch
Guido van Rossum <guido@python.org>
parents:
26701
diff
changeset
|
4051 break; |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4052 ch = CHILD(n, i); |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4053 if (TYPE(ch) == EQUAL) |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4054 i += 2; |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4055 else |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4056 REQ(ch, COMMA); |
|
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4057 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4058 if (complex) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4059 /* Generate code for complex arguments only after |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4060 having counted the simple arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4061 int ilocal = 0; |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4062 for (i = 0; i < nch; i++) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4063 node *ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4064 node *fp; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
4065 if (TYPE(ch) == STAR || TYPE(ch) == DOUBLESTAR) |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
4066 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4067 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4068 fp = CHILD(ch, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4069 if (TYPE(fp) != NAME) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4070 com_addoparg(c, LOAD_FAST, ilocal); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4071 com_push(c, 1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4072 com_fpdef(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4073 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4074 ilocal++; |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
4075 if (++i >= nch) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4076 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4077 ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4078 if (TYPE(ch) == EQUAL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4079 i += 2; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4080 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4081 REQ(ch, COMMA); |
| 584 | 4082 } |
| 4083 } | |
| 4084 } | |
| 4085 | |
| 4086 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4087 com_file_input(struct compiling *c, node *n) |
| 69 | 4088 { |
| 4089 int i; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4090 PyObject *doc; |
| 69 | 4091 REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
4092 doc = get_docstring(c, n); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4093 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4094 int i = com_addconst(c, doc); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4095 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4096 com_addoparg(c, LOAD_CONST, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4097 com_push(c, 1); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4098 com_addop_name(c, STORE_NAME, "__doc__"); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4099 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4100 } |
| 69 | 4101 for (i = 0; i < NCH(n); i++) { |
| 4102 node *ch = CHILD(n, i); | |
| 4103 if (TYPE(ch) != ENDMARKER && TYPE(ch) != NEWLINE) | |
| 4104 com_node(c, ch); | |
| 4105 } | |
| 4106 } | |
| 4107 | |
| 4108 /* Top-level compile-node interface */ | |
| 4109 | |
| 4110 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4111 compile_funcdef(struct compiling *c, node *n) |
| 69 | 4112 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4113 PyObject *doc; |
| 69 | 4114 node *ch; |
| 4115 REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */ | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
4116 c->c_name = STR(CHILD(n, 1)); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
4117 doc = get_docstring(c, CHILD(n, 4)); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4118 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4119 (void) com_addconst(c, doc); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4120 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4121 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4122 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4123 (void) com_addconst(c, Py_None); /* No docstring */ |
| 584 | 4124 ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */ |
| 4125 ch = CHILD(ch, 1); /* ')' | varargslist */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4126 if (TYPE(ch) == varargslist) |
| 584 | 4127 com_arglist(c, ch); |
| 86 | 4128 c->c_infunction = 1; |
| 69 | 4129 com_node(c, CHILD(n, 4)); |
| 86 | 4130 c->c_infunction = 0; |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4131 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4132 com_push(c, 1); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4133 com_addbyte(c, RETURN_VALUE); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4134 com_pop(c, 1); |
| 69 | 4135 } |
| 4136 | |
| 4137 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4138 compile_lambdef(struct compiling *c, node *n) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
4139 { |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4140 node *ch; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4141 REQ(n, lambdef); /* lambdef: 'lambda' [varargslist] ':' test */ |
|
2005
ed5d0ad5ea2f
set name to <lambda> instead of None for lambdas
Guido van Rossum <guido@python.org>
parents:
1833
diff
changeset
|
4142 c->c_name = "<lambda>"; |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4143 |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4144 ch = CHILD(n, 1); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4145 (void) com_addconst(c, Py_None); /* No docstring */ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4146 if (TYPE(ch) == varargslist) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4147 com_arglist(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4148 ch = CHILD(n, 3); |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4149 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4150 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4151 ch = CHILD(n, 2); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
4152 com_node(c, ch); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
4153 com_addbyte(c, RETURN_VALUE); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4154 com_pop(c, 1); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
4155 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
4156 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
4157 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4158 compile_classdef(struct compiling *c, node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4159 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4160 node *ch; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4161 PyObject *doc; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4162 REQ(n, classdef); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4163 /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4164 c->c_name = STR(CHILD(n, 1)); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4165 c->c_private = c->c_name; |
|
21725
5d2bfbd47f1b
A tentative fix for SF bug #503837 (Roeland Rengelink):
Guido van Rossum <guido@python.org>
parents:
21609
diff
changeset
|
4166 /* Initialize local __module__ from global __name__ */ |
|
5d2bfbd47f1b
A tentative fix for SF bug #503837 (Roeland Rengelink):
Guido van Rossum <guido@python.org>
parents:
21609
diff
changeset
|
4167 com_addop_name(c, LOAD_GLOBAL, "__name__"); |
|
5d2bfbd47f1b
A tentative fix for SF bug #503837 (Roeland Rengelink):
Guido van Rossum <guido@python.org>
parents:
21609
diff
changeset
|
4168 com_addop_name(c, STORE_NAME, "__module__"); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4169 ch = CHILD(n, NCH(n)-1); /* The suite */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19252
diff
changeset
|
4170 doc = get_docstring(c, ch); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4171 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4172 int i = com_addconst(c, doc); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4173 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4174 com_addoparg(c, LOAD_CONST, i); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4175 com_push(c, 1); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4176 com_addop_name(c, STORE_NAME, "__doc__"); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4177 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4178 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4179 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4180 (void) com_addconst(c, Py_None); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4181 com_node(c, ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4182 com_addbyte(c, LOAD_LOCALS); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4183 com_push(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4184 com_addbyte(c, RETURN_VALUE); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4185 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4186 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4187 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4188 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4189 compile_node(struct compiling *c, node *n) |
| 69 | 4190 { |
| 24844 | 4191 com_set_lineno(c, n->n_lineno); |
| 86 | 4192 |
| 69 | 4193 switch (TYPE(n)) { |
| 4194 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4195 case single_input: /* One interactive command */ |
| 69 | 4196 /* NEWLINE | simple_stmt | compound_stmt NEWLINE */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
4197 c->c_interactive++; |
| 69 | 4198 n = CHILD(n, 0); |
| 4199 if (TYPE(n) != NEWLINE) | |
| 4200 com_node(c, n); | |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4201 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4202 com_push(c, 1); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4203 com_addbyte(c, RETURN_VALUE); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4204 com_pop(c, 1); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
4205 c->c_interactive--; |
| 69 | 4206 break; |
| 4207 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4208 case file_input: /* A whole file, or built-in function exec() */ |
| 69 | 4209 com_file_input(c, n); |
|
25078
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4210 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None)); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4211 com_push(c, 1); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4212 com_addbyte(c, RETURN_VALUE); |
|
be2868a63ed5
Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
24858
diff
changeset
|
4213 com_pop(c, 1); |
| 69 | 4214 break; |
| 4215 | |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4216 case eval_input: /* Built-in function input() */ |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4217 com_node(c, CHILD(n, 0)); |
|
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4218 com_addbyte(c, RETURN_VALUE); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
4219 com_pop(c, 1); |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4220 break; |
|
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4221 |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4222 case lambdef: /* anonymous function definition */ |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4223 compile_lambdef(c, n); |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4224 break; |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4225 |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4226 case funcdef: /* A function definition */ |
| 69 | 4227 compile_funcdef(c, n); |
| 4228 break; | |
| 4229 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
4230 case classdef: /* A class definition */ |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
4231 compile_classdef(c, n); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4232 break; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
4233 |
| 69 | 4234 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4235 com_error(c, PyExc_SystemError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
4236 "compile_node: unexpected node type"); |
| 69 | 4237 } |
| 4238 } | |
| 4239 | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4240 static PyObject * |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4241 dict_keys_inorder(PyObject *dict, int offset) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4242 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4243 PyObject *tuple, *k, *v; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4244 int i, pos = 0, size = PyDict_Size(dict); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4245 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4246 tuple = PyTuple_New(size); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4247 if (tuple == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4248 return NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4249 while (PyDict_Next(dict, &pos, &k, &v)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4250 i = PyInt_AS_LONG(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4251 Py_INCREF(k); |
|
17078
7e181eba6b9b
Fixup handling of free variables in methods when the class scope also
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17076
diff
changeset
|
4252 assert((i - offset) < size); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4253 PyTuple_SET_ITEM(tuple, i - offset, k); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4254 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4255 return tuple; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4256 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4257 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4258 PyCodeObject * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
4259 PyNode_Compile(node *n, const char *filename) |
| 69 | 4260 { |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4261 return PyNode_CompileFlags(n, filename, NULL); |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4262 } |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4263 |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4264 PyCodeObject * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
4265 PyNode_CompileFlags(node *n, const char *filename, PyCompilerFlags *flags) |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4266 { |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4267 return jcompile(n, filename, NULL, flags); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4268 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4269 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4270 struct symtable * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
4271 PyNode_CompileSymtable(node *n, const char *filename) |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4272 { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4273 struct symtable *st; |
|
17112
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4274 PyFutureFeatures *ff; |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4275 |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4276 ff = PyNode_Future(n, filename); |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4277 if (ff == NULL) |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4278 return NULL; |
|
20867
40a88989d6cb
Part of SF bug #478003 possible memory leaks in err handling.
Tim Peters <tim.peters@gmail.com>
parents:
20517
diff
changeset
|
4279 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4280 st = symtable_init(); |
|
20867
40a88989d6cb
Part of SF bug #478003 possible memory leaks in err handling.
Tim Peters <tim.peters@gmail.com>
parents:
20517
diff
changeset
|
4281 if (st == NULL) { |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24373
diff
changeset
|
4282 PyObject_FREE((void *)ff); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4283 return NULL; |
|
20867
40a88989d6cb
Part of SF bug #478003 possible memory leaks in err handling.
Tim Peters <tim.peters@gmail.com>
parents:
20517
diff
changeset
|
4284 } |
|
17112
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4285 st->st_future = ff; |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4286 symtable_enter_scope(st, TOP, TYPE(n), n->n_lineno); |
|
17112
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4287 if (st->st_errors > 0) |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4288 goto fail; |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4289 symtable_node(st, n); |
|
17112
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4290 if (st->st_errors > 0) |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4291 goto fail; |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4292 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4293 return st; |
|
17112
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4294 fail: |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24373
diff
changeset
|
4295 PyObject_FREE((void *)ff); |
|
17112
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4296 st->st_future = NULL; |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4297 PySymtable_Free(st); |
|
76eab2ebce58
Update PyNode_CompileSymtable() to understand future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17104
diff
changeset
|
4298 return NULL; |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4299 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4300 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4301 static PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4302 icompile(node *n, struct compiling *base) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4303 { |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4304 return jcompile(n, base->c_filename, base, NULL); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4305 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4306 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4307 static PyCodeObject * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
4308 jcompile(node *n, const char *filename, struct compiling *base, |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4309 PyCompilerFlags *flags) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4310 { |
| 69 | 4311 struct compiling sc; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4312 PyCodeObject *co; |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
4313 if (!com_init(&sc, filename)) |
| 69 | 4314 return NULL; |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4315 if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) { |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4316 sc.c_encoding = "utf-8"; |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27712
diff
changeset
|
4317 } else if (TYPE(n) == encoding_decl) { |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4318 sc.c_encoding = STR(n); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4319 n = CHILD(n, 0); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4320 } else { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4321 sc.c_encoding = NULL; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4322 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4323 if (base) { |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4324 sc.c_private = base->c_private; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4325 sc.c_symtable = base->c_symtable; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4326 /* c_symtable still points to parent's symbols */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4327 if (base->c_nested |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4328 || (sc.c_symtable->st_cur->ste_type == TYPE_FUNCTION)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4329 sc.c_nested = 1; |
|
20491
149a65fa427c
Fix computation of stack depth for classdef and closures.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20432
diff
changeset
|
4330 sc.c_flags |= base->c_flags & PyCF_MASK; |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4331 if (base->c_encoding != NULL) { |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4332 assert(sc.c_encoding == NULL); |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4333 sc.c_encoding = base->c_encoding; |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
4334 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4335 } else { |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
4336 sc.c_private = NULL; |
|
16799
08d937107fe6
Improved __future__ parser; still more to do
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16783
diff
changeset
|
4337 sc.c_future = PyNode_Future(n, filename); |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4338 if (sc.c_future == NULL) { |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4339 com_free(&sc); |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4340 return NULL; |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4341 } |
|
19252
fbf1ae769306
Fix SF bug [ #450909 ] __future__.division fails at prompt
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19187
diff
changeset
|
4342 if (flags) { |
|
fbf1ae769306
Fix SF bug [ #450909 ] __future__.division fails at prompt
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19187
diff
changeset
|
4343 int merged = sc.c_future->ff_features | |
|
fbf1ae769306
Fix SF bug [ #450909 ] __future__.division fails at prompt
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19187
diff
changeset
|
4344 flags->cf_flags; |
|
fbf1ae769306
Fix SF bug [ #450909 ] __future__.division fails at prompt
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19187
diff
changeset
|
4345 sc.c_future->ff_features = merged; |
|
fbf1ae769306
Fix SF bug [ #450909 ] __future__.division fails at prompt
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19187
diff
changeset
|
4346 flags->cf_flags = merged; |
|
fbf1ae769306
Fix SF bug [ #450909 ] __future__.division fails at prompt
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19187
diff
changeset
|
4347 } |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
4348 if (symtable_build(&sc, n) < 0) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4349 com_free(&sc); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4350 return NULL; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4351 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4352 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4353 co = NULL; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4354 if (symtable_load_symbols(&sc) < 0) { |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4355 sc.c_errors++; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4356 goto exit; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4357 } |
| 69 | 4358 compile_node(&sc, n); |
| 4359 com_done(&sc); | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
4360 if (sc.c_errors == 0) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4361 PyObject *consts, *names, *varnames, *filename, *name, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4362 *freevars, *cellvars; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4363 consts = PyList_AsTuple(sc.c_consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4364 names = PyList_AsTuple(sc.c_names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4365 varnames = PyList_AsTuple(sc.c_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4366 cellvars = dict_keys_inorder(sc.c_cellvars, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4367 freevars = dict_keys_inorder(sc.c_freevars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4368 PyTuple_GET_SIZE(cellvars)); |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
4369 filename = PyString_InternFromString(sc.c_filename); |
|
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
4370 name = PyString_InternFromString(sc.c_name); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4371 if (!PyErr_Occurred()) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4372 co = PyCode_New(sc.c_argcount, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4373 sc.c_nlocals, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4374 sc.c_maxstacklevel, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4375 sc.c_flags, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4376 sc.c_code, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4377 consts, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4378 names, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4379 varnames, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4380 freevars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4381 cellvars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4382 filename, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4383 name, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4384 sc.c_firstlineno, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4385 sc.c_lnotab); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4386 Py_XDECREF(consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4387 Py_XDECREF(names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4388 Py_XDECREF(varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4389 Py_XDECREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4390 Py_XDECREF(cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4391 Py_XDECREF(filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
4392 Py_XDECREF(name); |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
4393 } |
|
13884
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4394 else if (!PyErr_Occurred()) { |
|
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4395 /* This could happen if someone called PyErr_Clear() after an |
|
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4396 error was reported above. That's not supposed to happen, |
|
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4397 but I just plugged one case and I'm not sure there can't be |
|
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4398 others. In that case, raise SystemError so that at least |
|
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4399 it gets reported instead dumping core. */ |
|
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4400 PyErr_SetString(PyExc_SystemError, "lost syntax error"); |
|
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
4401 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4402 exit: |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
4403 if (base == NULL) { |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4404 PySymtable_Free(sc.c_symtable); |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
4405 sc.c_symtable = NULL; |
|
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
4406 } |
| 69 | 4407 com_free(&sc); |
| 4408 return co; | |
| 4409 } | |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4410 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4411 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
4412 PyCode_Addr2Line(PyCodeObject *co, int addrq) |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4413 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4414 int size = PyString_Size(co->co_lnotab) / 2; |
| 11290 | 4415 unsigned char *p = (unsigned char*)PyString_AsString(co->co_lnotab); |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4416 int line = co->co_firstlineno; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4417 int addr = 0; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4418 while (--size >= 0) { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4419 addr += *p++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4420 if (addr > addrq) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4421 break; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4422 line += *p++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4423 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4424 return line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
4425 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4426 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4427 /* The test for LOCAL must come before the test for FREE in order to |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4428 handle classes where name is both local and free. The local var is |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4429 a method and the free var is a free var referenced within a method. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4430 */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4431 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4432 static int |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4433 get_ref_type(struct compiling *c, char *name) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4434 { |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4435 char buf[350]; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4436 PyObject *v; |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4437 |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4438 if (PyDict_GetItemString(c->c_cellvars, name) != NULL) |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4439 return CELL; |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4440 if (PyDict_GetItemString(c->c_locals, name) != NULL) |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4441 return LOCAL; |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4442 if (PyDict_GetItemString(c->c_freevars, name) != NULL) |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4443 return FREE; |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4444 v = PyDict_GetItemString(c->c_globals, name); |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4445 if (v) { |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4446 if (v == Py_None) |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4447 return GLOBAL_EXPLICIT; |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4448 else { |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4449 return GLOBAL_IMPLICIT; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4450 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4451 } |
|
21066
225c7dd17e37
Fixes for possible buffer overflows in sprintf() usages.
Marc-André Lemburg <mal@egenix.com>
parents:
20947
diff
changeset
|
4452 PyOS_snprintf(buf, sizeof(buf), |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4453 "unknown scope for %.100s in %.100s(%s) " |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4454 "in %s\nsymbols: %s\nlocals: %s\nglobals: %s\n", |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4455 name, c->c_name, |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4456 PyObject_REPR(c->c_symtable->st_cur->ste_id), |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4457 c->c_filename, |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4458 PyObject_REPR(c->c_symtable->st_cur->ste_symbols), |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4459 PyObject_REPR(c->c_locals), |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4460 PyObject_REPR(c->c_globals) |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4461 ); |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4462 |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4463 Py_FatalError(buf); |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4464 return -1; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4465 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4466 |
|
16933
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4467 /* Helper functions to issue warnings */ |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4468 |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4469 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26319
diff
changeset
|
4470 issue_warning(const char *msg, const char *filename, int lineno) |
|
16933
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4471 { |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4472 if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, filename, |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4473 lineno, NULL, NULL) < 0) { |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4474 if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) { |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4475 PyErr_SetString(PyExc_SyntaxError, msg); |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4476 PyErr_SyntaxLocation(filename, lineno); |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4477 } |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4478 return -1; |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4479 } |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4480 return 0; |
|
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4481 } |
|
16855
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4482 |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4483 static int |
|
16855
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4484 symtable_warn(struct symtable *st, char *msg) |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4485 { |
|
16933
b046a31af2e0
Refactored the warning-issuing code more.
Guido van Rossum <guido@python.org>
parents:
16916
diff
changeset
|
4486 if (issue_warning(msg, st->st_filename, st->st_cur->ste_lineno) < 0) { |
|
16855
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4487 st->st_errors++; |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4488 return -1; |
|
16855
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4489 } |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4490 return 0; |
|
16855
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4491 } |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4492 |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
4493 /* Helper function for setting lineno and filename */ |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
4494 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4495 static int |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4496 symtable_build(struct compiling *c, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4497 { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4498 if ((c->c_symtable = symtable_init()) == NULL) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4499 return -1; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
4500 c->c_symtable->st_future = c->c_future; |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
4501 c->c_symtable->st_filename = c->c_filename; |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4502 symtable_enter_scope(c->c_symtable, TOP, TYPE(n), n->n_lineno); |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4503 if (c->c_symtable->st_errors > 0) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4504 return -1; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4505 symtable_node(c->c_symtable, n); |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
4506 if (c->c_symtable->st_errors > 0) |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
4507 return -1; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4508 /* reset for second pass */ |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4509 c->c_symtable->st_nscopes = 1; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4510 c->c_symtable->st_pass = 2; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4511 return 0; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4512 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4513 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4514 static int |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4515 symtable_init_compiling_symbols(struct compiling *c) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4516 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4517 PyObject *varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4518 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4519 varnames = c->c_symtable->st_cur->ste_varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4520 if (varnames == NULL) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4521 varnames = PyList_New(0); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4522 if (varnames == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4523 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4524 c->c_symtable->st_cur->ste_varnames = varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4525 Py_INCREF(varnames); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4526 } else |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4527 Py_INCREF(varnames); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4528 c->c_varnames = varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4529 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4530 c->c_globals = PyDict_New(); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4531 if (c->c_globals == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4532 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4533 c->c_freevars = PyDict_New(); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4534 if (c->c_freevars == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4535 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4536 c->c_cellvars = PyDict_New(); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4537 if (c->c_cellvars == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4538 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4539 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4540 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4541 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4542 struct symbol_info { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4543 int si_nlocals; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4544 int si_ncells; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4545 int si_nfrees; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4546 int si_nimplicit; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4547 }; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4548 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4549 static void |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4550 symtable_init_info(struct symbol_info *si) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4551 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4552 si->si_nlocals = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4553 si->si_ncells = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4554 si->si_nfrees = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4555 si->si_nimplicit = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4556 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4557 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4558 static int |
|
17637
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4559 symtable_resolve_free(struct compiling *c, PyObject *name, int flags, |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4560 struct symbol_info *si) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4561 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4562 PyObject *dict, *v; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4563 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4564 /* Seperate logic for DEF_FREE. If it occurs in a function, |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4565 it indicates a local that we must allocate storage for (a |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4566 cell var). If it occurs in a class, then the class has a |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4567 method and a free variable with the same name. |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4568 */ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4569 if (c->c_symtable->st_cur->ste_type == TYPE_FUNCTION) { |
|
17637
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4570 /* If it isn't declared locally, it can't be a cell. */ |
|
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4571 if (!(flags & (DEF_LOCAL | DEF_PARAM))) |
|
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4572 return 0; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4573 v = PyInt_FromLong(si->si_ncells++); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4574 dict = c->c_cellvars; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4575 } else { |
|
17637
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4576 /* If it is free anyway, then there is no need to do |
|
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4577 anything here. |
|
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4578 */ |
|
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4579 if (is_free(flags ^ DEF_FREE_CLASS) |
|
17702
e3f0fd38c24b
Several small changes. Mostly reformatting, adding parens.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17637
diff
changeset
|
4580 || (flags == DEF_FREE_CLASS)) |
|
17637
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4581 return 0; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4582 v = PyInt_FromLong(si->si_nfrees++); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4583 dict = c->c_freevars; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4584 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4585 if (v == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4586 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4587 if (PyDict_SetItem(dict, name, v) < 0) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4588 Py_DECREF(v); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4589 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4590 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4591 Py_DECREF(v); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4592 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4593 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4594 |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4595 /* If a variable is a cell and an argument, make sure that appears in |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4596 co_cellvars before any variable to its right in varnames. |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4597 */ |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4598 |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4599 |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4600 static int |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4601 symtable_cellvar_offsets(PyObject **cellvars, int argcount, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4602 PyObject *varnames, int flags) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4603 { |
|
28402
5f5364ac4adb
symtable_cellvar_offsets(): This leaked references to little integers
Tim Peters <tim.peters@gmail.com>
parents:
27846
diff
changeset
|
4604 PyObject *v = NULL; |
|
5f5364ac4adb
symtable_cellvar_offsets(): This leaked references to little integers
Tim Peters <tim.peters@gmail.com>
parents:
27846
diff
changeset
|
4605 PyObject *w, *d, *list = NULL; |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4606 int i, pos; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4607 |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4608 if (flags & CO_VARARGS) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4609 argcount++; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4610 if (flags & CO_VARKEYWORDS) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4611 argcount++; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4612 for (i = argcount; --i >= 0; ) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4613 v = PyList_GET_ITEM(varnames, i); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4614 if (PyDict_GetItem(*cellvars, v)) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4615 if (list == NULL) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4616 list = PyList_New(1); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4617 if (list == NULL) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4618 return -1; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4619 PyList_SET_ITEM(list, 0, v); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4620 Py_INCREF(v); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4621 } else |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4622 PyList_Insert(list, 0, v); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4623 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4624 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4625 if (list == NULL || PyList_GET_SIZE(list) == 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4626 return 0; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4627 /* There are cellvars that are also arguments. Create a dict |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4628 to replace cellvars and put the args at the front. |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4629 */ |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4630 d = PyDict_New(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4631 for (i = PyList_GET_SIZE(list); --i >= 0; ) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4632 v = PyInt_FromLong(i); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4633 if (v == NULL) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4634 goto fail; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4635 if (PyDict_SetItem(d, PyList_GET_ITEM(list, i), v) < 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4636 goto fail; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4637 if (PyDict_DelItem(*cellvars, PyList_GET_ITEM(list, i)) < 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4638 goto fail; |
|
28402
5f5364ac4adb
symtable_cellvar_offsets(): This leaked references to little integers
Tim Peters <tim.peters@gmail.com>
parents:
27846
diff
changeset
|
4639 Py_DECREF(v); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4640 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4641 pos = 0; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4642 i = PyList_GET_SIZE(list); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4643 Py_DECREF(list); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4644 while (PyDict_Next(*cellvars, &pos, &v, &w)) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4645 w = PyInt_FromLong(i++); /* don't care about the old key */ |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4646 if (PyDict_SetItem(d, v, w) < 0) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4647 Py_DECREF(w); |
|
28402
5f5364ac4adb
symtable_cellvar_offsets(): This leaked references to little integers
Tim Peters <tim.peters@gmail.com>
parents:
27846
diff
changeset
|
4648 v = NULL; |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4649 goto fail; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4650 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4651 Py_DECREF(w); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4652 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4653 Py_DECREF(*cellvars); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4654 *cellvars = d; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4655 return 1; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4656 fail: |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4657 Py_DECREF(d); |
|
28402
5f5364ac4adb
symtable_cellvar_offsets(): This leaked references to little integers
Tim Peters <tim.peters@gmail.com>
parents:
27846
diff
changeset
|
4658 Py_XDECREF(v); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4659 return -1; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4660 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4661 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4662 static int |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4663 symtable_freevar_offsets(PyObject *freevars, int offset) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4664 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4665 PyObject *name, *v; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4666 int pos; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4667 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4668 /* The cell vars are the first elements of the closure, |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4669 followed by the free vars. Update the offsets in |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4670 c_freevars to account for number of cellvars. */ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4671 pos = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4672 while (PyDict_Next(freevars, &pos, &name, &v)) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4673 int i = PyInt_AS_LONG(v) + offset; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4674 PyObject *o = PyInt_FromLong(i); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4675 if (o == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4676 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4677 if (PyDict_SetItem(freevars, name, o) < 0) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4678 Py_DECREF(o); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4679 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4680 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4681 Py_DECREF(o); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4682 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4683 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4684 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4685 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4686 static int |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4687 symtable_check_unoptimized(struct compiling *c, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4688 PySymtableEntryObject *ste, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4689 struct symbol_info *si) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4690 { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4691 char buf[300]; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4692 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4693 if (!(si->si_ncells || si->si_nfrees || ste->ste_child_free |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4694 || (ste->ste_nested && si->si_nimplicit))) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4695 return 0; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4696 |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4697 #define ILLEGAL_CONTAINS "contains a nested function with free variables" |
|
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4698 |
|
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4699 #define ILLEGAL_IS "is a nested function" |
|
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4700 |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4701 #define ILLEGAL_IMPORT_STAR \ |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4702 "import * is not allowed in function '%.100s' because it %s" |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4703 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4704 #define ILLEGAL_BARE_EXEC \ |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4705 "unqualified exec is not allowed in function '%.100s' it %s" |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4706 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4707 #define ILLEGAL_EXEC_AND_IMPORT_STAR \ |
|
21834
c1d55a627897
Fix missing space between words. Bugfix candidate.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21833
diff
changeset
|
4708 "function '%.100s' uses import * and bare exec, which are illegal " \ |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4709 "because it %s" |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4710 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4711 /* XXX perhaps the linenos for these opt-breaking statements |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4712 should be stored so the exception can point to them. */ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4713 |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4714 if (ste->ste_child_free) { |
|
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4715 if (ste->ste_optimized == OPT_IMPORT_STAR) |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4716 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4717 ILLEGAL_IMPORT_STAR, |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4718 PyString_AS_STRING(ste->ste_name), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4719 ILLEGAL_CONTAINS); |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4720 else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC)) |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4721 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4722 ILLEGAL_BARE_EXEC, |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4723 PyString_AS_STRING(ste->ste_name), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4724 ILLEGAL_CONTAINS); |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4725 else { |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4726 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4727 ILLEGAL_EXEC_AND_IMPORT_STAR, |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4728 PyString_AS_STRING(ste->ste_name), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4729 ILLEGAL_CONTAINS); |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4730 } |
|
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4731 } else { |
|
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4732 if (ste->ste_optimized == OPT_IMPORT_STAR) |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4733 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4734 ILLEGAL_IMPORT_STAR, |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4735 PyString_AS_STRING(ste->ste_name), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4736 ILLEGAL_IS); |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4737 else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC)) |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4738 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4739 ILLEGAL_BARE_EXEC, |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4740 PyString_AS_STRING(ste->ste_name), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4741 ILLEGAL_IS); |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4742 else { |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4743 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4744 ILLEGAL_EXEC_AND_IMPORT_STAR, |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4745 PyString_AS_STRING(ste->ste_name), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
4746 ILLEGAL_IS); |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4747 } |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4748 } |
|
17131
1c90a1cf795c
Make error messages clearer for illegal combinations of nested
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17124
diff
changeset
|
4749 |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4750 PyErr_SetString(PyExc_SyntaxError, buf); |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4751 PyErr_SyntaxLocation(c->c_symtable->st_filename, |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4752 ste->ste_opt_lineno); |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4753 return -1; |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4754 } |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4755 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4756 static int |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4757 symtable_update_flags(struct compiling *c, PySymtableEntryObject *ste, |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4758 struct symbol_info *si) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4759 { |
|
19158
97a3d3d7029f
Refactor future feature handling
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19051
diff
changeset
|
4760 if (c->c_future) |
|
97a3d3d7029f
Refactor future feature handling
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19051
diff
changeset
|
4761 c->c_flags |= c->c_future->ff_features; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
4762 if (ste->ste_generator) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
4763 c->c_flags |= CO_GENERATOR; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4764 if (ste->ste_type != TYPE_MODULE) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4765 c->c_flags |= CO_NEWLOCALS; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4766 if (ste->ste_type == TYPE_FUNCTION) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4767 c->c_nlocals = si->si_nlocals; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4768 if (ste->ste_optimized == 0) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4769 c->c_flags |= CO_OPTIMIZED; |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4770 else if (ste->ste_optimized != OPT_EXEC) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4771 return symtable_check_unoptimized(c, ste, si); |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4772 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4773 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4774 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4775 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4776 static int |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4777 symtable_load_symbols(struct compiling *c) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4778 { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4779 struct symtable *st = c->c_symtable; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4780 PySymtableEntryObject *ste = st->st_cur; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4781 PyObject *name, *varnames, *v; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4782 int i, flags, pos; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4783 struct symbol_info si; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4784 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4785 v = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4786 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4787 if (symtable_init_compiling_symbols(c) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4788 goto fail; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4789 symtable_init_info(&si); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4790 varnames = st->st_cur->ste_varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4791 si.si_nlocals = PyList_GET_SIZE(varnames); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4792 c->c_argcount = si.si_nlocals; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4793 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4794 for (i = 0; i < si.si_nlocals; ++i) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4795 v = PyInt_FromLong(i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4796 if (PyDict_SetItem(c->c_locals, |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4797 PyList_GET_ITEM(varnames, i), v) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4798 goto fail; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4799 Py_DECREF(v); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4800 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4801 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4802 /* XXX The cases below define the rules for whether a name is |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4803 local or global. The logic could probably be clearer. */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4804 pos = 0; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4805 while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) { |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4806 flags = PyInt_AS_LONG(v); |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4807 |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4808 if (flags & DEF_FREE_GLOBAL) |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4809 /* undo the original DEF_FREE */ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4810 flags &= ~(DEF_FREE | DEF_FREE_CLASS); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4811 |
|
17078
7e181eba6b9b
Fixup handling of free variables in methods when the class scope also
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17076
diff
changeset
|
4812 /* Deal with names that need two actions: |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4813 1. Cell variables that are also locals. |
|
17078
7e181eba6b9b
Fixup handling of free variables in methods when the class scope also
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17076
diff
changeset
|
4814 2. Free variables in methods that are also class |
|
7e181eba6b9b
Fixup handling of free variables in methods when the class scope also
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17076
diff
changeset
|
4815 variables or declared global. |
|
7e181eba6b9b
Fixup handling of free variables in methods when the class scope also
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17076
diff
changeset
|
4816 */ |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4817 if (flags & (DEF_FREE | DEF_FREE_CLASS)) |
|
17637
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4818 symtable_resolve_free(c, name, flags, &si); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4819 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4820 if (flags & DEF_STAR) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4821 c->c_argcount--; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4822 c->c_flags |= CO_VARARGS; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4823 } else if (flags & DEF_DOUBLESTAR) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4824 c->c_argcount--; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4825 c->c_flags |= CO_VARKEYWORDS; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4826 } else if (flags & DEF_INTUPLE) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4827 c->c_argcount--; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4828 else if (flags & DEF_GLOBAL) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4829 if (flags & DEF_PARAM) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4830 PyErr_Format(PyExc_SyntaxError, LOCAL_GLOBAL, |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
4831 PyString_AS_STRING(name)); |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
4832 PyErr_SyntaxLocation(st->st_filename, |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4833 ste->ste_lineno); |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4834 st->st_errors++; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4835 goto fail; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4836 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4837 if (PyDict_SetItem(c->c_globals, name, Py_None) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4838 goto fail; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4839 } else if (flags & DEF_FREE_GLOBAL) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4840 si.si_nimplicit++; |
|
26701
45ab31127bf9
SF # 654960, remove unnecessary static variable
Neal Norwitz <nnorwitz@gmail.com>
parents:
26670
diff
changeset
|
4841 if (PyDict_SetItem(c->c_globals, name, Py_True) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4842 goto fail; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4843 } else if ((flags & DEF_LOCAL) && !(flags & DEF_PARAM)) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4844 v = PyInt_FromLong(si.si_nlocals++); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4845 if (v == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4846 goto fail; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4847 if (PyDict_SetItem(c->c_locals, name, v) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4848 goto fail; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4849 Py_DECREF(v); |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4850 if (ste->ste_type != TYPE_CLASS) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4851 if (PyList_Append(c->c_varnames, name) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4852 goto fail; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4853 } else if (is_free(flags)) { |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4854 if (ste->ste_nested) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4855 v = PyInt_FromLong(si.si_nfrees++); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4856 if (v == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4857 goto fail; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4858 if (PyDict_SetItem(c->c_freevars, name, v) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4859 goto fail; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4860 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4861 } else { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4862 si.si_nimplicit++; |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4863 if (PyDict_SetItem(c->c_globals, name, |
|
26701
45ab31127bf9
SF # 654960, remove unnecessary static variable
Neal Norwitz <nnorwitz@gmail.com>
parents:
26670
diff
changeset
|
4864 Py_True) < 0) |
|
19177
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4865 goto fail; |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4866 if (st->st_nscopes != 1) { |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4867 v = PyInt_FromLong(flags); |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4868 if (PyDict_SetItem(st->st_global, |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4869 name, v)) |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4870 goto fail; |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4871 Py_DECREF(v); |
|
50f88ee71d45
Remove st_nested_scopes from struct symtable,
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19160
diff
changeset
|
4872 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4873 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4874 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4875 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4876 |
|
17637
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4877 assert(PyDict_Size(c->c_freevars) == si.si_nfrees); |
|
8ff76cf30a8c
Fix 2.1 nested scopes crash reported by Evan Simpson
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17597
diff
changeset
|
4878 |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4879 if (si.si_ncells > 1) { /* one cell is always in order */ |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4880 if (symtable_cellvar_offsets(&c->c_cellvars, c->c_argcount, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4881 c->c_varnames, c->c_flags) < 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4882 return -1; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17078
diff
changeset
|
4883 } |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4884 if (symtable_freevar_offsets(c->c_freevars, si.si_ncells) < 0) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4885 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4886 return symtable_update_flags(c, ste, &si); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4887 fail: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4888 /* is this always the right thing to do? */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4889 Py_XDECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4890 return -1; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4891 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4892 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4893 static struct symtable * |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4894 symtable_init() |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4895 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4896 struct symtable *st; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4897 |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24373
diff
changeset
|
4898 st = (struct symtable *)PyObject_MALLOC(sizeof(struct symtable)); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4899 if (st == NULL) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4900 return NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4901 st->st_pass = 1; |
|
19160
9d024ae05837
st_nested_scopes was uninitialized trash. Jeremy should fix in a better
Tim Peters <tim.peters@gmail.com>
parents:
19158
diff
changeset
|
4902 |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
4903 st->st_filename = NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4904 if ((st->st_stack = PyList_New(0)) == NULL) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4905 goto fail; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4906 if ((st->st_symbols = PyDict_New()) == NULL) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4907 goto fail; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4908 st->st_cur = NULL; |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4909 st->st_nscopes = 0; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4910 st->st_errors = 0; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4911 st->st_tmpname = 0; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4912 st->st_private = NULL; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4913 return st; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4914 fail: |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4915 PySymtable_Free(st); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4916 return NULL; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4917 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4918 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4919 void |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4920 PySymtable_Free(struct symtable *st) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4921 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4922 Py_XDECREF(st->st_symbols); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4923 Py_XDECREF(st->st_stack); |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
4924 Py_XDECREF(st->st_cur); |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24373
diff
changeset
|
4925 PyObject_FREE((void *)st); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4926 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4927 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4928 /* When the compiler exits a scope, it must should update the scope's |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4929 free variable information with the list of free variables in its |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4930 children. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4931 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4932 Variables that are free in children and defined in the current |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4933 scope are cellvars. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4934 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4935 If the scope being exited is defined at the top-level (ste_nested is |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4936 false), free variables in children that are not defined here are |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4937 implicit globals. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4938 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4939 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4940 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4941 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4942 symtable_update_free_vars(struct symtable *st) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4943 { |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4944 int i, j, def; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4945 PyObject *o, *name, *list = NULL; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4946 PySymtableEntryObject *child, *ste = st->st_cur; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4947 |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4948 if (ste->ste_type == TYPE_CLASS) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4949 def = DEF_FREE_CLASS; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4950 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4951 def = DEF_FREE; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4952 for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4953 int pos = 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4954 |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4955 if (list) |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4956 PyList_SetSlice(list, 0, |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4957 ((PyVarObject*)list)->ob_size, 0); |
|
16754
23c7a0108f59
symtable_update_free_vars(), symtable_undo_free(),
Barry Warsaw <barry@python.org>
parents:
16753
diff
changeset
|
4958 child = (PySymtableEntryObject *) |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4959 PyList_GET_ITEM(ste->ste_children, i); |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4960 while (PyDict_Next(child->ste_symbols, &pos, &name, &o)) { |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4961 int flags = PyInt_AS_LONG(o); |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4962 if (!(is_free(flags))) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4963 continue; /* avoids indentation */ |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4964 if (list == NULL) { |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4965 list = PyList_New(0); |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4966 if (list == NULL) |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4967 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4968 } |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4969 ste->ste_child_free = 1; |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4970 if (PyList_Append(list, name) < 0) { |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4971 Py_DECREF(list); |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4972 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4973 } |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4974 } |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4975 for (j = 0; list && j < PyList_GET_SIZE(list); j++) { |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4976 PyObject *v; |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4977 name = PyList_GET_ITEM(list, j); |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4978 v = PyDict_GetItem(ste->ste_symbols, name); |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4979 /* If a name N is declared global in scope A and |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4980 referenced in scope B contained (perhaps |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4981 indirectly) in A and there are no scopes |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4982 with bindings for N between B and A, then N |
|
17702
e3f0fd38c24b
Several small changes. Mostly reformatting, adding parens.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17637
diff
changeset
|
4983 is global in B. Unless A is a class scope, |
|
e3f0fd38c24b
Several small changes. Mostly reformatting, adding parens.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17637
diff
changeset
|
4984 because class scopes are not considered for |
|
e3f0fd38c24b
Several small changes. Mostly reformatting, adding parens.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17637
diff
changeset
|
4985 nested scopes. |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4986 */ |
|
17078
7e181eba6b9b
Fixup handling of free variables in methods when the class scope also
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17076
diff
changeset
|
4987 if (v && (ste->ste_type != TYPE_CLASS)) { |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4988 int flags = PyInt_AS_LONG(v); |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4989 if (flags & DEF_GLOBAL) { |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4990 symtable_undo_free(st, child->ste_id, |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4991 name); |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4992 continue; |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4993 } |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4994 } |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4995 if (ste->ste_nested) { |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4996 if (symtable_add_def_o(st, ste->ste_symbols, |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4997 name, def) < 0) { |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4998 Py_DECREF(list); |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4999 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
5000 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5001 } else { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5002 if (symtable_check_global(st, child->ste_id, |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
5003 name) < 0) { |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
5004 Py_DECREF(list); |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
5005 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
5006 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5007 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5008 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5009 } |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
5010 |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
5011 Py_XDECREF(list); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5012 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5013 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5014 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5015 /* If the current scope is a non-nested class or if name is not |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5016 defined in the current, non-nested scope, then it is an implicit |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5017 global in all nested scopes. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5018 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5019 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5020 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5021 symtable_check_global(struct symtable *st, PyObject *child, PyObject *name) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5022 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5023 PyObject *o; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5024 int v; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5025 PySymtableEntryObject *ste = st->st_cur; |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
5026 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5027 if (ste->ste_type == TYPE_CLASS) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5028 return symtable_undo_free(st, child, name); |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5029 o = PyDict_GetItem(ste->ste_symbols, name); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5030 if (o == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5031 return symtable_undo_free(st, child, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5032 v = PyInt_AS_LONG(o); |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
5033 |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5034 if (is_free(v) || (v & DEF_GLOBAL)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5035 return symtable_undo_free(st, child, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5036 else |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5037 return symtable_add_def_o(st, ste->ste_symbols, |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5038 name, DEF_FREE); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5039 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5040 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5041 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5042 symtable_undo_free(struct symtable *st, PyObject *id, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5043 PyObject *name) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5044 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5045 int i, v, x; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5046 PyObject *info; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5047 PySymtableEntryObject *ste; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5048 |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5049 ste = (PySymtableEntryObject *)PyDict_GetItem(st->st_symbols, id); |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5050 if (ste == NULL) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5051 return -1; |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
5052 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5053 info = PyDict_GetItem(ste->ste_symbols, name); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5054 if (info == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5055 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5056 v = PyInt_AS_LONG(info); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5057 if (is_free(v)) { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5058 if (symtable_add_def_o(st, ste->ste_symbols, name, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5059 DEF_FREE_GLOBAL) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5060 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5061 } else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5062 /* If the name is defined here or declared global, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5063 then the recursion stops. */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5064 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5065 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5066 for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) { |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5067 PySymtableEntryObject *child; |
|
16754
23c7a0108f59
symtable_update_free_vars(), symtable_undo_free(),
Barry Warsaw <barry@python.org>
parents:
16753
diff
changeset
|
5068 child = (PySymtableEntryObject *) |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5069 PyList_GET_ITEM(ste->ste_children, i); |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5070 x = symtable_undo_free(st, child->ste_id, name); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5071 if (x < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5072 return x; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5073 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5074 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5075 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5076 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5077 /* symtable_enter_scope() gets a reference via PySymtableEntry_New(). |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5078 This reference is released when the scope is exited, via the DECREF |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5079 in symtable_exit_scope(). |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5080 */ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5081 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5082 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5083 symtable_exit_scope(struct symtable *st) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5084 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5085 int end; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5086 |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
5087 if (st->st_pass == 1) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5088 symtable_update_free_vars(st); |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5089 Py_DECREF(st->st_cur); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5090 end = PyList_GET_SIZE(st->st_stack) - 1; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5091 st->st_cur = (PySymtableEntryObject *)PyList_GET_ITEM(st->st_stack, |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5092 end); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5093 if (PySequence_DelItem(st->st_stack, end) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5094 return -1; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5095 return 0; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5096 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5097 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5098 static void |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5099 symtable_enter_scope(struct symtable *st, char *name, int type, |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5100 int lineno) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5101 { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5102 PySymtableEntryObject *prev = NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5103 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5104 if (st->st_cur) { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5105 prev = st->st_cur; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5106 if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) { |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5107 Py_DECREF(st->st_cur); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5108 st->st_errors++; |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5109 return; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5110 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5111 } |
|
16754
23c7a0108f59
symtable_update_free_vars(), symtable_undo_free(),
Barry Warsaw <barry@python.org>
parents:
16753
diff
changeset
|
5112 st->st_cur = (PySymtableEntryObject *) |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5113 PySymtableEntry_New(st, name, type, lineno); |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5114 if (strcmp(name, TOP) == 0) |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5115 st->st_global = st->st_cur->ste_symbols; |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
5116 if (prev && st->st_pass == 1) { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5117 if (PyList_Append(prev->ste_children, |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5118 (PyObject *)st->st_cur) < 0) |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5119 st->st_errors++; |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
5120 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5121 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5122 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5123 static int |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5124 symtable_lookup(struct symtable *st, char *name) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5125 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5126 char buffer[MANGLE_LEN]; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5127 PyObject *v; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5128 int flags; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5129 |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23868
diff
changeset
|
5130 if (_Py_Mangle(st->st_private, name, buffer, sizeof(buffer))) |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5131 name = buffer; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5132 v = PyDict_GetItemString(st->st_cur->ste_symbols, name); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5133 if (v == NULL) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5134 if (PyErr_Occurred()) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5135 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5136 else |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5137 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5138 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5139 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5140 flags = PyInt_AS_LONG(v); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5141 return flags; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5142 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5143 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5144 static int |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5145 symtable_add_def(struct symtable *st, char *name, int flag) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5146 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5147 PyObject *s; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5148 char buffer[MANGLE_LEN]; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5149 int ret; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5150 |
|
24858
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5151 /* Warn about None, except inside a tuple (where the assignment |
|
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5152 code already issues a warning). */ |
|
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5153 if ((flag & DEF_PARAM) && !(flag & DEF_INTUPLE) && |
|
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5154 *name == 'N' && strcmp(name, "None") == 0) |
|
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5155 { |
|
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5156 if (symtable_warn(st, "argument named None")) |
|
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5157 return -1; |
|
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5158 } |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23868
diff
changeset
|
5159 if (_Py_Mangle(st->st_private, name, buffer, sizeof(buffer))) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5160 name = buffer; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5161 if ((s = PyString_InternFromString(name)) == NULL) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5162 return -1; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5163 ret = symtable_add_def_o(st, st->st_cur->ste_symbols, s, flag); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5164 Py_DECREF(s); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5165 return ret; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5166 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5167 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5168 /* Must only be called with mangled names */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5169 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5170 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5171 symtable_add_def_o(struct symtable *st, PyObject *dict, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5172 PyObject *name, int flag) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5173 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5174 PyObject *o; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5175 int val; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5176 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5177 if ((o = PyDict_GetItem(dict, name))) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5178 val = PyInt_AS_LONG(o); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5179 if ((flag & DEF_PARAM) && (val & DEF_PARAM)) { |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5180 PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT, |
|
16394
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16357
diff
changeset
|
5181 PyString_AsString(name)); |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
5182 PyErr_SyntaxLocation(st->st_filename, |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5183 st->st_cur->ste_lineno); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5184 return -1; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5185 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5186 val |= flag; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5187 } else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5188 val = flag; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5189 o = PyInt_FromLong(val); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5190 if (PyDict_SetItem(dict, name, o) < 0) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5191 Py_DECREF(o); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5192 return -1; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5193 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5194 Py_DECREF(o); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5195 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5196 if (flag & DEF_PARAM) { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
5197 if (PyList_Append(st->st_cur->ste_varnames, name) < 0) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5198 return -1; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5199 } else if (flag & DEF_GLOBAL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5200 /* XXX need to update DEF_GLOBAL for other flags too; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5201 perhaps only DEF_FREE_GLOBAL */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5202 if ((o = PyDict_GetItem(st->st_global, name))) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5203 val = PyInt_AS_LONG(o); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5204 val |= flag; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5205 } else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5206 val = flag; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5207 o = PyInt_FromLong(val); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5208 if (PyDict_SetItem(st->st_global, name, o) < 0) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5209 Py_DECREF(o); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5210 return -1; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5211 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5212 Py_DECREF(o); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5213 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5214 return 0; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5215 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5216 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5217 #define symtable_add_use(ST, NAME) symtable_add_def((ST), (NAME), USE) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5218 |
|
18333
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
5219 /* Look for a yield stmt under n. Return 1 if found, else 0. |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
5220 This hack is used to look inside "if 0:" blocks (which are normally |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
5221 ignored) in case those are the only places a yield occurs (so that this |
|
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
5222 function is a generator). */ |
|
18274
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5223 static int |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5224 look_for_yield(node *n) |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5225 { |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5226 int i; |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5227 |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5228 for (i = 0; i < NCH(n); ++i) { |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5229 node *kid = CHILD(n, i); |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5230 |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5231 switch (TYPE(kid)) { |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5232 |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5233 case classdef: |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5234 case funcdef: |
|
18333
41243cb4ea05
Another "if 0:" hack, this time to complain about otherwise invisible
Tim Peters <tim.peters@gmail.com>
parents:
18274
diff
changeset
|
5235 case lambdef: |
|
18274
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5236 /* Stuff in nested functions and classes can't make |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5237 the parent a generator. */ |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5238 return 0; |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5239 |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5240 case yield_stmt: |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5241 return 1; |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5242 |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5243 default: |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5244 if (look_for_yield(kid)) |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5245 return 1; |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5246 } |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5247 } |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5248 return 0; |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5249 } |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5250 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5251 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5252 symtable_node(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5253 { |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5254 int i; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5255 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5256 loop: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5257 switch (TYPE(n)) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5258 case funcdef: { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5259 char *func_name = STR(CHILD(n, 1)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5260 symtable_add_def(st, func_name, DEF_LOCAL); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5261 symtable_default_args(st, CHILD(n, 2)); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5262 symtable_enter_scope(st, func_name, TYPE(n), n->n_lineno); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5263 symtable_funcdef(st, n); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5264 symtable_exit_scope(st); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5265 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5266 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5267 case lambdef: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5268 if (NCH(n) == 4) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5269 symtable_default_args(st, CHILD(n, 1)); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5270 symtable_enter_scope(st, "lambda", TYPE(n), n->n_lineno); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5271 symtable_funcdef(st, n); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5272 symtable_exit_scope(st); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5273 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5274 case classdef: { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5275 char *tmp, *class_name = STR(CHILD(n, 1)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5276 symtable_add_def(st, class_name, DEF_LOCAL); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5277 if (TYPE(CHILD(n, 2)) == LPAR) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5278 node *bases = CHILD(n, 3); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5279 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5280 for (i = 0; i < NCH(bases); i += 2) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5281 symtable_node(st, CHILD(bases, i)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5282 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5283 } |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
5284 symtable_enter_scope(st, class_name, TYPE(n), n->n_lineno); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5285 tmp = st->st_private; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5286 st->st_private = class_name; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5287 symtable_node(st, CHILD(n, NCH(n) - 1)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5288 st->st_private = tmp; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5289 symtable_exit_scope(st); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5290 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5291 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5292 case if_stmt: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5293 for (i = 0; i + 3 < NCH(n); i += 4) { |
|
18274
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5294 if (is_constant_false(NULL, (CHILD(n, i + 1)))) { |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5295 if (st->st_cur->ste_generator == 0) |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5296 st->st_cur->ste_generator = |
|
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5297 look_for_yield(CHILD(n, i+3)); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5298 continue; |
|
18274
86dab0d43b73
SF bug #436207: "if 0: yield x" is ignored.
Tim Peters <tim.peters@gmail.com>
parents:
18243
diff
changeset
|
5299 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5300 symtable_node(st, CHILD(n, i + 1)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5301 symtable_node(st, CHILD(n, i + 3)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5302 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5303 if (i + 2 < NCH(n)) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5304 symtable_node(st, CHILD(n, i + 2)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5305 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5306 case global_stmt: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5307 symtable_global(st, n); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5308 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5309 case import_stmt: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5310 symtable_import(st, n); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5311 break; |
|
16394
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16357
diff
changeset
|
5312 case exec_stmt: { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5313 st->st_cur->ste_optimized |= OPT_EXEC; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5314 symtable_node(st, CHILD(n, 1)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5315 if (NCH(n) > 2) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5316 symtable_node(st, CHILD(n, 3)); |
|
17132
55218e0495bc
Set the line number correctly for a nested function with an exec or
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17131
diff
changeset
|
5317 else { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5318 st->st_cur->ste_optimized |= OPT_BARE_EXEC; |
|
17132
55218e0495bc
Set the line number correctly for a nested function with an exec or
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17131
diff
changeset
|
5319 st->st_cur->ste_opt_lineno = n->n_lineno; |
|
55218e0495bc
Set the line number correctly for a nested function with an exec or
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17131
diff
changeset
|
5320 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5321 if (NCH(n) > 4) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5322 symtable_node(st, CHILD(n, 5)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5323 break; |
|
16394
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16357
diff
changeset
|
5324 |
|
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16357
diff
changeset
|
5325 } |
|
16680
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5326 case assert_stmt: |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5327 if (Py_OptimizeFlag) |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5328 return; |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5329 if (NCH(n) == 2) { |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5330 n = CHILD(n, 1); |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5331 goto loop; |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5332 } else { |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5333 symtable_node(st, CHILD(n, 1)); |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5334 n = CHILD(n, 3); |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5335 goto loop; |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
5336 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5337 case except_clause: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5338 if (NCH(n) == 4) |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5339 symtable_assign(st, CHILD(n, 3), 0); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5340 if (NCH(n) > 1) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5341 n = CHILD(n, 1); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5342 goto loop; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5343 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5344 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5345 case del_stmt: |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5346 symtable_assign(st, CHILD(n, 1), 0); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5347 break; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
5348 case yield_stmt: |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
5349 st->st_cur->ste_generator = 1; |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
5350 n = CHILD(n, 1); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
18065
diff
changeset
|
5351 goto loop; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5352 case expr_stmt: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5353 if (NCH(n) == 1) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5354 n = CHILD(n, 0); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5355 else { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5356 if (TYPE(CHILD(n, 1)) == augassign) { |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5357 symtable_assign(st, CHILD(n, 0), 0); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5358 symtable_node(st, CHILD(n, 2)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5359 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5360 } else { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5361 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5362 for (i = 0; i < NCH(n) - 2; i += 2) |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5363 symtable_assign(st, CHILD(n, i), 0); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5364 n = CHILD(n, NCH(n) - 1); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5365 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5366 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5367 goto loop; |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5368 case list_iter: |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5369 n = CHILD(n, 0); |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5370 if (TYPE(n) == list_for) { |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5371 st->st_tmpname++; |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5372 symtable_list_comprehension(st, n); |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5373 st->st_tmpname--; |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5374 } else { |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5375 REQ(n, list_if); |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5376 symtable_node(st, CHILD(n, 1)); |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5377 if (NCH(n) == 3) { |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5378 n = CHILD(n, 2); |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5379 goto loop; |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5380 } |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5381 } |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5382 break; |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5383 case for_stmt: |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5384 symtable_assign(st, CHILD(n, 1), 0); |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5385 for (i = 3; i < NCH(n); ++i) |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5386 if (TYPE(CHILD(n, i)) >= single_input) |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5387 symtable_node(st, CHILD(n, i)); |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5388 break; |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5389 /* The remaining cases fall through to default except in |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5390 special circumstances. This requires the individual cases |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5391 to be coded with great care, even though they look like |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5392 rather innocuous. Each case must double-check TYPE(n). |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5393 */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5394 case argument: |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5395 if (TYPE(n) == argument && NCH(n) == 3) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5396 n = CHILD(n, 2); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5397 goto loop; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5398 } |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5399 /* fall through */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5400 case listmaker: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5401 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) { |
|
17076
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5402 st->st_tmpname++; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5403 symtable_list_comprehension(st, CHILD(n, 1)); |
|
17076
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5404 symtable_node(st, CHILD(n, 0)); |
|
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5405 st->st_tmpname--; |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5406 break; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5407 } |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5408 /* fall through */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5409 case atom: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5410 if (TYPE(n) == atom && TYPE(CHILD(n, 0)) == NAME) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5411 symtable_add_use(st, STR(CHILD(n, 0))); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5412 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5413 } |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5414 /* fall through */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5415 default: |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5416 /* Walk over every non-token child with a special case |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5417 for one child. |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5418 */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5419 if (NCH(n) == 1) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5420 n = CHILD(n, 0); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5421 goto loop; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5422 } |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5423 for (i = 0; i < NCH(n); ++i) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5424 if (TYPE(CHILD(n, i)) >= single_input) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5425 symtable_node(st, CHILD(n, i)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5426 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5427 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5428 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5429 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5430 symtable_funcdef(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5431 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5432 node *body; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5433 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5434 if (TYPE(n) == lambdef) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5435 if (NCH(n) == 4) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5436 symtable_params(st, CHILD(n, 1)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5437 } else |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5438 symtable_params(st, CHILD(n, 2)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5439 body = CHILD(n, NCH(n) - 1); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5440 symtable_node(st, body); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5441 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5442 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5443 /* The next two functions parse the argument tuple. |
|
24858
592406e0c9b0
Add warnings for arguments named None. All set. (I could add a
Guido van Rossum <guido@python.org>
parents:
24856
diff
changeset
|
5444 symtable_default_args() checks for names in the default arguments, |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5445 which are references in the defining scope. symtable_params() |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5446 parses the parameter names, which are defined in the function's |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5447 body. |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5448 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5449 varargslist: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5450 (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5451 | fpdef ['=' test] (',' fpdef ['=' test])* [','] |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5452 */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5453 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5454 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5455 symtable_default_args(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5456 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5457 node *c; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5458 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5459 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5460 if (TYPE(n) == parameters) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5461 n = CHILD(n, 1); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5462 if (TYPE(n) == RPAR) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5463 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5464 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5465 REQ(n, varargslist); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5466 for (i = 0; i < NCH(n); i += 2) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5467 c = CHILD(n, i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5468 if (TYPE(c) == STAR || TYPE(c) == DOUBLESTAR) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5469 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5470 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5471 if (i > 0 && (TYPE(CHILD(n, i - 1)) == EQUAL)) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5472 symtable_node(st, CHILD(n, i)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5473 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5474 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5475 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5476 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5477 symtable_params(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5478 { |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5479 int i, complex = -1, ext = 0; |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
5480 node *c = NULL; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5481 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5482 if (TYPE(n) == parameters) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5483 n = CHILD(n, 1); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5484 if (TYPE(n) == RPAR) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5485 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5486 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5487 REQ(n, varargslist); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5488 for (i = 0; i < NCH(n); i += 2) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5489 c = CHILD(n, i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5490 if (TYPE(c) == STAR || TYPE(c) == DOUBLESTAR) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5491 ext = 1; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5492 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5493 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5494 if (TYPE(c) == test) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5495 continue; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5496 } |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
5497 if (TYPE(CHILD(c, 0)) == NAME) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5498 symtable_add_def(st, STR(CHILD(c, 0)), DEF_PARAM); |
|
26756
ccf0b027b585
Oops. Roll back that last change. It wasn't ready for release. :-(
Guido van Rossum <guido@python.org>
parents:
26754
diff
changeset
|
5499 else { |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5500 char nbuf[30]; |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5501 PyOS_snprintf(nbuf, sizeof(nbuf), ".%d", i); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5502 symtable_add_def(st, nbuf, DEF_PARAM); |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5503 complex = i; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5504 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5505 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5506 if (ext) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5507 c = CHILD(n, i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5508 if (TYPE(c) == STAR) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5509 i++; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5510 symtable_add_def(st, STR(CHILD(n, i)), |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5511 DEF_PARAM | DEF_STAR); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5512 i += 2; |
|
16137
883cb0e31bb2
prevent symtable_params() from dereferencing off the end of the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16096
diff
changeset
|
5513 if (i >= NCH(n)) |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5514 c = NULL; |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5515 else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5516 c = CHILD(n, i); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5517 } |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5518 if (c && TYPE(c) == DOUBLESTAR) { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5519 i++; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5520 symtable_add_def(st, STR(CHILD(n, i)), |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5521 DEF_PARAM | DEF_DOUBLESTAR); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5522 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5523 } |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5524 if (complex >= 0) { |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5525 int j; |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5526 for (j = 0; j <= complex; j++) { |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5527 c = CHILD(n, j); |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5528 if (TYPE(c) == COMMA) |
|
16699
7334b2cedda8
Fix for implicit tuple + default arguments, courtesy of Michael Hudson.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16680
diff
changeset
|
5529 c = CHILD(n, ++j); |
|
7334b2cedda8
Fix for implicit tuple + default arguments, courtesy of Michael Hudson.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16680
diff
changeset
|
5530 else if (TYPE(c) == EQUAL) |
|
7334b2cedda8
Fix for implicit tuple + default arguments, courtesy of Michael Hudson.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16680
diff
changeset
|
5531 c = CHILD(n, j += 3); |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5532 if (TYPE(CHILD(c, 0)) == LPAR) |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5533 symtable_params_fplist(st, CHILD(c, 1)); |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5534 } |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
5535 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5536 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5537 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5538 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5539 symtable_params_fplist(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5540 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5541 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5542 node *c; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5543 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5544 REQ(n, fplist); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5545 for (i = 0; i < NCH(n); i += 2) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5546 c = CHILD(n, i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5547 REQ(c, fpdef); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5548 if (NCH(c) == 1) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5549 symtable_add_def(st, STR(CHILD(c, 0)), |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5550 DEF_PARAM | DEF_INTUPLE); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5551 else |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5552 symtable_params_fplist(st, CHILD(c, 1)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5553 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5554 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5555 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5556 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5557 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5558 symtable_global(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5559 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5560 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5561 |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
5562 /* XXX It might be helpful to warn about module-level global |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
5563 statements, but it's hard to tell the difference between |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
5564 module-level and a string passed to exec. |
|
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16892
diff
changeset
|
5565 */ |
|
16871
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
5566 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5567 for (i = 1; i < NCH(n); i += 2) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5568 char *name = STR(CHILD(n, i)); |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5569 int flags; |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5570 |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5571 flags = symtable_lookup(st, name); |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5572 if (flags < 0) |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5573 continue; |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5574 if (flags && flags != DEF_GLOBAL) { |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5575 char buf[500]; |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5576 if (flags & DEF_PARAM) { |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5577 PyErr_Format(PyExc_SyntaxError, |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5578 "name '%.400s' is local and global", |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5579 name); |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
5580 PyErr_SyntaxLocation(st->st_filename, |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5581 st->st_cur->ste_lineno); |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5582 st->st_errors++; |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5583 return; |
|
16853
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
5584 } |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
5585 else { |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
5586 if (flags & DEF_LOCAL) |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5587 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5588 GLOBAL_AFTER_ASSIGN, |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5589 name); |
|
16853
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
5590 else |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5591 PyOS_snprintf(buf, sizeof(buf), |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5592 GLOBAL_AFTER_USE, name); |
|
16855
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
5593 symtable_warn(st, buf); |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5594 } |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
5595 } |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5596 symtable_add_def(st, name, DEF_GLOBAL); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5597 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5598 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5599 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5600 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5601 symtable_list_comprehension(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5602 { |
|
21086
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5603 char tmpname[30]; |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5604 |
|
ea5b0f0b716f
code_repr(), com_addop_varname(), com_list_comprehension(),
Barry Warsaw <barry@python.org>
parents:
21066
diff
changeset
|
5605 PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", st->st_tmpname); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5606 symtable_add_def(st, tmpname, DEF_LOCAL); |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5607 symtable_assign(st, CHILD(n, 1), 0); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5608 symtable_node(st, CHILD(n, 3)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5609 if (NCH(n) == 5) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5610 symtable_node(st, CHILD(n, 4)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5611 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5612 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5613 static void |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5614 symtable_import(struct symtable *st, node *n) |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5615 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5616 int i; |
|
16394
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16357
diff
changeset
|
5617 /* import_stmt: 'import' dotted_as_name (',' dotted_as_name)* |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5618 | 'from' dotted_name 'import' |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5619 ('*' | import_as_name (',' import_as_name)*) |
|
16394
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16357
diff
changeset
|
5620 import_as_name: NAME [NAME NAME] |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5621 */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5622 if (STR(CHILD(n, 0))[0] == 'f') { /* from */ |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5623 node *dotname = CHILD(n, 1); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5624 if (strcmp(STR(CHILD(dotname, 0)), "__future__") == 0) { |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5625 /* check for bogus imports */ |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5626 if (n->n_lineno >= st->st_future->ff_last_lineno) { |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5627 PyErr_SetString(PyExc_SyntaxError, |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5628 LATE_FUTURE); |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
5629 PyErr_SyntaxLocation(st->st_filename, |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5630 n->n_lineno); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5631 st->st_errors++; |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5632 return; |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5633 } |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5634 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5635 if (TYPE(CHILD(n, 3)) == STAR) { |
|
19018
821e35706c07
Fix SF bug [ #445474 ] warn about import * inside functions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18631
diff
changeset
|
5636 if (st->st_cur->ste_type != TYPE_MODULE) { |
|
19021
e5754f048f0b
Another bug fix for recent import * warning (caught by Thomas Wouters)
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19019
diff
changeset
|
5637 if (symtable_warn(st, |
|
e5754f048f0b
Another bug fix for recent import * warning (caught by Thomas Wouters)
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19019
diff
changeset
|
5638 "import * only allowed at module level") < 0) |
|
e5754f048f0b
Another bug fix for recent import * warning (caught by Thomas Wouters)
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19019
diff
changeset
|
5639 return; |
|
19018
821e35706c07
Fix SF bug [ #445474 ] warn about import * inside functions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18631
diff
changeset
|
5640 } |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5641 st->st_cur->ste_optimized |= OPT_IMPORT_STAR; |
|
17132
55218e0495bc
Set the line number correctly for a nested function with an exec or
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17131
diff
changeset
|
5642 st->st_cur->ste_opt_lineno = n->n_lineno; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5643 } else { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5644 for (i = 3; i < NCH(n); i += 2) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5645 node *c = CHILD(n, i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5646 if (NCH(c) > 1) /* import as */ |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5647 symtable_assign(st, CHILD(c, 2), |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5648 DEF_IMPORT); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5649 else |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5650 symtable_assign(st, CHILD(c, 0), |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5651 DEF_IMPORT); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5652 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5653 } |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5654 } else { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5655 for (i = 1; i < NCH(n); i += 2) { |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5656 symtable_assign(st, CHILD(n, i), DEF_IMPORT); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5657 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5658 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5659 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5660 |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5661 /* The third argument to symatble_assign() is a flag to be passed to |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5662 symtable_add_def() if it is eventually called. The flag is useful |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5663 to specify the particular type of assignment that should be |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5664 recorded, e.g. an assignment caused by import. |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5665 */ |
|
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5666 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5667 static void |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5668 symtable_assign(struct symtable *st, node *n, int def_flag) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5669 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5670 node *tmp; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5671 int i; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5672 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5673 loop: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5674 switch (TYPE(n)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5675 case lambdef: |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5676 /* invalid assignment, e.g. lambda x:x=2. The next |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5677 pass will catch this error. */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5678 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5679 case power: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5680 if (NCH(n) > 2) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5681 for (i = 2; i < NCH(n); ++i) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5682 if (TYPE(CHILD(n, i)) != DOUBLESTAR) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5683 symtable_node(st, CHILD(n, i)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5684 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5685 if (NCH(n) > 1) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5686 symtable_node(st, CHILD(n, 0)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5687 symtable_node(st, CHILD(n, 1)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5688 } else { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5689 n = CHILD(n, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5690 goto loop; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5691 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5692 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5693 case listmaker: |
|
17076
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5694 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) { |
|
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5695 /* XXX This is an error, but the next pass |
|
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5696 will catch it. */ |
|
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5697 return; |
|
85d74f040712
Fix crashes in nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16933
diff
changeset
|
5698 } else { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5699 for (i = 0; i < NCH(n); i += 2) |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5700 symtable_assign(st, CHILD(n, i), def_flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5701 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5702 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5703 case exprlist: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5704 case testlist: |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
23280
diff
changeset
|
5705 case testlist1: |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5706 if (NCH(n) == 1) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5707 n = CHILD(n, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5708 goto loop; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5709 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5710 else { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5711 int i; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5712 for (i = 0; i < NCH(n); i += 2) |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5713 symtable_assign(st, CHILD(n, i), def_flag); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5714 return; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5715 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5716 case atom: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5717 tmp = CHILD(n, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5718 if (TYPE(tmp) == LPAR || TYPE(tmp) == LSQB) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5719 n = CHILD(n, 1); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5720 goto loop; |
|
17185
f9a30015e8b0
Make it illegal to assign to __debug__ as per Guido's request.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17132
diff
changeset
|
5721 } else if (TYPE(tmp) == NAME) { |
|
20939
13df8b6c2b80
Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20867
diff
changeset
|
5722 if (strcmp(STR(tmp), "__debug__") == 0) { |
|
13df8b6c2b80
Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20867
diff
changeset
|
5723 PyErr_SetString(PyExc_SyntaxError, |
|
13df8b6c2b80
Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20867
diff
changeset
|
5724 ASSIGN_DEBUG); |
|
13df8b6c2b80
Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20867
diff
changeset
|
5725 PyErr_SyntaxLocation(st->st_filename, |
|
21179
485422900ef0
SF bug #488687 reported by Neal Norwitz
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21086
diff
changeset
|
5726 n->n_lineno); |
|
20939
13df8b6c2b80
Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20867
diff
changeset
|
5727 st->st_errors++; |
|
13df8b6c2b80
Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20867
diff
changeset
|
5728 } |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5729 symtable_add_def(st, STR(tmp), DEF_LOCAL | def_flag); |
|
17185
f9a30015e8b0
Make it illegal to assign to __debug__ as per Guido's request.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17132
diff
changeset
|
5730 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5731 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5732 case dotted_as_name: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5733 if (NCH(n) == 3) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5734 symtable_add_def(st, STR(CHILD(n, 2)), |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5735 DEF_LOCAL | def_flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5736 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5737 symtable_add_def(st, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5738 STR(CHILD(CHILD(n, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5739 0), 0)), |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5740 DEF_LOCAL | def_flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5741 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5742 case dotted_name: |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5743 symtable_add_def(st, STR(CHILD(n, 0)), DEF_LOCAL | def_flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5744 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5745 case NAME: |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5746 symtable_add_def(st, STR(n), DEF_LOCAL | def_flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5747 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5748 default: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5749 if (NCH(n) == 0) |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5750 return; |
|
16677
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5751 if (NCH(n) == 1) { |
|
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5752 n = CHILD(n, 0); |
|
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5753 goto loop; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5754 } |
|
16677
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5755 /* Should only occur for errors like x + 1 = 1, |
|
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5756 which will be caught in the next pass. */ |
|
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5757 for (i = 0; i < NCH(n); ++i) |
|
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5758 if (TYPE(CHILD(n, i)) >= single_input) |
|
20517
d51fe520e5fd
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20491
diff
changeset
|
5759 symtable_assign(st, CHILD(n, i), def_flag); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5760 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5761 } |
