Mercurial > cpython-lru_cache-weakref
annotate Python/compile.c @ 4596:4fa19659591e legacy-trunk
Keep gcc -Wall happy.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 05 Dec 1996 23:27:02 +0000 |
| parents | 65d2d8e67da3 |
| children | 32220c5728f5 |
| 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: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
35 XXX Compute maximum needed stack sizes while compiling; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
36 XXX then frame object can be one malloc and no stack checks are needed |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
37 XXX add __doc__ attribute == co_doc to code object attributes |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
38 XXX don't execute doc string |
| 86 | 39 XXX Generate simple jump for break/return outside 'try...finally' |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
40 XXX get rid of SET_LINENO instructions, use JAR's table trick |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
41 XXX (need an option to put them back in, for debugger!) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
42 XXX other JAR tricks? |
| 86 | 43 */ |
| 69 | 44 |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
45 #ifndef NO_PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
46 #define PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
47 #endif |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
48 |
| 86 | 49 #include "allobjects.h" |
| 50 | |
| 69 | 51 #include "node.h" |
| 52 #include "token.h" | |
| 53 #include "graminit.h" | |
| 54 #include "compile.h" | |
| 55 #include "opcode.h" | |
| 86 | 56 #include "structmember.h" |
| 57 | |
| 58 #include <ctype.h> | |
|
1319
cd397266dc1c
* Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents:
1289
diff
changeset
|
59 #include <errno.h> |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
60 |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
61 #define OP_DELETE 0 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
62 #define OP_ASSIGN 1 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
63 #define OP_APPLY 2 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
64 |
| 86 | 65 #define OFF(x) offsetof(codeobject, x) |
| 66 | |
| 67 static struct memberlist code_memberlist[] = { | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
68 {"co_argcount", T_INT, OFF(co_argcount), READONLY}, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
69 {"co_nlocals", T_INT, OFF(co_nlocals), READONLY}, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
70 {"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
|
71 {"co_code", T_OBJECT, OFF(co_code), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
72 {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, |
|
92509d304e47
add READONLY to member list.
Guido van Rossum <guido@python.org>
parents:
544
diff
changeset
|
73 {"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
|
74 {"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
|
75 {"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
|
76 {"co_name", T_OBJECT, OFF(co_name), READONLY}, |
| 86 | 77 {NULL} /* Sentinel */ |
| 78 }; | |
| 79 | |
| 80 static object * | |
| 81 code_getattr(co, name) | |
| 82 codeobject *co; | |
| 83 char *name; | |
| 84 { | |
| 85 return getmember((char *)co, code_memberlist, name); | |
| 86 } | |
| 69 | 87 |
| 88 static void | |
| 86 | 89 code_dealloc(co) |
| 90 codeobject *co; | |
| 69 | 91 { |
| 86 | 92 XDECREF(co->co_code); |
| 93 XDECREF(co->co_consts); | |
| 94 XDECREF(co->co_names); | |
| 95 XDECREF(co->co_filename); | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
96 XDECREF(co->co_name); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
97 XDECREF(co->co_varnames); |
| 86 | 98 DEL(co); |
| 69 | 99 } |
| 100 | |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
101 static object * |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
102 code_repr(co) |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
103 codeobject *co; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
104 { |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
105 char buf[500]; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
106 int lineno = -1; |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
107 char *p = GETSTRINGVALUE(co->co_code); |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
108 char *filename = "???"; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
109 char *name = "???"; |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
110 if (*p == SET_LINENO) |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
111 lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8); |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
112 if (co->co_filename && is_stringobject(co->co_filename)) |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
113 filename = getstringvalue(co->co_filename); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
114 if (co->co_name && is_stringobject(co->co_name)) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
115 name = getstringvalue(co->co_name); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
116 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
|
117 name, (long)co, filename, lineno); |
|
1029
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
118 return newstringobject(buf); |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
119 } |
|
2f9805c963e8
Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents:
792
diff
changeset
|
120 |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
121 static int |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
122 code_compare(co, cp) |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
123 codeobject *co, *cp; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
124 { |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
125 int cmp; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
126 cmp = cp->co_argcount - cp->co_argcount; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
127 if (cmp) return cmp; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
128 cmp = cp->co_nlocals - cp->co_nlocals; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
129 if (cmp) return cmp; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
130 cmp = cp->co_flags - cp->co_flags; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
131 if (cmp) return cmp; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
132 cmp = cmpobject((object *)co->co_code, (object *)cp->co_code); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
133 if (cmp) return cmp; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
134 cmp = cmpobject(co->co_consts, cp->co_consts); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
135 if (cmp) return cmp; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
136 cmp = cmpobject(co->co_names, cp->co_names); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
137 if (cmp) return cmp; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
138 cmp = cmpobject(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
|
139 return cmp; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
140 } |
|
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 static long |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
143 code_hash(co) |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
144 codeobject *co; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
145 { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
146 long h, h1, h2, h3, h4; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
147 h1 = hashobject((object *)co->co_code); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
148 if (h1 == -1) return -1; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
149 h2 = hashobject(co->co_consts); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
150 if (h2 == -1) return -1; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
151 h3 = hashobject(co->co_names); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
152 if (h3 == -1) return -1; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
153 h4 = hashobject(co->co_varnames); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
154 if (h4 == -1) return -1; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
155 h = h1 ^ h2 ^ h3 ^ h4 ^ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
156 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
|
157 if (h == -1) h = -2; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
158 return h; |
|
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 |
| 69 | 161 typeobject Codetype = { |
| 162 OB_HEAD_INIT(&Typetype) | |
| 163 0, | |
| 164 "code", | |
| 165 sizeof(codeobject), | |
| 166 0, | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
167 (destructor)code_dealloc, /*tp_dealloc*/ |
| 69 | 168 0, /*tp_print*/ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
169 (getattrfunc)code_getattr, /*tp_getattr*/ |
| 69 | 170 0, /*tp_setattr*/ |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
171 (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
|
172 (reprfunc)code_repr, /*tp_repr*/ |
| 69 | 173 0, /*tp_as_number*/ |
| 174 0, /*tp_as_sequence*/ | |
| 175 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
|
176 (hashfunc)code_hash, /*tp_hash*/ |
| 69 | 177 }; |
| 178 | |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
179 codeobject * |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
180 newcodeobject(argcount, nlocals, flags, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
181 code, consts, names, varnames, filename, name) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
182 int argcount; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
183 int nlocals; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
184 int flags; |
| 69 | 185 object *code; |
| 186 object *consts; | |
| 187 object *names; | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
188 object *varnames; |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
189 object *filename; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
190 object *name; |
| 69 | 191 { |
| 192 codeobject *co; | |
| 193 int i; | |
| 194 /* Check argument types */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
195 if (argcount < 0 || nlocals < 0 || |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
196 code == NULL || !is_stringobject(code) || |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
197 consts == NULL || !is_tupleobject(consts) || |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
198 names == NULL || !is_tupleobject(names) || |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
199 varnames == NULL || !is_tupleobject(varnames) || |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
200 name == NULL || !is_stringobject(name) || |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
201 filename == NULL || !is_stringobject(filename)) { |
| 69 | 202 err_badcall(); |
| 203 return NULL; | |
| 204 } | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
205 /* Make sure names and varnames are all strings */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
206 for (i = gettuplesize(names); --i >= 0; ) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
207 object *v = gettupleitem(names, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
208 if (v == NULL || !is_stringobject(v)) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
209 err_badcall(); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
210 return NULL; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
211 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
212 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
213 for (i = gettuplesize(varnames); --i >= 0; ) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
214 object *v = gettupleitem(varnames, i); |
| 69 | 215 if (v == NULL || !is_stringobject(v)) { |
| 216 err_badcall(); | |
| 217 return NULL; | |
| 218 } | |
| 219 } | |
| 220 co = NEWOBJ(codeobject, &Codetype); | |
| 221 if (co != NULL) { | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
222 co->co_argcount = argcount; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
223 co->co_nlocals = nlocals; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
224 co->co_flags = flags; |
| 69 | 225 INCREF(code); |
| 226 co->co_code = (stringobject *)code; | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
227 INCREF(consts); |
| 69 | 228 co->co_consts = consts; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
229 INCREF(names); |
| 69 | 230 co->co_names = names; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
231 INCREF(varnames); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
232 co->co_varnames = varnames; |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
233 INCREF(filename); |
|
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
234 co->co_filename = filename; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
235 INCREF(name); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
236 co->co_name = name; |
| 69 | 237 } |
| 238 return co; | |
| 239 } | |
| 240 | |
| 241 | |
| 242 /* Data structure used internally */ | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
243 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
244 #define MAXBLOCKS 20 /* Max static block nesting within a function */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
245 |
| 69 | 246 struct compiling { |
| 247 object *c_code; /* string */ | |
| 248 object *c_consts; /* list of objects */ | |
| 249 object *c_names; /* list of strings (names) */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
250 object *c_globals; /* dictionary (value=None) */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
251 object *c_locals; /* dictionary (value=localID) */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
252 object *c_varnames; /* list (inverse of c_locals) */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
253 int c_nlocals; /* index of next local */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
254 int c_argcount; /* number of top-level arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
255 int c_flags; /* same as co_flags */ |
| 69 | 256 int c_nexti; /* index into c_code */ |
| 257 int c_errors; /* counts errors occurred */ | |
| 86 | 258 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
|
259 int c_interactive; /* generating code for interactive command */ |
| 86 | 260 int c_loops; /* counts nested loops */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
261 int c_begin; /* begin of current loop, for 'continue' */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
262 int c_block[MAXBLOCKS]; /* stack of block types */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
263 int c_nblocks; /* current block stack level */ |
| 86 | 264 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
|
265 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
|
266 int c_lineno; /* Current line number */ |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
267 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
268 char *c_private; /* for private name mangling */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
269 #endif |
| 69 | 270 }; |
| 271 | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
272 |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
273 /* 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
|
274 |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
275 static void |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
276 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
|
277 struct compiling *c; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
278 object *exc; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
279 char *msg; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
280 { |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
281 int n = strlen(msg); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
282 object *v; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
283 char buffer[30]; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
284 char *s; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
285 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
|
286 /* Unknown line number or single interactive command */ |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
287 err_setstr(exc, msg); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
288 return; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
289 } |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
290 sprintf(buffer, " (line %d)", c->c_lineno); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
291 v = newsizedstringobject((char *)NULL, n + strlen(buffer)); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
292 if (v == NULL) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
293 return; /* MemoryError, too bad */ |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
294 s = GETSTRINGVALUE((stringobject *)v); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
295 strcpy(s, msg); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
296 strcat(s, buffer); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
297 err_setval(exc, v); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
298 DECREF(v); |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
299 c->c_errors++; |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
300 } |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
301 |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
302 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
303 /* Interface to the block stack */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
304 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
305 static void |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
306 block_push(c, type) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
307 struct compiling *c; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
308 int type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
309 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
310 if (c->c_nblocks >= MAXBLOCKS) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
311 com_error(c, SystemError, "too many statically nested blocks"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
312 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
313 else { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
314 c->c_block[c->c_nblocks++] = type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
315 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
316 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
317 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
318 static void |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
319 block_pop(c, type) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
320 struct compiling *c; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
321 int type; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
322 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
323 if (c->c_nblocks > 0) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
324 c->c_nblocks--; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
325 if (c->c_block[c->c_nblocks] != type && c->c_errors == 0) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
326 com_error(c, SystemError, "bad block pop"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
327 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
328 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
329 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
330 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
331 /* Prototype forward declarations */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
332 |
|
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
|
333 static int com_init PROTO((struct compiling *, char *)); |
| 69 | 334 static void com_free PROTO((struct compiling *)); |
| 335 static void com_done PROTO((struct compiling *)); | |
| 336 static void com_node PROTO((struct compiling *, struct _node *)); | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
337 static void com_factor PROTO((struct compiling *, struct _node *)); |
| 69 | 338 static void com_addbyte PROTO((struct compiling *, int)); |
| 339 static void com_addint PROTO((struct compiling *, int)); | |
| 340 static void com_addoparg PROTO((struct compiling *, int, int)); | |
| 341 static void com_addfwref PROTO((struct compiling *, int, int *)); | |
| 342 static void com_backpatch PROTO((struct compiling *, int)); | |
| 343 static int com_add PROTO((struct compiling *, object *, object *)); | |
| 344 static int com_addconst PROTO((struct compiling *, object *)); | |
| 345 static int com_addname PROTO((struct compiling *, object *)); | |
| 346 static void com_addopname PROTO((struct compiling *, int, node *)); | |
| 482 | 347 static void com_list PROTO((struct compiling *, node *, int)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
348 static int com_argdefs PROTO((struct compiling *, node *)); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
349 static int com_newlocal PROTO((struct compiling *, char *)); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
350 static codeobject *icompile PROTO((struct _node *, struct compiling *)); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
351 static codeobject *jcompile PROTO((struct _node *, char *, struct compiling *)); |
| 69 | 352 |
| 353 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
|
354 com_init(c, filename) |
| 69 | 355 struct compiling *c; |
| 86 | 356 char *filename; |
| 69 | 357 { |
|
160
afa48a96a444
Create code string with initial size of 1000 instead of 0.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
358 if ((c->c_code = newsizedstringobject((char *)NULL, 1000)) == NULL) |
| 69 | 359 goto fail_3; |
| 360 if ((c->c_consts = newlistobject(0)) == NULL) | |
| 361 goto fail_2; | |
| 362 if ((c->c_names = newlistobject(0)) == NULL) | |
| 363 goto fail_1; | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
364 if ((c->c_globals = newdictobject()) == NULL) |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
365 goto fail_0; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
366 if ((c->c_locals = newdictobject()) == NULL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
367 goto fail_00; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
368 if ((c->c_varnames = newlistobject(0)) == NULL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
369 goto fail_000; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
370 c->c_nlocals = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
371 c->c_argcount = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
372 c->c_flags = 0; |
| 69 | 373 c->c_nexti = 0; |
| 374 c->c_errors = 0; | |
| 86 | 375 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
|
376 c->c_interactive = 0; |
| 86 | 377 c->c_loops = 0; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
378 c->c_begin = 0; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
379 c->c_nblocks = 0; |
| 86 | 380 c->c_filename = filename; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
381 c->c_name = "?"; |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
382 c->c_lineno = 0; |
| 69 | 383 return 1; |
| 384 | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
385 fail_000: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
386 DECREF(c->c_locals); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
387 fail_00: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
388 DECREF(c->c_globals); |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
389 fail_0: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
390 DECREF(c->c_names); |
| 69 | 391 fail_1: |
| 392 DECREF(c->c_consts); | |
| 393 fail_2: | |
| 394 DECREF(c->c_code); | |
| 395 fail_3: | |
| 396 return 0; | |
| 397 } | |
| 398 | |
| 399 static void | |
| 400 com_free(c) | |
| 401 struct compiling *c; | |
| 402 { | |
| 403 XDECREF(c->c_code); | |
| 404 XDECREF(c->c_consts); | |
| 405 XDECREF(c->c_names); | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
406 XDECREF(c->c_globals); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
407 XDECREF(c->c_locals); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
408 XDECREF(c->c_varnames); |
| 69 | 409 } |
| 410 | |
| 411 static void | |
| 412 com_done(c) | |
| 413 struct compiling *c; | |
| 414 { | |
| 415 if (c->c_code != NULL) | |
| 416 resizestring(&c->c_code, c->c_nexti); | |
| 417 } | |
| 418 | |
| 419 static void | |
| 420 com_addbyte(c, byte) | |
| 421 struct compiling *c; | |
| 422 int byte; | |
| 423 { | |
| 424 int len; | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
425 /*fprintf(stderr, "%3d: %3d\n", c->c_nexti, byte);*/ |
| 69 | 426 if (byte < 0 || byte > 255) { |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
427 /* |
| 86 | 428 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
|
429 fatal("com_addbyte: byte out of range"); |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
430 */ |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
431 com_error(c, SystemError, "com_addbyte: byte out of range"); |
| 69 | 432 } |
| 433 if (c->c_code == NULL) | |
| 434 return; | |
| 435 len = getstringsize(c->c_code); | |
| 436 if (c->c_nexti >= len) { | |
| 437 if (resizestring(&c->c_code, len+1000) != 0) { | |
| 438 c->c_errors++; | |
| 439 return; | |
| 440 } | |
| 441 } | |
| 442 getstringvalue(c->c_code)[c->c_nexti++] = byte; | |
| 443 } | |
| 444 | |
| 445 static void | |
| 446 com_addint(c, x) | |
| 447 struct compiling *c; | |
| 448 int x; | |
| 449 { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
450 com_addbyte(c, x & 0xff); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
451 com_addbyte(c, x >> 8); /* XXX x should be positive */ |
| 69 | 452 } |
| 453 | |
| 454 static void | |
| 455 com_addoparg(c, op, arg) | |
| 456 struct compiling *c; | |
| 457 int op; | |
| 458 int arg; | |
| 459 { | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
460 if (op == SET_LINENO) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
461 c->c_lineno = arg; |
| 69 | 462 com_addbyte(c, op); |
| 463 com_addint(c, arg); | |
| 464 } | |
| 465 | |
| 466 static void | |
| 467 com_addfwref(c, op, p_anchor) | |
| 468 struct compiling *c; | |
| 469 int op; | |
| 470 int *p_anchor; | |
| 471 { | |
| 472 /* Compile a forward reference for backpatching */ | |
| 473 int here; | |
| 474 int anchor; | |
| 475 com_addbyte(c, op); | |
| 476 here = c->c_nexti; | |
| 477 anchor = *p_anchor; | |
| 478 *p_anchor = here; | |
| 479 com_addint(c, anchor == 0 ? 0 : here - anchor); | |
| 480 } | |
| 481 | |
| 482 static void | |
| 483 com_backpatch(c, anchor) | |
| 484 struct compiling *c; | |
| 485 int anchor; /* Must be nonzero */ | |
| 486 { | |
| 487 unsigned char *code = (unsigned char *) getstringvalue(c->c_code); | |
| 488 int target = c->c_nexti; | |
| 489 int dist; | |
| 490 int prev; | |
| 491 for (;;) { | |
| 492 /* Make the JUMP instruction at anchor point to target */ | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
493 prev = code[anchor] + (code[anchor+1] << 8); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
494 dist = target - (anchor+2); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
495 code[anchor] = dist & 0xff; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
496 code[anchor+1] = dist >> 8; |
| 69 | 497 if (!prev) |
| 498 break; | |
| 499 anchor -= prev; | |
| 500 } | |
| 501 } | |
| 502 | |
| 544 | 503 /* Handle literals and names uniformly */ |
| 69 | 504 |
| 505 static int | |
| 506 com_add(c, list, v) | |
| 507 struct compiling *c; | |
| 508 object *list; | |
| 509 object *v; | |
| 510 { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
511 int n = getlistsize(list); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
512 int i; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
513 for (i = n; --i >= 0; ) { |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
514 object *w = getlistitem(list, i); |
|
303
149dd121d0a6
Check for identical types before comparing objects to see if they
Guido van Rossum <guido@python.org>
parents:
266
diff
changeset
|
515 if (v->ob_type == w->ob_type && cmpobject(v, w) == 0) |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
516 return i; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
517 } |
| 69 | 518 if (addlistitem(list, v) != 0) |
| 519 c->c_errors++; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
520 return n; |
| 69 | 521 } |
| 522 | |
| 523 static int | |
| 524 com_addconst(c, v) | |
| 525 struct compiling *c; | |
| 526 object *v; | |
| 527 { | |
| 528 return com_add(c, c->c_consts, v); | |
| 529 } | |
| 530 | |
| 531 static int | |
| 532 com_addname(c, v) | |
| 533 struct compiling *c; | |
| 534 object *v; | |
| 535 { | |
| 536 return com_add(c, c->c_names, v); | |
| 537 } | |
| 538 | |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
539 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
540 static int |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
541 com_mangle(c, name, buffer, maxlen) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
542 struct compiling *c; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
543 char *name; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
544 char *buffer; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
545 int maxlen; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
546 { |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
547 /* Name mangling: __private becomes _classname__private. |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
548 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
|
549 char *p; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
550 int nlen, plen; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
551 nlen = strlen(name); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
552 if (nlen+2 >= maxlen) |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
553 return 0; /* Don't mangle __extremely_long_names */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
554 if (name[nlen-1] == '_' && name[nlen-2] == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
555 return 0; /* Don't mangle __whatever__ */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
556 p = c->c_private; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
557 /* Strip leading underscores from class name */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
558 while (*p == '_') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
559 p++; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
560 if (*p == '\0') |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
561 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
|
562 plen = strlen(p); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
563 if (plen + nlen >= maxlen) |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
564 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
|
565 /* 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
|
566 buffer[0] = '_'; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
567 strncpy(buffer+1, p, plen); |
|
4131
6b589334e0e9
Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents:
4130
diff
changeset
|
568 strcpy(buffer+1+plen, name); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
569 /* fprintf(stderr, "mangle %s -> %s\n", name, buffer); */ |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
570 return 1; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
571 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
572 #endif |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
573 |
| 69 | 574 static void |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
575 com_addopnamestr(c, op, name) |
| 69 | 576 struct compiling *c; |
| 577 int op; | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
578 char *name; |
| 69 | 579 { |
| 580 object *v; | |
| 581 int i; | |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
582 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
583 char buffer[256]; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
584 if (name != NULL && name[0] == '_' && name[1] == '_' && |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
585 c->c_private != NULL && |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
586 com_mangle(c, name, buffer, (int)sizeof(buffer))) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
587 name = buffer; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
588 #endif |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
589 if (name == NULL || (v = newstringobject(name)) == NULL) { |
| 69 | 590 c->c_errors++; |
| 591 i = 255; | |
| 592 } | |
| 593 else { | |
| 594 i = com_addname(c, v); | |
| 595 DECREF(v); | |
| 596 } | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
597 /* 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
|
598 switch (op) { |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
599 case LOAD_NAME: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
600 case STORE_NAME: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
601 case DELETE_NAME: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
602 if (dictlookup(c->c_globals, name) != NULL) { |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
603 switch (op) { |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
604 case LOAD_NAME: op = LOAD_GLOBAL; break; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
605 case STORE_NAME: op = STORE_GLOBAL; break; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
606 case DELETE_NAME: op = DELETE_GLOBAL; break; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
607 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
608 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
609 } |
| 69 | 610 com_addoparg(c, op, i); |
| 611 } | |
| 612 | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
613 static void |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
614 com_addopname(c, op, n) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
615 struct compiling *c; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
616 int op; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
617 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
618 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
619 char *name; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
620 char buffer[1000]; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
621 /* 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
|
622 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
|
623 bothered right now */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
624 if (TYPE(n) == STAR) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
625 name = "*"; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
626 else if (TYPE(n) == dotted_name) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
627 char *p = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
628 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
629 name = buffer; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
630 for (i = 0; i < NCH(n); i += 2) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
631 char *s = STR(CHILD(n, i)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
632 if (p + strlen(s) > buffer + (sizeof buffer) - 2) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
633 com_error(c, MemoryError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
634 "dotted_name too long"); |
|
2367
915fabec64a3
fix typo (== for =) in assignment
Guido van Rossum <guido@python.org>
parents:
2310
diff
changeset
|
635 name = NULL; |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
636 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
637 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
638 if (p != buffer) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
639 *p++ = '.'; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
640 strcpy(p, s); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
641 p = strchr(p, '\0'); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
642 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
643 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
644 else { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
645 REQ(n, NAME); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
646 name = STR(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
647 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
648 com_addopnamestr(c, op, name); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
649 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
650 |
| 69 | 651 static object * |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
652 parsenumber(co, s) |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
653 struct compiling *co; |
| 69 | 654 char *s; |
| 655 { | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
656 extern long mystrtol PROTO((const char *, char **, int)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
657 extern unsigned long mystrtoul PROTO((const char *, char **, int)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
658 extern double atof PROTO((const char *)); |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
659 char *end; |
| 69 | 660 long x; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
661 #ifndef WITHOUT_COMPLEX |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3366
diff
changeset
|
662 Py_complex c; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
663 int imflag; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
664 #endif |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
665 |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
666 errno = 0; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
667 end = s + strlen(s) - 1; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
668 #ifndef WITHOUT_COMPLEX |
|
3366
c25865884649
only use 'j' for imaginary constants
Guido van Rossum <guido@python.org>
parents:
3349
diff
changeset
|
669 imflag = *end == 'j' || *end == 'J'; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
670 #endif |
| 744 | 671 if (*end == 'l' || *end == 'L') |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
672 return long_scan(s, 0); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
673 if (s[0] == '0') |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
674 x = (long) mystrtoul(s, &end, 0); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
675 else |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
676 x = mystrtol(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
|
677 if (*end == '\0') { |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
678 if (errno != 0) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
679 com_error(co, OverflowError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
680 "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
|
681 return NULL; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
682 } |
| 69 | 683 return newintobject(x); |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
684 } |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
685 /* XXX Huge floats may silently fail */ |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
686 #ifndef WITHOUT_COMPLEX |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
687 if (imflag) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
688 c.real = 0.; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
689 c.imag = atof(s); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
690 return newcomplexobject(c); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
691 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
692 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
693 #endif |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
694 return newfloatobject(atof(s)); |
| 69 | 695 } |
| 696 | |
| 697 static object * | |
| 698 parsestr(s) | |
| 699 char *s; | |
| 700 { | |
| 701 object *v; | |
| 702 int len; | |
| 703 char *buf; | |
| 704 char *p; | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
705 char *end; |
| 69 | 706 int c; |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
707 int quote = *s; |
|
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
708 if (quote != '\'' && quote != '\"') { |
| 69 | 709 err_badcall(); |
| 710 return NULL; | |
| 711 } | |
| 712 s++; | |
| 713 len = strlen(s); | |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
714 if (s[--len] != quote) { |
| 69 | 715 err_badcall(); |
| 716 return NULL; | |
| 717 } | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
718 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
|
719 s += 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
720 len -= 2; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
721 if (s[--len] != quote || s[--len] != quote) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
722 err_badcall(); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
723 return NULL; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
724 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
725 } |
| 69 | 726 if (strchr(s, '\\') == NULL) |
| 727 return newsizedstringobject(s, len); | |
| 728 v = newsizedstringobject((char *)NULL, len); | |
| 729 p = buf = getstringvalue(v); | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
730 end = s + len; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
731 while (s < end) { |
| 69 | 732 if (*s != '\\') { |
| 733 *p++ = *s++; | |
| 734 continue; | |
| 735 } | |
| 736 s++; | |
| 737 switch (*s++) { | |
| 738 /* 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
|
739 case '\n': break; |
| 69 | 740 case '\\': *p++ = '\\'; break; |
| 741 case '\'': *p++ = '\''; break; | |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
742 case '\"': *p++ = '\"'; break; |
| 69 | 743 case 'b': *p++ = '\b'; break; |
| 744 case 'f': *p++ = '\014'; break; /* FF */ | |
| 745 case 't': *p++ = '\t'; break; | |
| 746 case 'n': *p++ = '\n'; break; | |
| 747 case 'r': *p++ = '\r'; break; | |
| 748 case 'v': *p++ = '\013'; break; /* VT */ | |
| 749 case 'a': *p++ = '\007'; break; /* BEL, not classic C */ | |
| 750 case '0': case '1': case '2': case '3': | |
| 751 case '4': case '5': case '6': case '7': | |
| 752 c = s[-1] - '0'; | |
| 753 if ('0' <= *s && *s <= '7') { | |
| 754 c = (c<<3) + *s++ - '0'; | |
| 755 if ('0' <= *s && *s <= '7') | |
| 756 c = (c<<3) + *s++ - '0'; | |
| 757 } | |
| 758 *p++ = c; | |
| 759 break; | |
| 760 case 'x': | |
| 2310 | 761 if (isxdigit(Py_CHARMASK(*s))) { |
| 69 | 762 sscanf(s, "%x", &c); |
| 763 *p++ = c; | |
| 764 do { | |
| 765 s++; | |
| 2310 | 766 } while (isxdigit(Py_CHARMASK(*s))); |
| 69 | 767 break; |
| 768 } | |
| 769 /* FALLTHROUGH */ | |
| 770 default: *p++ = '\\'; *p++ = s[-1]; break; | |
| 771 } | |
| 772 } | |
| 773 resizestring(&v, (int)(p - buf)); | |
| 774 return v; | |
| 775 } | |
| 776 | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
777 static object * |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
778 parsestrplus(n) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
779 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
780 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
781 object *v; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
782 int i; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
783 REQ(CHILD(n, 0), STRING); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
784 if ((v = parsestr(STR(CHILD(n, 0)))) != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
785 /* String literal concatenation */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
786 for (i = 1; i < NCH(n) && v != NULL; i++) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
787 joinstring_decref(&v, parsestr(STR(CHILD(n, i)))); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
788 } |
|
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 return v; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
791 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
792 |
| 69 | 793 static void |
| 794 com_list_constructor(c, n) | |
| 795 struct compiling *c; | |
| 796 node *n; | |
| 797 { | |
| 798 int len; | |
| 799 int i; | |
| 800 if (TYPE(n) != testlist) | |
| 801 REQ(n, exprlist); | |
| 802 /* exprlist: expr (',' expr)* [',']; likewise for testlist */ | |
| 803 len = (NCH(n) + 1) / 2; | |
| 804 for (i = 0; i < NCH(n); i += 2) | |
| 805 com_node(c, CHILD(n, i)); | |
| 806 com_addoparg(c, BUILD_LIST, len); | |
| 807 } | |
| 808 | |
| 809 static void | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
810 com_dictmaker(c, n) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
811 struct compiling *c; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
812 node *n; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
813 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
814 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
815 /* dictmaker: test ':' test (',' test ':' value)* [','] */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
816 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
|
817 /* 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
|
818 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
|
819 com_addbyte(c, DUP_TOP); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
820 com_node(c, CHILD(n, i+2)); /* value */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
821 com_addbyte(c, ROT_TWO); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
822 com_node(c, CHILD(n, i)); /* key */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
823 com_addbyte(c, STORE_SUBSCR); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
824 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
825 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
826 |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
827 static void |
| 69 | 828 com_atom(c, n) |
| 829 struct compiling *c; | |
| 830 node *n; | |
| 831 { | |
| 832 node *ch; | |
| 833 object *v; | |
| 834 int i; | |
| 835 REQ(n, atom); | |
| 836 ch = CHILD(n, 0); | |
| 837 switch (TYPE(ch)) { | |
| 838 case LPAR: | |
| 839 if (TYPE(CHILD(n, 1)) == RPAR) | |
| 840 com_addoparg(c, BUILD_TUPLE, 0); | |
| 841 else | |
| 842 com_node(c, CHILD(n, 1)); | |
| 843 break; | |
| 844 case LSQB: | |
| 845 if (TYPE(CHILD(n, 1)) == RSQB) | |
| 846 com_addoparg(c, BUILD_LIST, 0); | |
| 847 else | |
| 848 com_list_constructor(c, CHILD(n, 1)); | |
| 849 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
850 case LBRACE: /* '{' [dictmaker] '}' */ |
| 69 | 851 com_addoparg(c, BUILD_MAP, 0); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
852 if (TYPE(CHILD(n, 1)) != RBRACE) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
853 com_dictmaker(c, CHILD(n, 1)); |
| 69 | 854 break; |
| 855 case BACKQUOTE: | |
| 856 com_node(c, CHILD(n, 1)); | |
| 857 com_addbyte(c, UNARY_CONVERT); | |
| 858 break; | |
| 859 case NUMBER: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
860 if ((v = parsenumber(c, STR(ch))) == NULL) { |
| 69 | 861 i = 255; |
| 862 } | |
| 863 else { | |
| 864 i = com_addconst(c, v); | |
| 865 DECREF(v); | |
| 866 } | |
| 867 com_addoparg(c, LOAD_CONST, i); | |
| 868 break; | |
| 869 case STRING: | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
870 v = parsestrplus(n); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
871 if (v == NULL) { |
| 69 | 872 c->c_errors++; |
| 873 i = 255; | |
| 874 } | |
| 875 else { | |
| 876 i = com_addconst(c, v); | |
| 877 DECREF(v); | |
| 878 } | |
| 879 com_addoparg(c, LOAD_CONST, i); | |
| 880 break; | |
| 881 case NAME: | |
| 882 com_addopname(c, LOAD_NAME, ch); | |
| 883 break; | |
| 884 default: | |
| 885 fprintf(stderr, "node type %d\n", TYPE(ch)); | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
886 com_error(c, SystemError, "com_atom: unexpected node type"); |
| 69 | 887 } |
| 888 } | |
| 889 | |
| 890 static void | |
| 891 com_slice(c, n, op) | |
| 892 struct compiling *c; | |
| 893 node *n; | |
| 894 int op; | |
| 895 { | |
| 896 if (NCH(n) == 1) { | |
| 897 com_addbyte(c, op); | |
| 898 } | |
| 899 else if (NCH(n) == 2) { | |
| 900 if (TYPE(CHILD(n, 0)) != COLON) { | |
| 901 com_node(c, CHILD(n, 0)); | |
| 902 com_addbyte(c, op+1); | |
| 903 } | |
| 904 else { | |
| 905 com_node(c, CHILD(n, 1)); | |
| 906 com_addbyte(c, op+2); | |
| 907 } | |
| 908 } | |
| 909 else { | |
| 910 com_node(c, CHILD(n, 0)); | |
| 911 com_node(c, CHILD(n, 2)); | |
| 912 com_addbyte(c, op+3); | |
| 913 } | |
| 914 } | |
| 915 | |
|
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
|
916 static int |
|
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
|
917 com_argument(c, n, inkeywords) |
|
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
|
918 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
|
919 node *n; /* argument */ |
|
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
|
920 int inkeywords; |
|
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
|
921 { |
|
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
|
922 node *m; |
|
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
|
923 REQ(n, argument); /* [test '='] test; really [ keyword '='] keyword */ |
|
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
|
924 if (NCH(n) == 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
|
925 if (inkeywords) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
926 com_error(c, 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
|
927 "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
|
928 } |
|
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
|
929 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
|
930 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
|
931 } |
|
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
|
932 return 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
|
933 } |
|
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
|
934 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
|
935 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
|
936 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
|
937 } 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
|
938 if (TYPE(m) != NAME) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
939 com_error(c, SyntaxError, "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
|
940 } |
|
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
|
941 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
|
942 object *v = newstringobject(STR(m)); |
|
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
|
943 if (v == NULL) |
|
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
|
944 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
|
945 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
|
946 com_addoparg(c, LOAD_CONST, com_addconst(c, v)); |
|
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
|
947 DECREF(v); |
|
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
|
948 } |
|
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
|
949 } |
|
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
|
950 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
|
951 return 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
|
952 } |
|
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
|
953 |
| 69 | 954 static void |
| 955 com_call_function(c, n) | |
| 956 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
|
957 node *n; /* EITHER arglist OR ')' */ |
| 69 | 958 { |
| 959 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
|
960 com_addoparg(c, CALL_FUNCTION, 0); |
| 69 | 961 } |
| 962 else { | |
|
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
|
963 int inkeywords, i, na, 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
|
964 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
|
965 inkeywords = 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
|
966 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
|
967 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
|
968 for (i = 0; i < NCH(n); i += 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
|
969 inkeywords = com_argument(c, CHILD(n, i), inkeywords); |
|
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
|
970 if (!inkeywords) |
|
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
|
971 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
|
972 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
|
973 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
|
974 } |
|
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
|
975 if (na > 255 || nk > 255) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
976 com_error(c, SyntaxError, "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
|
977 } |
|
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
|
978 com_addoparg(c, CALL_FUNCTION, na | (nk << 8)); |
| 69 | 979 } |
| 980 } | |
| 981 | |
| 982 static void | |
| 983 com_select_member(c, n) | |
| 984 struct compiling *c; | |
| 985 node *n; | |
| 986 { | |
| 987 com_addopname(c, LOAD_ATTR, n); | |
| 988 } | |
| 989 | |
| 990 static void | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
991 com_sliceobj(c, n) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
992 struct compiling *c; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
993 node *n; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
994 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
995 int i=0; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
996 int ns=2; /* number of slice arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
997 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
998 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
999 /* first argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1000 if (TYPE(CHILD(n,i)) == COLON) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1001 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1002 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1003 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1004 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1005 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1006 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1007 REQ(CHILD(n,i),COLON); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1008 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1009 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1010 /* second argument */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1011 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
|
1012 com_node(c, CHILD(n,i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1013 i++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1014 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1015 else com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1016 /* remaining arguments */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1017 for (; i < NCH(n); i++) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1018 ns++; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1019 ch=CHILD(n,i); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1020 REQ(ch, sliceop); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1021 if (NCH(ch) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1022 /* right argument of ':' missing */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1023 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1024 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1025 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1026 com_node(c, CHILD(ch,1)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1027 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1028 com_addoparg(c, BUILD_SLICE, ns); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1029 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1030 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1031 static void |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1032 com_subscript(c, n) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1033 struct compiling *c; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1034 node *n; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1035 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1036 node *ch; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1037 REQ(n, subscript); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1038 ch = CHILD(n,0); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1039 /* check for rubber index */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1040 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
|
1041 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_Ellipsis)); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1042 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1043 /* check for slice */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1044 if ((TYPE(ch) == COLON || NCH(n) > 1)) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1045 com_sliceobj(c, n); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1046 else { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1047 REQ(ch, test); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1048 com_node(c, ch); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1049 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1050 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1051 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1052 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1053 static void |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1054 com_subscriptlist(c, n, assigning) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1055 struct compiling *c; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1056 node *n; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1057 int assigning; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1058 { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1059 int i, op; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1060 REQ(n, subscriptlist); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1061 /* 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
|
1062 if (NCH(n) == 1) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1063 node *sub = CHILD(n, 0); /* subscript */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1064 /* Make it is a simple slice. |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1065 should have exactly one colon. */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1066 if ((TYPE(CHILD(sub, 0)) == COLON |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1067 || (NCH(sub) > 1 && TYPE(CHILD(sub, 1)) == COLON)) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1068 && (TYPE(CHILD(sub,NCH(sub)-1)) != sliceop)) { |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1069 if (assigning == OP_APPLY) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1070 op = SLICE; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1071 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1072 op = ((assigning == OP_ASSIGN) ? STORE_SLICE : DELETE_SLICE); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1073 com_slice(c, sub, op); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1074 return; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1075 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1076 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1077 /* Else normal subscriptlist. Compile each subscript. */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1078 for (i = 0; i < NCH(n); i += 2) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1079 com_subscript(c, CHILD(n, i)); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1080 /* Put multiple subscripts into a tuple */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1081 if (NCH(n) > 1) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1082 com_addoparg(c, BUILD_TUPLE, (NCH(n)+1) / 2); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1083 if (assigning == OP_APPLY) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1084 op = BINARY_SUBSCR; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1085 else |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1086 op = ((assigning == OP_ASSIGN) ? STORE_SUBSCR : DELETE_SUBSCR); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1087 com_addbyte(c, op); |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1088 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1089 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1090 static void |
| 69 | 1091 com_apply_trailer(c, n) |
| 1092 struct compiling *c; | |
| 1093 node *n; | |
| 1094 { | |
| 1095 REQ(n, trailer); | |
| 1096 switch (TYPE(CHILD(n, 0))) { | |
| 1097 case LPAR: | |
| 1098 com_call_function(c, CHILD(n, 1)); | |
| 1099 break; | |
| 1100 case DOT: | |
| 1101 com_select_member(c, CHILD(n, 1)); | |
| 1102 break; | |
| 1103 case LSQB: | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1104 com_subscriptlist(c, CHILD(n, 1), OP_APPLY); |
| 69 | 1105 break; |
| 1106 default: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1107 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1108 "com_apply_trailer: unknown trailer type"); |
| 69 | 1109 } |
| 1110 } | |
| 1111 | |
| 1112 static void | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1113 com_power(c, n) |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1114 struct compiling *c; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1115 node *n; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1116 { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1117 int i; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1118 REQ(n, power); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1119 com_atom(c, CHILD(n, 0)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1120 for (i = 1; i < NCH(n); i++) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1121 if (TYPE(CHILD(n, i)) == DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1122 com_factor(c, CHILD(n, i+1)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1123 com_addbyte(c, BINARY_POWER); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1124 break; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1125 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1126 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1127 com_apply_trailer(c, CHILD(n, i)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1128 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1129 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1130 |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1131 static void |
| 69 | 1132 com_factor(c, n) |
| 1133 struct compiling *c; | |
| 1134 node *n; | |
| 1135 { | |
| 1136 REQ(n, factor); | |
| 1137 if (TYPE(CHILD(n, 0)) == PLUS) { | |
| 1138 com_factor(c, CHILD(n, 1)); | |
| 1139 com_addbyte(c, UNARY_POSITIVE); | |
| 1140 } | |
| 1141 else if (TYPE(CHILD(n, 0)) == MINUS) { | |
| 1142 com_factor(c, CHILD(n, 1)); | |
| 1143 com_addbyte(c, UNARY_NEGATIVE); | |
| 1144 } | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1145 else if (TYPE(CHILD(n, 0)) == TILDE) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1146 com_factor(c, CHILD(n, 1)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1147 com_addbyte(c, UNARY_INVERT); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1148 } |
| 69 | 1149 else { |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1150 com_power(c, CHILD(n, 0)); |
| 69 | 1151 } |
| 1152 } | |
| 1153 | |
| 1154 static void | |
| 1155 com_term(c, n) | |
| 1156 struct compiling *c; | |
| 1157 node *n; | |
| 1158 { | |
| 1159 int i; | |
| 1160 int op; | |
| 1161 REQ(n, term); | |
| 1162 com_factor(c, CHILD(n, 0)); | |
| 1163 for (i = 2; i < NCH(n); i += 2) { | |
| 1164 com_factor(c, CHILD(n, i)); | |
| 1165 switch (TYPE(CHILD(n, i-1))) { | |
| 1166 case STAR: | |
| 1167 op = BINARY_MULTIPLY; | |
| 1168 break; | |
| 1169 case SLASH: | |
| 1170 op = BINARY_DIVIDE; | |
| 1171 break; | |
| 1172 case PERCENT: | |
| 1173 op = BINARY_MODULO; | |
| 1174 break; | |
| 1175 default: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1176 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1177 "com_term: operator not *, / or %"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1178 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1179 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1180 com_addbyte(c, op); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1181 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1182 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1183 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1184 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1185 com_arith_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1186 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1187 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1188 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1189 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1190 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1191 REQ(n, arith_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1192 com_term(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1193 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1194 com_term(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1195 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1196 case PLUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1197 op = BINARY_ADD; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1198 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1199 case MINUS: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1200 op = BINARY_SUBTRACT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1201 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1202 default: |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1203 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1204 "com_arith_expr: operator not + or -"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1205 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1206 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1207 com_addbyte(c, op); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1208 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1209 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1210 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1211 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1212 com_shift_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1213 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1214 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1215 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1216 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1217 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1218 REQ(n, shift_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1219 com_arith_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1220 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1221 com_arith_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1222 switch (TYPE(CHILD(n, i-1))) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1223 case LEFTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1224 op = BINARY_LSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1225 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1226 case RIGHTSHIFT: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1227 op = BINARY_RSHIFT; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1228 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1229 default: |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1230 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1231 "com_shift_expr: operator not << or >>"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1232 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1233 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1234 com_addbyte(c, op); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1235 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1236 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1237 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1238 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1239 com_and_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1240 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1241 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1242 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1243 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1244 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1245 REQ(n, and_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1246 com_shift_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1247 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1248 com_shift_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1249 if (TYPE(CHILD(n, i-1)) == AMPER) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1250 op = BINARY_AND; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1251 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1252 else { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1253 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1254 "com_and_expr: operator not &"); |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1255 op = 255; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1256 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1257 com_addbyte(c, op); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1258 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1259 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1260 |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1261 static void |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1262 com_xor_expr(c, n) |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1263 struct compiling *c; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1264 node *n; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1265 { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1266 int i; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1267 int op; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1268 REQ(n, xor_expr); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1269 com_and_expr(c, CHILD(n, 0)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1270 for (i = 2; i < NCH(n); i += 2) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1271 com_and_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1272 if (TYPE(CHILD(n, i-1)) == CIRCUMFLEX) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1273 op = BINARY_XOR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1274 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1275 else { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1276 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1277 "com_xor_expr: operator not ^"); |
| 69 | 1278 op = 255; |
| 1279 } | |
| 1280 com_addbyte(c, op); | |
| 1281 } | |
| 1282 } | |
| 1283 | |
| 1284 static void | |
| 1285 com_expr(c, n) | |
| 1286 struct compiling *c; | |
| 1287 node *n; | |
| 1288 { | |
| 1289 int i; | |
| 1290 int op; | |
| 1291 REQ(n, expr); | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1292 com_xor_expr(c, CHILD(n, 0)); |
| 69 | 1293 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
|
1294 com_xor_expr(c, CHILD(n, i)); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1295 if (TYPE(CHILD(n, i-1)) == VBAR) { |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1296 op = BINARY_OR; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1297 } |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1298 else { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1299 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1300 "com_expr: expr operator not |"); |
| 69 | 1301 op = 255; |
| 1302 } | |
| 1303 com_addbyte(c, op); | |
| 1304 } | |
| 1305 } | |
| 1306 | |
| 1307 static enum cmp_op | |
| 1308 cmp_type(n) | |
| 1309 node *n; | |
| 1310 { | |
| 1311 REQ(n, comp_op); | |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1312 /* comp_op: '<' | '>' | '=' | '>=' | '<=' | '<>' | '!=' | '==' |
| 69 | 1313 | 'in' | 'not' 'in' | 'is' | 'is' not' */ |
| 1314 if (NCH(n) == 1) { | |
| 1315 n = CHILD(n, 0); | |
| 1316 switch (TYPE(n)) { | |
| 1317 case LESS: return LT; | |
| 1318 case GREATER: return GT; | |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1319 case EQEQUAL: /* == */ |
| 69 | 1320 case EQUAL: return EQ; |
|
388
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1321 case LESSEQUAL: return LE; |
|
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1322 case GREATEREQUAL: return GE; |
|
31d509e94271
Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents:
336
diff
changeset
|
1323 case NOTEQUAL: return NE; /* <> or != */ |
| 69 | 1324 case NAME: if (strcmp(STR(n), "in") == 0) return IN; |
| 1325 if (strcmp(STR(n), "is") == 0) return IS; | |
| 1326 } | |
| 1327 } | |
| 1328 else if (NCH(n) == 2) { | |
| 1329 switch (TYPE(CHILD(n, 0))) { | |
| 1330 case NAME: if (strcmp(STR(CHILD(n, 1)), "in") == 0) | |
| 1331 return NOT_IN; | |
| 1332 if (strcmp(STR(CHILD(n, 0)), "is") == 0) | |
| 1333 return IS_NOT; | |
| 1334 } | |
| 1335 } | |
| 1336 return BAD; | |
| 1337 } | |
| 1338 | |
| 1339 static void | |
| 1340 com_comparison(c, n) | |
| 1341 struct compiling *c; | |
| 1342 node *n; | |
| 1343 { | |
| 1344 int i; | |
| 1345 enum cmp_op op; | |
| 1346 int anchor; | |
| 1347 REQ(n, comparison); /* comparison: expr (comp_op expr)* */ | |
| 1348 com_expr(c, CHILD(n, 0)); | |
| 1349 if (NCH(n) == 1) | |
| 1350 return; | |
| 1351 | |
| 1352 /**************************************************************** | |
| 1353 The following code is generated for all but the last | |
| 1354 comparison in a chain: | |
| 1355 | |
| 1356 label: on stack: opcode: jump to: | |
| 1357 | |
| 1358 a <code to load b> | |
| 1359 a, b DUP_TOP | |
| 1360 a, b, b ROT_THREE | |
| 1361 b, a, b COMPARE_OP | |
| 1362 b, 0-or-1 JUMP_IF_FALSE L1 | |
| 1363 b, 1 POP_TOP | |
| 1364 b | |
| 1365 | |
| 1366 We are now ready to repeat this sequence for the next | |
| 1367 comparison in the chain. | |
| 1368 | |
| 1369 For the last we generate: | |
| 1370 | |
| 1371 b <code to load c> | |
| 1372 b, c COMPARE_OP | |
| 1373 0-or-1 | |
| 1374 | |
| 1375 If there were any jumps to L1 (i.e., there was more than one | |
| 1376 comparison), we generate: | |
| 1377 | |
| 1378 0-or-1 JUMP_FORWARD L2 | |
| 1379 L1: b, 0 ROT_TWO | |
| 1380 0, b POP_TOP | |
| 1381 0 | |
| 1382 L2: | |
| 1383 ****************************************************************/ | |
| 1384 | |
| 1385 anchor = 0; | |
| 1386 | |
| 1387 for (i = 2; i < NCH(n); i += 2) { | |
| 1388 com_expr(c, CHILD(n, i)); | |
| 1389 if (i+2 < NCH(n)) { | |
| 1390 com_addbyte(c, DUP_TOP); | |
| 1391 com_addbyte(c, ROT_THREE); | |
| 1392 } | |
| 1393 op = cmp_type(CHILD(n, i-1)); | |
| 1394 if (op == BAD) { | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1395 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1396 "com_comparison: unknown comparison op"); |
| 69 | 1397 } |
| 1398 com_addoparg(c, COMPARE_OP, op); | |
| 1399 if (i+2 < NCH(n)) { | |
| 1400 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 1401 com_addbyte(c, POP_TOP); | |
| 1402 } | |
| 1403 } | |
| 1404 | |
| 1405 if (anchor) { | |
| 1406 int anchor2 = 0; | |
| 1407 com_addfwref(c, JUMP_FORWARD, &anchor2); | |
| 1408 com_backpatch(c, anchor); | |
| 1409 com_addbyte(c, ROT_TWO); | |
| 1410 com_addbyte(c, POP_TOP); | |
| 1411 com_backpatch(c, anchor2); | |
| 1412 } | |
| 1413 } | |
| 1414 | |
| 1415 static void | |
| 1416 com_not_test(c, n) | |
| 1417 struct compiling *c; | |
| 1418 node *n; | |
| 1419 { | |
| 1420 REQ(n, not_test); /* 'not' not_test | comparison */ | |
| 1421 if (NCH(n) == 1) { | |
| 1422 com_comparison(c, CHILD(n, 0)); | |
| 1423 } | |
| 1424 else { | |
| 1425 com_not_test(c, CHILD(n, 1)); | |
| 1426 com_addbyte(c, UNARY_NOT); | |
| 1427 } | |
| 1428 } | |
| 1429 | |
| 1430 static void | |
| 1431 com_and_test(c, n) | |
| 1432 struct compiling *c; | |
| 1433 node *n; | |
| 1434 { | |
| 1435 int i; | |
| 1436 int anchor; | |
| 1437 REQ(n, and_test); /* not_test ('and' not_test)* */ | |
| 1438 anchor = 0; | |
| 1439 i = 0; | |
| 1440 for (;;) { | |
| 1441 com_not_test(c, CHILD(n, i)); | |
| 1442 if ((i += 2) >= NCH(n)) | |
| 1443 break; | |
| 1444 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 1445 com_addbyte(c, POP_TOP); | |
| 1446 } | |
| 1447 if (anchor) | |
| 1448 com_backpatch(c, anchor); | |
| 1449 } | |
| 1450 | |
| 1451 static void | |
| 1452 com_test(c, n) | |
| 1453 struct compiling *c; | |
| 1454 node *n; | |
| 1455 { | |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1456 REQ(n, test); /* and_test ('and' and_test)* | lambdef */ |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1457 if (NCH(n) == 1 && TYPE(CHILD(n, 0)) == lambdef) { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1458 object *v; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1459 int i; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1460 int ndefs = com_argdefs(c, CHILD(n, 0)); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
1461 v = (object *) 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
|
1462 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
|
1463 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
|
1464 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
|
1465 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1466 else { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1467 i = com_addconst(c, v); |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1468 DECREF(v); |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1469 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1470 com_addoparg(c, LOAD_CONST, i); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1471 com_addoparg(c, MAKE_FUNCTION, ndefs); |
| 69 | 1472 } |
|
1417
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1473 else { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1474 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
|
1475 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
|
1476 for (;;) { |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1477 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
|
1478 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
|
1479 break; |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1480 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
|
1481 com_addbyte(c, POP_TOP); |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1482 } |
|
f7edfa6d0dcb
change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
1483 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
|
1484 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
|
1485 } |
| 69 | 1486 } |
| 1487 | |
| 1488 static void | |
| 482 | 1489 com_list(c, n, toplevel) |
| 69 | 1490 struct compiling *c; |
| 1491 node *n; | |
| 482 | 1492 int toplevel; /* If nonzero, *always* build a tuple */ |
| 69 | 1493 { |
| 1494 /* exprlist: expr (',' expr)* [',']; likewise for testlist */ | |
| 482 | 1495 if (NCH(n) == 1 && !toplevel) { |
| 69 | 1496 com_node(c, CHILD(n, 0)); |
| 1497 } | |
| 1498 else { | |
| 1499 int i; | |
| 1500 int len; | |
| 1501 len = (NCH(n) + 1) / 2; | |
| 1502 for (i = 0; i < NCH(n); i += 2) | |
| 1503 com_node(c, CHILD(n, i)); | |
| 1504 com_addoparg(c, BUILD_TUPLE, len); | |
| 1505 } | |
| 1506 } | |
| 1507 | |
| 1508 | |
| 1509 /* Begin of assignment compilation */ | |
| 1510 | |
| 1511 static void com_assign_name PROTO((struct compiling *, node *, int)); | |
| 1512 static void com_assign PROTO((struct compiling *, node *, int)); | |
| 1513 | |
| 1514 static void | |
| 1515 com_assign_attr(c, n, assigning) | |
| 1516 struct compiling *c; | |
| 1517 node *n; | |
| 1518 int assigning; | |
| 1519 { | |
| 1520 com_addopname(c, assigning ? STORE_ATTR : DELETE_ATTR, n); | |
| 1521 } | |
| 1522 | |
| 1523 static void | |
| 1524 com_assign_trailer(c, n, assigning) | |
| 1525 struct compiling *c; | |
| 1526 node *n; | |
| 1527 int assigning; | |
| 1528 { | |
| 1529 REQ(n, trailer); | |
| 1530 switch (TYPE(CHILD(n, 0))) { | |
| 1531 case LPAR: /* '(' [exprlist] ')' */ | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1532 com_error(c, SyntaxError, "can't assign to function call"); |
| 69 | 1533 break; |
| 1534 case DOT: /* '.' NAME */ | |
| 1535 com_assign_attr(c, CHILD(n, 1), assigning); | |
| 1536 break; | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1537 case LSQB: /* '[' subscriptlist ']' */ |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1538 com_subscriptlist(c, CHILD(n, 1), assigning); |
| 69 | 1539 break; |
| 1540 default: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1541 com_error(c, SystemError, "unknown trailer type"); |
| 69 | 1542 } |
| 1543 } | |
| 1544 | |
| 1545 static void | |
| 1546 com_assign_tuple(c, n, assigning) | |
| 1547 struct compiling *c; | |
| 1548 node *n; | |
| 1549 int assigning; | |
| 1550 { | |
| 1551 int i; | |
| 1552 if (TYPE(n) != testlist) | |
| 1553 REQ(n, exprlist); | |
| 1554 if (assigning) | |
| 1555 com_addoparg(c, UNPACK_TUPLE, (NCH(n)+1)/2); | |
| 1556 for (i = 0; i < NCH(n); i += 2) | |
| 1557 com_assign(c, CHILD(n, i), assigning); | |
| 1558 } | |
| 1559 | |
| 1560 static void | |
| 1561 com_assign_list(c, n, assigning) | |
| 1562 struct compiling *c; | |
| 1563 node *n; | |
| 1564 int assigning; | |
| 1565 { | |
| 1566 int i; | |
| 1567 if (assigning) | |
| 1568 com_addoparg(c, UNPACK_LIST, (NCH(n)+1)/2); | |
| 1569 for (i = 0; i < NCH(n); i += 2) | |
| 1570 com_assign(c, CHILD(n, i), assigning); | |
| 1571 } | |
| 1572 | |
| 1573 static void | |
| 1574 com_assign_name(c, n, assigning) | |
| 1575 struct compiling *c; | |
| 1576 node *n; | |
| 1577 int assigning; | |
| 1578 { | |
| 1579 REQ(n, NAME); | |
| 1580 com_addopname(c, assigning ? STORE_NAME : DELETE_NAME, n); | |
| 1581 } | |
| 1582 | |
| 1583 static void | |
| 1584 com_assign(c, n, assigning) | |
| 1585 struct compiling *c; | |
| 1586 node *n; | |
| 1587 int assigning; | |
| 1588 { | |
| 1589 /* Loop to avoid trivial recursion */ | |
| 1590 for (;;) { | |
| 1591 switch (TYPE(n)) { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1592 |
| 69 | 1593 case exprlist: |
| 1594 case testlist: | |
| 1595 if (NCH(n) > 1) { | |
| 1596 com_assign_tuple(c, n, assigning); | |
| 1597 return; | |
| 1598 } | |
| 1599 n = CHILD(n, 0); | |
| 1600 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1601 |
| 69 | 1602 case test: |
| 1603 case and_test: | |
| 1604 case not_test: | |
| 1605 case comparison: | |
| 1606 case expr: | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1607 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1608 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1609 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
1610 case arith_expr: |
| 69 | 1611 case term: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1612 case factor: |
| 69 | 1613 if (NCH(n) > 1) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1614 com_error(c, SyntaxError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1615 "can't assign to operator"); |
| 69 | 1616 return; |
| 1617 } | |
| 1618 n = CHILD(n, 0); | |
| 1619 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1620 |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1621 case power: /* atom trailer* ('**' power)* */ |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1622 /* ('+'|'-'|'~') factor | atom trailer* */ |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1623 if (TYPE(CHILD(n, 0)) != atom) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1624 com_error(c, SyntaxError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1625 "can't assign to operator"); |
| 69 | 1626 return; |
| 1627 } | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1628 if (NCH(n) > 1) { /* trailer or exponent present */ |
| 69 | 1629 int i; |
| 1630 com_node(c, CHILD(n, 0)); | |
| 1631 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
|
1632 if (TYPE(CHILD(n, i)) == DOUBLESTAR) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1633 com_error(c, SyntaxError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1634 "can't assign to operator"); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1635 return; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
1636 } |
| 69 | 1637 com_apply_trailer(c, CHILD(n, i)); |
| 1638 } /* NB i is still alive */ | |
| 1639 com_assign_trailer(c, | |
| 1640 CHILD(n, i), assigning); | |
| 1641 return; | |
| 1642 } | |
| 1643 n = CHILD(n, 0); | |
| 1644 break; | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1645 |
| 69 | 1646 case atom: |
| 1647 switch (TYPE(CHILD(n, 0))) { | |
| 1648 case LPAR: | |
| 1649 n = CHILD(n, 1); | |
| 1650 if (TYPE(n) == RPAR) { | |
| 1651 /* XXX Should allow () = () ??? */ | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1652 com_error(c, SyntaxError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1653 "can't assign to ()"); |
| 69 | 1654 return; |
| 1655 } | |
| 1656 break; | |
| 1657 case LSQB: | |
| 1658 n = CHILD(n, 1); | |
| 1659 if (TYPE(n) == RSQB) { | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1660 com_error(c, SyntaxError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1661 "can't assign to []"); |
| 69 | 1662 return; |
| 1663 } | |
| 1664 com_assign_list(c, n, assigning); | |
| 1665 return; | |
| 1666 case NAME: | |
| 1667 com_assign_name(c, CHILD(n, 0), assigning); | |
| 1668 return; | |
| 1669 default: | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1670 com_error(c, SyntaxError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1671 "can't assign to literal"); |
| 69 | 1672 return; |
| 1673 } | |
| 1674 break; | |
|
3963
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1675 |
|
00722990b80c
Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1676 case lambdef: |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1677 com_error(c, SyntaxError, "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
|
1678 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1679 |
| 69 | 1680 default: |
| 1681 fprintf(stderr, "node type %d\n", TYPE(n)); | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1682 com_error(c, SystemError, "com_assign: bad node"); |
| 69 | 1683 return; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1684 |
| 69 | 1685 } |
| 1686 } | |
| 1687 } | |
| 1688 | |
| 1689 static void | |
| 1690 com_expr_stmt(c, n) | |
| 1691 struct compiling *c; | |
| 1692 node *n; | |
| 1693 { | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1694 REQ(n, expr_stmt); /* testlist ('=' testlist)* */ |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1695 com_node(c, CHILD(n, NCH(n)-1)); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1696 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
|
1697 if (c->c_interactive) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1698 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
|
1699 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
1700 com_addbyte(c, POP_TOP); |
| 69 | 1701 } |
| 1702 else { | |
| 1703 int i; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1704 for (i = 0; i < NCH(n)-2; i+=2) { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1705 if (i+2 < NCH(n)-2) |
| 69 | 1706 com_addbyte(c, DUP_TOP); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1707 com_assign(c, CHILD(n, i), OP_ASSIGN); |
| 69 | 1708 } |
| 1709 } | |
| 1710 } | |
| 1711 | |
| 1712 static void | |
| 1713 com_print_stmt(c, n) | |
| 1714 struct compiling *c; | |
| 1715 node *n; | |
| 1716 { | |
| 1717 int i; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1718 REQ(n, print_stmt); /* 'print' (test ',')* [test] */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1719 for (i = 1; i < NCH(n); i += 2) { |
| 69 | 1720 com_node(c, CHILD(n, i)); |
| 1721 com_addbyte(c, PRINT_ITEM); | |
| 1722 } | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1723 if (TYPE(CHILD(n, NCH(n)-1)) != COMMA) |
| 69 | 1724 com_addbyte(c, PRINT_NEWLINE); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1725 /* XXX Alternatively, LOAD_CONST '\n' and then PRINT_ITEM */ |
| 69 | 1726 } |
| 1727 | |
| 1728 static void | |
| 1729 com_return_stmt(c, n) | |
| 1730 struct compiling *c; | |
| 1731 node *n; | |
| 1732 { | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1733 REQ(n, return_stmt); /* 'return' [testlist] */ |
| 86 | 1734 if (!c->c_infunction) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1735 com_error(c, SyntaxError, "'return' outside function"); |
| 86 | 1736 } |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1737 if (NCH(n) < 2) |
| 69 | 1738 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
| 1739 else | |
| 1740 com_node(c, CHILD(n, 1)); | |
| 1741 com_addbyte(c, RETURN_VALUE); | |
| 1742 } | |
| 1743 | |
| 1744 static void | |
| 1745 com_raise_stmt(c, n) | |
| 1746 struct compiling *c; | |
| 1747 node *n; | |
| 1748 { | |
|
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
|
1749 REQ(n, raise_stmt); /* 'raise' test [',' test [',' test]] */ |
| 69 | 1750 com_node(c, CHILD(n, 1)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1751 if (NCH(n) > 3) { |
| 69 | 1752 com_node(c, CHILD(n, 3)); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1753 if (NCH(n) > 5) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1754 com_node(c, CHILD(n, 5)); |
|
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
|
1755 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1756 com_addoparg(c, RAISE_VARARGS, NCH(n)/2); |
| 69 | 1757 } |
| 1758 | |
| 1759 static void | |
| 1760 com_import_stmt(c, n) | |
| 1761 struct compiling *c; | |
| 1762 node *n; | |
| 1763 { | |
| 1764 int i; | |
| 1765 REQ(n, import_stmt); | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1766 /* 'import' dotted_name (',' dotted_name)* | |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1767 'from' dotted_name 'import' ('*' | NAME (',' NAME)*) */ |
| 69 | 1768 if (STR(CHILD(n, 0))[0] == 'f') { |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1769 /* 'from' dotted_name 'import' ... */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1770 REQ(CHILD(n, 1), dotted_name); |
| 69 | 1771 com_addopname(c, IMPORT_NAME, CHILD(n, 1)); |
| 1772 for (i = 3; i < NCH(n); i += 2) | |
| 1773 com_addopname(c, IMPORT_FROM, CHILD(n, i)); | |
| 1774 com_addbyte(c, POP_TOP); | |
| 1775 } | |
| 1776 else { | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
1777 /* 'import' ... */ |
| 69 | 1778 for (i = 1; i < NCH(n); i += 2) { |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1779 REQ(CHILD(n, i), dotted_name); |
| 69 | 1780 com_addopname(c, IMPORT_NAME, CHILD(n, i)); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1781 com_addopname(c, STORE_NAME, CHILD(CHILD(n, i), 0)); |
| 69 | 1782 } |
| 1783 } | |
| 1784 } | |
| 1785 | |
| 1786 static void | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1787 com_global_stmt(c, n) |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1788 struct compiling *c; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1789 node *n; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1790 { |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1791 int i; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1792 REQ(n, global_stmt); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1793 /* 'global' NAME (',' NAME)* */ |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1794 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
|
1795 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
|
1796 #ifdef PRIVATE_NAME_MANGLING |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
1797 char buffer[256]; |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
1798 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
|
1799 c->c_private != NULL && |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
1800 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
|
1801 s = buffer; |
|
7b84dae97ee8
Oops need to mangle global statement separately
Guido van Rossum <guido@python.org>
parents:
4129
diff
changeset
|
1802 #endif |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1803 if (dictlookup(c->c_locals, s) != NULL) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1804 com_error(c, SyntaxError, "name is local and global"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1805 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1806 else if (dictinsert(c->c_globals, s, None) != 0) |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1807 c->c_errors++; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1808 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1809 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1810 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1811 static int |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1812 com_newlocal_o(c, nameval) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1813 struct compiling *c; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1814 object *nameval; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1815 { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1816 int i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1817 object *ival; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1818 if (getlistsize(c->c_varnames) != c->c_nlocals) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1819 /* 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
|
1820 if (c->c_errors == 0) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
1821 com_error(c, SystemError, "mixed up var name/index"); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1822 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1823 return 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1824 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1825 ival = newintobject(i = c->c_nlocals++); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1826 if (ival == NULL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1827 c->c_errors++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1828 else if (mappinginsert(c->c_locals, nameval, ival) != 0) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1829 c->c_errors++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1830 else if (addlistitem(c->c_varnames, nameval) != 0) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1831 c->c_errors++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1832 XDECREF(ival); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1833 return i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1834 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1835 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1836 static int |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1837 com_addlocal_o(c, nameval) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1838 struct compiling *c; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1839 object *nameval; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1840 { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1841 object *ival = mappinglookup(c->c_locals, nameval); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1842 if (ival != NULL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1843 return getintvalue(ival); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1844 return com_newlocal_o(c, nameval); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1845 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1846 |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1847 static int |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1848 com_newlocal(c, name) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1849 struct compiling *c; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1850 char *name; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1851 { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1852 object *nameval = newstringobject(name); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1853 int i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1854 if (nameval == NULL) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1855 c->c_errors++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1856 return 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1857 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1858 i = com_newlocal_o(c, nameval); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1859 DECREF(nameval); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1860 return i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1861 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
1862 |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1863 #define strequ(a, b) (strcmp((a), (b)) == 0) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1864 |
|
4003
138fa15a1032
Disable support for access statement
Guido van Rossum <guido@python.org>
parents:
3963
diff
changeset
|
1865 #ifdef SUPPORT_OBSOLETE_ACCESS |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1866 static void |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1867 com_access_stmt(c, n) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1868 struct compiling *c; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1869 node *n; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1870 { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1871 int i, j, k, mode, imode; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1872 object *vmode; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1873 REQ(n, access_stmt); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1874 /* 'access' NAME (',' NAME)* ':' accesstype (',' accesstype)* |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1875 accesstype: NAME+ */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1876 |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1877 /* Find where the colon is */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1878 i = 1; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1879 while (TYPE(CHILD(n,i-1)) != COLON) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1880 i += 1; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1881 |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1882 /* Calculate the mode mask */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1883 mode = 0; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1884 for (j = i; j < NCH(n); j += 2) { |
|
1289
4d292c7857d4
Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
1885 int r = 0, w = 0, p = 0; |
|
4d292c7857d4
Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
1886 for (k = 0; k < NCH(CHILD(n,j)); k++) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1887 if (strequ(STR(CHILD(CHILD(n,j),k)), "public")) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1888 p = 0; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1889 else if (strequ(STR(CHILD(CHILD(n,j),k)), "protected")) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1890 p = 1; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1891 else if (strequ(STR(CHILD(CHILD(n,j),k)), "private")) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1892 p = 2; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1893 else if (strequ(STR(CHILD(CHILD(n,j),k)), "read")) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1894 r = 1; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1895 else if (strequ(STR(CHILD(CHILD(n,j),k)), "write")) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1896 w = 1; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1897 else /* XXX should make this an exception */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1898 fprintf(stderr, "bad access type %s\n", |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1899 STR(CHILD(CHILD(n,j),k))); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1900 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1901 if (r == 0 && w == 0) |
|
1289
4d292c7857d4
Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
1902 r = w = 1; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1903 if (p == 0) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1904 if (r == 1) mode |= AC_R_PUBLIC; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1905 if (w == 1) mode |= AC_W_PUBLIC; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1906 } else if (p == 1) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1907 if (r == 1) mode |= AC_R_PROTECTED; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1908 if (w == 1) mode |= AC_W_PROTECTED; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1909 } else { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1910 if (r == 1) mode |= AC_R_PRIVATE; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1911 if (w == 1) mode |= AC_W_PRIVATE; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1912 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1913 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1914 vmode = newintobject((long)mode); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1915 imode = com_addconst(c, vmode); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1916 XDECREF(vmode); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1917 for (i = 1; TYPE(CHILD(n,i-1)) != COLON; i+=2) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1918 com_addoparg(c, LOAD_CONST, imode); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1919 com_addopname(c, ACCESS_MODE, CHILD(n, i)); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1920 } |
|
4003
138fa15a1032
Disable support for access statement
Guido van Rossum <guido@python.org>
parents:
3963
diff
changeset
|
1921 } |
|
3166
938c433c876a
disable code generation for access statement
Guido van Rossum <guido@python.org>
parents:
3139
diff
changeset
|
1922 #endif |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1923 |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
1924 static void |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1925 com_exec_stmt(c, n) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1926 struct compiling *c; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1927 node *n; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1928 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1929 REQ(n, exec_stmt); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1930 /* 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
|
1931 com_node(c, CHILD(n, 1)); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1932 if (NCH(n) >= 4) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1933 com_node(c, CHILD(n, 3)); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1934 else |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1935 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1936 if (NCH(n) >= 6) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1937 com_node(c, CHILD(n, 5)); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1938 else |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1939 com_addbyte(c, DUP_TOP); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1940 com_addbyte(c, EXEC_STMT); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1941 } |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1942 |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
1943 static void |
| 69 | 1944 com_if_stmt(c, n) |
| 1945 struct compiling *c; | |
| 1946 node *n; | |
| 1947 { | |
| 1948 int i; | |
| 1949 int anchor = 0; | |
| 1950 REQ(n, if_stmt); | |
| 1951 /*'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] */ | |
| 1952 for (i = 0; i+3 < NCH(n); i+=4) { | |
| 1953 int a = 0; | |
| 86 | 1954 node *ch = CHILD(n, i+1); |
| 1955 if (i > 0) | |
| 1956 com_addoparg(c, SET_LINENO, ch->n_lineno); | |
| 69 | 1957 com_node(c, CHILD(n, i+1)); |
| 1958 com_addfwref(c, JUMP_IF_FALSE, &a); | |
| 1959 com_addbyte(c, POP_TOP); | |
| 1960 com_node(c, CHILD(n, i+3)); | |
| 1961 com_addfwref(c, JUMP_FORWARD, &anchor); | |
| 1962 com_backpatch(c, a); | |
| 1963 com_addbyte(c, POP_TOP); | |
| 1964 } | |
| 1965 if (i+2 < NCH(n)) | |
| 1966 com_node(c, CHILD(n, i+2)); | |
| 1967 com_backpatch(c, anchor); | |
| 1968 } | |
| 1969 | |
| 1970 static void | |
| 1971 com_while_stmt(c, n) | |
| 1972 struct compiling *c; | |
| 1973 node *n; | |
| 1974 { | |
| 1975 int break_anchor = 0; | |
| 1976 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1977 int save_begin = c->c_begin; |
| 69 | 1978 REQ(n, while_stmt); /* 'while' test ':' suite ['else' ':' suite] */ |
| 1979 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1980 block_push(c, SETUP_LOOP); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1981 c->c_begin = c->c_nexti; |
| 86 | 1982 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 1983 com_node(c, CHILD(n, 1)); |
| 1984 com_addfwref(c, JUMP_IF_FALSE, &anchor); | |
| 1985 com_addbyte(c, POP_TOP); | |
| 86 | 1986 c->c_loops++; |
| 69 | 1987 com_node(c, CHILD(n, 3)); |
| 86 | 1988 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1989 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1990 c->c_begin = save_begin; |
| 69 | 1991 com_backpatch(c, anchor); |
| 1992 com_addbyte(c, POP_TOP); | |
| 1993 com_addbyte(c, POP_BLOCK); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
1994 block_pop(c, SETUP_LOOP); |
| 69 | 1995 if (NCH(n) > 4) |
| 1996 com_node(c, CHILD(n, 6)); | |
| 1997 com_backpatch(c, break_anchor); | |
| 1998 } | |
| 1999 | |
| 2000 static void | |
| 2001 com_for_stmt(c, n) | |
| 2002 struct compiling *c; | |
| 2003 node *n; | |
| 2004 { | |
| 2005 object *v; | |
| 2006 int break_anchor = 0; | |
| 2007 int anchor = 0; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2008 int save_begin = c->c_begin; |
| 69 | 2009 REQ(n, for_stmt); |
| 2010 /* 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] */ | |
| 2011 com_addfwref(c, SETUP_LOOP, &break_anchor); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2012 block_push(c, SETUP_LOOP); |
| 69 | 2013 com_node(c, CHILD(n, 3)); |
| 2014 v = newintobject(0L); | |
| 2015 if (v == NULL) | |
| 2016 c->c_errors++; | |
| 2017 com_addoparg(c, LOAD_CONST, com_addconst(c, v)); | |
| 2018 XDECREF(v); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2019 c->c_begin = c->c_nexti; |
| 86 | 2020 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 2021 com_addfwref(c, FOR_LOOP, &anchor); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2022 com_assign(c, CHILD(n, 1), OP_ASSIGN); |
| 86 | 2023 c->c_loops++; |
| 69 | 2024 com_node(c, CHILD(n, 5)); |
| 86 | 2025 c->c_loops--; |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2026 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2027 c->c_begin = save_begin; |
| 69 | 2028 com_backpatch(c, anchor); |
| 2029 com_addbyte(c, POP_BLOCK); | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2030 block_pop(c, SETUP_LOOP); |
| 69 | 2031 if (NCH(n) > 8) |
| 2032 com_node(c, CHILD(n, 8)); | |
| 2033 com_backpatch(c, break_anchor); | |
| 2034 } | |
| 2035 | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2036 /* 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
|
2037 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2038 SETUP_FINALLY L |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2039 <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2040 POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2041 LOAD_CONST <nil> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2042 L: <code for Sf> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2043 END_FINALLY |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2044 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2045 The special instructions use the block stack. Each block |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2046 stack entry contains the instruction that created it (here |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2047 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
|
2048 block stack entry was created, and a label (here L). |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2049 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2050 SETUP_FINALLY: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2051 Pushes the current value stack level and the label |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2052 onto the block stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2053 POP_BLOCK: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2054 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
|
2055 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
|
2056 block stack. (The label is ignored.) |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2057 END_FINALLY: |
| 86 | 2058 Pops a variable number of entries from the *value* stack |
| 2059 and re-raises the exception they specify. The number of | |
| 2060 entries popped depends on the (pseudo) exception type. | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2061 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2062 The block stack is unwound when an exception is raised: |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2063 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
|
2064 onto the value stack (and the exception condition is cleared), |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2065 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
|
2066 stack. |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2067 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2068 Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...": |
| 86 | 2069 (The contents of the value stack is shown in [], with the top |
| 2070 at the right; 'tb' is trace-back info, 'val' the exception's | |
| 2071 associated value, and 'exc' the exception.) | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2072 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2073 Value stack Label Instruction Argument |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2074 [] SETUP_EXCEPT L1 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2075 [] <code for S> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2076 [] POP_BLOCK |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2077 [] JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2078 |
| 86 | 2079 [tb, val, exc] L1: DUP ) |
| 2080 [tb, val, exc, exc] <evaluate E1> ) | |
| 2081 [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1 | |
| 2082 [tb, val, exc, 1-or-0] JUMP_IF_FALSE L2 ) | |
| 2083 [tb, val, exc, 1] POP ) | |
| 2084 [tb, val, exc] POP | |
| 2085 [tb, val] <assign to V1> (or POP if no V1) | |
| 2086 [tb] POP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2087 [] <code for S1> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2088 JUMP_FORWARD L0 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2089 |
| 86 | 2090 [tb, val, exc, 0] L2: POP |
| 2091 [tb, val, exc] DUP | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2092 .............................etc....................... |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2093 |
| 86 | 2094 [tb, val, exc, 0] Ln+1: POP |
| 2095 [tb, val, exc] END_FINALLY # re-raise exception | |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2096 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2097 [] L0: <next statement> |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2098 |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2099 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
|
2100 */ |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2101 |
| 69 | 2102 static void |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2103 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
|
2104 struct compiling *c; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2105 node *n; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2106 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2107 int except_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2108 int end_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2109 int else_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2110 int i; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2111 node *ch; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2112 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2113 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
|
2114 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
|
2115 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
|
2116 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
|
2117 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
|
2118 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
|
2119 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
|
2120 for (i = 3; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2121 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
|
2122 i += 3) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2123 /* except_clause: 'except' [expr [',' expr]] */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2124 if (except_anchor == 0) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2125 com_error(c, SyntaxError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2126 "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
|
2127 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2128 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2129 except_anchor = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2130 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
|
2131 if (NCH(ch) > 1) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2132 com_addbyte(c, DUP_TOP); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2133 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
|
2134 com_addoparg(c, COMPARE_OP, EXC_MATCH); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2135 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
|
2136 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
|
2137 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2138 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
|
2139 if (NCH(ch) > 3) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2140 com_assign(c, CHILD(ch, 3), OP_ASSIGN); |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2141 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2142 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
|
2143 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
|
2144 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
|
2145 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
|
2146 if (except_anchor) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2147 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
|
2148 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
|
2149 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2150 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2151 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
|
2152 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
|
2153 if (i < NCH(n)) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2154 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
|
2155 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
|
2156 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2157 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2158 static void |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2159 com_try_finally(c, n) |
| 69 | 2160 struct compiling *c; |
| 2161 node *n; | |
| 2162 { | |
| 2163 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
|
2164 node *ch; |
|
792
dc3b455f7632
Only * can be used for varargs argument lists
Guido van Rossum <guido@python.org>
parents:
744
diff
changeset
|
2165 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2166 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
|
2167 block_push(c, SETUP_FINALLY); |
| 69 | 2168 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
|
2169 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
|
2170 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
|
2171 block_push(c, END_FINALLY); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2172 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2173 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
|
2174 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
|
2175 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
|
2176 com_node(c, ch); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2177 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
|
2178 block_pop(c, END_FINALLY); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2179 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2180 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2181 static void |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2182 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
|
2183 struct compiling *c; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2184 node *n; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2185 { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2186 REQ(n, try_stmt); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2187 /* '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
|
2188 | 'try' ':' suite 'finally' ':' suite */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2189 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
|
2190 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
|
2191 else |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2192 com_try_except(c, n); |
| 69 | 2193 } |
| 2194 | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2195 static object * |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2196 get_docstring(n) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2197 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2198 { |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2199 int i; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2200 |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2201 switch (TYPE(n)) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2202 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2203 case suite: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2204 if (NCH(n) == 1) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2205 return get_docstring(CHILD(n, 0)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2206 else { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2207 for (i = 0; i < NCH(n); i++) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2208 node *ch = CHILD(n, i); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2209 if (TYPE(ch) == stmt) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2210 return get_docstring(ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2211 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2212 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2213 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2214 |
|
2241
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2215 case file_input: |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2216 for (i = 0; i < NCH(n); i++) { |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2217 node *ch = CHILD(n, i); |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2218 if (TYPE(ch) == stmt) |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2219 return get_docstring(ch); |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2220 } |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2221 break; |
|
fefae37c053c
added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents:
2203
diff
changeset
|
2222 |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2223 case stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2224 case simple_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2225 case small_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2226 return get_docstring(CHILD(n, 0)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2227 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2228 case expr_stmt: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2229 case testlist: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2230 case test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2231 case and_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2232 case not_test: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2233 case comparison: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2234 case expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2235 case xor_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2236 case and_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2237 case shift_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2238 case arith_expr: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2239 case term: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2240 case factor: |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2241 case power: |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2242 if (NCH(n) == 1) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2243 return get_docstring(CHILD(n, 0)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2244 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2245 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2246 case atom: |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2247 if (TYPE(CHILD(n, 0)) == STRING) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2248 return parsestrplus(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2249 break; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2250 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2251 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2252 return NULL; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2253 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2254 |
| 69 | 2255 static void |
| 2256 com_suite(c, n) | |
| 2257 struct compiling *c; | |
| 2258 node *n; | |
| 2259 { | |
| 2260 REQ(n, suite); | |
| 2261 /* simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT */ | |
| 2262 if (NCH(n) == 1) { | |
| 2263 com_node(c, CHILD(n, 0)); | |
| 2264 } | |
| 2265 else { | |
| 2266 int i; | |
| 2267 for (i = 0; i < NCH(n); i++) { | |
| 2268 node *ch = CHILD(n, i); | |
| 2269 if (TYPE(ch) == stmt) | |
| 2270 com_node(c, ch); | |
| 2271 } | |
| 2272 } | |
| 2273 } | |
| 2274 | |
| 744 | 2275 /* ARGSUSED */ |
| 69 | 2276 static void |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2277 com_continue_stmt(c, n) |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2278 struct compiling *c; |
| 744 | 2279 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
|
2280 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2281 int i = c->c_nblocks; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2282 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
|
2283 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2284 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2285 else { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2286 com_error(c, SyntaxError, "'continue' not properly in loop"); |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2287 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2288 /* XXX Could allow it inside a 'finally' clause |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2289 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
|
2290 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2291 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2292 static int |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2293 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
|
2294 struct compiling *c; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2295 node *n; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2296 { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2297 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
|
2298 if (TYPE(n) == lambdef) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2299 /* lambdef: 'lambda' [varargslist] ':' test */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2300 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2301 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2302 else { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2303 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
|
2304 n = CHILD(n, 2); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2305 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
|
2306 n = CHILD(n, 1); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2307 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2308 if (TYPE(n) != varargslist) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2309 return 0; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2310 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2311 (fpdef ['=' test] ',')* '*' ....... | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2312 fpdef ['=' test] (',' fpdef ['=' test])* [','] */ |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2313 nch = NCH(n); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2314 nargs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2315 ndefs = 0; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2316 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
|
2317 int t; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2318 if (TYPE(CHILD(n, i)) == STAR || 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
|
2319 break; |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2320 nargs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2321 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2322 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
|
2323 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
|
2324 else |
|
e51e17b2d88b
fix bug with missing default for last arg (discovered by Tommy Burnette)
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
2325 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
|
2326 if (t == EQUAL) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2327 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2328 ndefs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2329 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
|
2330 i++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2331 if (i >= nch) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2332 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2333 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
|
2334 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2335 else { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2336 /* 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
|
2337 if (ndefs) { |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2338 com_addoparg(c, LOAD_CONST, |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2339 com_addconst(c, None)); |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2340 ndefs++; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2341 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2342 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2343 if (t != COMMA) |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2344 break; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2345 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2346 return ndefs; |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2347 } |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2348 |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2349 static void |
| 69 | 2350 com_funcdef(c, n) |
| 2351 struct compiling *c; | |
| 2352 node *n; | |
| 2353 { | |
| 2354 object *v; | |
| 2355 REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */ | |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2356 v = (object *)icompile(n, c); |
| 69 | 2357 if (v == NULL) |
| 2358 c->c_errors++; | |
| 2359 else { | |
| 2360 int i = com_addconst(c, v); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2361 int ndefs = com_argdefs(c, n); |
| 69 | 2362 com_addoparg(c, LOAD_CONST, i); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2363 com_addoparg(c, MAKE_FUNCTION, ndefs); |
| 69 | 2364 com_addopname(c, STORE_NAME, CHILD(n, 1)); |
| 2365 DECREF(v); | |
| 2366 } | |
| 2367 } | |
| 2368 | |
| 2369 static void | |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2370 com_bases(c, n) |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2371 struct compiling *c; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2372 node *n; |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2373 { |
| 744 | 2374 int i; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2375 REQ(n, testlist); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2376 /* testlist: test (',' test)* [','] */ |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2377 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
|
2378 com_node(c, CHILD(n, i)); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2379 com_addoparg(c, BUILD_TUPLE, (NCH(n)+1) / 2); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2380 } |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2381 |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2382 static void |
| 69 | 2383 com_classdef(c, n) |
| 2384 struct compiling *c; | |
| 2385 node *n; | |
| 2386 { | |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2387 int i; |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2388 object *v; |
| 69 | 2389 REQ(n, classdef); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2390 /* classdef: class NAME ['(' testlist ')'] ':' suite */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2391 if ((v = newstringobject(STR(CHILD(n, 1)))) == NULL) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2392 c->c_errors++; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2393 return; |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2394 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2395 /* Push the class name on the stack */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2396 i = com_addconst(c, v); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2397 com_addoparg(c, LOAD_CONST, i); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2398 DECREF(v); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2399 /* Push the tuple of base classes on the stack */ |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2400 if (TYPE(CHILD(n, 2)) != LPAR) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2401 com_addoparg(c, BUILD_TUPLE, 0); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2402 else |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2403 com_bases(c, CHILD(n, 3)); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2404 v = (object *)icompile(n, c); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2405 if (v == NULL) |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2406 c->c_errors++; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2407 else { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2408 i = com_addconst(c, v); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2409 com_addoparg(c, LOAD_CONST, i); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2410 com_addoparg(c, MAKE_FUNCTION, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2411 com_addoparg(c, CALL_FUNCTION, 0); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2412 com_addbyte(c, BUILD_CLASS); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2413 com_addopname(c, STORE_NAME, CHILD(n, 1)); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2414 DECREF(v); |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2415 } |
| 69 | 2416 } |
| 2417 | |
| 2418 static void | |
| 2419 com_node(c, n) | |
| 2420 struct compiling *c; | |
| 2421 node *n; | |
| 2422 { | |
| 2423 switch (TYPE(n)) { | |
| 2424 | |
| 2425 /* Definition nodes */ | |
| 2426 | |
| 2427 case funcdef: | |
| 2428 com_funcdef(c, n); | |
| 2429 break; | |
| 2430 case classdef: | |
| 2431 com_classdef(c, n); | |
| 2432 break; | |
| 2433 | |
| 2434 /* Trivial parse tree nodes */ | |
| 2435 | |
| 2436 case stmt: | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2437 case small_stmt: |
| 86 | 2438 case flow_stmt: |
| 2439 com_node(c, CHILD(n, 0)); | |
| 2440 break; | |
| 2441 | |
| 69 | 2442 case simple_stmt: |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2443 /* small_stmt (';' small_stmt)* [';'] NEWLINE */ |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2444 com_addoparg(c, SET_LINENO, n->n_lineno); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2445 { |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2446 int i; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2447 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
|
2448 com_node(c, CHILD(n, i)); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2449 } |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2450 break; |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2451 |
| 69 | 2452 case compound_stmt: |
| 86 | 2453 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 69 | 2454 com_node(c, CHILD(n, 0)); |
| 2455 break; | |
| 2456 | |
| 2457 /* Statement nodes */ | |
| 2458 | |
| 2459 case expr_stmt: | |
| 2460 com_expr_stmt(c, n); | |
| 2461 break; | |
| 2462 case print_stmt: | |
| 2463 com_print_stmt(c, n); | |
| 2464 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2465 case del_stmt: /* 'del' exprlist */ |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
2466 com_assign(c, CHILD(n, 1), OP_DELETE); |
| 69 | 2467 break; |
| 2468 case pass_stmt: | |
| 2469 break; | |
| 2470 case break_stmt: | |
| 86 | 2471 if (c->c_loops == 0) { |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2472 com_error(c, SyntaxError, "'break' outside loop"); |
| 86 | 2473 } |
| 69 | 2474 com_addbyte(c, BREAK_LOOP); |
| 2475 break; | |
|
317
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2476 case continue_stmt: |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2477 com_continue_stmt(c, n); |
|
325b40d77235
New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents:
303
diff
changeset
|
2478 break; |
| 69 | 2479 case return_stmt: |
| 2480 com_return_stmt(c, n); | |
| 2481 break; | |
| 2482 case raise_stmt: | |
| 2483 com_raise_stmt(c, n); | |
| 2484 break; | |
| 2485 case import_stmt: | |
| 2486 com_import_stmt(c, n); | |
| 2487 break; | |
|
466
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2488 case global_stmt: |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2489 com_global_stmt(c, n); |
|
90cbcb0b97dc
Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents:
409
diff
changeset
|
2490 break; |
|
4003
138fa15a1032
Disable support for access statement
Guido van Rossum <guido@python.org>
parents:
3963
diff
changeset
|
2491 #ifdef SUPPORT_OBSOLETE_ACCESS |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2492 case access_stmt: |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2493 com_access_stmt(c, n); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
2494 break; |
|
4003
138fa15a1032
Disable support for access statement
Guido van Rossum <guido@python.org>
parents:
3963
diff
changeset
|
2495 #endif |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2496 case exec_stmt: |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2497 com_exec_stmt(c, n); |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
2498 break; |
| 69 | 2499 case if_stmt: |
| 2500 com_if_stmt(c, n); | |
| 2501 break; | |
| 2502 case while_stmt: | |
| 2503 com_while_stmt(c, n); | |
| 2504 break; | |
| 2505 case for_stmt: | |
| 2506 com_for_stmt(c, n); | |
| 2507 break; | |
| 2508 case try_stmt: | |
| 2509 com_try_stmt(c, n); | |
| 2510 break; | |
| 2511 case suite: | |
| 2512 com_suite(c, n); | |
| 2513 break; | |
| 2514 | |
| 2515 /* Expression nodes */ | |
| 2516 | |
| 2517 case testlist: | |
| 482 | 2518 com_list(c, n, 0); |
| 69 | 2519 break; |
| 2520 case test: | |
| 2521 com_test(c, n); | |
| 2522 break; | |
| 2523 case and_test: | |
| 2524 com_and_test(c, n); | |
| 2525 break; | |
| 2526 case not_test: | |
| 2527 com_not_test(c, n); | |
| 2528 break; | |
| 2529 case comparison: | |
| 2530 com_comparison(c, n); | |
| 2531 break; | |
| 2532 case exprlist: | |
| 482 | 2533 com_list(c, n, 0); |
| 69 | 2534 break; |
| 2535 case expr: | |
| 2536 com_expr(c, n); | |
| 2537 break; | |
|
409
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2538 case xor_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2539 com_xor_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2540 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2541 case and_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2542 com_and_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2543 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2544 case shift_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2545 com_shift_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2546 break; |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2547 case arith_expr: |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2548 com_arith_expr(c, n); |
|
b5fe6482072f
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
388
diff
changeset
|
2549 break; |
| 69 | 2550 case term: |
| 2551 com_term(c, n); | |
| 2552 break; | |
| 2553 case factor: | |
| 2554 com_factor(c, n); | |
| 2555 break; | |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2556 case power: |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2557 com_power(c, n); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2558 break; |
| 69 | 2559 case atom: |
| 2560 com_atom(c, n); | |
| 2561 break; | |
| 2562 | |
| 2563 default: | |
| 2564 fprintf(stderr, "node type %d\n", TYPE(n)); | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2565 com_error(c, SystemError, "com_node: unexpected node type"); |
| 69 | 2566 } |
| 2567 } | |
| 2568 | |
| 2569 static void com_fplist PROTO((struct compiling *, node *)); | |
| 2570 | |
| 2571 static void | |
| 2572 com_fpdef(c, n) | |
| 2573 struct compiling *c; | |
| 2574 node *n; | |
| 2575 { | |
| 2576 REQ(n, fpdef); /* fpdef: NAME | '(' fplist ')' */ | |
| 2577 if (TYPE(CHILD(n, 0)) == LPAR) | |
| 2578 com_fplist(c, CHILD(n, 1)); | |
| 2579 else | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2580 com_addoparg(c, STORE_FAST, com_newlocal(c, STR(CHILD(n, 0)))); |
| 69 | 2581 } |
| 2582 | |
| 2583 static void | |
| 2584 com_fplist(c, n) | |
| 2585 struct compiling *c; | |
| 2586 node *n; | |
| 2587 { | |
| 544 | 2588 REQ(n, fplist); /* fplist: fpdef (',' fpdef)* [','] */ |
| 69 | 2589 if (NCH(n) == 1) { |
| 2590 com_fpdef(c, CHILD(n, 0)); | |
| 2591 } | |
| 2592 else { | |
| 2593 int i; | |
| 2594 com_addoparg(c, UNPACK_TUPLE, (NCH(n)+1)/2); | |
| 2595 for (i = 0; i < NCH(n); i += 2) | |
| 2596 com_fpdef(c, CHILD(n, i)); | |
| 2597 } | |
| 2598 } | |
| 2599 | |
| 2600 static void | |
| 584 | 2601 com_arglist(c, n) |
| 2602 struct compiling *c; | |
| 2603 node *n; | |
| 2604 { | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2605 int nch, i; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2606 int complex = 0; |
| 584 | 2607 REQ(n, varargslist); |
|
617
755bb8efcc2d
Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents:
584
diff
changeset
|
2608 /* varargslist: |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2609 (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
|
2610 nch = NCH(n); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2611 /* 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
|
2612 for (i = 0; i < nch; i++) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2613 node *ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2614 node *fp; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2615 char *name; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2616 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
|
2617 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2618 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2619 fp = CHILD(ch, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2620 if (TYPE(fp) == NAME) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2621 name = STR(fp); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2622 else { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2623 name = ""; |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3366
diff
changeset
|
2624 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
|
2625 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2626 com_newlocal(c, name); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2627 c->c_argcount++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2628 if (++i >= nch) |
| 584 | 2629 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2630 ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2631 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
|
2632 i += 2; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2633 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2634 REQ(ch, COMMA); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2635 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2636 /* Handle *arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2637 if (i < nch) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2638 node *ch; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2639 ch = CHILD(n, i); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2640 if (TYPE(ch) != DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2641 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2642 ch = CHILD(n, i+1); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2643 if (TYPE(ch) == NAME) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2644 c->c_flags |= CO_VARARGS; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2645 i += 3; |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2646 com_newlocal(c, STR(ch)); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2647 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2648 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2649 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2650 /* Handle **keywords */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2651 if (i < nch) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2652 node *ch; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2653 ch = CHILD(n, i); |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2654 if (TYPE(ch) != DOUBLESTAR) { |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2655 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2656 ch = CHILD(n, i+1); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2657 REQ(ch, STAR); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2658 ch = CHILD(n, i+2); |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2659 } |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2660 else |
|
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2661 ch = CHILD(n, i+1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2662 REQ(ch, NAME); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2663 c->c_flags |= CO_VARKEYWORDS; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2664 com_newlocal(c, STR(ch)); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2665 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2666 if (complex) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2667 /* Generate code for complex arguments only after |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2668 having counted the simple arguments */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2669 int ilocal = 0; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2670 for (i = 0; i < nch; i++) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2671 node *ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2672 node *fp; |
|
3324
36920bbd81a8
changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents:
3166
diff
changeset
|
2673 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
|
2674 break; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2675 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2676 fp = CHILD(ch, 0); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2677 if (TYPE(fp) != NAME) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2678 com_addoparg(c, LOAD_FAST, ilocal); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2679 com_fpdef(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2680 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2681 ilocal++; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2682 if (++i >= nch) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2683 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2684 ch = CHILD(n, i); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2685 if (TYPE(ch) == EQUAL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2686 i += 2; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2687 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2688 REQ(ch, COMMA); |
| 584 | 2689 } |
| 2690 } | |
| 2691 } | |
| 2692 | |
| 2693 static void | |
| 69 | 2694 com_file_input(c, n) |
| 2695 struct compiling *c; | |
| 2696 node *n; | |
| 2697 { | |
| 2698 int i; | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2699 object *doc; |
| 69 | 2700 REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */ |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2701 doc = get_docstring(n); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2702 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2703 int i = com_addconst(c, doc); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2704 DECREF(doc); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2705 com_addoparg(c, LOAD_CONST, i); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2706 com_addopnamestr(c, STORE_NAME, "__doc__"); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2707 } |
| 69 | 2708 for (i = 0; i < NCH(n); i++) { |
| 2709 node *ch = CHILD(n, i); | |
| 2710 if (TYPE(ch) != ENDMARKER && TYPE(ch) != NEWLINE) | |
| 2711 com_node(c, ch); | |
| 2712 } | |
| 2713 } | |
| 2714 | |
| 2715 /* Top-level compile-node interface */ | |
| 2716 | |
| 2717 static void | |
| 2718 compile_funcdef(c, n) | |
| 2719 struct compiling *c; | |
| 2720 node *n; | |
| 2721 { | |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2722 object *doc; |
| 69 | 2723 node *ch; |
| 2724 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
|
2725 c->c_name = STR(CHILD(n, 1)); |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2726 doc = get_docstring(CHILD(n, 4)); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2727 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2728 (void) com_addconst(c, doc); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2729 DECREF(doc); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2730 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2731 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2732 (void) com_addconst(c, None); /* No docstring */ |
| 584 | 2733 ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */ |
| 2734 ch = CHILD(ch, 1); /* ')' | varargslist */ | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2735 if (TYPE(ch) == varargslist) |
| 584 | 2736 com_arglist(c, ch); |
| 86 | 2737 c->c_infunction = 1; |
| 69 | 2738 com_node(c, CHILD(n, 4)); |
| 86 | 2739 c->c_infunction = 0; |
| 69 | 2740 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
| 2741 com_addbyte(c, RETURN_VALUE); | |
| 2742 } | |
| 2743 | |
| 2744 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
|
2745 compile_lambdef(c, n) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
2746 struct compiling *c; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
2747 node *n; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
2748 { |
|
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
|
2749 node *ch; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2750 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
|
2751 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
|
2752 |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
2753 ch = CHILD(n, 1); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2754 (void) com_addconst(c, None); /* No docstring */ |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2755 if (TYPE(ch) == varargslist) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2756 com_arglist(c, ch); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2757 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
|
2758 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2759 else |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2760 ch = CHILD(n, 2); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2761 com_node(c, ch); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
2762 com_addbyte(c, RETURN_VALUE); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
2763 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
2764 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
2765 static void |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2766 compile_classdef(c, n) |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2767 struct compiling *c; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2768 node *n; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2769 { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2770 node *ch; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2771 object *doc; |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2772 REQ(n, classdef); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2773 /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2774 c->c_name = STR(CHILD(n, 1)); |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2775 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2776 c->c_private = c->c_name; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2777 #endif |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2778 ch = CHILD(n, NCH(n)-1); /* The suite */ |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2779 doc = get_docstring(ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2780 if (doc != NULL) { |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2781 int i = com_addconst(c, doc); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2782 DECREF(doc); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2783 com_addoparg(c, LOAD_CONST, i); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2784 com_addopnamestr(c, STORE_NAME, "__doc__"); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2785 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2786 else |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2787 (void) com_addconst(c, None); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2788 com_node(c, ch); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2789 com_addbyte(c, LOAD_LOCALS); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2790 com_addbyte(c, RETURN_VALUE); |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2791 } |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2792 |
|
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2793 static void |
| 69 | 2794 compile_node(c, n) |
| 2795 struct compiling *c; | |
| 2796 node *n; | |
| 2797 { | |
| 86 | 2798 com_addoparg(c, SET_LINENO, n->n_lineno); |
| 2799 | |
| 69 | 2800 switch (TYPE(n)) { |
| 2801 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
2802 case single_input: /* One interactive command */ |
| 69 | 2803 /* 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
|
2804 c->c_interactive++; |
| 69 | 2805 n = CHILD(n, 0); |
| 2806 if (TYPE(n) != NEWLINE) | |
| 2807 com_node(c, n); | |
| 86 | 2808 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
| 2809 com_addbyte(c, RETURN_VALUE); | |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2810 c->c_interactive--; |
| 69 | 2811 break; |
| 2812 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
2813 case file_input: /* A whole file, or built-in function exec() */ |
| 69 | 2814 com_file_input(c, n); |
| 86 | 2815 com_addoparg(c, LOAD_CONST, com_addconst(c, None)); |
| 2816 com_addbyte(c, RETURN_VALUE); | |
| 69 | 2817 break; |
| 2818 | |
|
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
|
2819 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
|
2820 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
|
2821 com_addbyte(c, RETURN_VALUE); |
|
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
2822 break; |
|
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
2823 |
|
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
|
2824 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
|
2825 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
|
2826 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
|
2827 |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
2828 case funcdef: /* A function definition */ |
| 69 | 2829 compile_funcdef(c, n); |
| 2830 break; | |
| 2831 | |
|
120
c9a5fe1660f5
Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
2832 case classdef: /* A class definition */ |
|
2089
53aa51433f7f
Two independent chages:
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
2833 compile_classdef(c, n); |
|
73
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2834 break; |
|
3028acaa56b0
Compile class definitions.
Guido van Rossum <guido@python.org>
parents:
69
diff
changeset
|
2835 |
| 69 | 2836 default: |
| 2837 fprintf(stderr, "node type %d\n", TYPE(n)); | |
|
4315
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2838 com_error(c, SystemError, |
|
46d736fb9da3
Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents:
4131
diff
changeset
|
2839 "compile_node: unexpected node type"); |
| 69 | 2840 } |
| 2841 } | |
| 2842 | |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2843 /* 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
|
2844 |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2845 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
|
2846 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
|
2847 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
|
2848 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
|
2849 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2850 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
|
2851 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
|
2852 function definitions, class definitions and import statements. |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2853 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
|
2854 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
|
2855 |
|
1833
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2856 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
|
2857 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
|
2858 |
|
39a4c15acb32
* Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents:
1417
diff
changeset
|
2859 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
|
2860 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
|
2861 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
|
2862 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
|
2863 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
|
2864 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2865 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
|
2866 |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2867 static void |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2868 optimize(c) |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2869 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
|
2870 { |
|
203
ceb36ec6198d
BUGFIX! Instructions are unsigned bytes.
Guido van Rossum <guido@python.org>
parents:
176
diff
changeset
|
2871 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
|
2872 int opcode; |
| 4596 | 2873 int oparg = 0; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2874 object *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2005
diff
changeset
|
2875 object *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
|
2876 |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2877 #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
|
2878 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2]) |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2879 #define GETITEM(v, i) (getlistitem((v), (i))) |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2880 #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
|
2881 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2882 err_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
|
2883 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2884 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
|
2885 |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2886 next_instr = (unsigned char *) getstringvalue(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
|
2887 for (;;) { |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2888 opcode = NEXTOP(); |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2889 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
|
2890 break; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2891 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
|
2892 oparg = NEXTARG(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2893 switch (opcode) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2894 case STORE_NAME: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2895 case DELETE_NAME: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2896 case IMPORT_FROM: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2897 com_addlocal_o(c, GETNAMEOBJ(oparg)); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2898 break; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2899 case EXEC_STMT: |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2900 c->c_flags &= ~CO_OPTIMIZED; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2901 break; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2902 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2903 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2904 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2905 if (dictlookup(c->c_locals, "*") != NULL) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2906 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
|
2907 |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2908 next_instr = (unsigned char *) getstringvalue(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
|
2909 for (;;) { |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2910 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
|
2911 opcode = NEXTOP(); |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2912 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
|
2913 break; |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2914 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
|
2915 oparg = NEXTARG(); |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2916 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
|
2917 opcode == STORE_NAME || |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2918 opcode == DELETE_NAME) { |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2919 object *v; |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2920 int i; |
|
176
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2921 name = GETNAMEOBJ(oparg); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2922 v = dict2lookup(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
|
2923 if (v == NULL) { |
| 336 | 2924 err_clear(); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2925 if (opcode == LOAD_NAME && |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2926 (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
|
2927 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
|
2928 continue; |
| 336 | 2929 } |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2930 i = getintvalue(v); |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2931 switch (opcode) { |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2932 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
|
2933 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
|
2934 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
|
2935 } |
|
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2936 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
|
2937 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
|
2938 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2939 } |
|
1262
f820e6917f07
Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2940 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2941 if (c->c_errors == 0) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2942 err_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
|
2943 } |
|
229168a2fe28
Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents:
160
diff
changeset
|
2944 |
| 69 | 2945 codeobject * |
|
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
|
2946 compile(n, filename) |
| 69 | 2947 node *n; |
| 86 | 2948 char *filename; |
| 69 | 2949 { |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2950 return jcompile(n, filename, NULL); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2951 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2952 |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2953 static codeobject * |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2954 icompile(n, base) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2955 node *n; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2956 struct compiling *base; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2957 { |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2958 return jcompile(n, base->c_filename, base); |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2959 } |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2960 |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2961 static codeobject * |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2962 jcompile(n, filename, base) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2963 node *n; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2964 char *filename; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2965 struct compiling *base; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2966 { |
| 69 | 2967 struct compiling sc; |
| 2968 codeobject *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
|
2969 if (!com_init(&sc, filename)) |
| 69 | 2970 return NULL; |
|
4129
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2971 #ifdef PRIVATE_NAME_MANGLING |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2972 if (base) |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2973 sc.c_private = base->c_private; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2974 else |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2975 sc.c_private = NULL; |
|
eedaa59341b9
Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents:
4003
diff
changeset
|
2976 #endif |
| 69 | 2977 compile_node(&sc, n); |
| 2978 com_done(&sc); | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2979 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
|
2980 optimize(&sc); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2981 sc.c_flags |= CO_NEWLOCALS; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2982 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2983 else if (TYPE(n) == classdef) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2984 sc.c_flags |= CO_NEWLOCALS; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
2985 co = NULL; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1029
diff
changeset
|
2986 if (sc.c_errors == 0) { |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2987 object *consts, *names, *varnames, *filename, *name; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2988 consts = listtuple(sc.c_consts); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2989 names = listtuple(sc.c_names); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2990 varnames = listtuple(sc.c_varnames); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2991 filename = newstringobject(sc.c_filename); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2992 name = newstringobject(sc.c_name); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2993 if (!err_occurred()) |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2994 co = newcodeobject(sc.c_argcount, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2995 sc.c_nlocals, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2996 sc.c_flags, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2997 sc.c_code, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2998 consts, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
2999 names, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3000 varnames, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3001 filename, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3002 name); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3003 XDECREF(consts); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3004 XDECREF(names); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3005 XDECREF(varnames); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3006 XDECREF(filename); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2813
diff
changeset
|
3007 XDECREF(name); |
|
266
b5826bf29677
Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents:
238
diff
changeset
|
3008 } |
| 69 | 3009 com_free(&sc); |
| 3010 return co; | |
| 3011 } |
