Mercurial > cpython-lru_cache-weakref
annotate Python/compile.c @ 16892:f27d3299df39 legacy-trunk
Fix core dump in example from Samuele Pedroni:
from __future__ import nested_scopes
x=7
def f():
x=1
def g():
global x
def i():
def h():
return x
return h()
return i()
return g()
print f()
print x
This kind of code didn't work correctly because x was treated as free
in i, leading to an attempt to load x in g to make a closure for i.
Solution is to make global decl apply to nested scopes unless their is
an assignment. Thus, x in h is global.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Thu, 01 Mar 2001 06:09:34 +0000 |
| parents | 1cf52536c381 |
| children | b0456d3a0f1f |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
1 |
| 69 | 2 /* Compile an expression node to intermediate code */ |
| 3 | |
| 86 | 4 /* 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
|
5 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
|
6 XXX (it's currently the first item of the co_const tuple) |
| 86 | 7 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
|
8 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
|
9 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
|
10 XXX other JAR tricks? |
| 86 | 11 */ |
| 69 | 12 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
13 #include "Python.h" |
| 86 | 14 |
| 69 | 15 #include "node.h" |
| 16 #include "token.h" | |
| 17 #include "graminit.h" | |
| 18 #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
|
19 #include "symtable.h" |
| 69 | 20 #include "opcode.h" |
| 86 | 21 #include "structmember.h" |
| 22 | |
| 23 #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
|
24 |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
25 /* 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
|
26 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
|
27 (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
|
28 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
|
29 #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
|
30 #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
|
31 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
32 #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
|
33 #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
|
34 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
35 #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
|
36 #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
|
37 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
38 |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
39 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
|
40 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
41 #define OP_DELETE 0 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
42 #define OP_ASSIGN 1 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
43 #define OP_APPLY 2 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
44 |
|
16015
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_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
|
46 #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
|
47 #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
|
48 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
49 #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
|
50 "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
|
51 |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
52 #define DUPLICATE_ARGUMENT \ |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
53 "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
|
54 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
55 #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
|
56 "%.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
|
57 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
58 #define GLOBAL_AFTER_ASSIGN \ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
59 "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
|
60 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
61 #define GLOBAL_AFTER_USE \ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
62 "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
|
63 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
64 #define LOCAL_GLOBAL \ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
65 "name '%.400s' is a function paramter and declared global" |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
66 |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
67 #define LATE_FUTURE \ |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
68 "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
|
69 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
70 #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
|
71 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
72 #define OFF(x) offsetof(PyCodeObject, x) |
| 86 | 73 |
| 74 static struct memberlist code_memberlist[] = { | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
75 {"co_argcount", T_INT, OFF(co_argcount), READONLY}, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
76 {"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
|
77 {"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
|
78 {"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
|
79 {"co_code", T_OBJECT, OFF(co_code), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
80 {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
81 {"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
|
82 {"co_varnames", T_OBJECT, OFF(co_varnames), READONLY}, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
83 {"co_freevars", T_OBJECT, OFF(co_freevars), READONLY}, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
84 {"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
|
85 {"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
|
86 {"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
|
87 {"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
|
88 {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY}, |
| 86 | 89 {NULL} /* Sentinel */ |
| 90 }; | |
| 91 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
92 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
93 code_getattr(PyCodeObject *co, char *name) |
| 86 | 94 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
95 return PyMember_Get((char *)co, code_memberlist, name); |
| 86 | 96 } |
| 69 | 97 |
| 98 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
99 code_dealloc(PyCodeObject *co) |
| 69 | 100 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 Py_XDECREF(co->co_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
105 Py_XDECREF(co->co_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 Py_XDECREF(co->co_lnotab); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12538
diff
changeset
|
110 PyObject_DEL(co); |
| 69 | 111 } |
| 112 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
113 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
114 code_repr(PyCodeObject *co) |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
115 { |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
116 char buf[500]; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
117 int lineno = -1; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
118 char *filename = "???"; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
119 char *name = "???"; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
120 |
|
12278
647bf71912f0
Vladimir Marangozov: This fixes the line number in the string
Guido van Rossum <guido@python.org>
parents:
12086
diff
changeset
|
121 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
|
122 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
|
123 if (co->co_filename && PyString_Check(co->co_filename)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
124 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
|
125 if (co->co_name && PyString_Check(co->co_name)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
126 name = PyString_AS_STRING(co->co_name); |
|
13227
c2df5d28034d
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13096
diff
changeset
|
127 sprintf(buf, "<code object %.100s at %p, file \"%.300s\", line %d>", |
|
c2df5d28034d
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13096
diff
changeset
|
128 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
|
129 return PyString_FromString(buf); |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
130 } |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
131 |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
132 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
133 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
|
134 { |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
135 int cmp; |
|
12333
525b2358721e
Patch by Vladimir Marangozov to include the function name when
Guido van Rossum <guido@python.org>
parents:
12278
diff
changeset
|
136 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
|
137 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
|
138 cmp = co->co_argcount - cp->co_argcount; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
139 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
|
140 cmp = co->co_nlocals - cp->co_nlocals; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
141 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
|
142 cmp = co->co_flags - cp->co_flags; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
143 if (cmp) return cmp; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 if (cmp) return cmp; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
150 cmp = PyObject_Compare(co->co_varnames, cp->co_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
151 if (cmp) return cmp; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
152 cmp = PyObject_Compare(co->co_freevars, cp->co_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
153 if (cmp) return cmp; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
154 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
|
155 return cmp; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
156 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
157 |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
158 static long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
159 code_hash(PyCodeObject *co) |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
160 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 h4 = PyObject_Hash(co->co_varnames); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
171 if (h4 == -1) return -1; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
172 h5 = PyObject_Hash(co->co_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
173 if (h5 == -1) return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
174 h6 = PyObject_Hash(co->co_cellvars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
175 if (h6 == -1) return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
176 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
|
177 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
|
178 if (h == -1) h = -2; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
179 return h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
180 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
181 |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
182 /* 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
|
183 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
184 PyTypeObject PyCode_Type = { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
185 PyObject_HEAD_INIT(&PyType_Type) |
| 69 | 186 0, |
| 187 "code", | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
188 sizeof(PyCodeObject), |
| 69 | 189 0, |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
190 (destructor)code_dealloc, /*tp_dealloc*/ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
191 0, /*tp_print*/ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
192 (getattrfunc)code_getattr, /*tp_getattr*/ |
| 69 | 193 0, /*tp_setattr*/ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
194 (cmpfunc)code_compare, /*tp_compare*/ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
195 (reprfunc)code_repr, /*tp_repr*/ |
| 69 | 196 0, /*tp_as_number*/ |
| 197 0, /*tp_as_sequence*/ | |
| 198 0, /*tp_as_mapping*/ | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
199 (hashfunc)code_hash, /*tp_hash*/ |
| 69 | 200 }; |
| 201 | |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
202 #define NAME_CHARS \ |
|
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
203 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" |
|
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
204 |
|
16006
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
205 /* 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
|
206 |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
207 static int |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
208 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
|
209 { |
|
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
|
210 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
|
211 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
|
212 |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 } |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 } |
|
9d625303f914
Reindent a function that was somehow indented by 7 spaces. Also did a
Guido van Rossum <guido@python.org>
parents:
16428
diff
changeset
|
222 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
|
223 } |
|
51811d78a9da
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents:
15438
diff
changeset
|
224 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
225 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
226 intern_strings(PyObject *tuple) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
227 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
228 int i; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
229 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
230 for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
231 PyObject *v = PyTuple_GET_ITEM(tuple, i); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
232 if (v == NULL || !PyString_Check(v)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
233 Py_FatalError("non-string found in code slot"); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
234 PyErr_BadInternalCall(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
235 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
236 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
237 PyString_InternInPlace(&PyTuple_GET_ITEM(tuple, i)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
238 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
239 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
240 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
241 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
242 PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
243 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
|
244 PyObject *code, PyObject *consts, PyObject *names, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
245 PyObject *varnames, PyObject *freevars, PyObject *cellvars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
246 PyObject *filename, PyObject *name, int firstlineno, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
247 PyObject *lnotab) |
| 69 | 248 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
249 PyCodeObject *co; |
| 69 | 250 int i; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
251 PyBufferProcs *pb; |
| 69 | 252 /* Check argument types */ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
253 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
|
254 code == NULL || |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
255 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
|
256 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
|
257 varnames == NULL || !PyTuple_Check(varnames) || |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
258 freevars == NULL || !PyTuple_Check(freevars) || |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
259 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
|
260 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
|
261 filename == NULL || !PyString_Check(filename) || |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
262 lnotab == NULL || !PyString_Check(lnotab)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
263 PyErr_BadInternalCall(); |
| 69 | 264 return NULL; |
| 265 } | |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
266 pb = code->ob_type->tp_as_buffer; |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
267 if (pb == NULL || |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
268 pb->bf_getreadbuffer == NULL || |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
269 pb->bf_getsegcount == NULL || |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
270 (*pb->bf_getsegcount)(code, NULL) != 1) |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
271 { |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
272 PyErr_BadInternalCall(); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
273 return NULL; |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
274 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
275 intern_strings(names); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
276 intern_strings(varnames); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
277 if (freevars == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
278 freevars = PyTuple_New(0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
279 intern_strings(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
280 if (cellvars == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
281 cellvars = PyTuple_New(0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
282 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
|
283 /* 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
|
284 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
|
285 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
|
286 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
|
287 continue; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
288 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
|
289 continue; |
|
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
290 PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i)); |
| 69 | 291 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
292 co = PyObject_NEW(PyCodeObject, &PyCode_Type); |
| 69 | 293 if (co != NULL) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
294 co->co_argcount = argcount; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
295 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
|
296 co->co_stacksize = stacksize; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
297 co->co_flags = flags; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
298 Py_INCREF(code); |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
9215
diff
changeset
|
299 co->co_code = code; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
300 Py_INCREF(consts); |
| 69 | 301 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
|
302 Py_INCREF(names); |
| 69 | 303 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
|
304 Py_INCREF(varnames); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
305 co->co_varnames = varnames; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
306 Py_INCREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
307 co->co_freevars = freevars; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
308 Py_INCREF(cellvars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
309 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
|
310 Py_INCREF(filename); |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
311 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
|
312 Py_INCREF(name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 co->co_lnotab = lnotab; |
| 69 | 317 } |
| 318 return co; | |
| 319 } | |
| 320 | |
| 321 | |
| 322 /* Data structure used internally */ | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
323 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
324 /* 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
|
325 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
|
326 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
327 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
|
328 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
|
329 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
|
330 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
331 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
|
332 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
|
333 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
|
334 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
|
335 */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
336 |
| 69 | 337 struct compiling { |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
338 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
|
339 PyObject *c_consts; /* list of objects */ |
| 12522 | 340 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
|
341 PyObject *c_names; /* list of strings (names) */ |
| 12522 | 342 PyObject *c_name_dict; /* inverse of c_names */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
343 PyObject *c_globals; /* dictionary (value=None) */ |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
344 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
|
345 PyObject *c_varnames; /* list (inverse of c_locals) */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
346 PyObject *c_freevars; /* dictionary (value=None) */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
347 PyObject *c_cellvars; /* list */ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
348 int c_nlocals; /* index of next local */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
349 int c_argcount; /* number of top-level arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
350 int c_flags; /* same as co_flags */ |
| 69 | 351 int c_nexti; /* index into c_code */ |
| 352 int c_errors; /* counts errors occurred */ | |
| 86 | 353 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
|
354 int c_interactive; /* generating code for interactive command */ |
| 86 | 355 int c_loops; /* counts nested loops */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
356 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
|
357 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
|
358 int c_nblocks; /* current block stack level */ |
| 86 | 359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 int c_firstlineno; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
365 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
|
366 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
|
367 char *c_private; /* for private name mangling */ |
| 13936 | 368 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
|
369 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
|
370 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
|
371 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
|
372 PyFutureFeatures *c_future; /* pointer to module's __future__ */ |
| 69 | 373 }; |
| 374 | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
375 int is_free(int v) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
376 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
377 if ((v & (USE | DEF_FREE)) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
378 && !(v & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL))) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
379 return 1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
380 if (v & DEF_FREE_CLASS) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
381 return 1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
382 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
383 } |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
384 |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
385 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
386 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
|
387 { |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
388 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
|
389 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
390 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
|
391 /* 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
|
392 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
|
393 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
|
394 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
395 } |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
396 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
|
397 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
|
398 /* 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
|
399 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
|
400 return; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
401 } |
|
13993
716e1c4e3f78
When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents:
13956
diff
changeset
|
402 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
|
403 if (v == NULL) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
404 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
|
405 |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
406 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
|
407 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
|
408 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
|
409 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
|
410 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
411 t = Py_BuildValue("(ziOO)", c->c_filename, c->c_lineno, |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
412 Py_None, line); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
413 if (t == NULL) |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
414 goto exit; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
415 w = Py_BuildValue("(OO)", v, t); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
416 if (w == NULL) |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
417 goto exit; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
418 PyErr_SetObject(exc, w); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
419 exit: |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
420 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
|
421 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
|
422 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
|
423 Py_XDECREF(line); |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
424 } |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
425 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
426 /* Interface to the block stack */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
427 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
428 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
429 block_push(struct compiling *c, int type) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
430 { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
431 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
|
432 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
|
433 "too many statically nested blocks"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
434 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
435 else { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
436 c->c_block[c->c_nblocks++] = type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
437 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
438 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
439 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
440 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
441 block_pop(struct compiling *c, int type) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
442 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
443 if (c->c_nblocks > 0) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
444 c->c_nblocks--; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
445 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
|
446 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
|
447 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
448 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
449 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
450 /* Prototype forward declarations */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
451 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
452 static int com_init(struct compiling *, char *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 static void com_list(struct compiling *, node *, int); |
| 13936 | 469 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
|
470 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
|
471 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
|
472 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
|
473 static PyCodeObject *icompile(node *, struct compiling *); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
474 static PyCodeObject *jcompile(node *, char *, struct compiling *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
475 static PyObject *parsestrplus(node *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
476 static PyObject *parsestr(char *); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
477 static node *get_rawdocstring(node *); |
| 69 | 478 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
479 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
|
480 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
481 /* 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 static int symtable_add_def(struct symtable *, char *, int); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
488 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
|
489 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
500 static int symtable_update_free_vars(struct symtable *); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
501 static int symtable_undo_free(struct symtable *, PyObject *, PyObject *); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
502 static int symtable_check_global(struct symtable *, PyObject *, PyObject *); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
503 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
504 /* helper */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
505 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
|
506 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
|
507 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
512 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
513 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
|
514 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
|
515 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
516 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
|
517 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
|
518 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
519 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
|
520 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
|
521 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
|
522 depth--; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
523 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
|
524 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
|
525 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
526 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
527 #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
|
528 |
| 69 | 529 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
530 com_init(struct compiling *c, char *filename) |
| 69 | 531 { |
| 12522 | 532 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
|
533 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
|
534 1000)) == NULL) |
| 12522 | 535 goto fail; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
536 if ((c->c_consts = PyList_New(0)) == NULL) |
| 12522 | 537 goto fail; |
| 538 if ((c->c_const_dict = PyDict_New()) == NULL) | |
| 539 goto fail; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
540 if ((c->c_names = PyList_New(0)) == NULL) |
| 12522 | 541 goto fail; |
| 542 if ((c->c_name_dict = PyDict_New()) == NULL) | |
| 543 goto fail; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
544 if ((c->c_locals = PyDict_New()) == NULL) |
| 12522 | 545 goto fail; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
546 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
|
547 1000)) == NULL) |
| 12522 | 548 goto fail; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
549 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
|
550 c->c_varnames = NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
551 c->c_freevars = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
552 c->c_cellvars = NULL; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
553 c->c_nlocals = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
554 c->c_argcount = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
555 c->c_flags = 0; |
| 69 | 556 c->c_nexti = 0; |
| 557 c->c_errors = 0; | |
| 86 | 558 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
|
559 c->c_interactive = 0; |
| 86 | 560 c->c_loops = 0; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
561 c->c_begin = 0; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
562 c->c_nblocks = 0; |
| 86 | 563 c->c_filename = filename; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
564 c->c_name = "?"; |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
565 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
|
566 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
|
567 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
|
568 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
|
569 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
|
570 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
|
571 c->c_lnotab_next = 0; |
| 13936 | 572 c->c_tmpname = 0; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
573 c->c_nested = 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
574 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
|
575 c->c_symtable = NULL; |
| 69 | 576 return 1; |
| 577 | |
| 12522 | 578 fail: |
| 579 com_free(c); | |
| 69 | 580 return 0; |
| 581 } | |
| 582 | |
| 583 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
584 com_free(struct compiling *c) |
| 69 | 585 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
586 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
|
587 Py_XDECREF(c->c_consts); |
| 12522 | 588 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
|
589 Py_XDECREF(c->c_names); |
| 12522 | 590 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
|
591 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
|
592 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
|
593 Py_XDECREF(c->c_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
594 Py_XDECREF(c->c_freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
595 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
|
596 Py_XDECREF(c->c_lnotab); |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
597 if (c->c_future) |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
598 PyMem_Free((void *)c->c_future); |
| 69 | 599 } |
| 600 | |
| 601 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
602 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
|
603 { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
604 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
|
605 if (c->c_stacklevel > c->c_maxstacklevel) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
606 c->c_maxstacklevel = c->c_stacklevel; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
607 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
608 |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
609 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
610 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
|
611 { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
612 if (c->c_stacklevel < n) { |
|
9049
cbf72b2210ae
Comment out the print statement about underflow. (This only seems to
Guido van Rossum <guido@python.org>
parents:
8328
diff
changeset
|
613 /* fprintf(stderr, |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
614 "%s:%d: underflow! nexti=%d, level=%d, n=%d\n", |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
615 c->c_filename, c->c_lineno, |
|
9049
cbf72b2210ae
Comment out the print statement about underflow. (This only seems to
Guido van Rossum <guido@python.org>
parents:
8328
diff
changeset
|
616 c->c_nexti, 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
|
617 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
|
618 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
619 else |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
620 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
|
621 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
622 |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
623 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
624 com_done(struct compiling *c) |
| 69 | 625 { |
| 626 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
|
627 _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
|
628 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
|
629 _PyString_Resize(&c->c_lnotab, c->c_lnotab_next); |
| 69 | 630 } |
| 631 | |
| 632 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
633 com_addbyte(struct compiling *c, int byte) |
| 69 | 634 { |
| 635 int len; | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
636 /*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
|
637 assert(byte >= 0 && byte <= 255); |
| 69 | 638 if (byte < 0 || byte > 255) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
639 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
|
640 "com_addbyte: byte out of range"); |
| 69 | 641 } |
| 642 if (c->c_code == NULL) | |
| 643 return; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
644 len = PyString_Size(c->c_code); |
| 69 | 645 if (c->c_nexti >= len) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
646 if (_PyString_Resize(&c->c_code, len+1000) != 0) { |
| 69 | 647 c->c_errors++; |
| 648 return; | |
| 649 } | |
| 650 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
651 PyString_AsString(c->c_code)[c->c_nexti++] = byte; |
| 69 | 652 } |
| 653 | |
| 654 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
655 com_addint(struct compiling *c, int x) |
| 69 | 656 { |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
657 com_addbyte(c, x & 0xff); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
658 com_addbyte(c, x >> 8); /* XXX x should be positive */ |
| 69 | 659 } |
| 660 | |
| 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 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
|
663 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
664 int size; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
665 char *p; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
666 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
|
667 return; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
668 size = PyString_Size(c->c_lnotab); |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
669 if (c->c_lnotab_next+2 > size) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
670 if (_PyString_Resize(&c->c_lnotab, size + 1000) < 0) { |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
671 c->c_errors++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
672 return; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
673 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
674 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
675 p = PyString_AsString(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
|
676 *p++ = addr; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
677 *p++ = line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
678 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
|
679 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
680 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
681 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
682 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
|
683 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
684 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
|
685 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
|
686 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
|
687 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
688 else { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
689 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
|
690 int incr_line = lineno - c->c_last_line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
691 while (incr_addr > 0 || incr_line > 0) { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
692 int trunc_addr = incr_addr; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
693 int trunc_line = incr_line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
694 if (trunc_addr > 255) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
695 trunc_addr = 255; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
696 if (trunc_line > 255) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
697 trunc_line = 255; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
698 com_add_lnotab(c, trunc_addr, trunc_line); |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
699 incr_addr -= trunc_addr; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
700 incr_line -= trunc_line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
701 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
702 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
|
703 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
|
704 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
705 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
706 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
707 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
708 com_addoparg(struct compiling *c, int op, int arg) |
| 69 | 709 { |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
710 int extended_arg = arg >> 16; |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
711 if (op == SET_LINENO) { |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
712 com_set_lineno(c, arg); |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
713 if (Py_OptimizeFlag) |
|
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
714 return; |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
715 } |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
716 if (extended_arg){ |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
717 com_addbyte(c, EXTENDED_ARG); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
718 com_addint(c, extended_arg); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
719 arg &= 0xffff; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
720 } |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
721 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
|
722 com_addint(c, arg); |
| 69 | 723 } |
| 724 | |
| 725 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
726 com_addfwref(struct compiling *c, int op, int *p_anchor) |
| 69 | 727 { |
| 728 /* Compile a forward reference for backpatching */ | |
| 729 int here; | |
| 730 int anchor; | |
| 731 com_addbyte(c, op); | |
| 732 here = c->c_nexti; | |
| 733 anchor = *p_anchor; | |
| 734 *p_anchor = here; | |
| 735 com_addint(c, anchor == 0 ? 0 : here - anchor); | |
| 736 } | |
| 737 | |
| 738 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
739 com_backpatch(struct compiling *c, int anchor) |
| 69 | 740 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
741 unsigned char *code = (unsigned char *) PyString_AsString(c->c_code); |
| 69 | 742 int target = c->c_nexti; |
| 743 int dist; | |
| 744 int prev; | |
| 745 for (;;) { | |
| 746 /* Make the JUMP instruction at anchor point to target */ | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
747 prev = code[anchor] + (code[anchor+1] << 8); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
748 dist = target - (anchor+2); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
749 code[anchor] = dist & 0xff; |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
750 dist >>= 8; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
751 code[anchor+1] = dist; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
752 dist >>= 8; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
753 if (dist) { |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
754 com_error(c, PyExc_SystemError, |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
755 "com_backpatch: offset too large"); |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
756 break; |
|
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14117
diff
changeset
|
757 } |
| 69 | 758 if (!prev) |
| 759 break; | |
| 760 anchor -= prev; | |
| 761 } | |
| 762 } | |
| 763 | |
| 544 | 764 /* Handle literals and names uniformly */ |
| 69 | 765 |
| 766 static int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
767 com_add(struct compiling *c, PyObject *list, PyObject *dict, PyObject *v) |
| 69 | 768 { |
| 12522 | 769 PyObject *w, *t, *np=NULL; |
| 770 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
|
771 |
| 12522 | 772 t = Py_BuildValue("(OO)", v, v->ob_type); |
| 773 if (t == NULL) | |
| 774 goto fail; | |
| 775 w = PyDict_GetItem(dict, t); | |
| 776 if (w != NULL) { | |
| 777 n = PyInt_AsLong(w); | |
| 778 } else { | |
| 779 n = PyList_Size(list); | |
| 780 np = PyInt_FromLong(n); | |
| 781 if (np == NULL) | |
| 782 goto fail; | |
| 783 if (PyList_Append(list, v) != 0) | |
| 784 goto fail; | |
| 785 if (PyDict_SetItem(dict, t, np) != 0) | |
| 786 goto fail; | |
| 787 Py_DECREF(np); | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
788 } |
| 12522 | 789 Py_DECREF(t); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
790 return n; |
| 12522 | 791 fail: |
| 792 Py_XDECREF(np); | |
| 793 Py_XDECREF(t); | |
| 794 c->c_errors++; | |
| 795 return 0; | |
| 69 | 796 } |
| 797 | |
| 798 static int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
799 com_addconst(struct compiling *c, PyObject *v) |
| 69 | 800 { |
| 12522 | 801 return com_add(c, c->c_consts, c->c_const_dict, v); |
| 69 | 802 } |
| 803 | |
| 804 static int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
805 com_addname(struct compiling *c, PyObject *v) |
| 69 | 806 { |
| 12522 | 807 return com_add(c, c->c_names, c->c_name_dict, v); |
| 69 | 808 } |
| 809 | |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
810 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
|
811 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
|
812 { |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
813 /* Name mangling: __private becomes _classname__private. |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
814 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
|
815 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
|
816 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
|
817 return 0; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
818 nlen = strlen(name); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
819 if (nlen+2 >= maxlen) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
820 return 0; /* Don't mangle __extremely_long_names */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
821 if (name[nlen-1] == '_' && name[nlen-2] == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
822 return 0; /* Don't mangle __whatever__ */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
823 /* Strip leading underscores from class name */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
824 while (*p == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
825 p++; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
826 if (*p == '\0') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
827 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
|
828 plen = strlen(p); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
829 if (plen + nlen >= maxlen) |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
830 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
|
831 /* 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
|
832 buffer[0] = '_'; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
833 strncpy(buffer+1, p, plen); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
834 strcpy(buffer+1+plen, name); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
835 return 1; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
836 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
837 |
| 69 | 838 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
|
839 com_addop_name(struct compiling *c, int op, char *name) |
| 69 | 840 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
841 PyObject *v; |
| 69 | 842 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
|
843 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
|
844 |
|
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
845 if (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
|
846 name = buffer; |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
847 if (name == NULL || (v = PyString_InternFromString(name)) == NULL) { |
| 69 | 848 c->c_errors++; |
| 849 i = 255; | |
| 850 } | |
| 851 else { | |
| 852 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
|
853 Py_DECREF(v); |
| 69 | 854 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
855 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
|
856 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
857 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
858 #define NAME_LOCAL 0 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
859 #define NAME_GLOBAL 1 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
860 #define NAME_DEFAULT 2 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
861 #define NAME_CLOSURE 3 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
862 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
863 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
864 com_lookup_arg(PyObject *dict, PyObject *name) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
865 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
866 PyObject *v = PyDict_GetItem(dict, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
867 if (v == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
868 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
869 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
870 return PyInt_AS_LONG(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
871 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
872 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
873 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
|
874 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
|
875 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
876 PyObject *v; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
877 int i, reftype; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
878 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
|
879 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
|
880 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
|
881 |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
882 if (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
|
883 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
|
884 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
|
885 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
|
886 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
|
887 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
|
888 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
889 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
890 reftype = get_ref_type(c, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
891 switch (reftype) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
892 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
|
893 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
|
894 scope = NAME_LOCAL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
895 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
896 case GLOBAL_EXPLICIT: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
897 scope = NAME_GLOBAL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
898 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
899 case GLOBAL_IMPLICIT: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
900 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
|
901 scope = NAME_GLOBAL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
902 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
903 case FREE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
904 case CELL: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
905 scope = NAME_CLOSURE; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
906 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
|
907 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
908 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
909 i = com_addname(c, v); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
910 if (scope == NAME_LOCAL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
911 i = com_lookup_arg(c->c_locals, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
912 else if (reftype == FREE) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
913 i = com_lookup_arg(c->c_freevars, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
914 else if (reftype == CELL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
915 i = com_lookup_arg(c->c_cellvars, v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
916 if (i == -1) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
917 c->c_errors++; /* XXX no exception set */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
918 i = 255; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
919 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
|
920 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
921 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
|
922 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
923 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
|
924 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
|
925 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
|
926 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
|
927 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
|
928 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
929 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
|
930 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
|
931 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
932 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
|
933 op = LOAD_NAME; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
934 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
935 case NAME_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
936 op = LOAD_DEREF; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
937 break; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
938 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
939 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
940 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
|
941 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
|
942 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
|
943 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
|
944 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
945 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
|
946 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
|
947 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
948 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
|
949 op = STORE_NAME; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
950 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
951 case NAME_CLOSURE: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
952 op = STORE_DEREF; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
953 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
|
954 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
955 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 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
|
960 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
961 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
|
962 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
|
963 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
964 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
|
965 op = DELETE_NAME; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
966 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
967 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
|
968 char buf[500]; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
969 sprintf(buf, DEL_CLOSURE_ERROR, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
970 com_error(c, PyExc_SyntaxError, buf); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
971 i = 255; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
972 break; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
973 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
974 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
975 break; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
976 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
977 done: |
| 69 | 978 com_addoparg(c, op, i); |
| 979 } | |
| 980 | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
981 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
982 com_addopname(struct compiling *c, int op, node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
983 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
984 char *name; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
985 char buffer[1000]; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
986 /* 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
|
987 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
|
988 bothered right now */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
989 if (TYPE(n) == STAR) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
990 name = "*"; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
991 else if (TYPE(n) == dotted_name) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
992 char *p = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
993 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
994 name = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
995 for (i = 0; i < NCH(n); i += 2) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
996 char *s = STR(CHILD(n, i)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
997 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
|
998 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
|
999 "dotted_name too long"); |
|
2367
915fabec64a3
fix typo (== for =) in assignment
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
1000 name = NULL; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1001 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1002 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1003 if (p != buffer) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1004 *p++ = '.'; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1005 strcpy(p, s); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1006 p = strchr(p, '\0'); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1007 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1008 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1009 else { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1010 REQ(n, NAME); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1011 name = STR(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1012 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
1013 com_addop_name(c, op, name); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1014 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1015 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1016 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1017 parsenumber(struct compiling *co, char *s) |
| 69 | 1018 { |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1019 char *end; |
| 69 | 1020 long x; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1021 double dx; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1022 #ifndef WITHOUT_COMPLEX |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3366
diff
changeset
|
1023 Py_complex c; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1024 int imflag; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1025 #endif |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1026 |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
1027 errno = 0; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1028 end = s + strlen(s) - 1; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1029 #ifndef WITHOUT_COMPLEX |
|
3366
c25865884649
only use 'j' for imaginary constants
Guido van Rossum <guido@python.org>
parents:
3349
diff
changeset
|
1030 imflag = *end == 'j' || *end == 'J'; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1031 #endif |
| 744 | 1032 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
|
1033 return PyLong_FromString(s, (char **)0, 0); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
1034 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
|
1035 x = (long) PyOS_strtoul(s, &end, 0); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
1036 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1037 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
|
1038 if (*end == '\0') { |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
1039 if (errno != 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1040 com_error(co, PyExc_OverflowError, |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1041 "integer literal too large"); |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
1042 return NULL; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
1043 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1044 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
|
1045 } |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1046 /* XXX Huge floats may silently fail */ |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1047 #ifndef WITHOUT_COMPLEX |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1048 if (imflag) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1049 c.real = 0.; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1050 PyFPE_START_PROTECT("atof", return 0) |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1051 c.imag = atof(s); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5183
diff
changeset
|
1052 PyFPE_END_PROTECT(c) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1053 return PyComplex_FromCComplex(c); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1054 } |
|
6453
c9b139b9c5ff
Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents:
6186
diff
changeset
|
1055 else |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1056 #endif |
|
6453
c9b139b9c5ff
Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents:
6186
diff
changeset
|
1057 { |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1058 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
|
1059 dx = atof(s); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5183
diff
changeset
|
1060 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
|
1061 return PyFloat_FromDouble(dx); |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
1062 } |
| 69 | 1063 } |
| 1064 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1065 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1066 parsestr(char *s) |
| 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; |
|
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
|
1069 size_t len; |
| 69 | 1070 char *buf; |
| 1071 char *p; | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1072 char *end; |
| 69 | 1073 int c; |
|
5264
38878f1cd4f1
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
5233
diff
changeset
|
1074 int first = *s; |
|
38878f1cd4f1
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
5233
diff
changeset
|
1075 int quote = first; |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1076 int rawmode = 0; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1077 int unicode = 0; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1078 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
|
1079 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
|
1080 quote = *++s; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1081 unicode = 1; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1082 } |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1083 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
|
1084 quote = *++s; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1085 rawmode = 1; |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1086 } |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1087 } |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
1088 if (quote != '\'' && quote != '\"') { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1089 PyErr_BadInternalCall(); |
| 69 | 1090 return NULL; |
| 1091 } | |
| 1092 s++; | |
| 1093 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
|
1094 if (len > INT_MAX) { |
|
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
|
1095 PyErr_SetString(PyExc_OverflowError, "string to parse is too long"); |
|
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
|
1096 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
|
1097 } |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
1098 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
|
1099 PyErr_BadInternalCall(); |
| 69 | 1100 return NULL; |
| 1101 } | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1102 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
|
1103 s += 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1104 len -= 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1105 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
|
1106 PyErr_BadInternalCall(); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1107 return NULL; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1108 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1109 } |
| 12538 | 1110 if (unicode || Py_UnicodeFlag) { |
|
11974
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1111 if (rawmode) |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1112 return PyUnicode_DecodeRawUnicodeEscape( |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1113 s, len, NULL); |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1114 else |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1115 return PyUnicode_DecodeUnicodeEscape( |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1116 s, len, NULL); |
|
28003afa1a2f
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents:
11598
diff
changeset
|
1117 } |
|
14382
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1118 if (rawmode || strchr(s, '\\') == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1119 return PyString_FromStringAndSize(s, len); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1120 v = PyString_FromStringAndSize((char *)NULL, len); |
|
14382
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1121 if (v == NULL) |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1122 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1123 p = buf = PyString_AsString(v); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1124 end = s + len; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1125 while (s < end) { |
| 69 | 1126 if (*s != '\\') { |
| 1127 *p++ = *s++; | |
| 1128 continue; | |
| 1129 } | |
| 1130 s++; | |
| 1131 switch (*s++) { | |
| 1132 /* XXX This assumes ASCII! */ | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1133 case '\n': break; |
| 69 | 1134 case '\\': *p++ = '\\'; break; |
| 1135 case '\'': *p++ = '\''; break; | |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
1136 case '\"': *p++ = '\"'; break; |
| 69 | 1137 case 'b': *p++ = '\b'; break; |
| 1138 case 'f': *p++ = '\014'; break; /* FF */ | |
| 1139 case 't': *p++ = '\t'; break; | |
| 1140 case 'n': *p++ = '\n'; break; | |
| 1141 case 'r': *p++ = '\r'; break; | |
| 1142 case 'v': *p++ = '\013'; break; /* VT */ | |
| 1143 case 'a': *p++ = '\007'; break; /* BEL, not classic C */ | |
| 1144 case '0': case '1': case '2': case '3': | |
| 1145 case '4': case '5': case '6': case '7': | |
| 1146 c = s[-1] - '0'; | |
| 1147 if ('0' <= *s && *s <= '7') { | |
| 1148 c = (c<<3) + *s++ - '0'; | |
| 1149 if ('0' <= *s && *s <= '7') | |
| 1150 c = (c<<3) + *s++ - '0'; | |
| 1151 } | |
| 1152 *p++ = c; | |
| 1153 break; | |
| 1154 case 'x': | |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
1155 if (isxdigit(Py_CHARMASK(s[0])) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
1156 && isxdigit(Py_CHARMASK(s[1]))) { |
|
6501
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
1157 unsigned int x = 0; |
|
14382
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1158 c = Py_CHARMASK(*s); |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1159 s++; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1160 if (isdigit(c)) |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1161 x = c - '0'; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1162 else if (islower(c)) |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1163 x = 10 + c - 'a'; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1164 else |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1165 x = 10 + c - 'A'; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1166 x = x << 4; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1167 c = Py_CHARMASK(*s); |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1168 s++; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1169 if (isdigit(c)) |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1170 x += c - '0'; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1171 else if (islower(c)) |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1172 x += 10 + c - 'a'; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1173 else |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1174 x += 10 + c - 'A'; |
|
6501
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
1175 *p++ = x; |
| 69 | 1176 break; |
| 1177 } | |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
1178 PyErr_SetString(PyExc_ValueError, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
1179 "invalid \\x escape"); |
|
14382
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1180 Py_DECREF(v); |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1181 return NULL; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1182 default: |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1183 *p++ = '\\'; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1184 *p++ = s[-1]; |
|
2d6cf68aa64a
changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents:
14375
diff
changeset
|
1185 break; |
| 69 | 1186 } |
| 1187 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1188 _PyString_Resize(&v, (int)(p - buf)); |
| 69 | 1189 return v; |
| 1190 } | |
| 1191 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1192 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1193 parsestrplus(node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1194 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1195 PyObject *v; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1196 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1197 REQ(CHILD(n, 0), STRING); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1198 if ((v = parsestr(STR(CHILD(n, 0)))) != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1199 /* String literal concatenation */ |
|
12388
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1200 for (i = 1; i < NCH(n); i++) { |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1201 PyObject *s; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1202 s = parsestr(STR(CHILD(n, i))); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1203 if (s == NULL) |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1204 goto onError; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1205 if (PyString_Check(v) && PyString_Check(s)) { |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1206 PyString_ConcatAndDel(&v, s); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1207 if (v == NULL) |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1208 goto onError; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1209 } |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1210 else { |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1211 PyObject *temp; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1212 temp = PyUnicode_Concat(v, s); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1213 Py_DECREF(s); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1214 if (temp == NULL) |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1215 goto onError; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1216 Py_DECREF(v); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1217 v = temp; |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1218 } |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1219 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1220 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1221 return v; |
|
12388
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1222 |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1223 onError: |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1224 Py_XDECREF(v); |
|
c48172af13dc
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12333
diff
changeset
|
1225 return NULL; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1226 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1227 |
| 69 | 1228 static void |
| 13936 | 1229 com_list_for(struct compiling *c, node *n, node *e, char *t) |
| 1230 { | |
| 1231 PyObject *v; | |
| 1232 int anchor = 0; | |
| 1233 int save_begin = c->c_begin; | |
| 1234 | |
| 1235 /* list_iter: for v in expr [list_iter] */ | |
| 1236 com_node(c, CHILD(n, 3)); /* expr */ | |
| 1237 v = PyInt_FromLong(0L); | |
| 1238 if (v == NULL) | |
| 1239 c->c_errors++; | |
| 1240 com_addoparg(c, LOAD_CONST, com_addconst(c, v)); | |
| 1241 com_push(c, 1); | |
| 1242 Py_XDECREF(v); | |
| 1243 c->c_begin = c->c_nexti; | |
| 1244 com_addoparg(c, SET_LINENO, n->n_lineno); | |
| 1245 com_addfwref(c, FOR_LOOP, &anchor); | |
| 1246 com_push(c, 1); | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1247 com_assign(c, CHILD(n, 1), OP_ASSIGN, NULL); |
| 13936 | 1248 c->c_loops++; |
| 1249 com_list_iter(c, n, e, t); | |
| 1250 c->c_loops--; | |
| 1251 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); | |
| 1252 c->c_begin = save_begin; | |
| 1253 com_backpatch(c, anchor); | |
| 1254 com_pop(c, 2); /* FOR_LOOP has popped these */ | |
| 1255 } | |
| 1256 | |
| 1257 static void | |
| 1258 com_list_if(struct compiling *c, node *n, node *e, char *t) | |
| 1259 { | |
| 1260 int anchor = 0; | |
| 1261 int a = 0; | |
| 1262 /* list_iter: 'if' test [list_iter] */ | |
| 1263 com_addoparg(c, SET_LINENO, n->n_lineno); | |
| 1264 com_node(c, CHILD(n, 1)); | |
| 1265 com_addfwref(c, JUMP_IF_FALSE, &a); | |
| 1266 com_addbyte(c, POP_TOP); | |
| 1267 com_pop(c, 1); | |
| 1268 com_list_iter(c, n, e, t); | |
| 1269 com_addfwref(c, JUMP_FORWARD, &anchor); | |
| 1270 com_backpatch(c, a); | |
| 1271 /* We jump here with an extra entry which we now pop */ | |
| 1272 com_addbyte(c, POP_TOP); | |
| 1273 com_backpatch(c, anchor); | |
| 1274 } | |
| 1275 | |
| 1276 static void | |
| 1277 com_list_iter(struct compiling *c, | |
| 1278 node *p, /* parent of list_iter node */ | |
| 1279 node *e, /* element expression node */ | |
| 1280 char *t /* name of result list temp local */) | |
| 69 | 1281 { |
| 13936 | 1282 /* list_iter is the last child in a listmaker, list_for, or list_if */ |
| 1283 node *n = CHILD(p, NCH(p)-1); | |
| 1284 if (TYPE(n) == list_iter) { | |
| 1285 n = CHILD(n, 0); | |
| 1286 switch (TYPE(n)) { | |
| 1287 case list_for: | |
| 1288 com_list_for(c, n, e, t); | |
| 1289 break; | |
| 1290 case list_if: | |
| 1291 com_list_if(c, n, e, t); | |
| 1292 break; | |
| 1293 default: | |
| 1294 com_error(c, PyExc_SystemError, | |
| 1295 "invalid list_iter node type"); | |
| 1296 } | |
| 1297 } | |
| 1298 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
|
1299 com_addop_varname(c, VAR_LOAD, t); |
| 13936 | 1300 com_push(c, 1); |
| 1301 com_node(c, e); | |
| 1302 com_addoparg(c, CALL_FUNCTION, 1); | |
| 1303 com_addbyte(c, POP_TOP); | |
| 1304 com_pop(c, 2); | |
| 1305 } | |
| 1306 } | |
| 1307 | |
| 1308 static void | |
| 1309 com_list_comprehension(struct compiling *c, node *n) | |
| 1310 { | |
|
14117
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1311 /* listmaker: test list_for */ |
| 13936 | 1312 char tmpname[12]; |
|
16638
79568c0d3e77
Change temp names created by listcomps from [%d] to _[%d], so the one-liner
Tim Peters <tim.peters@gmail.com>
parents:
16571
diff
changeset
|
1313 sprintf(tmpname, "_[%d]", ++c->c_tmpname); |
| 13936 | 1314 com_addoparg(c, BUILD_LIST, 0); |
| 1315 com_addbyte(c, DUP_TOP); /* leave the result on the stack */ | |
| 1316 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
|
1317 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
|
1318 com_addop_varname(c, VAR_STORE, tmpname); |
| 13936 | 1319 com_pop(c, 1); |
|
14117
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1320 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
|
1321 com_addop_varname(c, VAR_DELETE, tmpname); |
| 13936 | 1322 --c->c_tmpname; |
| 1323 } | |
| 1324 | |
| 1325 static void | |
| 1326 com_listmaker(struct compiling *c, node *n) | |
| 1327 { | |
|
14117
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1328 /* listmaker: test ( list_for | (',' test)* [','] ) */ |
|
ac8809959d01
require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents:
14105
diff
changeset
|
1329 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) |
| 13936 | 1330 com_list_comprehension(c, n); |
| 1331 else { | |
| 1332 int len = 0; | |
| 1333 int i; | |
| 1334 for (i = 0; i < NCH(n); i += 2, len++) | |
| 1335 com_node(c, CHILD(n, i)); | |
| 1336 com_addoparg(c, BUILD_LIST, len); | |
| 1337 com_pop(c, len-1); | |
| 1338 } | |
| 69 | 1339 } |
| 1340 | |
| 1341 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1342 com_dictmaker(struct compiling *c, node *n) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1343 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1344 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1345 /* dictmaker: test ':' test (',' test ':' value)* [','] */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1346 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
|
1347 /* 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
|
1348 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
|
1349 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
|
1350 com_push(c, 1); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1351 com_node(c, CHILD(n, i+2)); /* value */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1352 com_addbyte(c, ROT_TWO); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1353 com_node(c, CHILD(n, i)); /* key */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1354 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
|
1355 com_pop(c, 3); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1356 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1357 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1358 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1359 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1360 com_atom(struct compiling *c, node *n) |
| 69 | 1361 { |
| 1362 node *ch; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1363 PyObject *v; |
| 69 | 1364 int i; |
| 1365 REQ(n, atom); | |
| 1366 ch = CHILD(n, 0); | |
| 1367 switch (TYPE(ch)) { | |
| 1368 case LPAR: | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1369 if (TYPE(CHILD(n, 1)) == RPAR) { |
| 69 | 1370 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
|
1371 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
|
1372 } |
| 69 | 1373 else |
| 1374 com_node(c, CHILD(n, 1)); | |
| 1375 break; | |
| 13936 | 1376 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
|
1377 if (TYPE(CHILD(n, 1)) == RSQB) { |
| 69 | 1378 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
|
1379 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
|
1380 } |
| 69 | 1381 else |
| 13936 | 1382 com_listmaker(c, CHILD(n, 1)); |
| 69 | 1383 break; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1384 case LBRACE: /* '{' [dictmaker] '}' */ |
| 69 | 1385 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
|
1386 com_push(c, 1); |
| 13936 | 1387 if (TYPE(CHILD(n, 1)) == dictmaker) |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1388 com_dictmaker(c, CHILD(n, 1)); |
| 69 | 1389 break; |
| 1390 case BACKQUOTE: | |
| 1391 com_node(c, CHILD(n, 1)); | |
| 1392 com_addbyte(c, UNARY_CONVERT); | |
| 1393 break; | |
| 1394 case NUMBER: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1395 if ((v = parsenumber(c, STR(ch))) == NULL) { |
| 69 | 1396 i = 255; |
| 1397 } | |
| 1398 else { | |
| 1399 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
|
1400 Py_DECREF(v); |
| 69 | 1401 } |
| 1402 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
|
1403 com_push(c, 1); |
| 69 | 1404 break; |
| 1405 case STRING: | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1406 v = parsestrplus(n); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1407 if (v == NULL) { |
| 69 | 1408 c->c_errors++; |
| 1409 i = 255; | |
| 1410 } | |
| 1411 else { | |
| 1412 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
|
1413 Py_DECREF(v); |
| 69 | 1414 } |
| 1415 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
|
1416 com_push(c, 1); |
| 69 | 1417 break; |
| 1418 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
|
1419 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
|
1420 com_push(c, 1); |
| 69 | 1421 break; |
| 1422 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1423 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
|
1424 "com_atom: unexpected node type"); |
| 69 | 1425 } |
| 1426 } | |
| 1427 | |
| 1428 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1429 com_slice(struct compiling *c, node *n, int op) |
| 69 | 1430 { |
| 1431 if (NCH(n) == 1) { | |
| 1432 com_addbyte(c, op); | |
| 1433 } | |
| 1434 else if (NCH(n) == 2) { | |
| 1435 if (TYPE(CHILD(n, 0)) != COLON) { | |
| 1436 com_node(c, CHILD(n, 0)); | |
| 1437 com_addbyte(c, op+1); | |
| 1438 } | |
| 1439 else { | |
| 1440 com_node(c, CHILD(n, 1)); | |
| 1441 com_addbyte(c, op+2); | |
| 1442 } | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1443 com_pop(c, 1); |
| 69 | 1444 } |
| 1445 else { | |
| 1446 com_node(c, CHILD(n, 0)); | |
| 1447 com_node(c, CHILD(n, 2)); | |
| 1448 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
|
1449 com_pop(c, 2); |
| 69 | 1450 } |
| 1451 } | |
| 1452 | |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1453 static void |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1454 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
|
1455 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1456 if (NCH(n) == 1) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1457 com_addbyte(c, DUP_TOP); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1458 com_push(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1459 com_addbyte(c, SLICE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1460 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1461 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1462 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1463 com_addbyte(c, ROT_TWO); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1464 com_addbyte(c, STORE_SLICE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1465 com_pop(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1466 } 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
|
1467 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
|
1468 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
|
1469 com_push(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1470 com_addbyte(c, SLICE+1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1471 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1472 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1473 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1474 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1475 com_addbyte(c, ROT_THREE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1476 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
|
1477 com_pop(c, 3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1478 } else if (NCH(n) == 2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1479 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
|
1480 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
|
1481 com_push(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1482 com_addbyte(c, SLICE+2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1483 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1484 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1485 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1486 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1487 com_addbyte(c, ROT_THREE); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1488 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
|
1489 com_pop(c, 3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1490 } else { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1491 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
|
1492 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
|
1493 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
|
1494 com_push(c, 3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1495 com_addbyte(c, SLICE+3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1496 com_pop(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1497 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1498 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1499 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1500 com_addbyte(c, ROT_FOUR); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1501 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
|
1502 com_pop(c, 4); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1503 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1504 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1505 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1506 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1507 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
|
1508 { |
|
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
|
1509 node *m; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1510 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
|
1511 if (NCH(n) == 1) { |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1512 if (*pkeywords != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1513 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
|
1514 "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
|
1515 } |
|
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
|
1516 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
|
1517 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
|
1518 } |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1519 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
|
1520 } |
|
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
|
1521 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
|
1522 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
|
1523 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
|
1524 } 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
|
1525 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
|
1526 /* 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
|
1527 * 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
|
1528 * 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
|
1529 * then is very confusing. |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1530 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1531 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
|
1532 TYPE(m) == lambdef ? |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1533 "lambda cannot contain assignment" : |
|
1a5a441772ff
Bug #132313 error message confusing for assignment in lambda.
Tim Peters <tim.peters@gmail.com>
parents:
16638
diff
changeset
|
1534 "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
|
1535 } |
|
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
|
1536 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1537 PyObject *v = PyString_InternFromString(STR(m)); |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1538 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
|
1539 *pkeywords = PyDict_New(); |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1540 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
|
1541 c->c_errors++; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1542 else if (*pkeywords == NULL) { |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1543 c->c_errors++; |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1544 Py_DECREF(v); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
1545 } else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1546 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
|
1547 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
|
1548 "duplicate keyword argument"); |
|
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1549 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1550 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
|
1551 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
|
1552 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
|
1553 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
|
1554 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
|
1555 } |
|
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
|
1556 } |
|
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
|
1557 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
|
1558 } |
|
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
|
1559 |
| 69 | 1560 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1561 com_call_function(struct compiling *c, node *n) |
| 69 | 1562 { |
| 1563 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
|
1564 com_addoparg(c, CALL_FUNCTION, 0); |
| 69 | 1565 } |
| 1566 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1567 PyObject *keywords = NULL; |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1568 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
|
1569 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
|
1570 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
|
1571 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
|
1572 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
|
1573 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
|
1574 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
|
1575 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
|
1576 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
|
1577 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
|
1578 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
|
1579 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
|
1580 break; |
|
9625
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1581 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
|
1582 lineno = ch->n_lineno; |
|
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1583 com_addoparg(c, SET_LINENO, lineno); |
|
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1584 } |
|
1fe48009d8ea
Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
1585 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
|
1586 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
|
1587 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
|
1588 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
|
1589 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
|
1590 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1591 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
|
1592 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
|
1593 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
|
1594 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
|
1595 i += 3; |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1596 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
|
1597 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
|
1598 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
|
1599 } |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1600 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
|
1601 } |
|
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
|
1602 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
|
1603 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
|
1604 "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
|
1605 } |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1606 if (star_flag || starstar_flag) |
|
12086
96ea1a800b23
remove reference (vestigal) to CALL_FUNCTION_STAR
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12082
diff
changeset
|
1607 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
|
1608 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
|
1609 else |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11974
diff
changeset
|
1610 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
|
1611 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
|
1612 com_pop(c, na + 2*nk + star_flag + starstar_flag); |
| 69 | 1613 } |
| 1614 } | |
| 1615 | |
| 1616 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1617 com_select_member(struct compiling *c, node *n) |
| 69 | 1618 { |
| 1619 com_addopname(c, LOAD_ATTR, n); | |
| 1620 } | |
| 1621 | |
| 1622 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1623 com_sliceobj(struct compiling *c, node *n) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1624 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1625 int i=0; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1626 int ns=2; /* number of slice arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1627 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1628 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1629 /* first argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1630 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
|
1631 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
|
1632 com_push(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1633 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1634 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1635 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1636 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1637 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1638 REQ(CHILD(n,i),COLON); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1639 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1640 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1641 /* second argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1642 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
|
1643 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1644 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1645 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1646 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1647 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
|
1648 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
|
1649 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1650 /* remaining arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1651 for (; i < NCH(n); i++) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1652 ns++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1653 ch=CHILD(n,i); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1654 REQ(ch, sliceop); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1655 if (NCH(ch) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1656 /* 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
|
1657 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
|
1658 com_push(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1659 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1660 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1661 com_node(c, CHILD(ch,1)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1662 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1663 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
|
1664 com_pop(c, 1 + (ns == 3)); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1665 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1666 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1667 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1668 com_subscript(struct compiling *c, node *n) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1669 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1670 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1671 REQ(n, subscript); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1672 ch = CHILD(n,0); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1673 /* 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
|
1674 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
|
1675 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
|
1676 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
|
1677 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1678 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1679 /* check for slice */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1680 if ((TYPE(ch) == COLON || NCH(n) > 1)) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1681 com_sliceobj(c, n); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1682 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1683 REQ(ch, test); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1684 com_node(c, ch); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1685 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1686 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1687 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1688 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1689 static void |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1690 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
|
1691 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1692 int i, op; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1693 REQ(n, subscriptlist); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1694 /* 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
|
1695 if (NCH(n) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1696 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
|
1697 /* '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
|
1698 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
|
1699 || (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
|
1700 && (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
|
1701 { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1702 switch (assigning) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1703 case OP_DELETE: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1704 op = DELETE_SLICE; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1705 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1706 case OP_ASSIGN: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1707 op = STORE_SLICE; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1708 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1709 case OP_APPLY: |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1710 op = SLICE; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1711 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1712 default: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1713 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
|
1714 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1715 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1716 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
|
1717 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
|
1718 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
|
1719 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
|
1720 com_pop(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1721 return; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1722 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1723 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1724 /* Else normal subscriptlist. Compile each subscript. */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1725 for (i = 0; i < NCH(n); i += 2) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1726 com_subscript(c, CHILD(n, i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1727 /* 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
|
1728 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
|
1729 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
|
1730 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
|
1731 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
|
1732 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1733 switch (assigning) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1734 case OP_DELETE: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1735 op = DELETE_SUBSCR; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1736 i = 2; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1737 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1738 default: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1739 case OP_ASSIGN: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1740 op = STORE_SUBSCR; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1741 i = 3; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1742 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1743 case OP_APPLY: |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1744 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
|
1745 i = 1; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1746 break; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1747 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1748 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1749 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
|
1750 com_push(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1751 com_addbyte(c, BINARY_SUBSCR); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1752 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1753 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1754 com_addbyte(c, assigning); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1755 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1756 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
|
1757 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1758 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
|
1759 com_pop(c, i); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1760 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1761 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1762 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1763 com_apply_trailer(struct compiling *c, node *n) |
| 69 | 1764 { |
| 1765 REQ(n, trailer); | |
| 1766 switch (TYPE(CHILD(n, 0))) { | |
| 1767 case LPAR: | |
| 1768 com_call_function(c, CHILD(n, 1)); | |
| 1769 break; | |
| 1770 case DOT: | |
| 1771 com_select_member(c, CHILD(n, 1)); | |
| 1772 break; | |
| 1773 case LSQB: | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
1774 com_subscriptlist(c, CHILD(n, 1), OP_APPLY, NULL); |
| 69 | 1775 break; |
| 1776 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1777 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
|
1778 "com_apply_trailer: unknown trailer type"); |
| 69 | 1779 } |
| 1780 } | |
| 1781 | |
| 1782 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1783 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
|
1784 { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1785 int i; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1786 REQ(n, power); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1787 com_atom(c, CHILD(n, 0)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1788 for (i = 1; i < NCH(n); i++) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1789 if (TYPE(CHILD(n, i)) == DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1790 com_factor(c, CHILD(n, i+1)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1791 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
|
1792 com_pop(c, 1); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1793 break; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1794 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1795 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1796 com_apply_trailer(c, CHILD(n, i)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1797 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1798 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1799 |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1800 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1801 com_factor(struct compiling *c, node *n) |
| 69 | 1802 { |
| 1803 REQ(n, factor); | |
| 1804 if (TYPE(CHILD(n, 0)) == PLUS) { | |
| 1805 com_factor(c, CHILD(n, 1)); | |
| 1806 com_addbyte(c, UNARY_POSITIVE); | |
| 1807 } | |
| 1808 else if (TYPE(CHILD(n, 0)) == MINUS) { | |
| 1809 com_factor(c, CHILD(n, 1)); | |
| 1810 com_addbyte(c, UNARY_NEGATIVE); | |
| 1811 } | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1812 else if (TYPE(CHILD(n, 0)) == TILDE) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1813 com_factor(c, CHILD(n, 1)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1814 com_addbyte(c, UNARY_INVERT); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1815 } |
| 69 | 1816 else { |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1817 com_power(c, CHILD(n, 0)); |
| 69 | 1818 } |
| 1819 } | |
| 1820 | |
| 1821 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1822 com_term(struct compiling *c, node *n) |
| 69 | 1823 { |
| 1824 int i; | |
| 1825 int op; | |
| 1826 REQ(n, term); | |
| 1827 com_factor(c, CHILD(n, 0)); | |
| 1828 for (i = 2; i < NCH(n); i += 2) { | |
| 1829 com_factor(c, CHILD(n, i)); | |
| 1830 switch (TYPE(CHILD(n, i-1))) { | |
| 1831 case STAR: | |
| 1832 op = BINARY_MULTIPLY; | |
| 1833 break; | |
| 1834 case SLASH: | |
| 1835 op = BINARY_DIVIDE; | |
| 1836 break; | |
| 1837 case PERCENT: | |
| 1838 op = BINARY_MODULO; | |
| 1839 break; | |
| 1840 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1841 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
|
1842 "com_term: operator not *, / or %"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1843 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1844 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1845 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
|
1846 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1847 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1848 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1849 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1850 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1851 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
|
1852 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1853 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1854 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1855 REQ(n, arith_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1856 com_term(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1857 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1858 com_term(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1859 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1860 case PLUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1861 op = BINARY_ADD; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1862 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1863 case MINUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1864 op = BINARY_SUBTRACT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1865 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1866 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1867 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
|
1868 "com_arith_expr: operator not + or -"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1869 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1870 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1871 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
|
1872 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1873 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1874 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1875 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1876 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1877 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
|
1878 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1879 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1880 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1881 REQ(n, shift_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1882 com_arith_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1883 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1884 com_arith_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1885 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1886 case LEFTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1887 op = BINARY_LSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1888 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1889 case RIGHTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1890 op = BINARY_RSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1891 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1892 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1893 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
|
1894 "com_shift_expr: operator not << or >>"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1895 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1896 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1897 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
|
1898 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1899 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1900 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1901 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1902 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1903 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
|
1904 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1905 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1906 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1907 REQ(n, and_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1908 com_shift_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1909 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1910 com_shift_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1911 if (TYPE(CHILD(n, i-1)) == AMPER) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1912 op = BINARY_AND; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1913 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1914 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1915 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
|
1916 "com_and_expr: operator not &"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1917 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1918 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1919 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
|
1920 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1921 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1922 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1923 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1924 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1925 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
|
1926 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1927 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1928 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1929 REQ(n, xor_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1930 com_and_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1931 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1932 com_and_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1933 if (TYPE(CHILD(n, i-1)) == CIRCUMFLEX) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1934 op = BINARY_XOR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1935 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1936 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1937 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
|
1938 "com_xor_expr: operator not ^"); |
| 69 | 1939 op = 255; |
| 1940 } | |
| 1941 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
|
1942 com_pop(c, 1); |
| 69 | 1943 } |
| 1944 } | |
| 1945 | |
| 1946 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
1947 com_expr(struct compiling *c, node *n) |
| 69 | 1948 { |
| 1949 int i; | |
| 1950 int op; | |
| 1951 REQ(n, expr); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1952 com_xor_expr(c, CHILD(n, 0)); |
| 69 | 1953 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
|
1954 com_xor_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1955 if (TYPE(CHILD(n, i-1)) == VBAR) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1956 op = BINARY_OR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1957 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1958 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1959 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
|
1960 "com_expr: expr operator not |"); |
| 69 | 1961 op = 255; |
| 1962 } | |
| 1963 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
|
1964 com_pop(c, 1); |
| 69 | 1965 } |
| 1966 } | |
| 1967 | |
| 1968 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
|
1969 cmp_type(node *n) |
| 69 | 1970 { |
| 1971 REQ(n, comp_op); | |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1972 /* comp_op: '<' | '>' | '=' | '>=' | '<=' | '<>' | '!=' | '==' |
| 69 | 1973 | 'in' | 'not' 'in' | 'is' | 'is' not' */ |
| 1974 if (NCH(n) == 1) { | |
| 1975 n = CHILD(n, 0); | |
| 1976 switch (TYPE(n)) { | |
| 1977 case LESS: return LT; | |
| 1978 case GREATER: return GT; | |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1979 case EQEQUAL: /* == */ |
| 69 | 1980 case EQUAL: return EQ; |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1981 case LESSEQUAL: return LE; |
|
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1982 case GREATEREQUAL: return GE; |
|
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1983 case NOTEQUAL: return NE; /* <> or != */ |
| 69 | 1984 case NAME: if (strcmp(STR(n), "in") == 0) return IN; |
| 1985 if (strcmp(STR(n), "is") == 0) return IS; | |
| 1986 } | |
| 1987 } | |
| 1988 else if (NCH(n) == 2) { | |
| 1989 switch (TYPE(CHILD(n, 0))) { | |
| 1990 case NAME: if (strcmp(STR(CHILD(n, 1)), "in") == 0) | |
| 1991 return NOT_IN; | |
| 1992 if (strcmp(STR(CHILD(n, 0)), "is") == 0) | |
| 1993 return IS_NOT; | |
| 1994 } | |
| 1995 } | |
| 1996 return BAD; | |
| 1997 } | |
| 1998 | |
| 1999 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2000 com_comparison(struct compiling *c, node *n) |
| 69 | 2001 { |
| 2002 int i; | |
| 2003 enum cmp_op op; | |
| 2004 int anchor; | |
| 2005 REQ(n, comparison); /* comparison: expr (comp_op expr)* */ | |
| 2006 com_expr(c, CHILD(n, 0)); | |
| 2007 if (NCH(n) == 1) | |
| 2008 return; | |
| 2009 | |
| 2010 /**************************************************************** | |
| 2011 The following code is generated for all but the last | |
| 2012 comparison in a chain: | |
| 2013 | |
| 2014 label: on stack: opcode: jump to: | |
| 2015 | |
| 2016 a <code to load b> | |
| 2017 a, b DUP_TOP | |
| 2018 a, b, b ROT_THREE | |
| 2019 b, a, b COMPARE_OP | |
| 2020 b, 0-or-1 JUMP_IF_FALSE L1 | |
| 2021 b, 1 POP_TOP | |
| 2022 b | |
| 2023 | |
| 2024 We are now ready to repeat this sequence for the next | |
| 2025 comparison in the chain. | |
| 2026 | |
| 2027 For the last we generate: | |
| 2028 | |
| 2029 b <code to load c> | |
| 2030 b, c COMPARE_OP | |
| 2031 0-or-1 | |
| 2032 | |
| 2033 If there were any jumps to L1 (i.e., there was more than one | |
| 2034 comparison), we generate: | |
| 2035 | |
| 2036 0-or-1 JUMP_FORWARD L2 | |
| 2037 L1: b, 0 ROT_TWO | |
| 2038 0, b POP_TOP | |
| 2039 0 | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2040 L2: 0-or-1 |
| 69 | 2041 ****************************************************************/ |
| 2042 | |
| 2043 anchor = 0; | |
| 2044 | |
| 2045 for (i = 2; i < NCH(n); i += 2) { | |
| 2046 com_expr(c, CHILD(n, i)); | |
| 2047 if (i+2 < NCH(n)) { | |
| 2048 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
|
2049 com_push(c, 1); |
| 69 | 2050 com_addbyte(c, ROT_THREE); |
| 2051 } | |
| 2052 op = cmp_type(CHILD(n, i-1)); | |
| 2053 if (op == BAD) { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2054 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
|
2055 "com_comparison: unknown comparison op"); |
| 69 | 2056 } |
| 2057 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
|
2058 com_pop(c, 1); |
| 69 | 2059 if (i+2 < NCH(n)) { |
| 2060 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 2061 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
|
2062 com_pop(c, 1); |
| 69 | 2063 } |
| 2064 } | |
| 2065 | |
| 2066 if (anchor) { | |
| 2067 int anchor2 = 0; | |
| 2068 com_addfwref(c, JUMP_FORWARD, &anchor2); | |
| 2069 com_backpatch(c, anchor); | |
| 2070 com_addbyte(c, ROT_TWO); | |
| 2071 com_addbyte(c, POP_TOP); | |
| 2072 com_backpatch(c, anchor2); | |
| 2073 } | |
| 2074 } | |
| 2075 | |
| 2076 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2077 com_not_test(struct compiling *c, node *n) |
| 69 | 2078 { |
| 2079 REQ(n, not_test); /* 'not' not_test | comparison */ | |
| 2080 if (NCH(n) == 1) { | |
| 2081 com_comparison(c, CHILD(n, 0)); | |
| 2082 } | |
| 2083 else { | |
| 2084 com_not_test(c, CHILD(n, 1)); | |
| 2085 com_addbyte(c, UNARY_NOT); | |
| 2086 } | |
| 2087 } | |
| 2088 | |
| 2089 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2090 com_and_test(struct compiling *c, node *n) |
| 69 | 2091 { |
| 2092 int i; | |
| 2093 int anchor; | |
| 2094 REQ(n, and_test); /* not_test ('and' not_test)* */ | |
| 2095 anchor = 0; | |
| 2096 i = 0; | |
| 2097 for (;;) { | |
| 2098 com_not_test(c, CHILD(n, i)); | |
| 2099 if ((i += 2) >= NCH(n)) | |
| 2100 break; | |
| 2101 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 2102 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
|
2103 com_pop(c, 1); |
| 69 | 2104 } |
| 2105 if (anchor) | |
| 2106 com_backpatch(c, anchor); | |
| 2107 } | |
| 2108 | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2109 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2110 com_make_closure(struct compiling *c, PyCodeObject *co) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2111 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2112 int i, free = PyTuple_GET_SIZE(co->co_freevars); |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
2113 /* If the code is compiled with st->st_nested_scopes == 0, |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
2114 then no variable will ever be added to co_freevars. |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
2115 */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2116 if (free == 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2117 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2118 for (i = 0; i < free; ++i) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2119 /* Bypass com_addop_varname because it will generate |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2120 LOAD_DEREF but LOAD_CLOSURE is needed. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2121 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2122 PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2123 int arg, reftype; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2124 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2125 /* Special case: If a class contains a method with a |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2126 free variable that has the same name as a method, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2127 the name will be considered free *and* local in the |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2128 class. It should be handled by the closure, as |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2129 well as by the normal name loookup logic. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2130 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2131 reftype = get_ref_type(c, PyString_AS_STRING(name)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2132 if (reftype == CELL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2133 arg = com_lookup_arg(c->c_cellvars, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2134 else /* (reftype == FREE) */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2135 arg = com_lookup_arg(c->c_freevars, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2136 if (arg == -1) { |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2137 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
|
2138 "freevars of %s: %s\n", |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2139 PyObject_REPR(name), |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2140 c->c_name, |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2141 reftype, arg, |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
2142 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
|
2143 PyObject_REPR(co->co_freevars)); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2144 Py_FatalError("com_make_closure()"); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2145 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2146 com_addoparg(c, LOAD_CLOSURE, arg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2147 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2148 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2149 com_push(c, free); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2150 return 1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2151 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2152 |
| 69 | 2153 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2154 com_test(struct compiling *c, node *n) |
| 69 | 2155 { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2156 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
|
2157 if (NCH(n) == 1 && TYPE(CHILD(n, 0)) == lambdef) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2158 PyObject *co; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2159 int i, closure; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2160 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
|
2161 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
|
2162 n->n_lineno); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2163 co = (PyObject *) 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
|
2164 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
|
2165 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
|
2166 return; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2167 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2168 symtable_exit_scope(c->c_symtable); |
|
16763
2f585cbe71da
Shuffle premature decref; nuke unreachable code block.
Tim Peters <tim.peters@gmail.com>
parents:
16754
diff
changeset
|
2169 i = com_addconst(c, co); |
|
2f585cbe71da
Shuffle premature decref; nuke unreachable code block.
Tim Peters <tim.peters@gmail.com>
parents:
16754
diff
changeset
|
2170 closure = com_make_closure(c, (PyCodeObject *)co); |
|
2f585cbe71da
Shuffle premature decref; nuke unreachable code block.
Tim Peters <tim.peters@gmail.com>
parents:
16754
diff
changeset
|
2171 Py_DECREF(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
|
2172 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
|
2173 com_push(c, 1); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2174 if (closure) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2175 com_addoparg(c, MAKE_CLOSURE, ndefs); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2176 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2177 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
|
2178 com_pop(c, ndefs); |
| 69 | 2179 } |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2180 else { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2181 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
|
2182 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
|
2183 for (;;) { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2184 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
|
2185 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
|
2186 break; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2187 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
|
2188 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
|
2189 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
|
2190 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
2191 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
|
2192 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
|
2193 } |
| 69 | 2194 } |
| 2195 | |
| 2196 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2197 com_list(struct compiling *c, node *n, int toplevel) |
| 69 | 2198 { |
| 2199 /* exprlist: expr (',' expr)* [',']; likewise for testlist */ | |
| 482 | 2200 if (NCH(n) == 1 && !toplevel) { |
| 69 | 2201 com_node(c, CHILD(n, 0)); |
| 2202 } | |
| 2203 else { | |
| 2204 int i; | |
| 2205 int len; | |
| 2206 len = (NCH(n) + 1) / 2; | |
| 2207 for (i = 0; i < NCH(n); i += 2) | |
| 2208 com_node(c, CHILD(n, i)); | |
| 2209 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
|
2210 com_pop(c, len-1); |
| 69 | 2211 } |
| 2212 } | |
| 2213 | |
| 2214 | |
| 2215 /* Begin of assignment compilation */ | |
| 2216 | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2217 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2218 static void |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2219 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
|
2220 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2221 com_addbyte(c, DUP_TOP); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2222 com_push(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2223 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
|
2224 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2225 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2226 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2227 com_addbyte(c, ROT_TWO); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2228 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
|
2229 com_pop(c, 2); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2230 } |
| 69 | 2231 |
| 2232 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2233 com_assign_attr(struct compiling *c, node *n, int assigning) |
| 69 | 2234 { |
| 2235 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
|
2236 com_pop(c, assigning ? 2 : 1); |
| 69 | 2237 } |
| 2238 | |
| 2239 static void | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2240 com_assign_trailer(struct compiling *c, node *n, int assigning, node *augn) |
| 69 | 2241 { |
| 2242 REQ(n, trailer); | |
| 2243 switch (TYPE(CHILD(n, 0))) { | |
| 2244 case LPAR: /* '(' [exprlist] ')' */ | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2245 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
|
2246 "can't assign to function call"); |
| 69 | 2247 break; |
| 2248 case DOT: /* '.' NAME */ | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2249 if (assigning > OP_APPLY) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2250 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
|
2251 else |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2252 com_assign_attr(c, CHILD(n, 1), assigning); |
| 69 | 2253 break; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2254 case LSQB: /* '[' subscriptlist ']' */ |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2255 com_subscriptlist(c, CHILD(n, 1), assigning, augn); |
| 69 | 2256 break; |
| 2257 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2258 com_error(c, PyExc_SystemError, "unknown trailer type"); |
| 69 | 2259 } |
| 2260 } | |
| 2261 | |
| 2262 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
|
2263 com_assign_sequence(struct compiling *c, node *n, int assigning) |
| 69 | 2264 { |
| 2265 int i; | |
|
14178
dff22d4a48da
Fix allowable node-types for assignment, need to add 'listmaker'.
Thomas Wouters <thomas@python.org>
parents:
14163
diff
changeset
|
2266 if (TYPE(n) != testlist && TYPE(n) != listmaker) |
| 69 | 2267 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
|
2268 if (assigning) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2269 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
|
2270 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
|
2271 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
|
2272 } |
| 69 | 2273 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
|
2274 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
|
2275 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2276 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2277 static void |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2278 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
|
2279 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2280 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
|
2281 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
|
2282 com_push(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2283 com_node(c, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2284 com_addbyte(c, opcode); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2285 com_pop(c, 1); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2286 com_assign_name(c, n, OP_ASSIGN); |
| 69 | 2287 } |
| 2288 | |
| 2289 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2290 com_assign_name(struct compiling *c, node *n, int assigning) |
| 69 | 2291 { |
| 2292 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
|
2293 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
|
2294 if (assigning) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2295 com_pop(c, 1); |
| 69 | 2296 } |
| 2297 | |
| 2298 static void | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2299 com_assign(struct compiling *c, node *n, int assigning, node *augn) |
| 69 | 2300 { |
| 2301 /* Loop to avoid trivial recursion */ | |
| 2302 for (;;) { | |
| 2303 switch (TYPE(n)) { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2304 |
| 69 | 2305 case exprlist: |
| 2306 case testlist: | |
| 2307 if (NCH(n) > 1) { | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2308 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2309 com_error(c, PyExc_SyntaxError, |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
2310 "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
|
2311 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2312 } |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13884
diff
changeset
|
2313 com_assign_sequence(c, n, assigning); |
| 69 | 2314 return; |
| 2315 } | |
| 2316 n = CHILD(n, 0); | |
| 2317 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2318 |
| 69 | 2319 case test: |
| 2320 case and_test: | |
| 2321 case not_test: | |
| 2322 case comparison: | |
| 2323 case expr: | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2324 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2325 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2326 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2327 case arith_expr: |
| 69 | 2328 case term: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2329 case factor: |
| 69 | 2330 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
|
2331 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
|
2332 "can't assign to operator"); |
| 69 | 2333 return; |
| 2334 } | |
| 2335 n = CHILD(n, 0); | |
| 2336 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2337 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
2338 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
|
2339 ('+'|'-'|'~') factor | atom trailer* */ |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2340 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
|
2341 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
|
2342 "can't assign to operator"); |
| 69 | 2343 return; |
| 2344 } | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2345 if (NCH(n) > 1) { /* trailer or exponent present */ |
| 69 | 2346 int i; |
| 2347 com_node(c, CHILD(n, 0)); | |
| 2348 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
|
2349 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
|
2350 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
|
2351 "can't assign to operator"); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2352 return; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2353 } |
| 69 | 2354 com_apply_trailer(c, CHILD(n, i)); |
| 2355 } /* NB i is still alive */ | |
| 2356 com_assign_trailer(c, | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2357 CHILD(n, i), assigning, augn); |
| 69 | 2358 return; |
| 2359 } | |
| 2360 n = CHILD(n, 0); | |
| 2361 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2362 |
| 69 | 2363 case atom: |
| 2364 switch (TYPE(CHILD(n, 0))) { | |
| 2365 case LPAR: | |
| 2366 n = CHILD(n, 1); | |
| 2367 if (TYPE(n) == RPAR) { | |
| 2368 /* XXX Should allow () = () ??? */ | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2369 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
|
2370 "can't assign to ()"); |
| 69 | 2371 return; |
| 2372 } | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2373 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2374 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
|
2375 "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
|
2376 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2377 } |
| 69 | 2378 break; |
| 2379 case LSQB: | |
| 2380 n = CHILD(n, 1); | |
| 2381 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
|
2382 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
|
2383 "can't assign to []"); |
| 69 | 2384 return; |
| 2385 } | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2386 if (assigning > OP_APPLY) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2387 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
|
2388 "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
|
2389 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2390 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2391 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
|
2392 && 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
|
2393 com_error(c, PyExc_SyntaxError, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
2394 "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
|
2395 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2396 } |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
13884
diff
changeset
|
2397 com_assign_sequence(c, n, assigning); |
| 69 | 2398 return; |
| 2399 case NAME: | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2400 if (assigning > OP_APPLY) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2401 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
|
2402 assigning, augn); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2403 else |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2404 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
|
2405 assigning); |
| 69 | 2406 return; |
| 2407 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2408 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
|
2409 "can't assign to literal"); |
| 69 | 2410 return; |
| 2411 } | |
| 2412 break; | |
|
3963
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
2413 |
|
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
2414 case lambdef: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2415 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
|
2416 "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
|
2417 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2418 |
| 69 | 2419 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2420 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
|
2421 "com_assign: bad node"); |
| 69 | 2422 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2423 |
| 69 | 2424 } |
| 2425 } | |
| 2426 } | |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2427 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2428 static void |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2429 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
|
2430 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2431 int opcode; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2432 |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2433 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
|
2434 case '+': opcode = INPLACE_ADD; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2435 case '-': opcode = INPLACE_SUBTRACT; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2436 case '/': opcode = INPLACE_DIVIDE; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2437 case '%': opcode = INPLACE_MODULO; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2438 case '<': opcode = INPLACE_LSHIFT; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2439 case '>': opcode = INPLACE_RSHIFT; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2440 case '&': opcode = INPLACE_AND; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2441 case '^': opcode = INPLACE_XOR; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2442 case '|': opcode = INPLACE_OR; break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2443 case '*': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2444 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
|
2445 opcode = INPLACE_POWER; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2446 else |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2447 opcode = INPLACE_MULTIPLY; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2448 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2449 default: |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2450 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
|
2451 return; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2452 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2453 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
|
2454 } |
| 69 | 2455 |
| 2456 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2457 com_expr_stmt(struct compiling *c, node *n) |
| 69 | 2458 { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2459 REQ(n, expr_stmt); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2460 /* 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
|
2461 /* 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
|
2462 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
|
2463 return; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2464 if (NCH(n) == 1) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2465 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
|
2466 if (c->c_interactive) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2467 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
|
2468 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2469 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
|
2470 com_pop(c, 1); |
| 69 | 2471 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2472 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
|
2473 com_augassign(c, n); |
| 69 | 2474 else { |
| 2475 int i; | |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2476 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
|
2477 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
|
2478 if (i+2 < NCH(n)-2) { |
| 69 | 2479 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
|
2480 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
|
2481 } |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2482 com_assign(c, CHILD(n, i), OP_ASSIGN, NULL); |
| 69 | 2483 } |
| 2484 } | |
| 2485 } | |
| 2486 | |
| 2487 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2488 com_assert_stmt(struct compiling *c, node *n) |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2489 { |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2490 int a = 0, b = 0; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2491 int i; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2492 REQ(n, assert_stmt); /* 'assert' test [',' test] */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2493 /* Generate code like for |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2494 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2495 if __debug__: |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2496 if not <test>: |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2497 raise AssertionError [, <message>] |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2498 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2499 where <message> is the second test, if present. |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2500 */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2501 |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2502 if (Py_OptimizeFlag) |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2503 return; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2504 com_addop_name(c, LOAD_GLOBAL, "__debug__"); |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2505 com_push(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2506 com_addfwref(c, JUMP_IF_FALSE, &a); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2507 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2508 com_pop(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2509 com_node(c, CHILD(n, 1)); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2510 com_addfwref(c, JUMP_IF_TRUE, &b); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2511 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2512 com_pop(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2513 /* 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
|
2514 com_addop_name(c, LOAD_GLOBAL, "AssertionError"); |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2515 com_push(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2516 i = NCH(n)/2; /* Either 2 or 4 */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2517 if (i > 1) |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2518 com_node(c, CHILD(n, 3)); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2519 com_addoparg(c, RAISE_VARARGS, i); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2520 com_pop(c, i); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2521 /* The interpreter does not fall through */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2522 /* All jumps converge here */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2523 com_backpatch(c, a); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2524 com_backpatch(c, b); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2525 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2526 } |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2527 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2528 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2529 com_print_stmt(struct compiling *c, node *n) |
| 69 | 2530 { |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2531 int i = 1; |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2532 node* stream = NULL; |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2533 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2534 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
|
2535 |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2536 /* 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
|
2537 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
|
2538 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
|
2539 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
|
2540 /* stack: [...] => [... stream] */ |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2541 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
|
2542 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
|
2543 i = 4; |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2544 else |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2545 i = 3; |
| 69 | 2546 } |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2547 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
|
2548 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
|
2549 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
|
2550 /* 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
|
2551 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
|
2552 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
|
2553 /* 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
|
2554 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
|
2555 /* 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
|
2556 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
|
2557 /* 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
|
2558 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
|
2559 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2560 else { |
|
14105
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2561 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
|
2562 /* stack: [...] => [... obj] */ |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2563 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
|
2564 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
|
2565 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2566 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2567 /* 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
|
2568 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
|
2569 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
|
2570 /* 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
|
2571 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
|
2572 /* stack: [... stream] => [...] */ |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2573 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
|
2574 } |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2575 } |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2576 else { |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2577 if (stream != NULL) { |
|
d809b9b75b99
com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents:
14099
diff
changeset
|
2578 /* 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
|
2579 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
|
2580 /* stack: [... stream] => [...] */ |
|
14099
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2581 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
|
2582 } |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2583 else |
|
468481135c49
PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents:
14077
diff
changeset
|
2584 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
|
2585 } |
| 69 | 2586 } |
| 2587 | |
| 2588 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2589 com_return_stmt(struct compiling *c, node *n) |
| 69 | 2590 { |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2591 REQ(n, return_stmt); /* 'return' [testlist] */ |
| 86 | 2592 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
|
2593 com_error(c, PyExc_SyntaxError, "'return' outside function"); |
| 86 | 2594 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2595 if (NCH(n) < 2) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2596 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
|
2597 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
|
2598 } |
| 69 | 2599 else |
| 2600 com_node(c, CHILD(n, 1)); | |
| 2601 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
|
2602 com_pop(c, 1); |
| 69 | 2603 } |
| 2604 | |
| 2605 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2606 com_raise_stmt(struct compiling *c, node *n) |
| 69 | 2607 { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2608 int i; |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2609 REQ(n, raise_stmt); /* 'raise' [test [',' test [',' test]]] */ |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2610 if (NCH(n) > 1) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2611 com_node(c, CHILD(n, 1)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2612 if (NCH(n) > 3) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2613 com_node(c, CHILD(n, 3)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2614 if (NCH(n) > 5) |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2615 com_node(c, CHILD(n, 5)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2616 } |
|
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
|
2617 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2618 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
|
2619 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
|
2620 com_pop(c, i); |
| 69 | 2621 } |
| 2622 | |
| 2623 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
|
2624 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
|
2625 { |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
2626 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
|
2627 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
|
2628 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
|
2629 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
|
2630 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
|
2631 return; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
2632 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2633 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
|
2634 } 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
|
2635 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
|
2636 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
|
2637 } |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
2638 |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
2639 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2640 com_import_stmt(struct compiling *c, node *n) |
| 69 | 2641 { |
| 2642 int i; | |
| 2643 REQ(n, import_stmt); | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2644 /* 'import' dotted_name (',' dotted_name)* | |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2645 'from' dotted_name 'import' ('*' | NAME (',' NAME)*) */ |
| 69 | 2646 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
|
2647 PyObject *tup; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2648 /* 'from' dotted_name 'import' ... */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2649 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
|
2650 |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
2651 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
|
2652 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
|
2653 } else { |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
2654 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
|
2655 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
|
2656 PyTuple_SET_ITEM(tup, (i-3)/2, |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
2657 PyString_FromString(STR( |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
2658 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
|
2659 } |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
2660 } |
|
1f1a156ed5af
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents:
14230
diff
changeset
|
2661 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
|
2662 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
|
2663 com_push(c, 1); |
| 69 | 2664 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
|
2665 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
|
2666 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
|
2667 else { |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
2668 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
|
2669 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
|
2670 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
|
2671 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2672 com_pop(c, 1); |
| 69 | 2673 } |
| 2674 else { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2675 /* 'import' ... */ |
| 69 | 2676 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
|
2677 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
|
2678 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
|
2679 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
|
2680 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
|
2681 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
|
2682 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
|
2683 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
|
2684 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
|
2685 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
|
2686 "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
|
2687 return; |
|
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13997
diff
changeset
|
2688 } |
|
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
|
2689 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
|
2690 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
|
2691 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
|
2692 j)); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
2693 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
|
2694 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
|
2695 } 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
|
2696 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
|
2697 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
|
2698 0))); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2699 com_pop(c, 1); |
| 69 | 2700 } |
| 2701 } | |
| 2702 } | |
| 2703 | |
| 2704 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2705 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
|
2706 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2707 REQ(n, exec_stmt); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2708 /* 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
|
2709 com_node(c, CHILD(n, 1)); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2710 if (NCH(n) >= 4) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2711 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
|
2712 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2713 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
|
2714 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
|
2715 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2716 if (NCH(n) >= 6) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2717 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
|
2718 else { |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2719 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
|
2720 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
|
2721 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2722 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
|
2723 com_pop(c, 3); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2724 } |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2725 |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2726 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2727 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
|
2728 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2729 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
|
2730 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
|
2731 /* 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
|
2732 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2733 /* 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
|
2734 next: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2735 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
|
2736 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2737 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
|
2738 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
|
2739 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
|
2740 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
|
2741 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2742 /* 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
|
2743 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
|
2744 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
|
2745 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
|
2746 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
|
2747 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
|
2748 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
|
2749 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2750 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2751 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2752 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2753 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
|
2754 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
|
2755 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
|
2756 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
|
2757 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
|
2758 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2759 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
|
2760 case testlist: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2761 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
|
2762 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
|
2763 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
|
2764 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
|
2765 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
|
2766 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
|
2767 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
|
2768 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
|
2769 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
|
2770 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
|
2771 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
|
2772 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
|
2773 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
|
2774 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
|
2775 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
|
2776 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
|
2777 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2778 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2779 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2780 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
|
2781 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
|
2782 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
|
2783 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2784 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2785 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
|
2786 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
|
2787 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2788 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
|
2789 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2790 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2791 i = PyObject_IsTrue(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2792 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
|
2793 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
|
2794 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2795 case STRING: |
|
5183
636757e812a4
Fix dumb bug calling parsestrplus with wrong node as argument.
Guido van Rossum <guido@python.org>
parents:
5181
diff
changeset
|
2796 v = parsestr(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
|
2797 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2798 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
|
2799 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2800 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2801 i = PyObject_IsTrue(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2802 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
|
2803 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
|
2804 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2805 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2806 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
|
2807 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2808 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2809 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2810 com_if_stmt(struct compiling *c, node *n) |
| 69 | 2811 { |
| 2812 int i; | |
| 2813 int anchor = 0; | |
| 2814 REQ(n, if_stmt); | |
| 2815 /*'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] */ | |
| 2816 for (i = 0; i+3 < NCH(n); i+=4) { | |
| 2817 int a = 0; | |
| 86 | 2818 node *ch = CHILD(n, i+1); |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2819 if (is_constant_false(c, ch)) |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2820 continue; |
| 86 | 2821 if (i > 0) |
| 2822 com_addoparg(c, SET_LINENO, 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
|
2823 com_node(c, ch); |
| 69 | 2824 com_addfwref(c, JUMP_IF_FALSE, &a); |
| 2825 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
|
2826 com_pop(c, 1); |
| 69 | 2827 com_node(c, CHILD(n, i+3)); |
| 2828 com_addfwref(c, JUMP_FORWARD, &anchor); | |
| 2829 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
|
2830 /* We jump here with an extra entry which we now pop */ |
| 69 | 2831 com_addbyte(c, POP_TOP); |
| 2832 } | |
| 2833 if (i+2 < NCH(n)) | |
| 2834 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
|
2835 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
|
2836 com_backpatch(c, anchor); |
| 69 | 2837 } |
| 2838 | |
| 2839 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2840 com_while_stmt(struct compiling *c, node *n) |
| 69 | 2841 { |
| 2842 int break_anchor = 0; | |
| 2843 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2844 int save_begin = c->c_begin; |
| 69 | 2845 REQ(n, while_stmt); /* 'while' test ':' suite ['else' ':' suite] */ |
| 2846 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2847 block_push(c, SETUP_LOOP); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2848 c->c_begin = c->c_nexti; |
| 86 | 2849 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 2850 com_node(c, CHILD(n, 1)); |
| 2851 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 2852 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
|
2853 com_pop(c, 1); |
| 86 | 2854 c->c_loops++; |
| 69 | 2855 com_node(c, CHILD(n, 3)); |
| 86 | 2856 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2857 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2858 c->c_begin = save_begin; |
| 69 | 2859 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
|
2860 /* We jump here with one entry more on the stack */ |
| 69 | 2861 com_addbyte(c, POP_TOP); |
| 2862 com_addbyte(c, POP_BLOCK); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2863 block_pop(c, SETUP_LOOP); |
| 69 | 2864 if (NCH(n) > 4) |
| 2865 com_node(c, CHILD(n, 6)); | |
| 2866 com_backpatch(c, break_anchor); | |
| 2867 } | |
| 2868 | |
| 2869 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2870 com_for_stmt(struct compiling *c, node *n) |
| 69 | 2871 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2872 PyObject *v; |
| 69 | 2873 int break_anchor = 0; |
| 2874 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2875 int save_begin = c->c_begin; |
| 69 | 2876 REQ(n, for_stmt); |
| 2877 /* 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] */ | |
| 2878 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2879 block_push(c, SETUP_LOOP); |
| 69 | 2880 com_node(c, CHILD(n, 3)); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2881 v = PyInt_FromLong(0L); |
| 69 | 2882 if (v == NULL) |
| 2883 c->c_errors++; | |
| 2884 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
|
2885 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
|
2886 Py_XDECREF(v); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2887 c->c_begin = c->c_nexti; |
| 86 | 2888 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 2889 com_addfwref(c, FOR_LOOP, &anchor); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2890 com_push(c, 1); |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
2891 com_assign(c, CHILD(n, 1), OP_ASSIGN, NULL); |
| 86 | 2892 c->c_loops++; |
| 69 | 2893 com_node(c, CHILD(n, 5)); |
| 86 | 2894 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2895 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2896 c->c_begin = save_begin; |
| 69 | 2897 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
|
2898 com_pop(c, 2); /* FOR_LOOP has popped these */ |
| 69 | 2899 com_addbyte(c, POP_BLOCK); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2900 block_pop(c, SETUP_LOOP); |
| 69 | 2901 if (NCH(n) > 8) |
| 2902 com_node(c, CHILD(n, 8)); | |
| 2903 com_backpatch(c, break_anchor); | |
| 2904 } | |
| 2905 | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2906 /* 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
|
2907 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2908 SETUP_FINALLY L |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2909 <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2910 POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2911 LOAD_CONST <nil> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2912 L: <code for Sf> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2913 END_FINALLY |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2914 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2915 The special instructions use the block stack. Each block |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2916 stack entry contains the instruction that created it (here |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2917 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
|
2918 block stack entry was created, and a label (here L). |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2919 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2920 SETUP_FINALLY: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2921 Pushes the current value stack level and the label |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2922 onto the block stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2923 POP_BLOCK: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2924 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
|
2925 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
|
2926 block stack. (The label is ignored.) |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2927 END_FINALLY: |
| 86 | 2928 Pops a variable number of entries from the *value* stack |
| 2929 and re-raises the exception they specify. The number of | |
| 2930 entries popped depends on the (pseudo) exception type. | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2931 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2932 The block stack is unwound when an exception is raised: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2933 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
|
2934 onto the value stack (and the exception condition is cleared), |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2935 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
|
2936 stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2937 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2938 Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...": |
| 86 | 2939 (The contents of the value stack is shown in [], with the top |
| 2940 at the right; 'tb' is trace-back info, 'val' the exception's | |
| 2941 associated value, and 'exc' the exception.) | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2942 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2943 Value stack Label Instruction Argument |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2944 [] SETUP_EXCEPT L1 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2945 [] <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2946 [] POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2947 [] JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2948 |
| 86 | 2949 [tb, val, exc] L1: DUP ) |
| 2950 [tb, val, exc, exc] <evaluate E1> ) | |
| 2951 [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1 | |
| 2952 [tb, val, exc, 1-or-0] JUMP_IF_FALSE L2 ) | |
| 2953 [tb, val, exc, 1] POP ) | |
| 2954 [tb, val, exc] POP | |
| 2955 [tb, val] <assign to V1> (or POP if no V1) | |
| 2956 [tb] POP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2957 [] <code for S1> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2958 JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2959 |
| 86 | 2960 [tb, val, exc, 0] L2: POP |
| 2961 [tb, val, exc] DUP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2962 .............................etc....................... |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2963 |
| 86 | 2964 [tb, val, exc, 0] Ln+1: POP |
| 2965 [tb, val, exc] END_FINALLY # re-raise exception | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2966 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2967 [] L0: <next statement> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2968 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2969 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
|
2970 */ |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2971 |
| 69 | 2972 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
2973 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
|
2974 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2975 int except_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2976 int end_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2977 int else_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2978 int i; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2979 node *ch; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2980 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2981 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
|
2982 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
|
2983 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
|
2984 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
|
2985 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
|
2986 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
|
2987 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
|
2988 for (i = 3; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2989 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
|
2990 i += 3) { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2991 /* 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
|
2992 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
|
2993 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
|
2994 "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
|
2995 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2996 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2997 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
|
2998 com_push(c, 3); /* tb, val, exc pushed by exception */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2999 com_addoparg(c, SET_LINENO, ch->n_lineno); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3000 if (NCH(ch) > 1) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3001 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
|
3002 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
|
3003 com_node(c, CHILD(ch, 1)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3004 com_addoparg(c, COMPARE_OP, EXC_MATCH); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3005 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
|
3006 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
|
3007 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
|
3008 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
|
3009 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3010 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
|
3011 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
|
3012 if (NCH(ch) > 3) |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
3013 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
|
3014 else { |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3015 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
|
3016 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
|
3017 } |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3018 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
|
3019 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
|
3020 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
|
3021 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
|
3022 if (except_anchor) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3023 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
|
3024 /* 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
|
3025 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
|
3026 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
|
3027 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
|
3028 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3029 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3030 /* 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
|
3031 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
|
3032 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
|
3033 anything. */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3034 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
|
3035 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
|
3036 if (i < NCH(n)) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3037 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
|
3038 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
|
3039 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3040 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3041 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3042 com_try_finally(struct compiling *c, node *n) |
| 69 | 3043 { |
| 3044 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
|
3045 node *ch; |
|
792
dc3b455f7632
Only * can be used for varargs argument lists
Guido van Rossum <guido@python.org>
parents:
744
diff
changeset
|
3046 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3047 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
|
3048 block_push(c, SETUP_FINALLY); |
| 69 | 3049 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
|
3050 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
|
3051 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
|
3052 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
|
3053 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
|
3054 /* 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
|
3055 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
|
3056 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
|
3057 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
|
3058 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
|
3059 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
|
3060 ch = CHILD(n, NCH(n)-1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3061 com_addoparg(c, SET_LINENO, ch->n_lineno); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3062 com_node(c, ch); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3063 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
|
3064 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
|
3065 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
|
3066 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3067 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3068 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3069 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
|
3070 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3071 REQ(n, try_stmt); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3072 /* '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
|
3073 | 'try' ':' suite 'finally' ':' suite */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3074 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
|
3075 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
|
3076 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3077 com_try_except(c, n); |
| 69 | 3078 } |
| 3079 | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3080 static node * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3081 get_rawdocstring(node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3082 { |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3083 int i; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3084 |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3085 /* 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
|
3086 next: |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3087 switch (TYPE(n)) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3088 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3089 case suite: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3090 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
|
3091 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
|
3092 goto next; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3093 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3094 /* Fall through */ |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3095 case file_input: |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3096 for (i = 0; i < NCH(n); i++) { |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3097 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
|
3098 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
|
3099 n = ch; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3100 goto next; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3101 } |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3102 } |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3103 break; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
3104 |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3105 case stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3106 case simple_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3107 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
|
3108 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
|
3109 goto next; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3110 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3111 case expr_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3112 case testlist: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3113 case test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3114 case and_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3115 case not_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3116 case comparison: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3117 case expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3118 case xor_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3119 case and_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3120 case shift_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3121 case arith_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3122 case term: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3123 case factor: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3124 case power: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3125 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
|
3126 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
|
3127 goto next; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3128 } |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3129 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3130 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3131 case atom: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3132 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
|
3133 return n; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3134 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3135 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3136 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3137 return NULL; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3138 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3139 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3140 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3141 get_docstring(node *n) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3142 { |
|
9987
b7bcc2cda1b3
Implement -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents:
9626
diff
changeset
|
3143 /* 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
|
3144 if (Py_OptimizeFlag > 1) |
|
b7bcc2cda1b3
Implement -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents:
9626
diff
changeset
|
3145 return NULL; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3146 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
|
3147 if (n == NULL) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3148 return NULL; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3149 return parsestrplus(n); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3150 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3151 |
| 69 | 3152 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3153 com_suite(struct compiling *c, node *n) |
| 69 | 3154 { |
| 3155 REQ(n, suite); | |
| 3156 /* simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT */ | |
| 3157 if (NCH(n) == 1) { | |
| 3158 com_node(c, CHILD(n, 0)); | |
| 3159 } | |
| 3160 else { | |
| 3161 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
|
3162 for (i = 0; i < NCH(n) && c->c_errors == 0; i++) { |
| 69 | 3163 node *ch = CHILD(n, i); |
| 3164 if (TYPE(ch) == stmt) | |
| 3165 com_node(c, ch); | |
| 3166 } | |
| 3167 } | |
| 3168 } | |
| 3169 | |
| 744 | 3170 /* ARGSUSED */ |
| 69 | 3171 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3172 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
|
3173 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3174 int i = c->c_nblocks; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3175 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
|
3176 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3177 } |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3178 else if (i <= 0) { |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3179 /* at the outer level */ |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3180 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
|
3181 "'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
|
3182 } |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3183 else { |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3184 int j; |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3185 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
|
3186 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
|
3187 break; |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3188 } |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3189 if (j >= 0) { |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3190 /* there is a loop, but something interferes */ |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3191 for (; i > j; --i) { |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3192 if (c->c_block[i] == SETUP_EXCEPT || |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3193 c->c_block[i] == SETUP_FINALLY) { |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3194 com_addoparg(c, CONTINUE_LOOP, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3195 c->c_begin); |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3196 return; |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3197 } |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3198 if (c->c_block[i] == END_FINALLY) { |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3199 com_error(c, PyExc_SyntaxError, |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3200 "'continue' not supported inside 'finally' clause"); |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3201 return; |
|
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16394
diff
changeset
|
3202 } |
|
14471
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3203 } |
|
c3c49859e80b
com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents:
14382
diff
changeset
|
3204 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3205 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
|
3206 "'continue' not properly in loop"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3207 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3208 /* XXX Could allow it inside a 'finally' clause |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3209 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
|
3210 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3211 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3212 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3213 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
|
3214 { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3215 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
|
3216 if (TYPE(n) == lambdef) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3217 /* lambdef: 'lambda' [varargslist] ':' test */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3218 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3219 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3220 else { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3221 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
|
3222 n = CHILD(n, 2); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3223 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
|
3224 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3225 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3226 if (TYPE(n) != varargslist) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3227 return 0; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3228 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3229 (fpdef ['=' test] ',')* '*' ....... | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3230 fpdef ['=' test] (',' fpdef ['=' test])* [','] */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3231 nch = NCH(n); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3232 nargs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3233 ndefs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3234 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
|
3235 int t; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3236 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
|
3237 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
|
3238 break; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3239 nargs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3240 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3241 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
|
3242 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
|
3243 else |
|
e51e17b2d88b
fix bug with missing default for last arg (discovered by Tommy Burnette)
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
3244 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
|
3245 if (t == EQUAL) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3246 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3247 ndefs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3248 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
|
3249 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3250 if (i >= nch) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3251 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3252 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
|
3253 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3254 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
|
3255 /* 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
|
3256 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
|
3257 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
|
3258 "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
|
3259 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3260 if (t != COMMA) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3261 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3262 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3263 return ndefs; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3264 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3265 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3266 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3267 com_funcdef(struct compiling *c, node *n) |
| 69 | 3268 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3269 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
|
3270 int ndefs; |
| 69 | 3271 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
|
3272 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
|
3273 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
|
3274 n->n_lineno); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3275 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
|
3276 symtable_exit_scope(c->c_symtable); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3277 if (co == NULL) |
| 69 | 3278 c->c_errors++; |
| 3279 else { | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3280 int closure = com_make_closure(c, (PyCodeObject *)co); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3281 int i = com_addconst(c, co); |
| 69 | 3282 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
|
3283 com_push(c, 1); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3284 if (closure) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3285 com_addoparg(c, MAKE_CLOSURE, ndefs); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3286 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3287 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
|
3288 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
|
3289 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
|
3290 com_pop(c, 1); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3291 Py_DECREF(co); |
| 69 | 3292 } |
| 3293 } | |
| 3294 | |
| 3295 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3296 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
|
3297 { |
| 744 | 3298 int i; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3299 REQ(n, testlist); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3300 /* testlist: test (',' test)* [','] */ |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3301 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
|
3302 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
|
3303 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
|
3304 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
|
3305 com_pop(c, i-1); |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3306 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3307 |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3308 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3309 com_classdef(struct compiling *c, node *n) |
| 69 | 3310 { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3311 int i; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3312 PyObject *co, *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
|
3313 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
|
3314 |
| 69 | 3315 REQ(n, classdef); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3316 /* 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
|
3317 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
|
3318 c->c_errors++; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3319 return; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3320 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3321 /* Push the class name on the stack */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3322 i = com_addconst(c, v); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3323 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
|
3324 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
|
3325 Py_DECREF(v); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3326 /* 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
|
3327 if (TYPE(CHILD(n, 2)) != LPAR) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3328 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
|
3329 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
|
3330 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3331 else |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
3332 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
|
3333 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
|
3334 symtable_enter_scope(c->c_symtable, name, TYPE(n), n->n_lineno); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3335 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
|
3336 symtable_exit_scope(c->c_symtable); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3337 if (co == NULL) |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3338 c->c_errors++; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3339 else { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3340 int closure = com_make_closure(c, (PyCodeObject *)co); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3341 i = com_addconst(c, co); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3342 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
|
3343 com_push(c, 1); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3344 if (closure) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3345 com_addoparg(c, MAKE_CLOSURE, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3346 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3347 com_addoparg(c, MAKE_FUNCTION, 0); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3348 com_addoparg(c, CALL_FUNCTION, 0); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3349 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
|
3350 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
|
3351 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 1))); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3352 Py_DECREF(co); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3353 } |
| 69 | 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_node(struct compiling *c, node *n) |
| 69 | 3358 { |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3359 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
|
3360 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
|
3361 return; |
| 69 | 3362 switch (TYPE(n)) { |
| 3363 | |
| 3364 /* Definition nodes */ | |
| 3365 | |
| 3366 case funcdef: | |
| 3367 com_funcdef(c, n); | |
| 3368 break; | |
| 3369 case classdef: | |
| 3370 com_classdef(c, n); | |
| 3371 break; | |
| 3372 | |
| 3373 /* Trivial parse tree nodes */ | |
| 3374 | |
| 3375 case stmt: | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3376 case small_stmt: |
| 86 | 3377 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
|
3378 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
|
3379 goto loop; |
| 86 | 3380 |
| 69 | 3381 case simple_stmt: |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3382 /* small_stmt (';' small_stmt)* [';'] NEWLINE */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3383 com_addoparg(c, SET_LINENO, n->n_lineno); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3384 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3385 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3386 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
|
3387 com_node(c, CHILD(n, i)); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3388 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3389 break; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3390 |
| 69 | 3391 case compound_stmt: |
| 86 | 3392 com_addoparg(c, SET_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
|
3393 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
|
3394 goto loop; |
| 69 | 3395 |
| 3396 /* Statement nodes */ | |
| 3397 | |
| 3398 case expr_stmt: | |
| 3399 com_expr_stmt(c, n); | |
| 3400 break; | |
| 3401 case print_stmt: | |
| 3402 com_print_stmt(c, n); | |
| 3403 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3404 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
|
3405 com_assign(c, CHILD(n, 1), OP_DELETE, NULL); |
| 69 | 3406 break; |
| 3407 case pass_stmt: | |
| 3408 break; | |
| 3409 case break_stmt: | |
| 86 | 3410 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
|
3411 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
|
3412 "'break' outside loop"); |
| 86 | 3413 } |
| 69 | 3414 com_addbyte(c, BREAK_LOOP); |
| 3415 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3416 case continue_stmt: |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3417 com_continue_stmt(c, n); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
3418 break; |
| 69 | 3419 case return_stmt: |
| 3420 com_return_stmt(c, n); | |
| 3421 break; | |
| 3422 case raise_stmt: | |
| 3423 com_raise_stmt(c, n); | |
| 3424 break; | |
| 3425 case import_stmt: | |
| 3426 com_import_stmt(c, n); | |
| 3427 break; | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3428 case global_stmt: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
3429 break; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3430 case exec_stmt: |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3431 com_exec_stmt(c, n); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
3432 break; |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3433 case assert_stmt: |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3434 com_assert_stmt(c, n); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3435 break; |
| 69 | 3436 case if_stmt: |
| 3437 com_if_stmt(c, n); | |
| 3438 break; | |
| 3439 case while_stmt: | |
| 3440 com_while_stmt(c, n); | |
| 3441 break; | |
| 3442 case for_stmt: | |
| 3443 com_for_stmt(c, n); | |
| 3444 break; | |
| 3445 case try_stmt: | |
| 3446 com_try_stmt(c, n); | |
| 3447 break; | |
| 3448 case suite: | |
| 3449 com_suite(c, n); | |
| 3450 break; | |
| 3451 | |
| 3452 /* Expression nodes */ | |
| 3453 | |
| 3454 case testlist: | |
| 482 | 3455 com_list(c, n, 0); |
| 69 | 3456 break; |
| 3457 case test: | |
| 3458 com_test(c, n); | |
| 3459 break; | |
| 3460 case and_test: | |
| 3461 com_and_test(c, n); | |
| 3462 break; | |
| 3463 case not_test: | |
| 3464 com_not_test(c, n); | |
| 3465 break; | |
| 3466 case comparison: | |
| 3467 com_comparison(c, n); | |
| 3468 break; | |
| 3469 case exprlist: | |
| 482 | 3470 com_list(c, n, 0); |
| 69 | 3471 break; |
| 3472 case expr: | |
| 3473 com_expr(c, n); | |
| 3474 break; | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3475 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3476 com_xor_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3477 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3478 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3479 com_and_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3480 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3481 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3482 com_shift_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3483 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3484 case arith_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3485 com_arith_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
3486 break; |
| 69 | 3487 case term: |
| 3488 com_term(c, n); | |
| 3489 break; | |
| 3490 case factor: | |
| 3491 com_factor(c, n); | |
| 3492 break; | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3493 case power: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3494 com_power(c, n); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3495 break; |
| 69 | 3496 case atom: |
| 3497 com_atom(c, n); | |
| 3498 break; | |
| 3499 | |
| 3500 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3501 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
|
3502 "com_node: unexpected node type"); |
| 69 | 3503 } |
| 3504 } | |
| 3505 | |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13330
diff
changeset
|
3506 static void com_fplist(struct compiling *, node *); |
| 69 | 3507 |
| 3508 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3509 com_fpdef(struct compiling *c, node *n) |
| 69 | 3510 { |
| 3511 REQ(n, fpdef); /* fpdef: NAME | '(' fplist ')' */ | |
| 3512 if (TYPE(CHILD(n, 0)) == LPAR) | |
| 3513 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
|
3514 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
|
3515 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
|
3516 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
|
3517 } |
| 69 | 3518 } |
| 3519 | |
| 3520 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3521 com_fplist(struct compiling *c, node *n) |
| 69 | 3522 { |
| 544 | 3523 REQ(n, fplist); /* fplist: fpdef (',' fpdef)* [','] */ |
| 69 | 3524 if (NCH(n) == 1) { |
| 3525 com_fpdef(c, CHILD(n, 0)); | |
| 3526 } | |
| 3527 else { | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3528 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
|
3529 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
|
3530 com_push(c, i-1); |
| 69 | 3531 for (i = 0; i < NCH(n); i += 2) |
| 3532 com_fpdef(c, CHILD(n, i)); | |
| 3533 } | |
| 3534 } | |
| 3535 | |
| 3536 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3537 com_arglist(struct compiling *c, node *n) |
| 584 | 3538 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3539 int nch, i, narg; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3540 int complex = 0; |
|
5754
9ed26afeeaa5
Fix bug reported by Just: anonymous arguments used for tuples should
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
3541 char nbuf[10]; |
| 584 | 3542 REQ(n, varargslist); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
3543 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3544 (fpdef ['=' test] ',')* (fpdef ['=' test] | '*' .....) */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3545 nch = NCH(n); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3546 /* Enter all arguments in table of locals */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3547 for (i = 0, narg = 0; i < nch; i++) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3548 node *ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3549 node *fp; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3550 char *name; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3551 if (TYPE(ch) == STAR || TYPE(ch) == 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
|
3552 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3553 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3554 fp = CHILD(ch, 0); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3555 if (TYPE(fp) == NAME) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3556 PyObject *v; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3557 name = STR(fp); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3558 v = PyDict_GetItemString(c->c_cellvars, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3559 if (v) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3560 com_addoparg(c, LOAD_FAST, narg); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3561 com_addoparg(c, STORE_DEREF, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3562 PyInt_AS_LONG(v)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3563 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3564 } else { |
|
5754
9ed26afeeaa5
Fix bug reported by Just: anonymous arguments used for tuples should
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
3565 name = nbuf; |
|
9ed26afeeaa5
Fix bug reported by Just: anonymous arguments used for tuples should
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
3566 sprintf(nbuf, ".%d", i); |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3366
diff
changeset
|
3567 complex = 1; |
|
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
|
3568 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3569 narg++; |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3570 /* all name updates handled by symtable */ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3571 if (++i >= nch) |
| 584 | 3572 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3573 ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3574 if (TYPE(ch) == EQUAL) |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3575 i += 2; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3576 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3577 REQ(ch, COMMA); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3578 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3579 /* Handle *arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3580 if (i < nch) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3581 node *ch; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3582 ch = CHILD(n, i); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3583 if (TYPE(ch) != DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3584 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3585 ch = CHILD(n, i+1); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3586 if (TYPE(ch) == NAME) { |
|
16540
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3587 PyObject *v; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3588 i += 3; |
|
16540
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3589 v = PyDict_GetItemString(c->c_cellvars, |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3590 STR(ch)); |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3591 if (v) { |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3592 com_addoparg(c, LOAD_FAST, narg); |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3593 com_addoparg(c, STORE_DEREF, |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3594 PyInt_AS_LONG(v)); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3595 } |
|
16540
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3596 narg++; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3597 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3598 } |
|
16540
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3599 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3600 /* Handle **keywords */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3601 if (i < nch) { |
|
16540
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3602 PyObject *v; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3603 node *ch; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3604 ch = CHILD(n, i); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3605 if (TYPE(ch) != DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3606 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3607 ch = CHILD(n, i+1); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3608 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3609 ch = CHILD(n, i+2); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3610 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3611 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3612 ch = CHILD(n, i+1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3613 REQ(ch, NAME); |
|
16540
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3614 v = PyDict_GetItemString(c->c_cellvars, STR(ch)); |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3615 if (v) { |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3616 com_addoparg(c, LOAD_FAST, narg); |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3617 com_addoparg(c, STORE_DEREF, PyInt_AS_LONG(v)); |
|
8236f3e7585e
SF patch 103589: Fix handling of cell vars that are either * or ** parameters.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
3618 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3619 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3620 if (complex) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3621 /* Generate code for complex arguments only after |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3622 having counted the simple arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3623 int ilocal = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3624 for (i = 0; i < nch; i++) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3625 node *ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3626 node *fp; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3627 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
|
3628 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3629 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3630 fp = CHILD(ch, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3631 if (TYPE(fp) != NAME) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3632 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
|
3633 com_push(c, 1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3634 com_fpdef(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3635 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3636 ilocal++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3637 if (++i >= nch) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3638 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3639 ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3640 if (TYPE(ch) == EQUAL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3641 i += 2; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3642 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3643 REQ(ch, COMMA); |
| 584 | 3644 } |
| 3645 } | |
| 3646 } | |
| 3647 | |
| 3648 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3649 com_file_input(struct compiling *c, node *n) |
| 69 | 3650 { |
| 3651 int i; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3652 PyObject *doc; |
| 69 | 3653 REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */ |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3654 doc = get_docstring(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3655 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3656 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
|
3657 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3658 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
|
3659 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
|
3660 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
|
3661 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3662 } |
| 69 | 3663 for (i = 0; i < NCH(n); i++) { |
| 3664 node *ch = CHILD(n, i); | |
| 3665 if (TYPE(ch) != ENDMARKER && TYPE(ch) != NEWLINE) | |
| 3666 com_node(c, ch); | |
| 3667 } | |
| 3668 } | |
| 3669 | |
| 3670 /* Top-level compile-node interface */ | |
| 3671 | |
| 3672 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3673 compile_funcdef(struct compiling *c, node *n) |
| 69 | 3674 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3675 PyObject *doc; |
| 69 | 3676 node *ch; |
| 3677 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
|
3678 c->c_name = STR(CHILD(n, 1)); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3679 doc = get_docstring(CHILD(n, 4)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3680 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3681 (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
|
3682 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3683 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3684 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3685 (void) com_addconst(c, Py_None); /* No docstring */ |
| 584 | 3686 ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */ |
| 3687 ch = CHILD(ch, 1); /* ')' | varargslist */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3688 if (TYPE(ch) == varargslist) |
| 584 | 3689 com_arglist(c, ch); |
| 86 | 3690 c->c_infunction = 1; |
| 69 | 3691 com_node(c, CHILD(n, 4)); |
| 86 | 3692 c->c_infunction = 0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3693 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
|
3694 com_push(c, 1); |
| 69 | 3695 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
|
3696 com_pop(c, 1); |
| 69 | 3697 } |
| 3698 | |
| 3699 static void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3700 compile_lambdef(struct compiling *c, node *n) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3701 { |
|
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
|
3702 node *ch; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3703 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
|
3704 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
|
3705 |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
3706 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
|
3707 (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
|
3708 if (TYPE(ch) == varargslist) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3709 com_arglist(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3710 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
|
3711 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3712 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3713 ch = CHILD(n, 2); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3714 com_node(c, ch); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3715 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
|
3716 com_pop(c, 1); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3717 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3718 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3719 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3720 compile_classdef(struct compiling *c, node *n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3721 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3722 node *ch; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3723 PyObject *doc; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3724 REQ(n, classdef); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3725 /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3726 c->c_name = STR(CHILD(n, 1)); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3727 c->c_private = c->c_name; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3728 ch = CHILD(n, NCH(n)-1); /* The suite */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3729 doc = get_docstring(ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3730 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3731 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
|
3732 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3733 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
|
3734 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
|
3735 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
|
3736 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3737 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3738 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3739 (void) com_addconst(c, Py_None); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3740 com_node(c, ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3741 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
|
3742 com_push(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3743 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
|
3744 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3745 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3746 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3747 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3748 compile_node(struct compiling *c, node *n) |
| 69 | 3749 { |
| 86 | 3750 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 3751 | |
| 69 | 3752 switch (TYPE(n)) { |
| 3753 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3754 case single_input: /* One interactive command */ |
| 69 | 3755 /* 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
|
3756 c->c_interactive++; |
| 69 | 3757 n = CHILD(n, 0); |
| 3758 if (TYPE(n) != NEWLINE) | |
| 3759 com_node(c, n); | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3760 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
|
3761 com_push(c, 1); |
| 86 | 3762 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
|
3763 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
|
3764 c->c_interactive--; |
| 69 | 3765 break; |
| 3766 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3767 case file_input: /* A whole file, or built-in function exec() */ |
| 69 | 3768 com_file_input(c, n); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3769 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
|
3770 com_push(c, 1); |
| 86 | 3771 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
|
3772 com_pop(c, 1); |
| 69 | 3773 break; |
| 3774 | |
|
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
|
3775 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
|
3776 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
|
3777 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
|
3778 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
|
3779 break; |
|
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3780 |
|
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
|
3781 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
|
3782 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
|
3783 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
|
3784 |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3785 case funcdef: /* A function definition */ |
| 69 | 3786 compile_funcdef(c, n); |
| 3787 break; | |
| 3788 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3789 case classdef: /* A class definition */ |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3790 compile_classdef(c, n); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3791 break; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3792 |
| 69 | 3793 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3794 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
|
3795 "compile_node: unexpected node type"); |
| 69 | 3796 } |
| 3797 } | |
| 3798 | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3799 static PyObject * |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3800 dict_keys_inorder(PyObject *dict, int offset) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3801 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3802 PyObject *tuple, *k, *v; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3803 int i, pos = 0, size = PyDict_Size(dict); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3804 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3805 tuple = PyTuple_New(size); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3806 if (tuple == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3807 return NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3808 while (PyDict_Next(dict, &pos, &k, &v)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3809 i = PyInt_AS_LONG(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3810 Py_INCREF(k); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3811 PyTuple_SET_ITEM(tuple, i - offset, k); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3812 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3813 return tuple; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3814 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3815 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3816 PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3817 PyNode_Compile(node *n, char *filename) |
| 69 | 3818 { |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3819 return jcompile(n, filename, NULL); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3820 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3821 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3822 struct symtable * |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3823 PyNode_CompileSymtable(node *n, char *filename) |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3824 { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3825 struct symtable *st; |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3826 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
3827 st = symtable_init(); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3828 if (st == NULL) |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3829 return NULL; |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
3830 assert(st->st_symbols != 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
|
3831 symtable_enter_scope(st, 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
|
3832 if (st->st_errors > 0) { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3833 PySymtable_Free(st); |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3834 return NULL; |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3835 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3836 symtable_node(st, n); |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3837 if (st->st_errors > 0) { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3838 PySymtable_Free(st); |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3839 return NULL; |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3840 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3841 return st; |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3842 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
3843 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3844 static PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3845 icompile(node *n, struct compiling *base) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3846 { |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3847 return jcompile(n, base->c_filename, base); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3848 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3849 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3850 static PyCodeObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3851 jcompile(node *n, char *filename, struct compiling *base) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3852 { |
| 69 | 3853 struct compiling sc; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3854 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
|
3855 if (!com_init(&sc, filename)) |
| 69 | 3856 return 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
|
3857 if (base) { |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3858 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
|
3859 sc.c_symtable = base->c_symtable; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3860 /* c_symtable still points to parent's symbols */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3861 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
|
3862 || (sc.c_symtable->st_cur->ste_type == TYPE_FUNCTION)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3863 sc.c_nested = 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
|
3864 } else { |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3865 sc.c_private = NULL; |
|
16799
08d937107fe6
Improved __future__ parser; still more to do
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16783
diff
changeset
|
3866 sc.c_future = PyNode_Future(n, filename); |
|
08d937107fe6
Improved __future__ parser; still more to do
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16783
diff
changeset
|
3867 if (sc.c_future == NULL || 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
|
3868 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
|
3869 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
|
3870 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3871 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3872 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
|
3873 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
|
3874 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
|
3875 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
|
3876 } |
| 69 | 3877 compile_node(&sc, n); |
| 3878 com_done(&sc); | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
3879 if (sc.c_errors == 0) { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3880 PyObject *consts, *names, *varnames, *filename, *name, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3881 *freevars, *cellvars; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3882 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
|
3883 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
|
3884 varnames = PyList_AsTuple(sc.c_varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3885 cellvars = dict_keys_inorder(sc.c_cellvars, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3886 freevars = dict_keys_inorder(sc.c_freevars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3887 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
|
3888 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
|
3889 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
|
3890 if (!PyErr_Occurred()) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3891 co = PyCode_New(sc.c_argcount, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3892 sc.c_nlocals, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3893 sc.c_maxstacklevel, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3894 sc.c_flags, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3895 sc.c_code, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3896 consts, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3897 names, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3898 varnames, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3899 freevars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3900 cellvars, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3901 filename, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3902 name, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3903 sc.c_firstlineno, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3904 sc.c_lnotab); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3905 Py_XDECREF(consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3906 Py_XDECREF(names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3907 Py_XDECREF(varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3908 Py_XDECREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3909 Py_XDECREF(cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3910 Py_XDECREF(filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3911 Py_XDECREF(name); |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
3912 } |
|
13884
8eeaff96b4c2
When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents:
13873
diff
changeset
|
3913 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
|
3914 /* 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
|
3915 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
|
3916 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
|
3917 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
|
3918 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
|
3919 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
|
3920 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3921 exit: |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
3922 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
|
3923 PySymtable_Free(sc.c_symtable); |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
3924 sc.c_symtable = NULL; |
|
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
3925 } |
| 69 | 3926 com_free(&sc); |
| 3927 return co; | |
| 3928 } | |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3929 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3930 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13585
diff
changeset
|
3931 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
|
3932 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3933 int size = PyString_Size(co->co_lnotab) / 2; |
| 11290 | 3934 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
|
3935 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
|
3936 int addr = 0; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3937 while (--size >= 0) { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3938 addr += *p++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3939 if (addr > addrq) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3940 break; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3941 line += *p++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3942 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3943 return line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3944 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3945 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3946 /* 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
|
3947 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
|
3948 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
|
3949 */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3950 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3951 static int |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3952 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
|
3953 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3954 PyObject *v; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3955 if (c->c_symtable->st_nested_scopes) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3956 if (PyDict_GetItemString(c->c_cellvars, name) != NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3957 return CELL; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3958 if (PyDict_GetItemString(c->c_locals, name) != NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3959 return LOCAL; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3960 if (PyDict_GetItemString(c->c_freevars, name) != NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3961 return FREE; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3962 v = PyDict_GetItemString(c->c_globals, name); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3963 if (v) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3964 if (v == Py_None) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3965 return GLOBAL_EXPLICIT; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3966 else { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3967 return GLOBAL_IMPLICIT; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3968 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3969 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3970 } else { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3971 if (PyDict_GetItemString(c->c_locals, name) != NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3972 return LOCAL; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3973 v = PyDict_GetItemString(c->c_globals, name); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3974 if (v) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3975 if (v == Py_None) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3976 return GLOBAL_EXPLICIT; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3977 else { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3978 return GLOBAL_IMPLICIT; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
3979 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3980 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3981 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3982 { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
3983 char buf[350]; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
3984 sprintf(buf, |
|
16878
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3985 "unknown scope for %.100s in %.100s(%s) " |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3986 "in %s\nsymbols: %s\nlocals: %s\nglobals: %s\n", |
|
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
|
3987 name, c->c_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
|
3988 PyObject_REPR(c->c_symtable->st_cur->ste_id), |
|
16878
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3989 c->c_filename, |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3990 PyObject_REPR(c->c_symtable->st_cur->ste_symbols), |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3991 PyObject_REPR(c->c_locals), |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3992 PyObject_REPR(c->c_globals) |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3993 ); |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
3994 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3995 Py_FatalError(buf); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3996 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
3997 return -1; /* can't get here */ |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3998 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
3999 |
|
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
|
4000 /* Helper function to issue symbol table warnings */ |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4001 |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4002 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
|
4003 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
|
4004 { |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4005 if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename, |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4006 st->st_cur->ste_lineno, NULL, NULL) < 0) { |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4007 if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) { |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4008 PyErr_SetString(PyExc_SyntaxError, 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
|
4009 PyErr_SyntaxLocation(st->st_filename, |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4010 st->st_cur->ste_lineno); |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4011 } |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4012 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
|
4013 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
|
4014 } |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4015 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
|
4016 } |
|
ec9083ac26df
Let's have some sanity. Introduce a helper to issue a symbol table
Guido van Rossum <guido@python.org>
parents:
16853
diff
changeset
|
4017 |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16823
diff
changeset
|
4018 /* 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
|
4019 |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4020 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
|
4021 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
|
4022 { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4023 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
|
4024 return -1; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
4025 c->c_symtable->st_future = c->c_future; |
|
16799
08d937107fe6
Improved __future__ parser; still more to do
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16783
diff
changeset
|
4026 if (c->c_future->ff_nested_scopes) |
|
08d937107fe6
Improved __future__ parser; still more to do
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16783
diff
changeset
|
4027 c->c_symtable->st_nested_scopes = 1; |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
4028 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
|
4029 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
|
4030 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
|
4031 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
|
4032 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
|
4033 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
|
4034 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
|
4035 /* 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
|
4036 c->c_symtable->st_nscopes = 1; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4037 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
|
4038 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
|
4039 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4040 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4041 static int |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4042 symtable_init_compiling_symbols(struct compiling *c) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4043 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4044 PyObject *varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4045 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4046 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
|
4047 if (varnames == NULL) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4048 varnames = PyList_New(0); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4049 if (varnames == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4050 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4051 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
|
4052 Py_INCREF(varnames); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4053 } else |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4054 Py_INCREF(varnames); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4055 c->c_varnames = varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4056 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4057 c->c_globals = PyDict_New(); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4058 if (c->c_globals == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4059 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4060 c->c_freevars = PyDict_New(); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4061 if (c->c_freevars == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4062 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4063 c->c_cellvars = PyDict_New(); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4064 if (c->c_cellvars == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4065 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4066 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4067 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4068 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4069 struct symbol_info { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4070 int si_nlocals; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4071 int si_ncells; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4072 int si_nfrees; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4073 int si_nimplicit; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4074 }; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4075 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4076 static void |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4077 symtable_init_info(struct symbol_info *si) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4078 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4079 si->si_nlocals = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4080 si->si_ncells = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4081 si->si_nfrees = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4082 si->si_nimplicit = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4083 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4084 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4085 static int |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4086 symtable_resolve_free(struct compiling *c, PyObject *name, |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4087 struct symbol_info *si) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4088 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4089 PyObject *dict, *v; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4090 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4091 /* 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
|
4092 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
|
4093 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
|
4094 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
|
4095 */ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4096 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4097 if (c->c_symtable->st_cur->ste_type == TYPE_FUNCTION) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4098 v = PyInt_FromLong(si->si_ncells++); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4099 dict = c->c_cellvars; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4100 } else { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4101 v = PyInt_FromLong(si->si_nfrees++); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4102 dict = c->c_freevars; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4103 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4104 if (v == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4105 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4106 if (PyDict_SetItem(dict, name, v) < 0) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4107 Py_DECREF(v); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4108 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4109 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4110 Py_DECREF(v); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4111 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4112 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4113 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4114 static int |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4115 symtable_freevar_offsets(PyObject *freevars, int offset) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4116 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4117 PyObject *name, *v; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4118 int pos; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4119 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4120 /* 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
|
4121 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
|
4122 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
|
4123 pos = 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4124 while (PyDict_Next(freevars, &pos, &name, &v)) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4125 int i = PyInt_AS_LONG(v) + offset; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4126 PyObject *o = PyInt_FromLong(i); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4127 if (o == NULL) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4128 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4129 if (PyDict_SetItem(freevars, name, o) < 0) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4130 Py_DECREF(o); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4131 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4132 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4133 Py_DECREF(o); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4134 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4135 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4136 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4137 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4138 static int |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4139 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
|
4140 PySymtableEntryObject *ste, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4141 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
|
4142 { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4143 char buf[300]; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4144 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4145 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
|
4146 || (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
|
4147 return 0; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4148 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4149 #define ILLEGAL_IMPORT_STAR \ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4150 "import * is not allowed in function '%.100s' " \ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4151 "because it contains a nested function with free variables" |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4152 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4153 #define ILLEGAL_BARE_EXEC \ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4154 "unqualified exec is not allowed in function '%.100s' " \ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4155 "because it contains a nested function with free variables" |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4156 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4157 #define ILLEGAL_EXEC_AND_IMPORT_STAR \ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4158 "function '%.100s' uses import * and bare exec, which are illegal" \ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4159 "because it contains a nested function with free variables" |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4160 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4161 /* 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
|
4162 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
|
4163 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4164 if (ste->ste_optimized == OPT_IMPORT_STAR) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4165 sprintf(buf, ILLEGAL_IMPORT_STAR, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4166 PyString_AS_STRING(ste->ste_name)); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4167 else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC)) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4168 sprintf(buf, ILLEGAL_BARE_EXEC, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4169 PyString_AS_STRING(ste->ste_name)); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4170 else { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4171 sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4172 PyString_AS_STRING(ste->ste_name)); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4173 } |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4174 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4175 if (c->c_symtable->st_nested_scopes) { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4176 PyErr_SetString(PyExc_SyntaxError, buf); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4177 PyErr_SyntaxLocation(c->c_symtable->st_filename, |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4178 ste->ste_lineno); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4179 return -1; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4180 } else { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4181 /* XXX if the warning becomes an exception, we should |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4182 attached more info to it. */ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4183 if (PyErr_Warn(PyExc_SyntaxWarning, buf) < 0) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4184 return -1; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4185 } |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4186 return 0; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4187 } |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4188 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4189 static int |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4190 symtable_check_shadow(struct symtable *st, PyObject *name, int flags) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4191 { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4192 char buf[500]; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4193 PyObject *children, *v; |
|
16871
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4194 PySymtableEntryObject *child = NULL; |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4195 int i; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4196 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4197 if (!(flags & DEF_BOUND)) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4198 return 0; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4199 /* The semantics of this code will change with nested scopes. |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4200 It is defined in the current scope and referenced in a |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4201 child scope. Under the old rules, the child will see a |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4202 global. Under the new rules, the child will see the |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4203 binding in the current scope. |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4204 */ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4205 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4206 /* Find name of child function that has free variable */ |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4207 children = st->st_cur->ste_children; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4208 for (i = 0; i < PyList_GET_SIZE(children); i++) { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4209 int cflags; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4210 child = (PySymtableEntryObject *)PyList_GET_ITEM(children, i); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4211 v = PyDict_GetItem(child->ste_symbols, name); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4212 if (v == NULL) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4213 continue; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4214 cflags = PyInt_AS_LONG(v); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4215 if (!(cflags & DEF_BOUND)) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4216 break; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4217 } |
|
16871
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4218 |
|
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4219 assert(child != NULL); |
|
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4220 |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4221 sprintf(buf, "local name '%.100s' in '%.100s' shadows " |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4222 "use of '%.100s' as global in nested scope '%.100s'", |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4223 PyString_AS_STRING(name), |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4224 PyString_AS_STRING(st->st_cur->ste_name), |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4225 PyString_AS_STRING(name), |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4226 PyString_AS_STRING(child->ste_name) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4227 ); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4228 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4229 return symtable_warn(st, buf); |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4230 } |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4231 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4232 static int |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4233 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
|
4234 struct symbol_info *si) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4235 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4236 if (ste->ste_type != TYPE_MODULE) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4237 c->c_flags |= CO_NEWLOCALS; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4238 if (ste->ste_type == TYPE_FUNCTION) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4239 c->c_nlocals = si->si_nlocals; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4240 if (ste->ste_optimized == 0) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4241 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
|
4242 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
|
4243 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
|
4244 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4245 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4246 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4247 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4248 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
|
4249 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
|
4250 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4251 static PyObject *implicit = NULL; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4252 struct symtable *st = c->c_symtable; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4253 PySymtableEntryObject *ste = st->st_cur; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4254 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
|
4255 int i, flags, pos; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4256 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
|
4257 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4258 if (implicit == NULL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4259 implicit = PyInt_FromLong(1); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4260 if (implicit == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4261 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4262 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4263 v = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4264 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4265 if (symtable_init_compiling_symbols(c) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4266 goto fail; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4267 symtable_init_info(&si); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4268 varnames = st->st_cur->ste_varnames; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4269 si.si_nlocals = PyList_GET_SIZE(varnames); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4270 c->c_argcount = si.si_nlocals; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4271 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4272 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
|
4273 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
|
4274 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
|
4275 PyList_GET_ITEM(varnames, i), v) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4276 goto fail; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4277 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
|
4278 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4279 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4280 /* 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
|
4281 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
|
4282 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
|
4283 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
|
4284 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
|
4285 |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4286 if (st->st_nested_scopes == 0 |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4287 && (flags & (DEF_FREE | DEF_FREE_CLASS))) { |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4288 if (symtable_check_shadow(st, name, flags) < 0) |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4289 goto fail; |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4290 } |
|
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4291 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4292 if (flags & DEF_FREE_GLOBAL) |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4293 /* undo the original DEF_FREE */ |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4294 flags &= ~(DEF_FREE | DEF_FREE_CLASS); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4295 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4296 if ((flags & (DEF_FREE | DEF_FREE_CLASS)) |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4297 && (flags & (DEF_LOCAL | DEF_PARAM))) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4298 symtable_resolve_free(c, name, &si); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4299 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4300 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
|
4301 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
|
4302 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
|
4303 } 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
|
4304 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
|
4305 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
|
4306 } 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
|
4307 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
|
4308 else if (flags & DEF_GLOBAL) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4309 if (flags & DEF_PARAM) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4310 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
|
4311 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
|
4312 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
|
4313 ste->ste_lineno); |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4314 st->st_errors++; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4315 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
|
4316 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4317 if (PyDict_SetItem(c->c_globals, name, Py_None) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4318 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
|
4319 } else if (flags & DEF_FREE_GLOBAL) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4320 si.si_nimplicit++; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4321 if (PyDict_SetItem(c->c_globals, name, implicit) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4322 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
|
4323 } 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
|
4324 v = PyInt_FromLong(si.si_nlocals++); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4325 if (v == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4326 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
|
4327 if (PyDict_SetItem(c->c_locals, name, v) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4328 goto fail; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4329 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
|
4330 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
|
4331 if (PyList_Append(c->c_varnames, name) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4332 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
|
4333 } else if (is_free(flags)) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4334 if (ste->ste_nested && st->st_nested_scopes) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4335 v = PyInt_FromLong(si.si_nfrees++); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4336 if (v == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4337 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
|
4338 if (PyDict_SetItem(c->c_freevars, name, v) < 0) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4339 goto fail; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4340 Py_DECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4341 } else { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4342 si.si_nimplicit++; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4343 if (PyDict_SetItem(c->c_globals, name, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4344 implicit) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4345 goto fail; |
|
16878
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
4346 if (st->st_nscopes != 1) { |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
4347 v = PyInt_FromLong(flags); |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
4348 if (PyDict_SetItem(st->st_global, |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
4349 name, v)) |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
4350 goto fail; |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
4351 Py_DECREF(v); |
|
1cf52536c381
Don't add global names to st->st_global if we're already iterating
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16873
diff
changeset
|
4352 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4353 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4354 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4355 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4356 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4357 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
|
4358 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4359 return symtable_update_flags(c, ste, &si); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4360 fail: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4361 /* is this always the right thing to do? */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4362 Py_XDECREF(v); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4363 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
|
4364 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4365 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4366 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
|
4367 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
|
4368 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4369 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
|
4370 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4371 st = (struct symtable *)PyMem_Malloc(sizeof(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
|
4372 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
|
4373 return NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4374 st->st_pass = 1; |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4375 st->st_nested_scopes = NESTED_SCOPES_DEFAULT; |
|
16428
6496844c4a42
Fix symbol table pass to generation SyntaxError exceptions that
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16421
diff
changeset
|
4376 st->st_filename = NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4377 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
|
4378 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
|
4379 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
|
4380 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
|
4381 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
|
4382 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
|
4383 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
|
4384 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
|
4385 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
|
4386 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
|
4387 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
|
4388 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
|
4389 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
|
4390 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4391 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4392 void |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4393 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
|
4394 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4395 Py_XDECREF(st->st_symbols); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4396 Py_XDECREF(st->st_stack); |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
4397 Py_XDECREF(st->st_cur); |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4398 PyMem_Free((void *)st); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4399 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4400 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4401 /* 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
|
4402 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
|
4403 children. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4404 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4405 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
|
4406 scope are cellvars. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4407 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4408 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
|
4409 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
|
4410 implicit globals. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4411 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4412 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4413 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4414 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4415 symtable_update_free_vars(struct symtable *st) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4416 { |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4417 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
|
4418 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
|
4419 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
|
4420 |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4421 if (ste->ste_type == TYPE_CLASS) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4422 def = DEF_FREE_CLASS; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4423 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4424 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
|
4425 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
|
4426 int pos = 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4427 |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4428 if (list) |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4429 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
|
4430 ((PyVarObject*)list)->ob_size, 0); |
|
16754
23c7a0108f59
symtable_update_free_vars(), symtable_undo_free(),
Barry Warsaw <barry@python.org>
parents:
16753
diff
changeset
|
4431 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
|
4432 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
|
4433 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
|
4434 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
|
4435 if (!(is_free(flags))) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4436 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
|
4437 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
|
4438 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
|
4439 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
|
4440 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4441 } |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4442 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
|
4443 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
|
4444 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
|
4445 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4446 } |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4447 } |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4448 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
|
4449 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
|
4450 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
|
4451 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
|
4452 /* 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
|
4453 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
|
4454 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
|
4455 with bindings for N between B and A, then N |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4456 is global in B. |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4457 */ |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4458 if (v) { |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4459 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
|
4460 if (flags & DEF_GLOBAL) { |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4461 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
|
4462 name); |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4463 continue; |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4464 } |
|
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4465 } |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4466 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
|
4467 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
|
4468 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
|
4469 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
|
4470 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4471 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4472 } 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
|
4473 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
|
4474 name) < 0) { |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4475 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
|
4476 return -1; |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4477 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4478 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4479 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4480 } |
|
16571
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4481 |
|
2c6417ef4628
In symtable_update_free_vars() do not modify the dictionary while
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16540
diff
changeset
|
4482 Py_XDECREF(list); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4483 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4484 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4485 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4486 /* 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
|
4487 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
|
4488 global in all nested scopes. |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4489 */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4490 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4491 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4492 symtable_check_global(struct symtable *st, PyObject *child, PyObject *name) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4493 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4494 PyObject *o; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4495 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
|
4496 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
|
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 (ste->ste_type == TYPE_CLASS) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4499 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
|
4500 o = PyDict_GetItem(ste->ste_symbols, name); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4501 if (o == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4502 return symtable_undo_free(st, child, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4503 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
|
4504 |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
4505 if (is_free(v) || (v & DEF_GLOBAL)) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4506 return symtable_undo_free(st, child, name); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4507 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
|
4508 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
|
4509 name, DEF_FREE); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4510 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4511 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4512 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4513 symtable_undo_free(struct symtable *st, PyObject *id, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4514 PyObject *name) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4515 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4516 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
|
4517 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
|
4518 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
|
4519 |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4520 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
|
4521 if (ste == NULL) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4522 return -1; |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4523 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4524 info = PyDict_GetItem(ste->ste_symbols, name); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4525 if (info == NULL) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4526 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4527 v = PyInt_AS_LONG(info); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4528 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
|
4529 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
|
4530 DEF_FREE_GLOBAL) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4531 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4532 } else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4533 /* If the name is defined here or declared global, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4534 then the recursion stops. */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4535 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4536 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4537 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
|
4538 PySymtableEntryObject *child; |
|
16754
23c7a0108f59
symtable_update_free_vars(), symtable_undo_free(),
Barry Warsaw <barry@python.org>
parents:
16753
diff
changeset
|
4539 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
|
4540 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
|
4541 x = symtable_undo_free(st, child->ste_id, name); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4542 if (x < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4543 return x; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4544 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4545 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4546 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4547 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4548 /* 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
|
4549 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
|
4550 in symtable_exit_scope(). |
|
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 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4553 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4554 symtable_exit_scope(struct symtable *st) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4555 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4556 int end; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4557 |
|
16862
77a5470299db
Add warning/error handlin for problematic nested scopes cases as
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16855
diff
changeset
|
4558 if (st->st_pass == 1) |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4559 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
|
4560 Py_DECREF(st->st_cur); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4561 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
|
4562 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
|
4563 end); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4564 if (PySequence_DelItem(st->st_stack, end) < 0) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4565 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
|
4566 return 0; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4567 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4568 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4569 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
|
4570 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
|
4571 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
|
4572 { |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16523
diff
changeset
|
4573 PySymtableEntryObject *prev = NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4574 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4575 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
|
4576 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
|
4577 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
|
4578 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
|
4579 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
|
4580 return; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4581 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4582 } |
|
16754
23c7a0108f59
symtable_update_free_vars(), symtable_undo_free(),
Barry Warsaw <barry@python.org>
parents:
16753
diff
changeset
|
4583 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
|
4584 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
|
4585 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
|
4586 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
|
4587 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
|
4588 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
|
4589 (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
|
4590 st->st_errors++; |
|
16753
51977af230fa
Fix for bug 133489: compiler leaks memory
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16699
diff
changeset
|
4591 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4592 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4593 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4594 static int |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4595 symtable_lookup(struct symtable *st, char *name) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4596 { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4597 char buffer[MANGLE_LEN]; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4598 PyObject *v; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4599 int flags; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4600 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4601 if (mangle(st->st_private, name, buffer, sizeof(buffer))) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4602 name = buffer; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4603 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
|
4604 if (v == NULL) { |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4605 if (PyErr_Occurred()) |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4606 return -1; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4607 else |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4608 return 0; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4609 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4610 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4611 flags = PyInt_AS_LONG(v); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4612 return flags; |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4613 } |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4614 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4615 static int |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4616 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
|
4617 { |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4618 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
|
4619 char buffer[MANGLE_LEN]; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
4620 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
|
4621 |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
4622 if (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
|
4623 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
|
4624 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
|
4625 return -1; |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
4626 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
|
4627 Py_DECREF(s); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
4628 return ret; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4629 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4630 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4631 /* Must only be called with mangled names */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4632 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4633 static int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4634 symtable_add_def_o(struct symtable *st, PyObject *dict, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4635 PyObject *name, int flag) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4636 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4637 PyObject *o; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4638 int val; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4639 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4640 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
|
4641 val = PyInt_AS_LONG(o); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4642 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
|
4643 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
|
4644 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
|
4645 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
|
4646 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
|
4647 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
|
4648 } |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4649 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
|
4650 } else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4651 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
|
4652 o = PyInt_FromLong(val); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4653 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
|
4654 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
|
4655 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
|
4656 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4657 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
|
4658 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4659 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
|
4660 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
|
4661 return -1; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4662 } else if (flag & DEF_GLOBAL) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4663 /* XXX need to update DEF_GLOBAL for other flags too; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4664 perhaps only DEF_FREE_GLOBAL */ |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4665 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
|
4666 val = PyInt_AS_LONG(o); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4667 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
|
4668 } else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4669 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
|
4670 o = PyInt_FromLong(val); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4671 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
|
4672 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
|
4673 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
|
4674 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4675 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
|
4676 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4677 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
|
4678 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4679 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4680 #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
|
4681 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4682 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
|
4683 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
|
4684 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4685 int i, start = 0; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4686 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4687 loop: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4688 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
|
4689 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
|
4690 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
|
4691 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
|
4692 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
|
4693 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
|
4694 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
|
4695 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
|
4696 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4697 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4698 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
|
4699 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
|
4700 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
|
4701 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
|
4702 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
|
4703 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
|
4704 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4705 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
|
4706 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
|
4707 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
|
4708 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
|
4709 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
|
4710 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
|
4711 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
|
4712 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
|
4713 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4714 } |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16408
diff
changeset
|
4715 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
|
4716 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
|
4717 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
|
4718 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
|
4719 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
|
4720 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
|
4721 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4722 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4723 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
|
4724 for (i = 0; i + 3 < NCH(n); i += 4) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4725 if (is_constant_false(NULL, (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
|
4726 continue; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4727 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
|
4728 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
|
4729 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4730 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
|
4731 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
|
4732 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4733 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
|
4734 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
|
4735 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4736 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
|
4737 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
|
4738 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
|
4739 case exec_stmt: { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4740 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
|
4741 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
|
4742 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
|
4743 symtable_node(st, CHILD(n, 3)); |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4744 else |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4745 st->st_cur->ste_optimized |= OPT_BARE_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
|
4746 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
|
4747 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
|
4748 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
|
4749 |
|
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16357
diff
changeset
|
4750 } |
|
16680
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
4751 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
|
4752 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
|
4753 return; |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
4754 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
|
4755 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
|
4756 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
|
4757 } else { |
|
17ed61fd5b65
When running python -O, do not include blocks defined in asserts in
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16677
diff
changeset
|
4758 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
|
4759 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
|
4760 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
|
4761 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4762 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
|
4763 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
|
4764 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
|
4765 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
|
4766 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
|
4767 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
|
4768 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4769 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4770 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
|
4771 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
|
4772 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4773 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
|
4774 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
|
4775 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
|
4776 else { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4777 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
|
4778 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
|
4779 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
|
4780 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4781 } else { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4782 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
|
4783 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
|
4784 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
|
4785 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
|
4786 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4787 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4788 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
|
4789 /* watchout for fall-through logic below */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4790 case argument: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4791 if (NCH(n) == 3) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4792 n = CHILD(n, 2); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4793 goto loop; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4794 } |
|
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 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
|
4796 if (NCH(n) > 1 && 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
|
4797 symtable_list_comprehension(st, CHILD(n, 1)); |
|
16138
49b7c1bc6004
Visit the initial test element of the listmaker for a list
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16137
diff
changeset
|
4798 n = CHILD(n, 0); |
|
49b7c1bc6004
Visit the initial test element of the listmaker for a list
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16137
diff
changeset
|
4799 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
|
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 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
|
4802 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
|
4803 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
|
4804 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4805 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4806 case for_stmt: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4807 if (TYPE(n) == for_stmt) { |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
4808 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
|
4809 start = 3; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4810 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4811 default: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4812 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
|
4813 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
|
4814 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
|
4815 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4816 for (i = start; 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
|
4817 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
|
4818 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
|
4819 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4820 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4821 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4822 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
|
4823 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
|
4824 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4825 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
|
4826 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4827 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
|
4828 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
|
4829 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
|
4830 } else |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4831 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
|
4832 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
|
4833 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
|
4834 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4835 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4836 /* The next two functions parse the argument tuple. |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4837 symtable_default_arg() checks for names in the default arguments, |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4838 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
|
4839 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
|
4840 body. |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4841 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4842 varargslist: |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4843 (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
|
4844 | 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
|
4845 */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4846 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4847 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
|
4848 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
|
4849 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4850 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
|
4851 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
|
4852 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4853 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
|
4854 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
|
4855 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
|
4856 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4857 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4858 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
|
4859 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
|
4860 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
|
4861 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
|
4862 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4863 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4864 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
|
4865 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
|
4866 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4867 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4868 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4869 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
|
4870 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
|
4871 { |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
4872 int i, complex = -1, ext = 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
|
4873 node *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
|
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 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
|
4876 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
|
4877 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
|
4878 return; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4879 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4880 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
|
4881 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
|
4882 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
|
4883 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
|
4884 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
|
4885 break; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4886 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4887 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
|
4888 continue; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4889 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4890 if (TYPE(CHILD(c, 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
|
4891 symtable_add_def(st, STR(CHILD(c, 0)), DEF_PARAM); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4892 else { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4893 char nbuf[10]; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4894 sprintf(nbuf, ".%d", i); |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4895 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
|
4896 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
|
4897 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4898 } |
|
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 (ext) { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4900 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
|
4901 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
|
4902 i++; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4903 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
|
4904 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
|
4905 i += 2; |
|
16137
883cb0e31bb2
prevent symtable_params() from dereferencing off the end of the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16096
diff
changeset
|
4906 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
|
4907 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
|
4908 else |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
4909 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
|
4910 } |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
4911 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
|
4912 i++; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4913 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
|
4914 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
|
4915 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4916 } |
|
16250
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
4917 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
|
4918 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
|
4919 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
|
4920 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
|
4921 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
|
4922 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
|
4923 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
|
4924 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
|
4925 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
|
4926 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
|
4927 } |
|
aab871635ffa
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16138
diff
changeset
|
4928 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4929 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4930 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4931 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
|
4932 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
|
4933 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4934 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
|
4935 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
|
4936 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4937 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
|
4938 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
|
4939 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
|
4940 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
|
4941 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
|
4942 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
|
4943 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
|
4944 else |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4945 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
|
4946 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4947 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4948 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4949 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4950 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
|
4951 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
|
4952 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4953 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
|
4954 |
|
16871
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4955 if (st->st_nscopes == 1) { |
|
16892
f27d3299df39
Fix core dump in example from Samuele Pedroni:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16878
diff
changeset
|
4956 /* XXX must check that we are compiling file_input */ |
|
16871
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4957 if (symtable_warn(st, |
|
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4958 "global statement has no meaning at module level") < 0) |
|
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4959 return; |
|
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4960 } |
|
d675d75af839
Warn about global statement at the module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16862
diff
changeset
|
4961 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4962 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
|
4963 char *name = STR(CHILD(n, i)); |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4964 int flags; |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4965 |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4966 flags = symtable_lookup(st, name); |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
4967 if (flags < 0) |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
4968 continue; |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4969 if (flags && flags != DEF_GLOBAL) { |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4970 char buf[500]; |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4971 if (flags & DEF_PARAM) { |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4972 PyErr_Format(PyExc_SyntaxError, |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4973 "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
|
4974 name); |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
4975 PyErr_SyntaxLocation(st->st_filename, |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4976 st->st_cur->ste_lineno); |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4977 st->st_errors++; |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4978 return; |
|
16853
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
4979 } |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
4980 else { |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
4981 if (flags & DEF_LOCAL) |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
4982 sprintf(buf, GLOBAL_AFTER_ASSIGN, |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
4983 name); |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
4984 else |
|
05785bdf289c
Use the new PyErr_WarnExplicit() API to issue better warnings for
Guido van Rossum <guido@python.org>
parents:
16838
diff
changeset
|
4985 sprintf(buf, 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
|
4986 symtable_warn(st, buf); |
|
16783
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4987 } |
|
4feea99be777
Add warnings about undefined "global"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
4988 } |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4989 symtable_add_def(st, name, DEF_GLOBAL); |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
4990 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4991 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4992 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4993 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
|
4994 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
|
4995 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4996 char tmpname[12]; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
4997 |
|
16638
79568c0d3e77
Change temp names created by listcomps from [%d] to _[%d], so the one-liner
Tim Peters <tim.peters@gmail.com>
parents:
16571
diff
changeset
|
4998 sprintf(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
|
4999 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
|
5000 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
|
5001 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
|
5002 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
|
5003 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
|
5004 --st->st_tmpname; |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5005 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5006 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5007 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
|
5008 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
|
5009 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5010 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
|
5011 /* 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
|
5012 | '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
|
5013 ('*' | 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
|
5014 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
|
5015 */ |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5016 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
|
5017 node *dotname = CHILD(n, 1); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5018 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
|
5019 /* check for bogus imports */ |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5020 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
|
5021 PyErr_SetString(PyExc_SyntaxError, |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5022 LATE_FUTURE); |
|
16838
09f6c1372056
Improve SyntaxErrors for bad future statements. Set file and location
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16831
diff
changeset
|
5023 PyErr_SyntaxLocation(st->st_filename, |
|
16823
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5024 n->n_lineno); |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5025 st->st_errors++; |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5026 return; |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5027 } |
|
acbe74f3a786
Presumed correct compiler pass for future statements
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16799
diff
changeset
|
5028 } |
|
16015
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5029 if (TYPE(CHILD(n, 3)) == STAR) { |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5030 st->st_cur->ste_optimized |= OPT_IMPORT_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
|
5031 } else { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5032 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
|
5033 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
|
5034 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
|
5035 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
|
5036 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
|
5037 else |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5038 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
|
5039 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
|
5040 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5041 } |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16763
diff
changeset
|
5042 } 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
|
5043 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
|
5044 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
|
5045 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5046 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5047 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5048 |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5049 static void |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5050 symtable_assign(struct symtable *st, node *n, 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
|
5051 { |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5052 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
|
5053 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
|
5054 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5055 loop: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5056 switch (TYPE(n)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5057 case lambdef: |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5058 /* 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
|
5059 pass will catch this error. */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5060 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5061 case power: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5062 if (NCH(n) > 2) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5063 for (i = 2; i < NCH(n); ++i) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5064 if (TYPE(CHILD(n, i)) != DOUBLESTAR) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5065 symtable_node(st, CHILD(n, i)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5066 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5067 if (NCH(n) > 1) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5068 symtable_node(st, CHILD(n, 0)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5069 symtable_node(st, CHILD(n, 1)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5070 } else { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5071 n = CHILD(n, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5072 goto loop; |
|
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; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5075 case listmaker: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5076 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5077 symtable_list_comprehension(st, CHILD(n, 1)); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5078 else { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5079 for (i = 0; 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
|
5080 symtable_assign(st, CHILD(n, i), flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5081 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5082 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5083 case exprlist: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5084 case testlist: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5085 if (NCH(n) == 1) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5086 n = CHILD(n, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5087 goto loop; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5088 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5089 else { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5090 int i; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5091 for (i = 0; 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
|
5092 symtable_assign(st, CHILD(n, i), 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
|
5093 return; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5094 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5095 goto loop; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5096 case atom: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5097 tmp = CHILD(n, 0); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5098 if (TYPE(tmp) == LPAR || TYPE(tmp) == LSQB) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5099 n = CHILD(n, 1); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5100 goto loop; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5101 } else if (TYPE(tmp) == NAME) |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5102 symtable_add_def(st, STR(tmp), DEF_LOCAL | flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5103 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5104 case dotted_as_name: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5105 if (NCH(n) == 3) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5106 symtable_add_def(st, STR(CHILD(n, 2)), |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5107 DEF_LOCAL | flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5108 else |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5109 symtable_add_def(st, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5110 STR(CHILD(CHILD(n, |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5111 0), 0)), |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5112 DEF_LOCAL | flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5113 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5114 case dotted_name: |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5115 symtable_add_def(st, STR(CHILD(n, 0)), DEF_LOCAL | flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5116 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5117 case NAME: |
|
16357
9f2ca855fa44
Enforce two illegal import statements that were outlawed in the
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16353
diff
changeset
|
5118 symtable_add_def(st, STR(n), DEF_LOCAL | flag); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5119 return; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5120 default: |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16250
diff
changeset
|
5121 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
|
5122 return; |
|
16677
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5123 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
|
5124 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
|
5125 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
|
5126 } |
|
16677
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5127 /* 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
|
5128 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
|
5129 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
|
5130 if (TYPE(CHILD(n, i)) >= single_input) |
|
b955e74955d5
Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16658
diff
changeset
|
5131 symtable_assign(st, CHILD(n, i), 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
|
5132 } |
|
c832ef72499d
This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16006
diff
changeset
|
5133 } |
