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