Mercurial > cpython-lru_cache-weakref
annotate Python/compile.c @ 9049:cbf72b2210ae legacy-trunk
Comment out the print statement about underflow. (This only seems to
happen when you use a non-keyword argument after a keyword argument,
and in this case you also get a syntax error. I fully suspect that
the underflow is caused by the code that stops generating code when it
detects the syntax error, but I can't find the culprit right now. I
know, I know.)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 25 Aug 1998 18:22:17 +0000 |
| parents | 48240f525ec3 |
| children | c259c3c4d0cc |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
3 The Netherlands. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
4 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
5 All Rights Reserved |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
15 permission. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
29 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
30 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
120
diff
changeset
|
31 |
| 69 | 32 /* Compile an expression node to intermediate code */ |
| 33 | |
| 86 | 34 /* 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
|
35 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
|
36 XXX (it's currently the first item of the co_const tuple) |
| 86 | 37 XXX Generate simple jump for break/return outside 'try...finally' |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
38 XXX Allow 'continue' inside try-finally |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
39 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
|
40 XXX other JAR tricks? |
| 86 | 41 */ |
| 69 | 42 |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
43 #ifndef NO_PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
44 #define PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
45 #endif |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
46 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
47 #include "Python.h" |
| 86 | 48 |
| 69 | 49 #include "node.h" |
| 50 #include "token.h" | |
| 51 #include "graminit.h" | |
| 52 #include "compile.h" | |
| 53 #include "opcode.h" | |
| 86 | 54 #include "structmember.h" |
| 55 | |
| 56 #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
|
57 |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
58 /* 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
|
59 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
|
60 (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
|
61 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
|
62 #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
|
63 #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
|
64 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
65 #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
|
66 #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
|
67 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
68 #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
|
69 #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
|
70 #endif |
|
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
71 |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
72 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
|
73 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
74 #define OP_DELETE 0 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
75 #define OP_ASSIGN 1 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
76 #define OP_APPLY 2 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
77 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
78 #define OFF(x) offsetof(PyCodeObject, x) |
| 86 | 79 |
| 80 static struct memberlist code_memberlist[] = { | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
81 {"co_argcount", T_INT, OFF(co_argcount), READONLY}, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
82 {"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
|
83 {"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
|
84 {"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
|
85 {"co_code", T_OBJECT, OFF(co_code), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
86 {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
87 {"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
|
88 {"co_varnames", T_OBJECT, OFF(co_varnames), READONLY}, |
|
568
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
89 {"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
|
90 {"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
|
91 {"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
|
92 {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY}, |
| 86 | 93 {NULL} /* Sentinel */ |
| 94 }; | |
| 95 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
96 static PyObject * |
| 86 | 97 code_getattr(co, name) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
98 PyCodeObject *co; |
| 86 | 99 char *name; |
| 100 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
101 return PyMember_Get((char *)co, code_memberlist, name); |
| 86 | 102 } |
| 69 | 103 |
| 104 static void | |
| 86 | 105 code_dealloc(co) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
106 PyCodeObject *co; |
| 69 | 107 { |
|
5373
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_code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
109 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
|
110 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
|
111 Py_XDECREF(co->co_varnames); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
112 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
|
113 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
|
114 Py_XDECREF(co->co_lnotab); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
115 PyMem_DEL(co); |
| 69 | 116 } |
| 117 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
118 static PyObject * |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
119 code_repr(co) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
120 PyCodeObject *co; |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
121 { |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
122 char buf[500]; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
123 int lineno = -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
124 char *p = PyString_AS_STRING(co->co_code); |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
125 char *filename = "???"; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
126 char *name = "???"; |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
127 if (*p == SET_LINENO) |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
128 lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
129 if (co->co_filename && PyString_Check(co->co_filename)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
130 filename = PyString_AsString(co->co_filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
131 if (co->co_name && PyString_Check(co->co_name)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
132 name = PyString_AsString(co->co_name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
133 sprintf(buf, "<code object %.100s at %lx, file \"%.300s\", line %d>", |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
134 name, (long)co, filename, lineno); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
135 return PyString_FromString(buf); |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
136 } |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
137 |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
138 static int |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
139 code_compare(co, cp) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
140 PyCodeObject *co, *cp; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
141 { |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
142 int cmp; |
|
6186
2e755d1ff661
Cprrect stuoid tyops -- was comparing variabes with themselves because
Guido van Rossum <guido@python.org>
parents:
5901
diff
changeset
|
143 cmp = co->co_argcount - cp->co_argcount; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
144 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
|
145 cmp = co->co_nlocals - cp->co_nlocals; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
146 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
|
147 cmp = co->co_flags - cp->co_flags; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
148 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
|
149 cmp = PyObject_Compare((PyObject *)co->co_code, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
150 (PyObject *)cp->co_code); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 if (cmp) return cmp; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
156 cmp = PyObject_Compare(co->co_varnames, cp->co_varnames); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
157 return cmp; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
158 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
159 |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
160 static long |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
161 code_hash(co) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
162 PyCodeObject *co; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
163 { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
164 long h, h1, h2, h3, h4; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
165 h1 = PyObject_Hash((PyObject *)co->co_code); |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 h4 = PyObject_Hash(co->co_varnames); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
172 if (h4 == -1) return -1; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
173 h = h1 ^ h2 ^ h3 ^ h4 ^ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
174 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
|
175 if (h == -1) h = -2; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
176 return h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
177 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
178 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
179 PyTypeObject PyCode_Type = { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
180 PyObject_HEAD_INIT(&PyType_Type) |
| 69 | 181 0, |
| 182 "code", | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
183 sizeof(PyCodeObject), |
| 69 | 184 0, |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
185 (destructor)code_dealloc, /*tp_dealloc*/ |
| 69 | 186 0, /*tp_print*/ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
187 (getattrfunc)code_getattr, /*tp_getattr*/ |
| 69 | 188 0, /*tp_setattr*/ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
189 (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
|
190 (reprfunc)code_repr, /*tp_repr*/ |
| 69 | 191 0, /*tp_as_number*/ |
| 192 0, /*tp_as_sequence*/ | |
| 193 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
|
194 (hashfunc)code_hash, /*tp_hash*/ |
| 69 | 195 }; |
| 196 | |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
197 #define NAME_CHARS \ |
|
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
198 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" |
|
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
199 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
200 PyCodeObject * |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
201 PyCode_New(argcount, nlocals, stacksize, flags, |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
202 code, consts, names, varnames, filename, name, |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
203 firstlineno, lnotab) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
204 int argcount; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
205 int nlocals; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
206 int stacksize; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
207 int flags; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
208 PyObject *code; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
209 PyObject *consts; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
210 PyObject *names; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
211 PyObject *varnames; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
212 PyObject *filename; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
213 PyObject *name; |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
214 int firstlineno; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
215 PyObject *lnotab; |
| 69 | 216 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
217 PyCodeObject *co; |
| 69 | 218 int i; |
| 219 /* Check argument types */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
220 if (argcount < 0 || nlocals < 0 || |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
221 code == NULL || !PyString_Check(code) || |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
222 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
|
223 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
|
224 varnames == NULL || !PyTuple_Check(varnames) || |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 PyErr_BadInternalCall(); |
| 69 | 229 return NULL; |
| 230 } | |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
231 /* Make sure names and varnames are all strings, & intern them */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
232 for (i = PyTuple_Size(names); --i >= 0; ) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
233 PyObject *v = PyTuple_GetItem(names, i); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
234 if (v == NULL || !PyString_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
235 PyErr_BadInternalCall(); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
236 return NULL; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
237 } |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
238 PyString_InternInPlace(&PyTuple_GET_ITEM(names, i)); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
239 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
240 for (i = PyTuple_Size(varnames); --i >= 0; ) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
241 PyObject *v = PyTuple_GetItem(varnames, i); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
242 if (v == NULL || !PyString_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
243 PyErr_BadInternalCall(); |
| 69 | 244 return NULL; |
| 245 } | |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
246 PyString_InternInPlace(&PyTuple_GET_ITEM(varnames, i)); |
|
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
247 } |
|
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
248 /* 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
|
249 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
|
250 PyObject *v = PyTuple_GetItem(consts, i); |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
251 char *p; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
252 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
|
253 continue; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
254 p = PyString_AsString(v); |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
5264
diff
changeset
|
255 if ((int)strspn(p, NAME_CHARS) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
256 != PyString_Size(v)) |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
257 continue; |
|
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
258 PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i)); |
| 69 | 259 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
260 co = PyObject_NEW(PyCodeObject, &PyCode_Type); |
| 69 | 261 if (co != NULL) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
262 co->co_argcount = argcount; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
263 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
|
264 co->co_stacksize = stacksize; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
265 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
|
266 Py_INCREF(code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
267 co->co_code = (PyStringObject *)code; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
268 Py_INCREF(consts); |
| 69 | 269 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
|
270 Py_INCREF(names); |
| 69 | 271 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
|
272 Py_INCREF(varnames); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
273 co->co_varnames = varnames; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
274 Py_INCREF(filename); |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
275 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
|
276 Py_INCREF(name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 co->co_lnotab = lnotab; |
| 69 | 281 } |
| 282 return co; | |
| 283 } | |
| 284 | |
| 285 | |
| 286 /* Data structure used internally */ | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
287 |
| 69 | 288 struct compiling { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
289 PyObject *c_code; /* string */ |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
290 PyObject *c_consts; /* list of objects */ |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
291 PyObject *c_names; /* list of strings (names) */ |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
292 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
|
293 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
|
294 PyObject *c_varnames; /* list (inverse of c_locals) */ |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
295 int c_nlocals; /* index of next local */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
296 int c_argcount; /* number of top-level arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
297 int c_flags; /* same as co_flags */ |
| 69 | 298 int c_nexti; /* index into c_code */ |
| 299 int c_errors; /* counts errors occurred */ | |
| 86 | 300 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
|
301 int c_interactive; /* generating code for interactive command */ |
| 86 | 302 int c_loops; /* counts nested loops */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
303 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
|
304 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
|
305 int c_nblocks; /* current block stack level */ |
| 86 | 306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 int c_firstlineno; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
312 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
|
313 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
|
314 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
315 char *c_private; /* for private name mangling */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
316 #endif |
| 69 | 317 }; |
| 318 | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
319 |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
320 /* Error message including line number */ |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
321 |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
322 static void |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
323 com_error(c, exc, msg) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
324 struct compiling *c; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
325 PyObject *exc; |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
326 char *msg; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
327 { |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
328 int n = strlen(msg); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
329 PyObject *v; |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
330 char buffer[30]; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
331 char *s; |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
332 c->c_errors++; |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
333 if (c->c_lineno <= 1) { |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
334 /* Unknown line number or single interactive command */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
335 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
|
336 return; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
337 } |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
338 sprintf(buffer, " (line %d)", c->c_lineno); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
339 v = PyString_FromStringAndSize((char *)NULL, n + strlen(buffer)); |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
340 if (v == NULL) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
341 return; /* MemoryError, too bad */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
342 s = PyString_AS_STRING((PyStringObject *)v); |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
343 strcpy(s, msg); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
344 strcat(s, buffer); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
345 PyErr_SetObject(exc, v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
346 Py_DECREF(v); |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
347 } |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
348 |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
349 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
350 /* Interface to the block stack */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
351 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
352 static void |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
353 block_push(c, type) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
354 struct compiling *c; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
355 int type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
356 { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
357 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
|
358 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
|
359 "too many statically nested blocks"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
360 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
361 else { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
362 c->c_block[c->c_nblocks++] = type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
363 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
364 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
365 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
366 static void |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
367 block_pop(c, type) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
368 struct compiling *c; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
369 int type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
370 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
371 if (c->c_nblocks > 0) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
372 c->c_nblocks--; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
373 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
|
374 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
|
375 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
376 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
377 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
378 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
379 /* Prototype forward declarations */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
380 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
381 static int com_init Py_PROTO((struct compiling *, char *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
382 static void com_free Py_PROTO((struct compiling *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
383 static void com_push Py_PROTO((struct compiling *, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
384 static void com_pop Py_PROTO((struct compiling *, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
385 static void com_done Py_PROTO((struct compiling *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
386 static void com_node Py_PROTO((struct compiling *, struct _node *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
387 static void com_factor Py_PROTO((struct compiling *, struct _node *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
388 static void com_addbyte Py_PROTO((struct compiling *, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
389 static void com_addint Py_PROTO((struct compiling *, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
390 static void com_addoparg Py_PROTO((struct compiling *, int, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
391 static void com_addfwref Py_PROTO((struct compiling *, int, int *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
392 static void com_backpatch Py_PROTO((struct compiling *, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
393 static int com_add Py_PROTO((struct compiling *, PyObject *, PyObject *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
394 static int com_addconst Py_PROTO((struct compiling *, PyObject *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
395 static int com_addname Py_PROTO((struct compiling *, PyObject *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
396 static void com_addopname Py_PROTO((struct compiling *, int, node *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
397 static void com_list Py_PROTO((struct compiling *, node *, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
398 static int com_argdefs Py_PROTO((struct compiling *, node *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
399 static int com_newlocal Py_PROTO((struct compiling *, char *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
400 static PyCodeObject *icompile Py_PROTO((struct _node *, struct compiling *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
401 static PyCodeObject *jcompile Py_PROTO((struct _node *, char *, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
402 struct compiling *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
403 static PyObject *parsestrplus Py_PROTO((node *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
404 static PyObject *parsestr Py_PROTO((char *)); |
| 69 | 405 |
| 406 static int | |
|
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
|
407 com_init(c, filename) |
| 69 | 408 struct compiling *c; |
| 86 | 409 char *filename; |
| 69 | 410 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
411 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
|
412 1000)) == NULL) |
| 69 | 413 goto fail_3; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
414 if ((c->c_consts = PyList_New(0)) == NULL) |
| 69 | 415 goto fail_2; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
416 if ((c->c_names = PyList_New(0)) == NULL) |
| 69 | 417 goto fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
418 if ((c->c_globals = PyDict_New()) == NULL) |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
419 goto fail_0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
420 if ((c->c_locals = PyDict_New()) == NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
421 goto fail_00; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
422 if ((c->c_varnames = PyList_New(0)) == NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
423 goto fail_000; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
424 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
|
425 1000)) == NULL) |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
426 goto fail_0000; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
427 c->c_nlocals = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
428 c->c_argcount = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
429 c->c_flags = 0; |
| 69 | 430 c->c_nexti = 0; |
| 431 c->c_errors = 0; | |
| 86 | 432 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
|
433 c->c_interactive = 0; |
| 86 | 434 c->c_loops = 0; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
435 c->c_begin = 0; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
436 c->c_nblocks = 0; |
| 86 | 437 c->c_filename = filename; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
438 c->c_name = "?"; |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 c->c_last_line = 0; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
445 c-> c_lnotab_next = 0; |
| 69 | 446 return 1; |
| 447 | |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
448 fail_0000: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
449 Py_DECREF(c->c_lnotab); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
450 fail_000: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
451 Py_DECREF(c->c_locals); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
452 fail_00: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
453 Py_DECREF(c->c_globals); |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
454 fail_0: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
455 Py_DECREF(c->c_names); |
| 69 | 456 fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
457 Py_DECREF(c->c_consts); |
| 69 | 458 fail_2: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
459 Py_DECREF(c->c_code); |
| 69 | 460 fail_3: |
| 461 return 0; | |
| 462 } | |
| 463 | |
| 464 static void | |
| 465 com_free(c) | |
| 466 struct compiling *c; | |
| 467 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
468 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
|
469 Py_XDECREF(c->c_consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
470 Py_XDECREF(c->c_names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
471 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
|
472 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
|
473 Py_XDECREF(c->c_varnames); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
474 Py_XDECREF(c->c_lnotab); |
| 69 | 475 } |
| 476 | |
| 477 static void | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
478 com_push(c, n) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
479 struct compiling *c; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
480 int n; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
481 { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
482 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
|
483 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
|
484 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
|
485 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
486 |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
487 static void |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
488 com_pop(c, n) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
489 struct compiling *c; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
490 int n; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
491 { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
492 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
|
493 /* fprintf(stderr, |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
494 "%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
|
495 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
|
496 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
|
497 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
|
498 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
499 else |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
500 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
|
501 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
502 |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
503 static void |
| 69 | 504 com_done(c) |
| 505 struct compiling *c; | |
| 506 { | |
| 507 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
|
508 _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
|
509 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
|
510 _PyString_Resize(&c->c_lnotab, c->c_lnotab_next); |
| 69 | 511 } |
| 512 | |
| 513 static void | |
| 514 com_addbyte(c, byte) | |
| 515 struct compiling *c; | |
| 516 int byte; | |
| 517 { | |
| 518 int len; | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
519 /*fprintf(stderr, "%3d: %3d\n", c->c_nexti, byte);*/ |
| 69 | 520 if (byte < 0 || byte > 255) { |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
521 /* |
| 86 | 522 fprintf(stderr, "XXX compiling bad byte: %d\n", byte); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2005
diff
changeset
|
523 fatal("com_addbyte: byte out of range"); |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
524 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
525 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
|
526 "com_addbyte: byte out of range"); |
| 69 | 527 } |
| 528 if (c->c_code == NULL) | |
| 529 return; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
530 len = PyString_Size(c->c_code); |
| 69 | 531 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
|
532 if (_PyString_Resize(&c->c_code, len+1000) != 0) { |
| 69 | 533 c->c_errors++; |
| 534 return; | |
| 535 } | |
| 536 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
537 PyString_AsString(c->c_code)[c->c_nexti++] = byte; |
| 69 | 538 } |
| 539 | |
| 540 static void | |
| 541 com_addint(c, x) | |
| 542 struct compiling *c; | |
| 543 int x; | |
| 544 { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
545 com_addbyte(c, x & 0xff); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
546 com_addbyte(c, x >> 8); /* XXX x should be positive */ |
| 69 | 547 } |
| 548 | |
| 549 static void | |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
550 com_add_lnotab(c, addr, line) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
551 struct compiling *c; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
552 int addr; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
553 int line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
554 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
555 int size; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
556 char *p; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
557 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
|
558 return; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 c->c_errors++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
563 return; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
564 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
565 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
566 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
|
567 *p++ = addr; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
568 *p++ = line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
569 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
|
570 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
571 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
572 static void |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
573 com_set_lineno(c, lineno) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
574 struct compiling *c; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
575 int lineno; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
576 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
577 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
|
578 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
|
579 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
|
580 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
581 else { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
582 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
|
583 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
|
584 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
|
585 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
|
586 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
|
587 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
|
588 trunc_addr = 255; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
589 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
|
590 trunc_line = 255; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
591 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
|
592 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
|
593 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
|
594 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
595 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
|
596 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
|
597 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
598 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
599 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
600 static void |
| 69 | 601 com_addoparg(c, op, arg) |
| 602 struct compiling *c; | |
| 603 int op; | |
| 604 int arg; | |
| 605 { | |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
606 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
|
607 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
|
608 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
|
609 return; |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
610 } |
|
5164
8c277f29b535
Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
611 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
|
612 com_addint(c, arg); |
| 69 | 613 } |
| 614 | |
| 615 static void | |
| 616 com_addfwref(c, op, p_anchor) | |
| 617 struct compiling *c; | |
| 618 int op; | |
| 619 int *p_anchor; | |
| 620 { | |
| 621 /* Compile a forward reference for backpatching */ | |
| 622 int here; | |
| 623 int anchor; | |
| 624 com_addbyte(c, op); | |
| 625 here = c->c_nexti; | |
| 626 anchor = *p_anchor; | |
| 627 *p_anchor = here; | |
| 628 com_addint(c, anchor == 0 ? 0 : here - anchor); | |
| 629 } | |
| 630 | |
| 631 static void | |
| 632 com_backpatch(c, anchor) | |
| 633 struct compiling *c; | |
| 634 int anchor; /* Must be nonzero */ | |
| 635 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
636 unsigned char *code = (unsigned char *) PyString_AsString(c->c_code); |
| 69 | 637 int target = c->c_nexti; |
| 638 int dist; | |
| 639 int prev; | |
| 640 for (;;) { | |
| 641 /* Make the JUMP instruction at anchor point to target */ | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
642 prev = code[anchor] + (code[anchor+1] << 8); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
643 dist = target - (anchor+2); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
644 code[anchor] = dist & 0xff; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
645 code[anchor+1] = dist >> 8; |
| 69 | 646 if (!prev) |
| 647 break; | |
| 648 anchor -= prev; | |
| 649 } | |
| 650 } | |
| 651 | |
| 544 | 652 /* Handle literals and names uniformly */ |
| 69 | 653 |
| 654 static int | |
| 655 com_add(c, list, v) | |
| 656 struct compiling *c; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
657 PyObject *list; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
658 PyObject *v; |
| 69 | 659 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
660 int n = PyList_Size(list); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
661 int i; |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
662 /* XXX This is quadratic in the number of names per compilation unit. |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
663 XXX Should use a dictionary. */ |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
664 for (i = n; --i >= 0; ) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
665 PyObject *w = PyList_GetItem(list, i); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
666 if (v->ob_type == w->ob_type && PyObject_Compare(v, w) == 0) |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
667 return i; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
668 } |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5566
diff
changeset
|
669 /* Check for error from PyObject_Compare */ |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5566
diff
changeset
|
670 if (PyErr_Occurred() || PyList_Append(list, v) != 0) |
| 69 | 671 c->c_errors++; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
672 return n; |
| 69 | 673 } |
| 674 | |
| 675 static int | |
| 676 com_addconst(c, v) | |
| 677 struct compiling *c; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
678 PyObject *v; |
| 69 | 679 { |
| 680 return com_add(c, c->c_consts, v); | |
| 681 } | |
| 682 | |
| 683 static int | |
| 684 com_addname(c, v) | |
| 685 struct compiling *c; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
686 PyObject *v; |
| 69 | 687 { |
| 688 return com_add(c, c->c_names, v); | |
| 689 } | |
| 690 | |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
691 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
692 static int |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
693 com_mangle(c, name, buffer, maxlen) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
694 struct compiling *c; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
695 char *name; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
696 char *buffer; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
697 int maxlen; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
698 { |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
699 /* Name mangling: __private becomes _classname__private. |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
700 This is independent from how the name is used. */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
701 char *p; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
702 int nlen, plen; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
703 nlen = strlen(name); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
704 if (nlen+2 >= maxlen) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
705 return 0; /* Don't mangle __extremely_long_names */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
706 if (name[nlen-1] == '_' && name[nlen-2] == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
707 return 0; /* Don't mangle __whatever__ */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
708 p = c->c_private; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
709 /* Strip leading underscores from class name */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
710 while (*p == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
711 p++; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
712 if (*p == '\0') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
713 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
|
714 plen = strlen(p); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
715 if (plen + nlen >= maxlen) |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
716 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
|
717 /* 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
|
718 buffer[0] = '_'; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
719 strncpy(buffer+1, p, plen); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
720 strcpy(buffer+1+plen, name); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
721 /* fprintf(stderr, "mangle %s -> %s\n", name, buffer); */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
722 return 1; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
723 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
724 #endif |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
725 |
| 69 | 726 static void |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
727 com_addopnamestr(c, op, name) |
| 69 | 728 struct compiling *c; |
| 729 int op; | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
730 char *name; |
| 69 | 731 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
732 PyObject *v; |
| 69 | 733 int i; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
734 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
735 char buffer[256]; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
736 if (name != NULL && name[0] == '_' && name[1] == '_' && |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
737 c->c_private != NULL && |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
738 com_mangle(c, name, buffer, (int)sizeof(buffer))) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
739 name = buffer; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
740 #endif |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
741 if (name == NULL || (v = PyString_InternFromString(name)) == NULL) { |
| 69 | 742 c->c_errors++; |
| 743 i = 255; | |
| 744 } | |
| 745 else { | |
| 746 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
|
747 Py_DECREF(v); |
| 69 | 748 } |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
749 /* Hack to replace *_NAME opcodes by *_GLOBAL if necessary */ |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
750 switch (op) { |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
751 case LOAD_NAME: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
752 case STORE_NAME: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
753 case DELETE_NAME: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
754 if (PyDict_GetItemString(c->c_globals, name) != NULL) { |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
755 switch (op) { |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
756 case LOAD_NAME: op = LOAD_GLOBAL; break; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
757 case STORE_NAME: op = STORE_GLOBAL; break; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
758 case DELETE_NAME: op = DELETE_GLOBAL; break; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
759 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
760 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
761 } |
| 69 | 762 com_addoparg(c, op, i); |
| 763 } | |
| 764 | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
765 static void |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
766 com_addopname(c, op, n) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
767 struct compiling *c; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
768 int op; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
769 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
770 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
771 char *name; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
772 char buffer[1000]; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
773 /* 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
|
774 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
|
775 bothered right now */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
776 if (TYPE(n) == STAR) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
777 name = "*"; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
778 else if (TYPE(n) == dotted_name) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
779 char *p = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
780 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
781 name = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
782 for (i = 0; i < NCH(n); i += 2) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
783 char *s = STR(CHILD(n, i)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
784 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
|
785 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
|
786 "dotted_name too long"); |
|
2367
915fabec64a3
fix typo (== for =) in assignment
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
787 name = NULL; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
788 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
789 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
790 if (p != buffer) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
791 *p++ = '.'; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
792 strcpy(p, s); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
793 p = strchr(p, '\0'); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
794 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
795 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
796 else { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
797 REQ(n, NAME); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
798 name = STR(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
799 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
800 com_addopnamestr(c, op, name); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
801 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
802 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
803 static PyObject * |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
804 parsenumber(co, s) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
805 struct compiling *co; |
| 69 | 806 char *s; |
| 807 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
808 extern long PyOS_strtol Py_PROTO((const char *, char **, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
809 extern unsigned long PyOS_strtoul Py_PROTO((const char *, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
810 char **, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
811 extern double atof Py_PROTO((const char *)); |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
812 char *end; |
| 69 | 813 long x; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
814 double dx; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
815 #ifndef WITHOUT_COMPLEX |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3366
diff
changeset
|
816 Py_complex c; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
817 int imflag; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
818 #endif |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
819 |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
820 errno = 0; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
821 end = s + strlen(s) - 1; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
822 #ifndef WITHOUT_COMPLEX |
|
3366
c25865884649
only use 'j' for imaginary constants
Guido van Rossum <guido@python.org>
parents:
3349
diff
changeset
|
823 imflag = *end == 'j' || *end == 'J'; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
824 #endif |
| 744 | 825 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
|
826 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
|
827 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
|
828 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
|
829 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
830 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
|
831 if (*end == '\0') { |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
832 if (errno != 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
833 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
|
834 "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
|
835 return NULL; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
836 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
837 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
|
838 } |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
839 /* XXX Huge floats may silently fail */ |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
840 #ifndef WITHOUT_COMPLEX |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
841 if (imflag) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
842 c.real = 0.; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
843 PyFPE_START_PROTECT("atof", return 0) |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
844 c.imag = atof(s); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5183
diff
changeset
|
845 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
|
846 return PyComplex_FromCComplex(c); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
847 } |
|
6453
c9b139b9c5ff
Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents:
6186
diff
changeset
|
848 else |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
849 #endif |
|
6453
c9b139b9c5ff
Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents:
6186
diff
changeset
|
850 { |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
851 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
|
852 dx = atof(s); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5183
diff
changeset
|
853 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
|
854 return PyFloat_FromDouble(dx); |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5041
diff
changeset
|
855 } |
| 69 | 856 } |
| 857 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
858 static PyObject * |
| 69 | 859 parsestr(s) |
| 860 char *s; | |
| 861 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
862 PyObject *v; |
| 69 | 863 int len; |
| 864 char *buf; | |
| 865 char *p; | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
866 char *end; |
| 69 | 867 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
|
868 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
|
869 int quote = first; |
|
38878f1cd4f1
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
5233
diff
changeset
|
870 if (isalpha(quote) || quote == '_') |
|
38878f1cd4f1
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
5233
diff
changeset
|
871 quote = *++s; |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
872 if (quote != '\'' && quote != '\"') { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
873 PyErr_BadInternalCall(); |
| 69 | 874 return NULL; |
| 875 } | |
| 876 s++; | |
| 877 len = strlen(s); | |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
878 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
|
879 PyErr_BadInternalCall(); |
| 69 | 880 return NULL; |
| 881 } | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
882 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
|
883 s += 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
884 len -= 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
885 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
|
886 PyErr_BadInternalCall(); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
887 return NULL; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
888 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
889 } |
|
5264
38878f1cd4f1
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
5233
diff
changeset
|
890 if (first != quote || strchr(s, '\\') == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
891 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
|
892 v = PyString_FromStringAndSize((char *)NULL, len); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
893 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
|
894 end = s + len; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
895 while (s < end) { |
| 69 | 896 if (*s != '\\') { |
| 897 *p++ = *s++; | |
| 898 continue; | |
| 899 } | |
| 900 s++; | |
| 901 switch (*s++) { | |
| 902 /* 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
|
903 case '\n': break; |
| 69 | 904 case '\\': *p++ = '\\'; break; |
| 905 case '\'': *p++ = '\''; break; | |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
906 case '\"': *p++ = '\"'; break; |
| 69 | 907 case 'b': *p++ = '\b'; break; |
| 908 case 'f': *p++ = '\014'; break; /* FF */ | |
| 909 case 't': *p++ = '\t'; break; | |
| 910 case 'n': *p++ = '\n'; break; | |
| 911 case 'r': *p++ = '\r'; break; | |
| 912 case 'v': *p++ = '\013'; break; /* VT */ | |
| 913 case 'a': *p++ = '\007'; break; /* BEL, not classic C */ | |
| 914 case '0': case '1': case '2': case '3': | |
| 915 case '4': case '5': case '6': case '7': | |
| 916 c = s[-1] - '0'; | |
| 917 if ('0' <= *s && *s <= '7') { | |
| 918 c = (c<<3) + *s++ - '0'; | |
| 919 if ('0' <= *s && *s <= '7') | |
| 920 c = (c<<3) + *s++ - '0'; | |
| 921 } | |
| 922 *p++ = c; | |
| 923 break; | |
| 924 case 'x': | |
| 2310 | 925 if (isxdigit(Py_CHARMASK(*s))) { |
|
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
|
926 unsigned int x = 0; |
| 69 | 927 do { |
|
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
|
928 c = Py_CHARMASK(*s); |
| 69 | 929 s++; |
|
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
|
930 x = (x<<4) & ~0xF; |
|
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
931 if (isdigit(c)) |
|
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
932 x += c - '0'; |
|
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
933 else if (islower(c)) |
|
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
934 x += 10 + c - 'a'; |
|
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
935 else |
|
9ef9cadd978c
Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents:
6453
diff
changeset
|
936 x += 10 + c - 'A'; |
| 2310 | 937 } while (isxdigit(Py_CHARMASK(*s))); |
|
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
|
938 *p++ = x; |
| 69 | 939 break; |
| 940 } | |
| 941 /* FALLTHROUGH */ | |
| 942 default: *p++ = '\\'; *p++ = s[-1]; break; | |
| 943 } | |
| 944 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
945 _PyString_Resize(&v, (int)(p - buf)); |
| 69 | 946 return v; |
| 947 } | |
| 948 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
949 static PyObject * |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
950 parsestrplus(n) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
951 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
952 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
953 PyObject *v; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
954 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
955 REQ(CHILD(n, 0), STRING); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
956 if ((v = parsestr(STR(CHILD(n, 0)))) != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
957 /* String literal concatenation */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
958 for (i = 1; i < NCH(n) && v != NULL; i++) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
959 PyString_ConcatAndDel(&v, parsestr(STR(CHILD(n, i)))); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
960 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
961 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
962 return v; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
963 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
964 |
| 69 | 965 static void |
| 966 com_list_constructor(c, n) | |
| 967 struct compiling *c; | |
| 968 node *n; | |
| 969 { | |
| 970 int len; | |
| 971 int i; | |
| 972 if (TYPE(n) != testlist) | |
| 973 REQ(n, exprlist); | |
| 974 /* exprlist: expr (',' expr)* [',']; likewise for testlist */ | |
| 975 len = (NCH(n) + 1) / 2; | |
| 976 for (i = 0; i < NCH(n); i += 2) | |
| 977 com_node(c, CHILD(n, i)); | |
| 978 com_addoparg(c, BUILD_LIST, len); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
979 com_pop(c, len-1); |
| 69 | 980 } |
| 981 | |
| 982 static void | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
983 com_dictmaker(c, n) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
984 struct compiling *c; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
985 node *n; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
986 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
987 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
988 /* dictmaker: test ':' test (',' test ':' value)* [','] */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
989 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
|
990 /* 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
|
991 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
|
992 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
|
993 com_push(c, 1); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
994 com_node(c, CHILD(n, i+2)); /* value */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
995 com_addbyte(c, ROT_TWO); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
996 com_node(c, CHILD(n, i)); /* key */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
997 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
|
998 com_pop(c, 3); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
999 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1000 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1001 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1002 static void |
| 69 | 1003 com_atom(c, n) |
| 1004 struct compiling *c; | |
| 1005 node *n; | |
| 1006 { | |
| 1007 node *ch; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1008 PyObject *v; |
| 69 | 1009 int i; |
| 1010 REQ(n, atom); | |
| 1011 ch = CHILD(n, 0); | |
| 1012 switch (TYPE(ch)) { | |
| 1013 case LPAR: | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1014 if (TYPE(CHILD(n, 1)) == RPAR) { |
| 69 | 1015 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
|
1016 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
|
1017 } |
| 69 | 1018 else |
| 1019 com_node(c, CHILD(n, 1)); | |
| 1020 break; | |
| 1021 case LSQB: | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1022 if (TYPE(CHILD(n, 1)) == RSQB) { |
| 69 | 1023 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
|
1024 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
|
1025 } |
| 69 | 1026 else |
| 1027 com_list_constructor(c, CHILD(n, 1)); | |
| 1028 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1029 case LBRACE: /* '{' [dictmaker] '}' */ |
| 69 | 1030 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
|
1031 com_push(c, 1); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1032 if (TYPE(CHILD(n, 1)) != RBRACE) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1033 com_dictmaker(c, CHILD(n, 1)); |
| 69 | 1034 break; |
| 1035 case BACKQUOTE: | |
| 1036 com_node(c, CHILD(n, 1)); | |
| 1037 com_addbyte(c, UNARY_CONVERT); | |
| 1038 break; | |
| 1039 case NUMBER: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1040 if ((v = parsenumber(c, STR(ch))) == NULL) { |
| 69 | 1041 i = 255; |
| 1042 } | |
| 1043 else { | |
| 1044 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
|
1045 Py_DECREF(v); |
| 69 | 1046 } |
| 1047 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
|
1048 com_push(c, 1); |
| 69 | 1049 break; |
| 1050 case STRING: | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1051 v = parsestrplus(n); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1052 if (v == NULL) { |
| 69 | 1053 c->c_errors++; |
| 1054 i = 255; | |
| 1055 } | |
| 1056 else { | |
| 1057 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
|
1058 Py_DECREF(v); |
| 69 | 1059 } |
| 1060 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
|
1061 com_push(c, 1); |
| 69 | 1062 break; |
| 1063 case NAME: | |
| 1064 com_addopname(c, LOAD_NAME, ch); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1065 com_push(c, 1); |
| 69 | 1066 break; |
| 1067 default: | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1068 /* XXX fprintf(stderr, "node type %d\n", TYPE(ch)); */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1069 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
|
1070 "com_atom: unexpected node type"); |
| 69 | 1071 } |
| 1072 } | |
| 1073 | |
| 1074 static void | |
| 1075 com_slice(c, n, op) | |
| 1076 struct compiling *c; | |
| 1077 node *n; | |
| 1078 int op; | |
| 1079 { | |
| 1080 if (NCH(n) == 1) { | |
| 1081 com_addbyte(c, op); | |
| 1082 } | |
| 1083 else if (NCH(n) == 2) { | |
| 1084 if (TYPE(CHILD(n, 0)) != COLON) { | |
| 1085 com_node(c, CHILD(n, 0)); | |
| 1086 com_addbyte(c, op+1); | |
| 1087 } | |
| 1088 else { | |
| 1089 com_node(c, CHILD(n, 1)); | |
| 1090 com_addbyte(c, op+2); | |
| 1091 } | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1092 com_pop(c, 1); |
| 69 | 1093 } |
| 1094 else { | |
| 1095 com_node(c, CHILD(n, 0)); | |
| 1096 com_node(c, CHILD(n, 2)); | |
| 1097 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
|
1098 com_pop(c, 2); |
| 69 | 1099 } |
| 1100 } | |
| 1101 | |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1102 static void |
|
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1103 com_argument(c, n, 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
|
1104 struct compiling *c; |
|
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
|
1105 node *n; /* argument */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1106 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
|
1107 { |
|
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
|
1108 node *m; |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1109 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
|
1110 if (NCH(n) == 1) { |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1111 if (*pkeywords != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1112 com_error(c, PyExc_SyntaxError, |
|
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
|
1113 "non-keyword arg after keyword arg"); |
|
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
|
1114 } |
|
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
|
1115 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
|
1116 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
|
1117 } |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1118 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
|
1119 } |
|
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
|
1120 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
|
1121 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
|
1122 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
|
1123 } 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
|
1124 if (TYPE(m) != NAME) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1125 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
|
1126 "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
|
1127 } |
|
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
|
1128 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1129 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
|
1130 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
|
1131 *pkeywords = PyDict_New(); |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1132 if (v == NULL || *pkeywords == 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
|
1133 c->c_errors++; |
|
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
|
1134 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1135 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
|
1136 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
|
1137 "duplicate keyword argument"); |
|
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1138 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1139 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
|
1140 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
|
1141 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
|
1142 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
|
1143 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
|
1144 } |
|
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
|
1145 } |
|
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
|
1146 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
|
1147 } |
|
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
|
1148 |
| 69 | 1149 static void |
| 1150 com_call_function(c, n) | |
| 1151 struct compiling *c; | |
|
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
|
1152 node *n; /* EITHER arglist OR ')' */ |
| 69 | 1153 { |
| 1154 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
|
1155 com_addoparg(c, CALL_FUNCTION, 0); |
| 69 | 1156 } |
| 1157 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1158 PyObject *keywords = NULL; |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1159 int i, na, nk; |
|
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
|
1160 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
|
1161 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
|
1162 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
|
1163 for (i = 0; i < NCH(n); i += 2) { |
|
4905
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1164 com_argument(c, CHILD(n, i), &keywords); |
|
32220c5728f5
Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1165 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
|
1166 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
|
1167 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
|
1168 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
|
1169 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1170 Py_XDECREF(keywords); |
|
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
|
1171 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
|
1172 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
|
1173 "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
|
1174 } |
|
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
|
1175 com_addoparg(c, CALL_FUNCTION, na | (nk << 8)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1176 com_pop(c, na + 2*nk); |
| 69 | 1177 } |
| 1178 } | |
| 1179 | |
| 1180 static void | |
| 1181 com_select_member(c, n) | |
| 1182 struct compiling *c; | |
| 1183 node *n; | |
| 1184 { | |
| 1185 com_addopname(c, LOAD_ATTR, n); | |
| 1186 } | |
| 1187 | |
| 1188 static void | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1189 com_sliceobj(c, n) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1190 struct compiling *c; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1191 node *n; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1192 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1193 int i=0; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1194 int ns=2; /* number of slice arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1195 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1196 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1197 /* first argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1198 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
|
1199 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
|
1200 com_push(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1201 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1202 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1203 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1204 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1205 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1206 REQ(CHILD(n,i),COLON); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1207 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1208 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1209 /* second argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1210 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
|
1211 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1212 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1213 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1214 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1215 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
|
1216 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
|
1217 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1218 /* remaining arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1219 for (; i < NCH(n); i++) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1220 ns++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1221 ch=CHILD(n,i); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1222 REQ(ch, sliceop); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1223 if (NCH(ch) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1224 /* 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
|
1225 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
|
1226 com_push(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1227 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1228 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1229 com_node(c, CHILD(ch,1)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1230 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1231 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
|
1232 com_pop(c, 1 + (ns == 3)); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1233 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1234 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1235 static void |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1236 com_subscript(c, n) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1237 struct compiling *c; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1238 node *n; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1239 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1240 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1241 REQ(n, subscript); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1242 ch = CHILD(n,0); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1243 /* 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
|
1244 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
|
1245 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
|
1246 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
|
1247 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1248 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1249 /* check for slice */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1250 if ((TYPE(ch) == COLON || NCH(n) > 1)) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1251 com_sliceobj(c, n); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1252 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1253 REQ(ch, test); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1254 com_node(c, ch); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1255 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1256 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1257 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1258 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1259 static void |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1260 com_subscriptlist(c, n, assigning) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1261 struct compiling *c; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1262 node *n; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1263 int assigning; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1264 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1265 int i, op; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1266 REQ(n, subscriptlist); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1267 /* 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
|
1268 if (NCH(n) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1269 node *sub = CHILD(n, 0); /* subscript */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1270 /* Make it is a simple slice. |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1271 Should have exactly one colon. */ |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1272 if ((TYPE(CHILD(sub, 0)) == COLON |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1273 || (NCH(sub) > 1 && TYPE(CHILD(sub, 1)) == COLON)) |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1274 && (TYPE(CHILD(sub,NCH(sub)-1)) != sliceop)) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1275 { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1276 if (assigning == OP_APPLY) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1277 op = SLICE; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1278 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1279 op = ((assigning == OP_ASSIGN) ? |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1280 STORE_SLICE : DELETE_SLICE); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1281 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
|
1282 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
|
1283 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
|
1284 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
|
1285 com_pop(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1286 return; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1287 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1288 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1289 /* Else normal subscriptlist. Compile each subscript. */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1290 for (i = 0; i < NCH(n); i += 2) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1291 com_subscript(c, CHILD(n, i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1292 /* 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
|
1293 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
|
1294 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
|
1295 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
|
1296 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
|
1297 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1298 if (assigning == OP_APPLY) { |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1299 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
|
1300 i = 1; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1301 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1302 else if (assigning == OP_ASSIGN) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1303 op = STORE_SUBSCR; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1304 i = 3; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1305 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1306 else { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1307 op = DELETE_SUBSCR; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1308 i = 2; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1309 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1310 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
|
1311 com_pop(c, i); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1312 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1313 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1314 static void |
| 69 | 1315 com_apply_trailer(c, n) |
| 1316 struct compiling *c; | |
| 1317 node *n; | |
| 1318 { | |
| 1319 REQ(n, trailer); | |
| 1320 switch (TYPE(CHILD(n, 0))) { | |
| 1321 case LPAR: | |
| 1322 com_call_function(c, CHILD(n, 1)); | |
| 1323 break; | |
| 1324 case DOT: | |
| 1325 com_select_member(c, CHILD(n, 1)); | |
| 1326 break; | |
| 1327 case LSQB: | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1328 com_subscriptlist(c, CHILD(n, 1), OP_APPLY); |
| 69 | 1329 break; |
| 1330 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1331 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
|
1332 "com_apply_trailer: unknown trailer type"); |
| 69 | 1333 } |
| 1334 } | |
| 1335 | |
| 1336 static void | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1337 com_power(c, n) |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1338 struct compiling *c; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1339 node *n; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1340 { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1341 int i; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1342 REQ(n, power); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1343 com_atom(c, CHILD(n, 0)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1344 for (i = 1; i < NCH(n); i++) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1345 if (TYPE(CHILD(n, i)) == DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1346 com_factor(c, CHILD(n, i+1)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1347 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
|
1348 com_pop(c, 1); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1349 break; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1350 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1351 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1352 com_apply_trailer(c, CHILD(n, i)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1353 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1354 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1355 |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1356 static void |
| 69 | 1357 com_factor(c, n) |
| 1358 struct compiling *c; | |
| 1359 node *n; | |
| 1360 { | |
| 1361 REQ(n, factor); | |
| 1362 if (TYPE(CHILD(n, 0)) == PLUS) { | |
| 1363 com_factor(c, CHILD(n, 1)); | |
| 1364 com_addbyte(c, UNARY_POSITIVE); | |
| 1365 } | |
| 1366 else if (TYPE(CHILD(n, 0)) == MINUS) { | |
| 1367 com_factor(c, CHILD(n, 1)); | |
| 1368 com_addbyte(c, UNARY_NEGATIVE); | |
| 1369 } | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1370 else if (TYPE(CHILD(n, 0)) == TILDE) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1371 com_factor(c, CHILD(n, 1)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1372 com_addbyte(c, UNARY_INVERT); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1373 } |
| 69 | 1374 else { |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1375 com_power(c, CHILD(n, 0)); |
| 69 | 1376 } |
| 1377 } | |
| 1378 | |
| 1379 static void | |
| 1380 com_term(c, n) | |
| 1381 struct compiling *c; | |
| 1382 node *n; | |
| 1383 { | |
| 1384 int i; | |
| 1385 int op; | |
| 1386 REQ(n, term); | |
| 1387 com_factor(c, CHILD(n, 0)); | |
| 1388 for (i = 2; i < NCH(n); i += 2) { | |
| 1389 com_factor(c, CHILD(n, i)); | |
| 1390 switch (TYPE(CHILD(n, i-1))) { | |
| 1391 case STAR: | |
| 1392 op = BINARY_MULTIPLY; | |
| 1393 break; | |
| 1394 case SLASH: | |
| 1395 op = BINARY_DIVIDE; | |
| 1396 break; | |
| 1397 case PERCENT: | |
| 1398 op = BINARY_MODULO; | |
| 1399 break; | |
| 1400 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1401 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
|
1402 "com_term: operator not *, / or %"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1403 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1404 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1405 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
|
1406 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1407 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1408 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1409 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1410 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1411 com_arith_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1412 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1413 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1414 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1415 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1416 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1417 REQ(n, arith_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1418 com_term(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1419 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1420 com_term(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1421 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1422 case PLUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1423 op = BINARY_ADD; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1424 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1425 case MINUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1426 op = BINARY_SUBTRACT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1427 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1428 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1429 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
|
1430 "com_arith_expr: operator not + or -"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1431 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1432 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1433 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
|
1434 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1435 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1436 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1437 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1438 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1439 com_shift_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1440 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1441 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1442 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1443 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1444 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1445 REQ(n, shift_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1446 com_arith_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1447 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1448 com_arith_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1449 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1450 case LEFTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1451 op = BINARY_LSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1452 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1453 case RIGHTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1454 op = BINARY_RSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1455 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1456 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1457 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
|
1458 "com_shift_expr: operator not << or >>"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1459 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1460 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1461 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
|
1462 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1463 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1464 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1465 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1466 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1467 com_and_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1468 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1469 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1470 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1471 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1472 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1473 REQ(n, and_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1474 com_shift_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1475 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1476 com_shift_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1477 if (TYPE(CHILD(n, i-1)) == AMPER) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1478 op = BINARY_AND; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1479 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1480 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1481 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
|
1482 "com_and_expr: operator not &"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1483 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1484 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1485 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
|
1486 com_pop(c, 1); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1487 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1488 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1489 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1490 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1491 com_xor_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1492 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1493 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1494 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1495 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1496 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1497 REQ(n, xor_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1498 com_and_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1499 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1500 com_and_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1501 if (TYPE(CHILD(n, i-1)) == CIRCUMFLEX) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1502 op = BINARY_XOR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1503 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1504 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1505 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
|
1506 "com_xor_expr: operator not ^"); |
| 69 | 1507 op = 255; |
| 1508 } | |
| 1509 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
|
1510 com_pop(c, 1); |
| 69 | 1511 } |
| 1512 } | |
| 1513 | |
| 1514 static void | |
| 1515 com_expr(c, n) | |
| 1516 struct compiling *c; | |
| 1517 node *n; | |
| 1518 { | |
| 1519 int i; | |
| 1520 int op; | |
| 1521 REQ(n, expr); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1522 com_xor_expr(c, CHILD(n, 0)); |
| 69 | 1523 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
|
1524 com_xor_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1525 if (TYPE(CHILD(n, i-1)) == VBAR) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1526 op = BINARY_OR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1527 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1528 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1529 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
|
1530 "com_expr: expr operator not |"); |
| 69 | 1531 op = 255; |
| 1532 } | |
| 1533 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
|
1534 com_pop(c, 1); |
| 69 | 1535 } |
| 1536 } | |
| 1537 | |
| 1538 static enum cmp_op | |
| 1539 cmp_type(n) | |
| 1540 node *n; | |
| 1541 { | |
| 1542 REQ(n, comp_op); | |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1543 /* comp_op: '<' | '>' | '=' | '>=' | '<=' | '<>' | '!=' | '==' |
| 69 | 1544 | 'in' | 'not' 'in' | 'is' | 'is' not' */ |
| 1545 if (NCH(n) == 1) { | |
| 1546 n = CHILD(n, 0); | |
| 1547 switch (TYPE(n)) { | |
| 1548 case LESS: return LT; | |
| 1549 case GREATER: return GT; | |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1550 case EQEQUAL: /* == */ |
| 69 | 1551 case EQUAL: return EQ; |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1552 case LESSEQUAL: return LE; |
|
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1553 case GREATEREQUAL: return GE; |
|
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1554 case NOTEQUAL: return NE; /* <> or != */ |
| 69 | 1555 case NAME: if (strcmp(STR(n), "in") == 0) return IN; |
| 1556 if (strcmp(STR(n), "is") == 0) return IS; | |
| 1557 } | |
| 1558 } | |
| 1559 else if (NCH(n) == 2) { | |
| 1560 switch (TYPE(CHILD(n, 0))) { | |
| 1561 case NAME: if (strcmp(STR(CHILD(n, 1)), "in") == 0) | |
| 1562 return NOT_IN; | |
| 1563 if (strcmp(STR(CHILD(n, 0)), "is") == 0) | |
| 1564 return IS_NOT; | |
| 1565 } | |
| 1566 } | |
| 1567 return BAD; | |
| 1568 } | |
| 1569 | |
| 1570 static void | |
| 1571 com_comparison(c, n) | |
| 1572 struct compiling *c; | |
| 1573 node *n; | |
| 1574 { | |
| 1575 int i; | |
| 1576 enum cmp_op op; | |
| 1577 int anchor; | |
| 1578 REQ(n, comparison); /* comparison: expr (comp_op expr)* */ | |
| 1579 com_expr(c, CHILD(n, 0)); | |
| 1580 if (NCH(n) == 1) | |
| 1581 return; | |
| 1582 | |
| 1583 /**************************************************************** | |
| 1584 The following code is generated for all but the last | |
| 1585 comparison in a chain: | |
| 1586 | |
| 1587 label: on stack: opcode: jump to: | |
| 1588 | |
| 1589 a <code to load b> | |
| 1590 a, b DUP_TOP | |
| 1591 a, b, b ROT_THREE | |
| 1592 b, a, b COMPARE_OP | |
| 1593 b, 0-or-1 JUMP_IF_FALSE L1 | |
| 1594 b, 1 POP_TOP | |
| 1595 b | |
| 1596 | |
| 1597 We are now ready to repeat this sequence for the next | |
| 1598 comparison in the chain. | |
| 1599 | |
| 1600 For the last we generate: | |
| 1601 | |
| 1602 b <code to load c> | |
| 1603 b, c COMPARE_OP | |
| 1604 0-or-1 | |
| 1605 | |
| 1606 If there were any jumps to L1 (i.e., there was more than one | |
| 1607 comparison), we generate: | |
| 1608 | |
| 1609 0-or-1 JUMP_FORWARD L2 | |
| 1610 L1: b, 0 ROT_TWO | |
| 1611 0, b POP_TOP | |
| 1612 0 | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1613 L2: 0-or-1 |
| 69 | 1614 ****************************************************************/ |
| 1615 | |
| 1616 anchor = 0; | |
| 1617 | |
| 1618 for (i = 2; i < NCH(n); i += 2) { | |
| 1619 com_expr(c, CHILD(n, i)); | |
| 1620 if (i+2 < NCH(n)) { | |
| 1621 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
|
1622 com_push(c, 1); |
| 69 | 1623 com_addbyte(c, ROT_THREE); |
| 1624 } | |
| 1625 op = cmp_type(CHILD(n, i-1)); | |
| 1626 if (op == BAD) { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1627 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
|
1628 "com_comparison: unknown comparison op"); |
| 69 | 1629 } |
| 1630 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
|
1631 com_pop(c, 1); |
| 69 | 1632 if (i+2 < NCH(n)) { |
| 1633 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 1634 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
|
1635 com_pop(c, 1); |
| 69 | 1636 } |
| 1637 } | |
| 1638 | |
| 1639 if (anchor) { | |
| 1640 int anchor2 = 0; | |
| 1641 com_addfwref(c, JUMP_FORWARD, &anchor2); | |
| 1642 com_backpatch(c, anchor); | |
| 1643 com_addbyte(c, ROT_TWO); | |
| 1644 com_addbyte(c, POP_TOP); | |
| 1645 com_backpatch(c, anchor2); | |
| 1646 } | |
| 1647 } | |
| 1648 | |
| 1649 static void | |
| 1650 com_not_test(c, n) | |
| 1651 struct compiling *c; | |
| 1652 node *n; | |
| 1653 { | |
| 1654 REQ(n, not_test); /* 'not' not_test | comparison */ | |
| 1655 if (NCH(n) == 1) { | |
| 1656 com_comparison(c, CHILD(n, 0)); | |
| 1657 } | |
| 1658 else { | |
| 1659 com_not_test(c, CHILD(n, 1)); | |
| 1660 com_addbyte(c, UNARY_NOT); | |
| 1661 } | |
| 1662 } | |
| 1663 | |
| 1664 static void | |
| 1665 com_and_test(c, n) | |
| 1666 struct compiling *c; | |
| 1667 node *n; | |
| 1668 { | |
| 1669 int i; | |
| 1670 int anchor; | |
| 1671 REQ(n, and_test); /* not_test ('and' not_test)* */ | |
| 1672 anchor = 0; | |
| 1673 i = 0; | |
| 1674 for (;;) { | |
| 1675 com_not_test(c, CHILD(n, i)); | |
| 1676 if ((i += 2) >= NCH(n)) | |
| 1677 break; | |
| 1678 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 1679 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
|
1680 com_pop(c, 1); |
| 69 | 1681 } |
| 1682 if (anchor) | |
| 1683 com_backpatch(c, anchor); | |
| 1684 } | |
| 1685 | |
| 1686 static void | |
| 1687 com_test(c, n) | |
| 1688 struct compiling *c; | |
| 1689 node *n; | |
| 1690 { | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1691 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
|
1692 if (NCH(n) == 1 && TYPE(CHILD(n, 0)) == lambdef) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1693 PyObject *v; |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1694 int i; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1695 int ndefs = com_argdefs(c, CHILD(n, 0)); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1696 v = (PyObject *) icompile(CHILD(n, 0), c); |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1697 if (v == NULL) { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1698 c->c_errors++; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1699 i = 255; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1700 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1701 else { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1702 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
|
1703 Py_DECREF(v); |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1704 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1705 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
|
1706 com_push(c, 1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1707 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
|
1708 com_pop(c, ndefs); |
| 69 | 1709 } |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1710 else { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1711 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
|
1712 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
|
1713 for (;;) { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1714 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
|
1715 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
|
1716 break; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1717 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
|
1718 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
|
1719 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
|
1720 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1721 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
|
1722 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
|
1723 } |
| 69 | 1724 } |
| 1725 | |
| 1726 static void | |
| 482 | 1727 com_list(c, n, toplevel) |
| 69 | 1728 struct compiling *c; |
| 1729 node *n; | |
| 482 | 1730 int toplevel; /* If nonzero, *always* build a tuple */ |
| 69 | 1731 { |
| 1732 /* exprlist: expr (',' expr)* [',']; likewise for testlist */ | |
| 482 | 1733 if (NCH(n) == 1 && !toplevel) { |
| 69 | 1734 com_node(c, CHILD(n, 0)); |
| 1735 } | |
| 1736 else { | |
| 1737 int i; | |
| 1738 int len; | |
| 1739 len = (NCH(n) + 1) / 2; | |
| 1740 for (i = 0; i < NCH(n); i += 2) | |
| 1741 com_node(c, CHILD(n, i)); | |
| 1742 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
|
1743 com_pop(c, len-1); |
| 69 | 1744 } |
| 1745 } | |
| 1746 | |
| 1747 | |
| 1748 /* Begin of assignment compilation */ | |
| 1749 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1750 static void com_assign_name Py_PROTO((struct compiling *, node *, int)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1751 static void com_assign Py_PROTO((struct compiling *, node *, int)); |
| 69 | 1752 |
| 1753 static void | |
| 1754 com_assign_attr(c, n, assigning) | |
| 1755 struct compiling *c; | |
| 1756 node *n; | |
| 1757 int assigning; | |
| 1758 { | |
| 1759 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
|
1760 com_pop(c, assigning ? 2 : 1); |
| 69 | 1761 } |
| 1762 | |
| 1763 static void | |
| 1764 com_assign_trailer(c, n, assigning) | |
| 1765 struct compiling *c; | |
| 1766 node *n; | |
| 1767 int assigning; | |
| 1768 { | |
| 1769 REQ(n, trailer); | |
| 1770 switch (TYPE(CHILD(n, 0))) { | |
| 1771 case LPAR: /* '(' [exprlist] ')' */ | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1772 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
|
1773 "can't assign to function call"); |
| 69 | 1774 break; |
| 1775 case DOT: /* '.' NAME */ | |
| 1776 com_assign_attr(c, CHILD(n, 1), assigning); | |
| 1777 break; | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1778 case LSQB: /* '[' subscriptlist ']' */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1779 com_subscriptlist(c, CHILD(n, 1), assigning); |
| 69 | 1780 break; |
| 1781 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1782 com_error(c, PyExc_SystemError, "unknown trailer type"); |
| 69 | 1783 } |
| 1784 } | |
| 1785 | |
| 1786 static void | |
| 1787 com_assign_tuple(c, n, assigning) | |
| 1788 struct compiling *c; | |
| 1789 node *n; | |
| 1790 int assigning; | |
| 1791 { | |
| 1792 int i; | |
| 1793 if (TYPE(n) != testlist) | |
| 1794 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
|
1795 if (assigning) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1796 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
|
1797 com_addoparg(c, UNPACK_TUPLE, i); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1798 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
|
1799 } |
| 69 | 1800 for (i = 0; i < NCH(n); i += 2) |
| 1801 com_assign(c, CHILD(n, i), assigning); | |
| 1802 } | |
| 1803 | |
| 1804 static void | |
| 1805 com_assign_list(c, n, assigning) | |
| 1806 struct compiling *c; | |
| 1807 node *n; | |
| 1808 int assigning; | |
| 1809 { | |
| 1810 int i; | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1811 if (assigning) { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1812 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
|
1813 com_addoparg(c, UNPACK_LIST, i); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1814 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
|
1815 } |
| 69 | 1816 for (i = 0; i < NCH(n); i += 2) |
| 1817 com_assign(c, CHILD(n, i), assigning); | |
| 1818 } | |
| 1819 | |
| 1820 static void | |
| 1821 com_assign_name(c, n, assigning) | |
| 1822 struct compiling *c; | |
| 1823 node *n; | |
| 1824 int assigning; | |
| 1825 { | |
| 1826 REQ(n, NAME); | |
| 1827 com_addopname(c, assigning ? STORE_NAME : DELETE_NAME, n); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1828 if (assigning) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1829 com_pop(c, 1); |
| 69 | 1830 } |
| 1831 | |
| 1832 static void | |
| 1833 com_assign(c, n, assigning) | |
| 1834 struct compiling *c; | |
| 1835 node *n; | |
| 1836 int assigning; | |
| 1837 { | |
| 1838 /* Loop to avoid trivial recursion */ | |
| 1839 for (;;) { | |
| 1840 switch (TYPE(n)) { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1841 |
| 69 | 1842 case exprlist: |
| 1843 case testlist: | |
| 1844 if (NCH(n) > 1) { | |
| 1845 com_assign_tuple(c, n, assigning); | |
| 1846 return; | |
| 1847 } | |
| 1848 n = CHILD(n, 0); | |
| 1849 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1850 |
| 69 | 1851 case test: |
| 1852 case and_test: | |
| 1853 case not_test: | |
| 1854 case comparison: | |
| 1855 case expr: | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1856 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1857 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1858 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1859 case arith_expr: |
| 69 | 1860 case term: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1861 case factor: |
| 69 | 1862 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
|
1863 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
|
1864 "can't assign to operator"); |
| 69 | 1865 return; |
| 1866 } | |
| 1867 n = CHILD(n, 0); | |
| 1868 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1869 |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1870 case power: /* atom trailer* ('**' power)* */ |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1871 /* ('+'|'-'|'~') factor | atom trailer* */ |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1872 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
|
1873 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
|
1874 "can't assign to operator"); |
| 69 | 1875 return; |
| 1876 } | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1877 if (NCH(n) > 1) { /* trailer or exponent present */ |
| 69 | 1878 int i; |
| 1879 com_node(c, CHILD(n, 0)); | |
| 1880 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
|
1881 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
|
1882 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
|
1883 "can't assign to operator"); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1884 return; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1885 } |
| 69 | 1886 com_apply_trailer(c, CHILD(n, i)); |
| 1887 } /* NB i is still alive */ | |
| 1888 com_assign_trailer(c, | |
| 1889 CHILD(n, i), assigning); | |
| 1890 return; | |
| 1891 } | |
| 1892 n = CHILD(n, 0); | |
| 1893 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1894 |
| 69 | 1895 case atom: |
| 1896 switch (TYPE(CHILD(n, 0))) { | |
| 1897 case LPAR: | |
| 1898 n = CHILD(n, 1); | |
| 1899 if (TYPE(n) == RPAR) { | |
| 1900 /* XXX Should allow () = () ??? */ | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1901 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
|
1902 "can't assign to ()"); |
| 69 | 1903 return; |
| 1904 } | |
| 1905 break; | |
| 1906 case LSQB: | |
| 1907 n = CHILD(n, 1); | |
| 1908 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
|
1909 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
|
1910 "can't assign to []"); |
| 69 | 1911 return; |
| 1912 } | |
| 1913 com_assign_list(c, n, assigning); | |
| 1914 return; | |
| 1915 case NAME: | |
| 1916 com_assign_name(c, CHILD(n, 0), assigning); | |
| 1917 return; | |
| 1918 default: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1919 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
|
1920 "can't assign to literal"); |
| 69 | 1921 return; |
| 1922 } | |
| 1923 break; | |
|
3963
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1924 |
|
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1925 case lambdef: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1926 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
|
1927 "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
|
1928 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1929 |
| 69 | 1930 default: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1931 /* XXX fprintf(stderr, "node type %d\n", TYPE(n)); */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1932 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
|
1933 "com_assign: bad node"); |
| 69 | 1934 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1935 |
| 69 | 1936 } |
| 1937 } | |
| 1938 } | |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
1939 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
1940 /* Forward */ static node *get_rawdocstring Py_PROTO((node *)); |
| 69 | 1941 |
| 1942 static void | |
| 1943 com_expr_stmt(c, n) | |
| 1944 struct compiling *c; | |
| 1945 node *n; | |
| 1946 { | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1947 REQ(n, expr_stmt); /* testlist ('=' testlist)* */ |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
1948 /* 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
|
1949 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
|
1950 return; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1951 com_node(c, CHILD(n, NCH(n)-1)); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1952 if (NCH(n) == 1) { |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1953 if (c->c_interactive) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1954 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
|
1955 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1956 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
|
1957 com_pop(c, 1); |
| 69 | 1958 } |
| 1959 else { | |
| 1960 int i; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1961 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
|
1962 if (i+2 < NCH(n)-2) { |
| 69 | 1963 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
|
1964 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
|
1965 } |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1966 com_assign(c, CHILD(n, i), OP_ASSIGN); |
| 69 | 1967 } |
| 1968 } | |
| 1969 } | |
| 1970 | |
| 1971 static void | |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1972 com_assert_stmt(c, n) |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1973 struct compiling *c; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1974 node *n; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1975 { |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1976 int a = 0, b = 0; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1977 int i; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1978 REQ(n, assert_stmt); /* 'assert' test [',' test] */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1979 /* Generate code like for |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1980 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1981 if __debug__: |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1982 if not <test>: |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1983 raise AssertionError [, <message>] |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1984 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1985 where <message> is the second test, if present. |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1986 */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1987 if (Py_OptimizeFlag) |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1988 return; |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1989 com_addopnamestr(c, LOAD_GLOBAL, "__debug__"); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1990 com_push(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1991 com_addfwref(c, JUMP_IF_FALSE, &a); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1992 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1993 com_pop(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1994 com_node(c, CHILD(n, 1)); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1995 com_addfwref(c, JUMP_IF_TRUE, &b); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1996 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1997 com_pop(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1998 /* Raise that exception! */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1999 com_addopnamestr(c, LOAD_GLOBAL, "AssertionError"); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2000 com_push(c, 1); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2001 i = NCH(n)/2; /* Either 2 or 4 */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2002 if (i > 1) |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2003 com_node(c, CHILD(n, 3)); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2004 com_addoparg(c, RAISE_VARARGS, i); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2005 com_pop(c, i); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2006 /* The interpreter does not fall through */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2007 /* All jumps converge here */ |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2008 com_backpatch(c, a); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2009 com_backpatch(c, b); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2010 com_addbyte(c, POP_TOP); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2011 } |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2012 |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2013 static void |
| 69 | 2014 com_print_stmt(c, n) |
| 2015 struct compiling *c; | |
| 2016 node *n; | |
| 2017 { | |
| 2018 int i; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2019 REQ(n, print_stmt); /* 'print' (test ',')* [test] */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2020 for (i = 1; i < NCH(n); i += 2) { |
| 69 | 2021 com_node(c, CHILD(n, i)); |
| 2022 com_addbyte(c, PRINT_ITEM); | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2023 com_pop(c, 1); |
| 69 | 2024 } |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2025 if (TYPE(CHILD(n, NCH(n)-1)) != COMMA) |
| 69 | 2026 com_addbyte(c, PRINT_NEWLINE); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2027 /* XXX Alternatively, LOAD_CONST '\n' and then PRINT_ITEM */ |
| 69 | 2028 } |
| 2029 | |
| 2030 static void | |
| 2031 com_return_stmt(c, n) | |
| 2032 struct compiling *c; | |
| 2033 node *n; | |
| 2034 { | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2035 REQ(n, return_stmt); /* 'return' [testlist] */ |
| 86 | 2036 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
|
2037 com_error(c, PyExc_SyntaxError, "'return' outside function"); |
| 86 | 2038 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2039 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
|
2040 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
|
2041 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
|
2042 } |
| 69 | 2043 else |
| 2044 com_node(c, CHILD(n, 1)); | |
| 2045 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
|
2046 com_pop(c, 1); |
| 69 | 2047 } |
| 2048 | |
| 2049 static void | |
| 2050 com_raise_stmt(c, n) | |
| 2051 struct compiling *c; | |
| 2052 node *n; | |
| 2053 { | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2054 int i; |
|
7946
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2055 REQ(n, raise_stmt); /* 'raise' [test [',' test [',' test]]] */ |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2056 if (NCH(n) > 1) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2057 com_node(c, CHILD(n, 1)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2058 if (NCH(n) > 3) { |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2059 com_node(c, CHILD(n, 3)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2060 if (NCH(n) > 5) |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2061 com_node(c, CHILD(n, 5)); |
|
ad114620f8c2
Make first raise argument optional
Guido van Rossum <guido@python.org>
parents:
6501
diff
changeset
|
2062 } |
|
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
|
2063 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2064 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
|
2065 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
|
2066 com_pop(c, i); |
| 69 | 2067 } |
| 2068 | |
| 2069 static void | |
| 2070 com_import_stmt(c, n) | |
| 2071 struct compiling *c; | |
| 2072 node *n; | |
| 2073 { | |
| 2074 int i; | |
| 2075 REQ(n, import_stmt); | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2076 /* 'import' dotted_name (',' dotted_name)* | |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2077 'from' dotted_name 'import' ('*' | NAME (',' NAME)*) */ |
| 69 | 2078 if (STR(CHILD(n, 0))[0] == 'f') { |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2079 /* 'from' dotted_name 'import' ... */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2080 REQ(CHILD(n, 1), dotted_name); |
| 69 | 2081 com_addopname(c, IMPORT_NAME, 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
|
2082 com_push(c, 1); |
| 69 | 2083 for (i = 3; i < NCH(n); i += 2) |
| 2084 com_addopname(c, IMPORT_FROM, CHILD(n, i)); | |
| 2085 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
|
2086 com_pop(c, 1); |
| 69 | 2087 } |
| 2088 else { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2089 /* 'import' ... */ |
| 69 | 2090 for (i = 1; i < NCH(n); i += 2) { |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2091 REQ(CHILD(n, i), dotted_name); |
| 69 | 2092 com_addopname(c, IMPORT_NAME, 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
|
2093 com_push(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2094 com_addopname(c, STORE_NAME, CHILD(CHILD(n, i), 0)); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2095 com_pop(c, 1); |
| 69 | 2096 } |
| 2097 } | |
| 2098 } | |
| 2099 | |
| 2100 static void | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2101 com_global_stmt(c, n) |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2102 struct compiling *c; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2103 node *n; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2104 { |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2105 int i; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2106 REQ(n, global_stmt); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2107 /* 'global' NAME (',' NAME)* */ |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2108 for (i = 1; i < NCH(n); i += 2) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2109 char *s = STR(CHILD(n, i)); |
|
4130
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
2110 #ifdef PRIVATE_NAME_MANGLING |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
2111 char buffer[256]; |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
2112 if (s != NULL && s[0] == '_' && s[1] == '_' && |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
2113 c->c_private != NULL && |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
2114 com_mangle(c, s, buffer, (int)sizeof(buffer))) |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
2115 s = buffer; |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
2116 #endif |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2117 if (PyDict_GetItemString(c->c_locals, s) != NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2118 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
|
2119 "name is local and global"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2120 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2121 else if (PyDict_SetItemString(c->c_globals, s, Py_None) != 0) |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2122 c->c_errors++; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2123 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2124 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2125 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2126 static int |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2127 com_newlocal_o(c, nameval) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2128 struct compiling *c; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2129 PyObject *nameval; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2130 { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2131 int i; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2132 PyObject *ival; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2133 if (PyList_Size(c->c_varnames) != c->c_nlocals) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2134 /* This is usually caused by an error on a previous call */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2135 if (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
|
2136 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
|
2137 "mixed up var name/index"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2138 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2139 return 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2140 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2141 ival = PyInt_FromLong(i = c->c_nlocals++); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2142 if (ival == NULL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2143 c->c_errors++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2144 else if (PyDict_SetItem(c->c_locals, nameval, ival) != 0) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2145 c->c_errors++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2146 else if (PyList_Append(c->c_varnames, nameval) != 0) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2147 c->c_errors++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2148 Py_XDECREF(ival); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2149 return i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2150 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2151 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2152 static int |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2153 com_addlocal_o(c, nameval) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2154 struct compiling *c; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2155 PyObject *nameval; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2156 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2157 PyObject *ival = PyDict_GetItem(c->c_locals, nameval); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2158 if (ival != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2159 return PyInt_AsLong(ival); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2160 return com_newlocal_o(c, nameval); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2161 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2162 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2163 static int |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2164 com_newlocal(c, name) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2165 struct compiling *c; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2166 char *name; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2167 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2168 PyObject *nameval = PyString_InternFromString(name); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2169 int i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2170 if (nameval == NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2171 c->c_errors++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2172 return 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2173 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2174 i = com_newlocal_o(c, nameval); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2175 Py_DECREF(nameval); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2176 return i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2177 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2178 |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2179 static void |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2180 com_exec_stmt(c, n) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2181 struct compiling *c; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2182 node *n; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2183 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2184 REQ(n, exec_stmt); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2185 /* 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
|
2186 com_node(c, CHILD(n, 1)); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2187 if (NCH(n) >= 4) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2188 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
|
2189 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2190 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
|
2191 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
|
2192 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2193 if (NCH(n) >= 6) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2194 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
|
2195 else { |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2196 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
|
2197 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
|
2198 } |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2199 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
|
2200 com_pop(c, 3); |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2201 } |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2202 |
|
5181
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2203 static int |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2204 is_constant_false(c, n) |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2205 struct compiling *c; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2206 node *n; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2207 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2208 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
|
2209 int i; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2210 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2211 /* 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
|
2212 next: |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2213 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
|
2214 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2215 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
|
2216 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
|
2217 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
|
2218 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
|
2219 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2220 /* 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
|
2221 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
|
2222 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
|
2223 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
|
2224 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
|
2225 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
|
2226 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
|
2227 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2228 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2229 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2230 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2231 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
|
2232 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
|
2233 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
|
2234 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
|
2235 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
|
2236 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2237 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
|
2238 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
|
2239 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
|
2240 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
|
2241 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
|
2242 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
|
2243 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
|
2244 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
|
2245 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
|
2246 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
|
2247 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
|
2248 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
|
2249 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
|
2250 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
|
2251 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
|
2252 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
|
2253 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
|
2254 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
|
2255 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2256 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2257 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2258 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
|
2259 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
|
2260 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
|
2261 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2262 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2263 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
|
2264 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
|
2265 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2266 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
|
2267 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2268 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2269 i = PyObject_IsTrue(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2270 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
|
2271 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
|
2272 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2273 case STRING: |
|
5183
636757e812a4
Fix dumb bug calling parsestrplus with wrong node as argument.
Guido van Rossum <guido@python.org>
parents:
5181
diff
changeset
|
2274 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
|
2275 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2276 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
|
2277 break; |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2278 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2279 i = PyObject_IsTrue(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2280 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
|
2281 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
|
2282 |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2283 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2284 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
|
2285 } |
|
8a0b80dc6e71
Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents:
5164
diff
changeset
|
2286 |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2287 static void |
| 69 | 2288 com_if_stmt(c, n) |
| 2289 struct compiling *c; | |
| 2290 node *n; | |
| 2291 { | |
| 2292 int i; | |
| 2293 int anchor = 0; | |
| 2294 REQ(n, if_stmt); | |
| 2295 /*'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] */ | |
| 2296 for (i = 0; i+3 < NCH(n); i+=4) { | |
| 2297 int a = 0; | |
| 86 | 2298 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
|
2299 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
|
2300 continue; |
| 86 | 2301 if (i > 0) |
| 2302 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
|
2303 com_node(c, ch); |
| 69 | 2304 com_addfwref(c, JUMP_IF_FALSE, &a); |
| 2305 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
|
2306 com_pop(c, 1); |
| 69 | 2307 com_node(c, CHILD(n, i+3)); |
| 2308 com_addfwref(c, JUMP_FORWARD, &anchor); | |
| 2309 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
|
2310 /* We jump here with an extra entry which we now pop */ |
| 69 | 2311 com_addbyte(c, POP_TOP); |
| 2312 } | |
| 2313 if (i+2 < NCH(n)) | |
| 2314 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
|
2315 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
|
2316 com_backpatch(c, anchor); |
| 69 | 2317 } |
| 2318 | |
| 2319 static void | |
| 2320 com_while_stmt(c, n) | |
| 2321 struct compiling *c; | |
| 2322 node *n; | |
| 2323 { | |
| 2324 int break_anchor = 0; | |
| 2325 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2326 int save_begin = c->c_begin; |
| 69 | 2327 REQ(n, while_stmt); /* 'while' test ':' suite ['else' ':' suite] */ |
| 2328 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2329 block_push(c, SETUP_LOOP); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2330 c->c_begin = c->c_nexti; |
| 86 | 2331 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 2332 com_node(c, CHILD(n, 1)); |
| 2333 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 2334 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
|
2335 com_pop(c, 1); |
| 86 | 2336 c->c_loops++; |
| 69 | 2337 com_node(c, CHILD(n, 3)); |
| 86 | 2338 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2339 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2340 c->c_begin = save_begin; |
| 69 | 2341 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
|
2342 /* We jump here with one entry more on the stack */ |
| 69 | 2343 com_addbyte(c, POP_TOP); |
| 2344 com_addbyte(c, POP_BLOCK); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2345 block_pop(c, SETUP_LOOP); |
| 69 | 2346 if (NCH(n) > 4) |
| 2347 com_node(c, CHILD(n, 6)); | |
| 2348 com_backpatch(c, break_anchor); | |
| 2349 } | |
| 2350 | |
| 2351 static void | |
| 2352 com_for_stmt(c, n) | |
| 2353 struct compiling *c; | |
| 2354 node *n; | |
| 2355 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2356 PyObject *v; |
| 69 | 2357 int break_anchor = 0; |
| 2358 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2359 int save_begin = c->c_begin; |
| 69 | 2360 REQ(n, for_stmt); |
| 2361 /* 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] */ | |
| 2362 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2363 block_push(c, SETUP_LOOP); |
| 69 | 2364 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
|
2365 v = PyInt_FromLong(0L); |
| 69 | 2366 if (v == NULL) |
| 2367 c->c_errors++; | |
| 2368 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
|
2369 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
|
2370 Py_XDECREF(v); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2371 c->c_begin = c->c_nexti; |
| 86 | 2372 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 2373 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
|
2374 com_push(c, 1); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2375 com_assign(c, CHILD(n, 1), OP_ASSIGN); |
| 86 | 2376 c->c_loops++; |
| 69 | 2377 com_node(c, CHILD(n, 5)); |
| 86 | 2378 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2379 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2380 c->c_begin = save_begin; |
| 69 | 2381 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
|
2382 com_pop(c, 2); /* FOR_LOOP has popped these */ |
| 69 | 2383 com_addbyte(c, POP_BLOCK); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2384 block_pop(c, SETUP_LOOP); |
| 69 | 2385 if (NCH(n) > 8) |
| 2386 com_node(c, CHILD(n, 8)); | |
| 2387 com_backpatch(c, break_anchor); | |
| 2388 } | |
| 2389 | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2390 /* 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
|
2391 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2392 SETUP_FINALLY L |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2393 <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2394 POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2395 LOAD_CONST <nil> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2396 L: <code for Sf> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2397 END_FINALLY |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2398 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2399 The special instructions use the block stack. Each block |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2400 stack entry contains the instruction that created it (here |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2401 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
|
2402 block stack entry was created, and a label (here L). |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2403 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2404 SETUP_FINALLY: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2405 Pushes the current value stack level and the label |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2406 onto the block stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2407 POP_BLOCK: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2408 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
|
2409 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
|
2410 block stack. (The label is ignored.) |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2411 END_FINALLY: |
| 86 | 2412 Pops a variable number of entries from the *value* stack |
| 2413 and re-raises the exception they specify. The number of | |
| 2414 entries popped depends on the (pseudo) exception type. | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2415 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2416 The block stack is unwound when an exception is raised: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2417 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
|
2418 onto the value stack (and the exception condition is cleared), |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2419 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
|
2420 stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2421 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2422 Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...": |
| 86 | 2423 (The contents of the value stack is shown in [], with the top |
| 2424 at the right; 'tb' is trace-back info, 'val' the exception's | |
| 2425 associated value, and 'exc' the exception.) | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2426 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2427 Value stack Label Instruction Argument |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2428 [] SETUP_EXCEPT L1 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2429 [] <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2430 [] POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2431 [] JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2432 |
| 86 | 2433 [tb, val, exc] L1: DUP ) |
| 2434 [tb, val, exc, exc] <evaluate E1> ) | |
| 2435 [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1 | |
| 2436 [tb, val, exc, 1-or-0] JUMP_IF_FALSE L2 ) | |
| 2437 [tb, val, exc, 1] POP ) | |
| 2438 [tb, val, exc] POP | |
| 2439 [tb, val] <assign to V1> (or POP if no V1) | |
| 2440 [tb] POP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2441 [] <code for S1> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2442 JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2443 |
| 86 | 2444 [tb, val, exc, 0] L2: POP |
| 2445 [tb, val, exc] DUP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2446 .............................etc....................... |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2447 |
| 86 | 2448 [tb, val, exc, 0] Ln+1: POP |
| 2449 [tb, val, exc] END_FINALLY # re-raise exception | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2450 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2451 [] L0: <next statement> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2452 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2453 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
|
2454 */ |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2455 |
| 69 | 2456 static void |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2457 com_try_except(c, n) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2458 struct compiling *c; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2459 node *n; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2460 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2461 int except_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2462 int end_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2463 int else_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2464 int i; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2465 node *ch; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2466 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2467 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
|
2468 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
|
2469 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
|
2470 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
|
2471 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
|
2472 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
|
2473 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
|
2474 for (i = 3; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2475 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
|
2476 i += 3) { |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2477 /* 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
|
2478 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
|
2479 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
|
2480 "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
|
2481 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2482 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2483 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
|
2484 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
|
2485 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
|
2486 if (NCH(ch) > 1) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2487 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
|
2488 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
|
2489 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
|
2490 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
|
2491 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
|
2492 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
|
2493 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
|
2494 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
|
2495 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2496 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
|
2497 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
|
2498 if (NCH(ch) > 3) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2499 com_assign(c, CHILD(ch, 3), OP_ASSIGN); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2500 else { |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2501 com_addbyte(c, POP_TOP); |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2502 com_pop(c, 1); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2503 } |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2504 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
|
2505 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
|
2506 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
|
2507 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
|
2508 if (except_anchor) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2509 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
|
2510 /* 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
|
2511 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
|
2512 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
|
2513 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
|
2514 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2515 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2516 /* 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
|
2517 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
|
2518 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
|
2519 anything. */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2520 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
|
2521 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
|
2522 if (i < NCH(n)) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2523 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
|
2524 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
|
2525 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2526 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2527 static void |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2528 com_try_finally(c, n) |
| 69 | 2529 struct compiling *c; |
| 2530 node *n; | |
| 2531 { | |
| 2532 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
|
2533 node *ch; |
|
792
dc3b455f7632
Only * can be used for varargs argument lists
Guido van Rossum <guido@python.org>
parents:
744
diff
changeset
|
2534 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2535 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
|
2536 block_push(c, SETUP_FINALLY); |
| 69 | 2537 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
|
2538 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
|
2539 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
|
2540 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
|
2541 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
|
2542 /* 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
|
2543 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
|
2544 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
|
2545 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
|
2546 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
|
2547 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
|
2548 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
|
2549 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
|
2550 com_node(c, ch); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2551 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
|
2552 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
|
2553 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
|
2554 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2555 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2556 static void |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2557 com_try_stmt(c, n) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2558 struct compiling *c; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2559 node *n; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2560 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2561 REQ(n, try_stmt); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2562 /* '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
|
2563 | 'try' ':' suite 'finally' ':' suite */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2564 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
|
2565 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
|
2566 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2567 com_try_except(c, n); |
| 69 | 2568 } |
| 2569 | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2570 static node * |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2571 get_rawdocstring(n) |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2572 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2573 { |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2574 int i; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2575 |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2576 /* 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
|
2577 next: |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2578 switch (TYPE(n)) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2579 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2580 case suite: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2581 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
|
2582 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
|
2583 goto next; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2584 } |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2585 /* Fall through */ |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2586 case file_input: |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2587 for (i = 0; i < NCH(n); i++) { |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2588 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
|
2589 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
|
2590 n = ch; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2591 goto next; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2592 } |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2593 } |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2594 break; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2595 |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2596 case stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2597 case simple_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2598 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
|
2599 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
|
2600 goto next; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2601 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2602 case expr_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2603 case testlist: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2604 case test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2605 case and_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2606 case not_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2607 case comparison: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2608 case expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2609 case xor_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2610 case and_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2611 case shift_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2612 case arith_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2613 case term: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2614 case factor: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2615 case power: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2616 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
|
2617 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
|
2618 goto next; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2619 } |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2620 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2621 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2622 case atom: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2623 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
|
2624 return n; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2625 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2626 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2627 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2628 return NULL; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2629 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2630 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2631 static PyObject * |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2632 get_docstring(n) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2633 node *n; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2634 { |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2635 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
|
2636 if (n == NULL) |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2637 return NULL; |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2638 return parsestrplus(n); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2639 } |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2640 |
| 69 | 2641 static void |
| 2642 com_suite(c, n) | |
| 2643 struct compiling *c; | |
| 2644 node *n; | |
| 2645 { | |
| 2646 REQ(n, suite); | |
| 2647 /* simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT */ | |
| 2648 if (NCH(n) == 1) { | |
| 2649 com_node(c, CHILD(n, 0)); | |
| 2650 } | |
| 2651 else { | |
| 2652 int i; | |
| 2653 for (i = 0; i < NCH(n); i++) { | |
| 2654 node *ch = CHILD(n, i); | |
| 2655 if (TYPE(ch) == stmt) | |
| 2656 com_node(c, ch); | |
| 2657 } | |
| 2658 } | |
| 2659 } | |
| 2660 | |
| 744 | 2661 /* ARGSUSED */ |
| 69 | 2662 static void |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2663 com_continue_stmt(c, n) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2664 struct compiling *c; |
| 744 | 2665 node *n; /* Not used, but passed for consistency */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2666 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2667 int i = c->c_nblocks; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2668 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
|
2669 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2670 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2671 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2672 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
|
2673 "'continue' not properly in loop"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2674 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2675 /* XXX Could allow it inside a 'finally' clause |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2676 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
|
2677 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2678 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2679 static int |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2680 com_argdefs(c, n) |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2681 struct compiling *c; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2682 node *n; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2683 { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2684 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
|
2685 if (TYPE(n) == lambdef) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2686 /* lambdef: 'lambda' [varargslist] ':' test */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2687 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2688 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2689 else { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2690 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
|
2691 n = CHILD(n, 2); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2692 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
|
2693 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2694 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2695 if (TYPE(n) != varargslist) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2696 return 0; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2697 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2698 (fpdef ['=' test] ',')* '*' ....... | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2699 fpdef ['=' test] (',' fpdef ['=' test])* [','] */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2700 nch = NCH(n); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2701 nargs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2702 ndefs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2703 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
|
2704 int t; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2705 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
|
2706 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
|
2707 break; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2708 nargs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2709 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2710 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
|
2711 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
|
2712 else |
|
e51e17b2d88b
fix bug with missing default for last arg (discovered by Tommy Burnette)
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
2713 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
|
2714 if (t == EQUAL) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2715 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2716 ndefs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2717 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
|
2718 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2719 if (i >= nch) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2720 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2721 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
|
2722 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2723 else { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2724 /* Treat "(a=1, b)" as "(a=1, b=None)" */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2725 if (ndefs) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2726 com_addoparg(c, LOAD_CONST, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2727 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
|
2728 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
|
2729 ndefs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2730 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2731 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2732 if (t != COMMA) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2733 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2734 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2735 return ndefs; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2736 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2737 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2738 static void |
| 69 | 2739 com_funcdef(c, n) |
| 2740 struct compiling *c; | |
| 2741 node *n; | |
| 2742 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2743 PyObject *v; |
| 69 | 2744 REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2745 v = (PyObject *)icompile(n, c); |
| 69 | 2746 if (v == NULL) |
| 2747 c->c_errors++; | |
| 2748 else { | |
| 2749 int i = com_addconst(c, v); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2750 int ndefs = com_argdefs(c, n); |
| 69 | 2751 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
|
2752 com_push(c, 1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2753 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
|
2754 com_pop(c, ndefs); |
| 69 | 2755 com_addopname(c, STORE_NAME, 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
|
2756 com_pop(c, 1); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2757 Py_DECREF(v); |
| 69 | 2758 } |
| 2759 } | |
| 2760 | |
| 2761 static void | |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2762 com_bases(c, n) |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2763 struct compiling *c; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2764 node *n; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2765 { |
| 744 | 2766 int i; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2767 REQ(n, testlist); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2768 /* testlist: test (',' test)* [','] */ |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2769 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
|
2770 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
|
2771 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
|
2772 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
|
2773 com_pop(c, i-1); |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2774 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2775 |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2776 static void |
| 69 | 2777 com_classdef(c, n) |
| 2778 struct compiling *c; | |
| 2779 node *n; | |
| 2780 { | |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2781 int i; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2782 PyObject *v; |
| 69 | 2783 REQ(n, classdef); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2784 /* 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
|
2785 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
|
2786 c->c_errors++; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2787 return; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2788 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2789 /* Push the class name on the stack */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2790 i = com_addconst(c, v); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2791 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
|
2792 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
|
2793 Py_DECREF(v); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2794 /* 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
|
2795 if (TYPE(CHILD(n, 2)) != LPAR) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2796 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
|
2797 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
|
2798 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2799 else |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2800 com_bases(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
|
2801 v = (PyObject *)icompile(n, c); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2802 if (v == NULL) |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2803 c->c_errors++; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2804 else { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2805 i = com_addconst(c, v); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2806 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
|
2807 com_push(c, 1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2808 com_addoparg(c, MAKE_FUNCTION, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2809 com_addoparg(c, CALL_FUNCTION, 0); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2810 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
|
2811 com_pop(c, 2); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2812 com_addopname(c, STORE_NAME, CHILD(n, 1)); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2813 Py_DECREF(v); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2814 } |
| 69 | 2815 } |
| 2816 | |
| 2817 static void | |
| 2818 com_node(c, n) | |
| 2819 struct compiling *c; | |
| 2820 node *n; | |
| 2821 { | |
| 2822 switch (TYPE(n)) { | |
| 2823 | |
| 2824 /* Definition nodes */ | |
| 2825 | |
| 2826 case funcdef: | |
| 2827 com_funcdef(c, n); | |
| 2828 break; | |
| 2829 case classdef: | |
| 2830 com_classdef(c, n); | |
| 2831 break; | |
| 2832 | |
| 2833 /* Trivial parse tree nodes */ | |
| 2834 | |
| 2835 case stmt: | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2836 case small_stmt: |
| 86 | 2837 case flow_stmt: |
| 2838 com_node(c, CHILD(n, 0)); | |
| 2839 break; | |
| 2840 | |
| 69 | 2841 case simple_stmt: |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2842 /* small_stmt (';' small_stmt)* [';'] NEWLINE */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2843 com_addoparg(c, SET_LINENO, n->n_lineno); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2844 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2845 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2846 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
|
2847 com_node(c, CHILD(n, i)); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2848 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2849 break; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2850 |
| 69 | 2851 case compound_stmt: |
| 86 | 2852 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 2853 com_node(c, CHILD(n, 0)); |
| 2854 break; | |
| 2855 | |
| 2856 /* Statement nodes */ | |
| 2857 | |
| 2858 case expr_stmt: | |
| 2859 com_expr_stmt(c, n); | |
| 2860 break; | |
| 2861 case print_stmt: | |
| 2862 com_print_stmt(c, n); | |
| 2863 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2864 case del_stmt: /* 'del' exprlist */ |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2865 com_assign(c, CHILD(n, 1), OP_DELETE); |
| 69 | 2866 break; |
| 2867 case pass_stmt: | |
| 2868 break; | |
| 2869 case break_stmt: | |
| 86 | 2870 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
|
2871 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
|
2872 "'break' outside loop"); |
| 86 | 2873 } |
| 69 | 2874 com_addbyte(c, BREAK_LOOP); |
| 2875 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2876 case continue_stmt: |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2877 com_continue_stmt(c, n); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2878 break; |
| 69 | 2879 case return_stmt: |
| 2880 com_return_stmt(c, n); | |
| 2881 break; | |
| 2882 case raise_stmt: | |
| 2883 com_raise_stmt(c, n); | |
| 2884 break; | |
| 2885 case import_stmt: | |
| 2886 com_import_stmt(c, n); | |
| 2887 break; | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2888 case global_stmt: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2889 com_global_stmt(c, n); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2890 break; |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2891 case exec_stmt: |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2892 com_exec_stmt(c, n); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2893 break; |
|
5233
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2894 case assert_stmt: |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2895 com_assert_stmt(c, n); |
|
b749d2dd7582
Added assert statement.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
2896 break; |
| 69 | 2897 case if_stmt: |
| 2898 com_if_stmt(c, n); | |
| 2899 break; | |
| 2900 case while_stmt: | |
| 2901 com_while_stmt(c, n); | |
| 2902 break; | |
| 2903 case for_stmt: | |
| 2904 com_for_stmt(c, n); | |
| 2905 break; | |
| 2906 case try_stmt: | |
| 2907 com_try_stmt(c, n); | |
| 2908 break; | |
| 2909 case suite: | |
| 2910 com_suite(c, n); | |
| 2911 break; | |
| 2912 | |
| 2913 /* Expression nodes */ | |
| 2914 | |
| 2915 case testlist: | |
| 482 | 2916 com_list(c, n, 0); |
| 69 | 2917 break; |
| 2918 case test: | |
| 2919 com_test(c, n); | |
| 2920 break; | |
| 2921 case and_test: | |
| 2922 com_and_test(c, n); | |
| 2923 break; | |
| 2924 case not_test: | |
| 2925 com_not_test(c, n); | |
| 2926 break; | |
| 2927 case comparison: | |
| 2928 com_comparison(c, n); | |
| 2929 break; | |
| 2930 case exprlist: | |
| 482 | 2931 com_list(c, n, 0); |
| 69 | 2932 break; |
| 2933 case expr: | |
| 2934 com_expr(c, n); | |
| 2935 break; | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2936 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2937 com_xor_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2938 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2939 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2940 com_and_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2941 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2942 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2943 com_shift_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2944 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2945 case arith_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2946 com_arith_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2947 break; |
| 69 | 2948 case term: |
| 2949 com_term(c, n); | |
| 2950 break; | |
| 2951 case factor: | |
| 2952 com_factor(c, n); | |
| 2953 break; | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2954 case power: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2955 com_power(c, n); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2956 break; |
| 69 | 2957 case atom: |
| 2958 com_atom(c, n); | |
| 2959 break; | |
| 2960 | |
| 2961 default: | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2962 /* XXX fprintf(stderr, "node type %d\n", TYPE(n)); */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2963 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
|
2964 "com_node: unexpected node type"); |
| 69 | 2965 } |
| 2966 } | |
| 2967 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
2968 static void com_fplist Py_PROTO((struct compiling *, node *)); |
| 69 | 2969 |
| 2970 static void | |
| 2971 com_fpdef(c, n) | |
| 2972 struct compiling *c; | |
| 2973 node *n; | |
| 2974 { | |
| 2975 REQ(n, fpdef); /* fpdef: NAME | '(' fplist ')' */ | |
| 2976 if (TYPE(CHILD(n, 0)) == LPAR) | |
| 2977 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
|
2978 else { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2979 com_addoparg(c, STORE_FAST, com_newlocal(c, 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
|
2980 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
|
2981 } |
| 69 | 2982 } |
| 2983 | |
| 2984 static void | |
| 2985 com_fplist(c, n) | |
| 2986 struct compiling *c; | |
| 2987 node *n; | |
| 2988 { | |
| 544 | 2989 REQ(n, fplist); /* fplist: fpdef (',' fpdef)* [','] */ |
| 69 | 2990 if (NCH(n) == 1) { |
| 2991 com_fpdef(c, CHILD(n, 0)); | |
| 2992 } | |
| 2993 else { | |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2994 int 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
|
2995 com_addoparg(c, UNPACK_TUPLE, i); |
|
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
2996 com_push(c, i-1); |
| 69 | 2997 for (i = 0; i < NCH(n); i += 2) |
| 2998 com_fpdef(c, CHILD(n, i)); | |
| 2999 } | |
| 3000 } | |
| 3001 | |
| 3002 static void | |
| 584 | 3003 com_arglist(c, n) |
| 3004 struct compiling *c; | |
| 3005 node *n; | |
| 3006 { | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3007 int nch, i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3008 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
|
3009 char nbuf[10]; |
| 584 | 3010 REQ(n, varargslist); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
3011 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3012 (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
|
3013 nch = NCH(n); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3014 /* Enter all arguments in table of locals */ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3015 for (i = 0; i < nch; i++) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3016 node *ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3017 node *fp; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3018 char *name; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3019 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
|
3020 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3021 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3022 fp = CHILD(ch, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3023 if (TYPE(fp) == NAME) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3024 name = STR(fp); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3025 else { |
|
5754
9ed26afeeaa5
Fix bug reported by Just: anonymous arguments used for tuples should
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
3026 name = nbuf; |
|
9ed26afeeaa5
Fix bug reported by Just: anonymous arguments used for tuples should
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
3027 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
|
3028 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
|
3029 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3030 com_newlocal(c, name); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3031 c->c_argcount++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3032 if (++i >= nch) |
| 584 | 3033 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3034 ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3035 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
|
3036 i += 2; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3037 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3038 REQ(ch, COMMA); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3039 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3040 /* Handle *arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3041 if (i < nch) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3042 node *ch; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3043 ch = CHILD(n, i); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3044 if (TYPE(ch) != DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3045 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3046 ch = CHILD(n, i+1); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3047 if (TYPE(ch) == NAME) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3048 c->c_flags |= CO_VARARGS; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3049 i += 3; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3050 com_newlocal(c, STR(ch)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3051 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3052 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3053 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3054 /* Handle **keywords */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3055 if (i < nch) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3056 node *ch; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3057 ch = CHILD(n, i); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3058 if (TYPE(ch) != DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3059 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3060 ch = CHILD(n, i+1); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3061 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3062 ch = CHILD(n, i+2); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3063 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3064 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3065 ch = CHILD(n, i+1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3066 REQ(ch, NAME); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3067 c->c_flags |= CO_VARKEYWORDS; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3068 com_newlocal(c, STR(ch)); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3069 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3070 if (complex) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3071 /* Generate code for complex arguments only after |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3072 having counted the simple arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3073 int ilocal = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3074 for (i = 0; i < nch; i++) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3075 node *ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3076 node *fp; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
3077 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
|
3078 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3079 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3080 fp = CHILD(ch, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3081 if (TYPE(fp) != NAME) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3082 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
|
3083 com_push(c, 1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3084 com_fpdef(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3085 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3086 ilocal++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3087 if (++i >= nch) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3088 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3089 ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3090 if (TYPE(ch) == EQUAL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3091 i += 2; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3092 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3093 REQ(ch, COMMA); |
| 584 | 3094 } |
| 3095 } | |
| 3096 } | |
| 3097 | |
| 3098 static void | |
| 69 | 3099 com_file_input(c, n) |
| 3100 struct compiling *c; | |
| 3101 node *n; | |
| 3102 { | |
| 3103 int i; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3104 PyObject *doc; |
| 69 | 3105 REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */ |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3106 doc = get_docstring(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3107 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3108 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
|
3109 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3110 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
|
3111 com_push(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3112 com_addopnamestr(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
|
3113 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3114 } |
| 69 | 3115 for (i = 0; i < NCH(n); i++) { |
| 3116 node *ch = CHILD(n, i); | |
| 3117 if (TYPE(ch) != ENDMARKER && TYPE(ch) != NEWLINE) | |
| 3118 com_node(c, ch); | |
| 3119 } | |
| 3120 } | |
| 3121 | |
| 3122 /* Top-level compile-node interface */ | |
| 3123 | |
| 3124 static void | |
| 3125 compile_funcdef(c, n) | |
| 3126 struct compiling *c; | |
| 3127 node *n; | |
| 3128 { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3129 PyObject *doc; |
| 69 | 3130 node *ch; |
| 3131 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
|
3132 c->c_name = STR(CHILD(n, 1)); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3133 doc = get_docstring(CHILD(n, 4)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3134 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3135 (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
|
3136 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3137 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3138 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3139 (void) com_addconst(c, Py_None); /* No docstring */ |
| 584 | 3140 ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */ |
| 3141 ch = CHILD(ch, 1); /* ')' | varargslist */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3142 if (TYPE(ch) == varargslist) |
| 584 | 3143 com_arglist(c, ch); |
| 86 | 3144 c->c_infunction = 1; |
| 69 | 3145 com_node(c, CHILD(n, 4)); |
| 86 | 3146 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
|
3147 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
|
3148 com_push(c, 1); |
| 69 | 3149 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
|
3150 com_pop(c, 1); |
| 69 | 3151 } |
| 3152 | |
| 3153 static void | |
|
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
|
3154 compile_lambdef(c, n) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3155 struct compiling *c; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3156 node *n; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3157 { |
|
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
|
3158 node *ch; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3159 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
|
3160 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
|
3161 |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
3162 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
|
3163 (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
|
3164 if (TYPE(ch) == varargslist) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3165 com_arglist(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3166 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
|
3167 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3168 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3169 ch = CHILD(n, 2); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3170 com_node(c, ch); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3171 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
|
3172 com_pop(c, 1); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3173 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3174 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
3175 static void |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3176 compile_classdef(c, n) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3177 struct compiling *c; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3178 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3179 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3180 node *ch; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3181 PyObject *doc; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3182 REQ(n, classdef); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3183 /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3184 c->c_name = STR(CHILD(n, 1)); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3185 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3186 c->c_private = c->c_name; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3187 #endif |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3188 ch = CHILD(n, NCH(n)-1); /* The suite */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3189 doc = get_docstring(ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3190 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3191 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
|
3192 Py_DECREF(doc); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3193 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
|
3194 com_push(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3195 com_addopnamestr(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
|
3196 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3197 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3198 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3199 (void) com_addconst(c, Py_None); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3200 com_node(c, ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3201 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
|
3202 com_push(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3203 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
|
3204 com_pop(c, 1); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3205 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3206 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3207 static void |
| 69 | 3208 compile_node(c, n) |
| 3209 struct compiling *c; | |
| 3210 node *n; | |
| 3211 { | |
| 86 | 3212 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 3213 | |
| 69 | 3214 switch (TYPE(n)) { |
| 3215 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3216 case single_input: /* One interactive command */ |
| 69 | 3217 /* 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
|
3218 c->c_interactive++; |
| 69 | 3219 n = CHILD(n, 0); |
| 3220 if (TYPE(n) != NEWLINE) | |
| 3221 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
|
3222 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
|
3223 com_push(c, 1); |
| 86 | 3224 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
|
3225 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
|
3226 c->c_interactive--; |
| 69 | 3227 break; |
| 3228 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3229 case file_input: /* A whole file, or built-in function exec() */ |
| 69 | 3230 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
|
3231 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
|
3232 com_push(c, 1); |
| 86 | 3233 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
|
3234 com_pop(c, 1); |
| 69 | 3235 break; |
| 3236 | |
|
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
|
3237 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
|
3238 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
|
3239 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
|
3240 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
|
3241 break; |
|
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3242 |
|
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
|
3243 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
|
3244 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
|
3245 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
|
3246 |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3247 case funcdef: /* A function definition */ |
| 69 | 3248 compile_funcdef(c, n); |
| 3249 break; | |
| 3250 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
3251 case classdef: /* A class definition */ |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
3252 compile_classdef(c, n); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3253 break; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
3254 |
| 69 | 3255 default: |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3256 /* XXX fprintf(stderr, "node type %d\n", TYPE(n)); */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3257 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
|
3258 "compile_node: unexpected node type"); |
| 69 | 3259 } |
| 3260 } | |
| 3261 | |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3262 /* Optimization for local variables in functions (and *only* functions). |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
3263 |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3264 This replaces all LOAD_NAME, STORE_NAME and DELETE_NAME |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3265 instructions that refer to local variables with LOAD_FAST etc. |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3266 The latter instructions are much faster because they don't need to |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3267 look up the variable name in a dictionary. |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3268 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3269 To find all local variables, we check all STORE_NAME, IMPORT_FROM |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3270 and DELETE_NAME instructions. This yields all local variables, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3271 function definitions, class definitions and import statements. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3272 Argument names have already been entered into the list by the |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3273 special processing for the argument list. |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3274 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3275 All remaining LOAD_NAME instructions must refer to non-local (global |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3276 or builtin) variables, so are replaced by LOAD_GLOBAL. |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3277 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3278 There are two problems: 'from foo import *' and 'exec' may introduce |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3279 local variables that we can't know while compiling. If this is the |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3280 case, we can still optimize bona fide locals (since those |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3281 statements will be surrounded by fast_2_locals() and |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3282 locals_2_fast()), but we can't change LOAD_NAME to LOAD_GLOBAL. |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3283 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3284 NB: this modifies the string object c->c_code! */ |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3285 |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3286 static void |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3287 optimize(c) |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3288 struct compiling *c; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3289 { |
|
203
ceb36ec6198d
BUGFIX! Instructions are unsigned bytes.
Guido van Rossum <guido@python.org>
parents:
176
diff
changeset
|
3290 unsigned char *next_instr, *cur_instr; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3291 int opcode; |
| 4596 | 3292 int oparg = 0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3293 PyObject *name; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3294 PyObject *error_type, *error_value, *error_traceback; |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3295 |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3296 #define NEXTOP() (*next_instr++) |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3297 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2]) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3298 #define GETITEM(v, i) (PyList_GetItem((v), (i))) |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3299 #define GETNAMEOBJ(i) (GETITEM(c->c_names, (i))) |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3300 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3301 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3302 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3303 c->c_flags |= CO_OPTIMIZED; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3304 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3305 next_instr = (unsigned char *) PyString_AsString(c->c_code); |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3306 for (;;) { |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3307 opcode = NEXTOP(); |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3308 if (opcode == STOP_CODE) |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3309 break; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3310 if (HAS_ARG(opcode)) |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3311 oparg = NEXTARG(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3312 switch (opcode) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3313 case STORE_NAME: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3314 case DELETE_NAME: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3315 case IMPORT_FROM: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3316 com_addlocal_o(c, GETNAMEOBJ(oparg)); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3317 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3318 case EXEC_STMT: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3319 c->c_flags &= ~CO_OPTIMIZED; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3320 break; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3321 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3322 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3323 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3324 if (PyDict_GetItemString(c->c_locals, "*") != NULL) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3325 c->c_flags &= ~CO_OPTIMIZED; |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3326 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3327 next_instr = (unsigned char *) PyString_AsString(c->c_code); |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3328 for (;;) { |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3329 cur_instr = next_instr; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3330 opcode = NEXTOP(); |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3331 if (opcode == STOP_CODE) |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3332 break; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3333 if (HAS_ARG(opcode)) |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3334 oparg = NEXTARG(); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3335 if (opcode == LOAD_NAME || |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3336 opcode == STORE_NAME || |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3337 opcode == DELETE_NAME) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3338 PyObject *v; |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3339 int i; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3340 name = GETNAMEOBJ(oparg); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3341 v = PyDict_GetItem(c->c_locals, name); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3342 if (v == NULL) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3343 if (opcode == LOAD_NAME && |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3344 (c->c_flags&CO_OPTIMIZED)) |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
3345 cur_instr[0] = LOAD_GLOBAL; |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3346 continue; |
| 336 | 3347 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3348 i = PyInt_AsLong(v); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3349 switch (opcode) { |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3350 case LOAD_NAME: cur_instr[0] = LOAD_FAST; break; |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3351 case STORE_NAME: cur_instr[0] = STORE_FAST; break; |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3352 case DELETE_NAME: cur_instr[0] = DELETE_FAST; break; |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3353 } |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3354 cur_instr[1] = i & 0xff; |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3355 cur_instr[2] = (i>>8) & 0xff; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3356 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3357 } |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3358 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3359 if (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
|
3360 PyErr_Restore(error_type, error_value, error_traceback); |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3361 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
3362 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3363 PyCodeObject * |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3364 PyNode_Compile(n, filename) |
| 69 | 3365 node *n; |
| 86 | 3366 char *filename; |
| 69 | 3367 { |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3368 return jcompile(n, filename, NULL); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3369 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3370 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3371 static PyCodeObject * |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3372 icompile(n, base) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3373 node *n; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3374 struct compiling *base; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3375 { |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3376 return jcompile(n, base->c_filename, base); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3377 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3378 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3379 static PyCodeObject * |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3380 jcompile(n, filename, base) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3381 node *n; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3382 char *filename; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3383 struct compiling *base; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3384 { |
| 69 | 3385 struct compiling sc; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3386 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
|
3387 if (!com_init(&sc, filename)) |
| 69 | 3388 return NULL; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3389 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3390 if (base) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3391 sc.c_private = base->c_private; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3392 else |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3393 sc.c_private = NULL; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
3394 #endif |
| 69 | 3395 compile_node(&sc, n); |
| 3396 com_done(&sc); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3397 if ((TYPE(n) == funcdef || TYPE(n) == lambdef) && sc.c_errors == 0) { |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3398 optimize(&sc); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3399 sc.c_flags |= CO_NEWLOCALS; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3400 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3401 else if (TYPE(n) == classdef) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3402 sc.c_flags |= CO_NEWLOCALS; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
3403 co = NULL; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
3404 if (sc.c_errors == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3405 PyObject *consts, *names, *varnames, *filename, *name; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3406 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
|
3407 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
|
3408 varnames = PyList_AsTuple(sc.c_varnames); |
|
5009
402e36c83d20
Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents:
4991
diff
changeset
|
3409 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
|
3410 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
|
3411 if (!PyErr_Occurred()) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3412 co = PyCode_New(sc.c_argcount, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3413 sc.c_nlocals, |
|
4991
8276916e1ea8
Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents:
4905
diff
changeset
|
3414 sc.c_maxstacklevel, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3415 sc.c_flags, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3416 sc.c_code, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3417 consts, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3418 names, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3419 varnames, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3420 filename, |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3421 name, |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3422 sc.c_firstlineno, |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3423 sc.c_lnotab); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3424 Py_XDECREF(consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3425 Py_XDECREF(names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3426 Py_XDECREF(varnames); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3427 Py_XDECREF(filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
3428 Py_XDECREF(name); |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
3429 } |
| 69 | 3430 com_free(&sc); |
| 3431 return co; | |
| 3432 } | |
|
5041
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3433 |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3434 int |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3435 PyCode_Addr2Line(co, addrq) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3436 PyCodeObject *co; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3437 int addrq; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3438 { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3439 int size = PyString_Size(co->co_lnotab) / 2; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3440 char *p = PyString_AsString(co->co_lnotab); |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3441 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
|
3442 int addr = 0; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3443 while (--size >= 0) { |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3444 addr += *p++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3445 if (addr > addrq) |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3446 break; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3447 line += *p++; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3448 } |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3449 return line; |
|
c497929b2371
Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents:
5011
diff
changeset
|
3450 } |
