annotate Python/compile.c @ 16015:c832ef72499d legacy-trunk

This patch introduces an extra pass to the compiler that generates a symbol table for each top-level compilation unit. The information in the symbol table allows the elimination of the later optimize() pass; the bytecode generation emits the correct opcodes. The current version passes the complete regression test, but may still contain some bugs. It's a fairly substantial revision. The current code adds an assert() and a test that may lead to a Py_FatalError(). I expect to remove these before 2.1 beta 1. The symbol table (struct symtable) is described in comments in the code. The changes affects the several com_XXX() functions that were used to emit LOAD_NAME and its ilk. The primary interface for this bytecode is now com_addop_varname() which takes a kind and a name, where kind is one of VAR_LOAD, VAR_STORE, or VAR_DELETE. There are many other smaller changes: - The name mangling code is no longer contained in ifdefs. There are two functions that expose the mangling logical: com_mangle() and symtable_mangle(). - The com_error() function can accept NULL for its first argument; this is useful with is_constant_false() is called during symbol table generation. - The loop index names used by list comprehensions have been changed from __1__ to [1], so that they can not be accessed by Python code. - in com_funcdef(), com_argdefs() is now called before the body of the function is compiled. This provides consistency with com_lambdef() and symtable_funcdef(). - Helpers do_pad(), dump(), and DUMP() are added to aid in debugging the compiler.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 19 Jan 2001 03:21:30 +0000
parents 51811d78a9da
children 596edf8129a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 120
diff changeset
1
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Compile an expression node to intermediate code */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
4 /* XXX TO DO:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
5 XXX add __doc__ attribute == co_doc to code object attributes?
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
6 XXX (it's currently the first item of the co_const tuple)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
7 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
8 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
9 XXX New opcode for loading the initial index for a for loop
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
10 XXX other JAR tricks?
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
11 */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
13 #include "Python.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
14
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #include "node.h"
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 #include "token.h"
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #include "graminit.h"
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #include "compile.h"
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 #include "opcode.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
20 #include "structmember.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
21
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
22 #include <ctype.h>
176
229168a2fe28 Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents: 160
diff changeset
23
5438
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
24 /* Three symbols from graminit.h are also defined in Python.h, with
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
25 Py_ prefixes to their names. Python.h can't include graminit.h
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
26 (which defines too many confusing symbols), but we can check here
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
27 that they haven't changed (which is very unlikely, but possible). */
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
28 #if Py_single_input != single_input
5566
19d4a2874645 Indent the #error directives so a classic K&R cpp doesn't see them.
Guido van Rossum <guido@python.org>
parents: 5453
diff changeset
29 #error "single_input has changed -- update Py_single_input in Python.h"
5438
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
30 #endif
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
31 #if Py_file_input != file_input
5566
19d4a2874645 Indent the #error directives so a classic K&R cpp doesn't see them.
Guido van Rossum <guido@python.org>
parents: 5453
diff changeset
32 #error "file_input has changed -- update Py_file_input in Python.h"
5438
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
33 #endif
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
34 #if Py_eval_input != eval_input
5566
19d4a2874645 Indent the #error directives so a classic K&R cpp doesn't see them.
Guido van Rossum <guido@python.org>
parents: 5453
diff changeset
35 #error "eval_input has changed -- update Py_eval_input in Python.h"
5438
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
36 #endif
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
37
5164
8c277f29b535 Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents: 5119
diff changeset
38 int Py_OptimizeFlag = 0;
8c277f29b535 Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents: 5119
diff changeset
39
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
40 #define OP_DELETE 0
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
41 #define OP_ASSIGN 1
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
42 #define OP_APPLY 2
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
43
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
44 #define VAR_LOAD 0
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
45 #define VAR_STORE 1
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
46 #define VAR_DELETE 2
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
47
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
48 #define NAME_LOCAL 0
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
49 #define NAME_GLOBAL 1
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
50 #define NAME_DEFAULT 2
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
51
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
52 #define TYPE_FUNCTION 0
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
53 #define TYPE_CLASS 1
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
54 #define TYPE_MODULE 2
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
55
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
56 #define IMPLICIT_GLOBAL 1
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
57 #define EXPLICIT_GLOBAL 2
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
58
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
59 #define MANGLE_LEN 256
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
60
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
61 #define OFF(x) offsetof(PyCodeObject, x)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
62
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
63 static struct memberlist code_memberlist[] = {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
64 {"co_argcount", T_INT, OFF(co_argcount), READONLY},
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
65 {"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
66 {"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
67 {"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
68 {"co_code", T_OBJECT, OFF(co_code), READONLY},
92509d304e47 add READONLY to member list.
Guido van Rossum <guido@python.org>
parents: 544
diff changeset
69 {"co_consts", T_OBJECT, OFF(co_consts), READONLY},
92509d304e47 add READONLY to member list.
Guido van Rossum <guido@python.org>
parents: 544
diff changeset
70 {"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
71 {"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
72 {"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
73 {"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
74 {"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
75 {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY},
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
76 {NULL} /* Sentinel */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
77 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
78
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
79 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
80 code_getattr(PyCodeObject *co, char *name)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
81 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
82 return PyMember_Get((char *)co, code_memberlist, name);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
83 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
86 code_dealloc(PyCodeObject *co)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 {
5373
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_code);
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_consts);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
90 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
91 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
92 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
93 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
94 Py_XDECREF(co->co_lnotab);
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12538
diff changeset
95 PyObject_DEL(co);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
98 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
99 code_repr(PyCodeObject *co)
1029
2f9805c963e8 Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents: 792
diff changeset
100 {
2f9805c963e8 Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents: 792
diff changeset
101 char buf[500];
2f9805c963e8 Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents: 792
diff changeset
102 int lineno = -1;
2f9805c963e8 Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents: 792
diff changeset
103 char *filename = "???";
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1029
diff changeset
104 char *name = "???";
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
105
12278
647bf71912f0 Vladimir Marangozov: This fixes the line number in the string
Guido van Rossum <guido@python.org>
parents: 12086
diff changeset
106 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
107 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
108 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
109 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
110 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
111 name = PyString_AsString(co->co_name);
13227
c2df5d28034d Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13096
diff changeset
112 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
113 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
114 return PyString_FromString(buf);
1029
2f9805c963e8 Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents: 792
diff changeset
115 }
2f9805c963e8 Give code objects a more useful representation.
Guido van Rossum <guido@python.org>
parents: 792
diff changeset
116
1399
cc172ce05561 Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
117 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
118 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
119 {
cc172ce05561 Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
120 int cmp;
12333
525b2358721e Patch by Vladimir Marangozov to include the function name when
Guido van Rossum <guido@python.org>
parents: 12278
diff changeset
121 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
122 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
123 cmp = co->co_argcount - cp->co_argcount;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
124 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
125 cmp = co->co_nlocals - cp->co_nlocals;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
126 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
127 cmp = co->co_flags - cp->co_flags;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
128 if (cmp) return cmp;
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
129 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
130 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
131 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
132 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
133 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
134 if (cmp) return cmp;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
135 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
136 return cmp;
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
cc172ce05561 Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
139 static long
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
140 code_hash(PyCodeObject *co)
1399
cc172ce05561 Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
141 {
12333
525b2358721e Patch by Vladimir Marangozov to include the function name when
Guido van Rossum <guido@python.org>
parents: 12278
diff changeset
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 h4 = PyObject_Hash(co->co_varnames);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
152 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
153 h = h0 ^ h1 ^ h2 ^ h3 ^ h4 ^
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
154 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
155 if (h == -1) h = -2;
cc172ce05561 Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
156 return h;
cc172ce05561 Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
157 }
cc172ce05561 Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
158
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
159 PyTypeObject PyCode_Type = {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
160 PyObject_HEAD_INIT(&PyType_Type)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 0,
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 "code",
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
163 sizeof(PyCodeObject),
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 0,
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
165 (destructor)code_dealloc, /*tp_dealloc*/
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 0, /*tp_print*/
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
167 (getattrfunc)code_getattr, /*tp_getattr*/
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 0, /*tp_setattr*/
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
169 (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
170 (reprfunc)code_repr, /*tp_repr*/
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 0, /*tp_as_number*/
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 0, /*tp_as_sequence*/
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 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
174 (hashfunc)code_hash, /*tp_hash*/
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 };
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5264
diff changeset
177 #define NAME_CHARS \
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5264
diff changeset
178 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5264
diff changeset
179
16006
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
180 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
181
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
182 static int
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
183 all_name_chars(unsigned char *s)
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
184 {
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
185 static char ok_name_char[256];
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
186 static unsigned char *name_chars = NAME_CHARS;
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
187
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
188 if (ok_name_char[*name_chars] == 0) {
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
189 unsigned char *p;
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
190 for (p = name_chars; *p; p++)
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
191 ok_name_char[*p] = 1;
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
192 }
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
193 while (*s) {
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
194 if (ok_name_char[*s++] == 0)
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
195 return 0;
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
196 }
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
197 return 1;
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
198 }
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
199
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
200 PyCodeObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
201 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
202 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
203 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
204 int firstlineno, PyObject *lnotab)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
206 PyCodeObject *co;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 int i;
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
208 PyBufferProcs *pb;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 /* Check argument types */
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
210 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
211 code == NULL ||
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
212 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
213 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
214 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
215 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
216 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
217 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
218 PyErr_BadInternalCall();
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 }
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
221 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
222 if (pb == NULL ||
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
223 pb->bf_getreadbuffer == NULL ||
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
224 pb->bf_getsegcount == NULL ||
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
225 (*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
226 {
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
227 PyErr_BadInternalCall();
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
228 return NULL;
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
229 }
5009
402e36c83d20 Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents: 4991
diff changeset
230 /* 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
231 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
232 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
233 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
234 PyErr_BadInternalCall();
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
235 return NULL;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
236 }
5009
402e36c83d20 Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents: 4991
diff changeset
237 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
238 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
239 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
240 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
241 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
242 PyErr_BadInternalCall();
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 }
5009
402e36c83d20 Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents: 4991
diff changeset
245 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
246 }
402e36c83d20 Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents: 4991
diff changeset
247 /* 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
248 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
249 PyObject *v = PyTuple_GetItem(consts, i);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
250 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
251 continue;
16006
51811d78a9da SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Guido van Rossum <guido@python.org>
parents: 15438
diff changeset
252 if (!all_name_chars((unsigned char *)PyString_AsString(v)))
5009
402e36c83d20 Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents: 4991
diff changeset
253 continue;
402e36c83d20 Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents: 4991
diff changeset
254 PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
256 co = PyObject_NEW(PyCodeObject, &PyCode_Type);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 if (co != NULL) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
258 co->co_argcount = argcount;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
259 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
260 co->co_stacksize = stacksize;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
261 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
262 Py_INCREF(code);
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 9215
diff changeset
263 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
264 Py_INCREF(consts);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 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
266 Py_INCREF(names);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 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
268 Py_INCREF(varnames);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
269 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
270 Py_INCREF(filename);
266
b5826bf29677 Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents: 238
diff changeset
271 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
272 Py_INCREF(name);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1029
diff changeset
273 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
274 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
275 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
276 co->co_lnotab = lnotab;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 return co;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
280
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
281
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 /* Data structure used internally */
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
283
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
284 /* The compiler uses two passes to generate bytecodes. The first pass
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
285 builds the symbol table. The second pass generates the bytecode.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
286
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
287 The first pass uses a single symtable struct. The second pass uses
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
288 a compiling struct for each code block. The compiling structs
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
289 share a reference to the symtable.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
290
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
291 The two passes communicate via symtable_load_symbols() and via
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
292 is_local() and is_global(). The former initializes several slots
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
293 in the compiling struct: c_varnames, c_locals, c_nlocals,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
294 c_argcount, c_globals, and c_flags.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
295 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
296
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 struct compiling {
14471
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
298 PyObject *c_code; /* string */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
299 PyObject *c_consts; /* list of objects */
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
300 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
301 PyObject *c_names; /* list of strings (names) */
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
302 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
303 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
304 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
305 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
306 int c_nlocals; /* index of next local */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
307 int c_argcount; /* number of top-level arguments */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
308 int c_flags; /* same as co_flags */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 int c_nexti; /* index into c_code */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 int c_errors; /* counts errors occurred */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
311 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
312 int c_interactive; /* generating code for interactive command */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
313 int c_loops; /* counts nested loops */
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
314 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
315 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
316 int c_nblocks; /* current block stack level */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
317 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
318 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
319 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
320 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
321 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
322 int c_firstlineno;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
323 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
324 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
325 char *c_private; /* for private name mangling */
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
326 int c_tmpname; /* temporary local name counter */
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
327 struct symtable *c_symtable; /* pointer to module symbol table */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 };
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
330 /* The symbol table is constructed each time PyNode_Compile() is
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
331 called. The table walks the entire parse tree and identifies each
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
332 use or definition of a variable.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
333
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
334 The symbol table contains a dictionary for each code block in a
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
335 module: The symbol dictionary for the block. They keys of these
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
336 dictionaries are the name of all variables used or defined in the
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
337 block; the integer values are used to store several flags,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
338 e.g. DEF_PARAM indicates that a variable is a parameter to a
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
339 function.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
340
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
341 The slots st_cur, st_cur_id, and st_cur_type always refer to the
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
342 current code block. The st_cur slot is the symbol dictionary. The
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
343 st_cur_id slot is the id is the key in st_symbols. The st_cur_type
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
344 slot is one of TYPE_FUNCTION, TYPE_CLASS, or TYPE_MODULE.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
345
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
346 The st_symbols slot is a dictionary that maps code block ids to
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
347 symbol dictionaries. The keys are generated by a counter that is
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
348 incremented each time a new code block is found. The counter is
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
349 identifies a specific scope, because both passes walk the parse
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
350 tree in the same order.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
351
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
352 The st_varnames slot is a dictionary that maps code block ids to
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
353 parameter lists. The st_global slot always refers to the symbol
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
354 dictionary for the module.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
355 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
356
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
357 struct symtable {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
358 PyObject *st_symbols; /* dictionary of symbol tables */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
359 PyObject *st_varnames; /* dictionary of parameter lists */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
360 PyObject *st_namespaces; /* pointer to list of namespaces */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
361 PyObject *st_types; /* pointer to list of namespace types */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
362 PyObject *st_cur; /* borrowed ref to dict in st_symbols */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
363 PyObject *st_cur_id; /* int id of current code block */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
364 int st_cur_type; /* type of current scope */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
365 PyObject *st_global; /* borrowed ref to MODULE in st_symbols */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
366 int st_scopes; /* number of scopes */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
367 int st_errors; /* number of errors */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
368 char *st_private; /* name of current class or NULL */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
369 int st_tmpname; /* temporary name counter */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
370 };
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
371
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
372 #define GLOBAL "global"
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
373 #define NOOPT ".noopt"
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
374
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
375 /* Flags for def-use information */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
376
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
377 #define DEF_GLOBAL 1
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
378 #define DEF_LOCAL 2
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
379 #define DEF_PARAM 2<<1
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
380 #define USE 2<<2
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
381 #define DEF_STAR 2<<3
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
382 #define DEF_DOUBLESTAR 2<<4
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
383 #define DEF_INTUPLE 2<<5
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
384
4315
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
385 /* 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
386
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
387 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
388 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
389 {
13993
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
390 PyObject *v, *tb, *tmp;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
391 if (c == NULL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
392 /* Error occurred via symtable call to
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
393 is_constant_false */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
394 PyErr_SetString(exc, msg);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
395 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
396 }
4905
32220c5728f5 Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
397 c->c_errors++;
4315
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
398 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
399 /* 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
400 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
401 return;
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
402 }
13993
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
403 v = PyString_FromString(msg);
4315
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
404 if (v == NULL)
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
405 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
406 PyErr_SetObject(exc, v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
407 Py_DECREF(v);
13993
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
408
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
409 /* add attributes for the line number and filename for the error */
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
410 PyErr_Fetch(&exc, &v, &tb);
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
411 PyErr_NormalizeException(&exc, &v, &tb);
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
412 tmp = PyInt_FromLong(c->c_lineno);
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
413 if (tmp == NULL)
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
414 PyErr_Clear();
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
415 else {
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
416 if (PyObject_SetAttrString(v, "lineno", tmp))
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
417 PyErr_Clear();
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
418 Py_DECREF(tmp);
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
419 }
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
420 if (c->c_filename != NULL) {
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
421 tmp = PyString_FromString(c->c_filename);
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
422 if (tmp == NULL)
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
423 PyErr_Clear();
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
424 else {
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
425 if (PyObject_SetAttrString(v, "filename", tmp))
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
426 PyErr_Clear();
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
427 Py_DECREF(tmp);
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
428 }
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
429 }
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
430 PyErr_Restore(exc, v, tb);
4315
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
431 }
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
432
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
433
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
434 /* Interface to the block stack */
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
435
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
436 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
437 block_push(struct compiling *c, int type)
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
438 {
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
439 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
440 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
441 "too many statically nested blocks");
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
442 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
443 else {
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
444 c->c_block[c->c_nblocks++] = type;
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
445 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
446 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
447
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
448 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
449 block_pop(struct compiling *c, int type)
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
450 {
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
451 if (c->c_nblocks > 0)
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
452 c->c_nblocks--;
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
453 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
454 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
455 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
456 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
457
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
458
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
459 /* Prototype forward declarations */
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
460
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13330
diff changeset
461 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
462 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
463 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
464 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
465 static void com_done(struct compiling *);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
466 static void com_node(struct compiling *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
467 static void com_factor(struct compiling *, node *);
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13330
diff changeset
468 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
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 static void com_list(struct compiling *, node *, int);
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
478 static void com_list_iter(struct compiling *, node *, node *, char *);
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13330
diff changeset
479 static int com_argdefs(struct compiling *, node *);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
480 static void com_assign(struct compiling *, node *, int, node *);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
481 static void com_assign_name(struct compiling *, node *, int);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
482 static PyCodeObject *icompile(node *, struct compiling *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
483 static PyCodeObject *jcompile(node *, char *, struct compiling *);
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13330
diff changeset
484 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
485 static PyObject *parsestr(char *);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
486 static node *get_rawdocstring(node *);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
487
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
488 static int is_local(struct compiling *, char *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
489 static int is_global(struct compiling *, char *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
490
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
491 /* symtable operations */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
492 static int symtable_build(struct compiling *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
493 static int symtable_load_symbols(struct compiling *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
494 static struct symtable *symtable_init(void);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
495 static void symtable_free(struct symtable *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
496 static int symtable_enter_scope(struct symtable *, char *, int);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
497 static int symtable_exit_scope(struct symtable *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
498 static int symtable_update_cur(struct symtable *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
499 static int symtable_add_def(struct symtable *, char *, int);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
500 static int symtable_add_use(struct symtable *, char *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
501
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
502 static void symtable_node(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
503 static void symtable_funcdef(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
504 static void symtable_default_args(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
505 static void symtable_params(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
506 static void symtable_params_fplist(struct symtable *, node *n);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
507 static void symtable_global(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
508 static void symtable_import(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
509 static void symtable_assign(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
510 static void symtable_list_comprehension(struct symtable *, node *);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
511
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
512 /* helper */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
513 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
514 do_pad(int pad)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
515 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
516 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
517 for (i = 0; i < pad; ++i)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
518 fprintf(stderr, " ");
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
519 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
520
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
521 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
522 dump(node *n, int pad, int depth)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
523 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
524 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
525 if (depth == 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
526 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
527 do_pad(pad);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
528 fprintf(stderr, "%d: %s\n", TYPE(n), STR(n));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
529 if (depth > 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
530 depth--;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
531 for (i = 0; i < NCH(n); ++i)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
532 dump(CHILD(n, i), pad + 1, depth);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
533 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
534
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
535 #define DUMP(N) dump(N, 0, -1)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
536
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
538 com_init(struct compiling *c, char *filename)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
539 {
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
540 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
541 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
542 1000)) == NULL)
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
543 goto fail;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
544 if ((c->c_consts = PyList_New(0)) == NULL)
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
545 goto fail;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
546 if ((c->c_const_dict = PyDict_New()) == NULL)
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
547 goto fail;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
548 if ((c->c_names = PyList_New(0)) == NULL)
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
549 goto fail;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
550 if ((c->c_name_dict = PyDict_New()) == NULL)
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
551 goto fail;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
552 if ((c->c_globals = PyDict_New()) == NULL)
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
553 goto fail;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
554 if ((c->c_locals = PyDict_New()) == NULL)
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
555 goto fail;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
556 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
557 1000)) == NULL)
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
558 goto fail;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
559 c->c_varnames = NULL;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
560 c->c_nlocals = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
561 c->c_argcount = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
562 c->c_flags = 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
563 c->c_nexti = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 c->c_errors = 0;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
565 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
566 c->c_interactive = 0;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
567 c->c_loops = 0;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
568 c->c_begin = 0;
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
569 c->c_nblocks = 0;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
570 c->c_filename = filename;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1029
diff changeset
571 c->c_name = "?";
4315
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
572 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
573 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
574 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
575 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
576 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
577 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
578 c-> c_lnotab_next = 0;
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
579 c->c_tmpname = 0;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
580 c->c_symtable = NULL;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
581 return 1;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
582
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
583 fail:
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
584 com_free(c);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
585 return 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
586 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
587
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
588 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
589 com_free(struct compiling *c)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
591 Py_XDECREF(c->c_code);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
592 Py_XDECREF(c->c_consts);
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
593 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
594 Py_XDECREF(c->c_names);
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
595 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
596 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
597 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
598 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
599 Py_XDECREF(c->c_lnotab);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
600 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
601
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
603 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
604 {
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
605 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
606 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
607 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
608 }
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
609
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
610 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
611 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
612 {
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
613 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
614 /* fprintf(stderr,
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
615 "%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
616 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
617 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
618 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
619 }
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
620 else
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
621 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
622 }
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
623
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
624 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
625 com_done(struct compiling *c)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 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
628 _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
629 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
630 _PyString_Resize(&c->c_lnotab, c->c_lnotab_next);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
632
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
634 com_addbyte(struct compiling *c, int byte)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
635 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
636 int len;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
637 /*fprintf(stderr, "%3d: %3d\n", c->c_nexti, byte);*/
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
638 assert(byte >= 0 && byte <= 255);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
639 if (byte < 0 || byte > 255) {
388
31d509e94271 Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents: 336
diff changeset
640 /*
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
641 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
642 fatal("com_addbyte: byte out of range");
388
31d509e94271 Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents: 336
diff changeset
643 */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
644 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
645 "com_addbyte: byte out of range");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
647 if (c->c_code == NULL)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
648 return;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
649 len = PyString_Size(c->c_code);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
650 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
651 if (_PyString_Resize(&c->c_code, len+1000) != 0) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
652 c->c_errors++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
653 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
654 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
655 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
656 PyString_AsString(c->c_code)[c->c_nexti++] = byte;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
657 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
658
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
659 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
660 com_addint(struct compiling *c, int x)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
661 {
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
662 com_addbyte(c, x & 0xff);
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
663 com_addbyte(c, x >> 8); /* XXX x should be positive */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
664 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
665
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
666 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
667 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
668 {
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
669 int size;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
670 char *p;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
671 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
672 return;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
673 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
674 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
675 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
676 c->c_errors++;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
677 return;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
678 }
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
679 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
680 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
681 *p++ = addr;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
682 *p++ = line;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
683 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
684 }
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
685
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
686 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
687 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
688 {
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
689 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
690 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
691 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
692 }
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
693 else {
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
694 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
695 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
696 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
697 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
698 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
699 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
700 trunc_addr = 255;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
701 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
702 trunc_line = 255;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
703 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
704 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
705 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
706 }
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
707 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
708 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
709 }
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
710 }
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
711
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
712 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
713 com_addoparg(struct compiling *c, int op, int arg)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 {
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
715 int extended_arg = arg >> 16;
5164
8c277f29b535 Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents: 5119
diff changeset
716 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
717 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
718 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
719 return;
5041
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
720 }
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
721 if (extended_arg){
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
722 com_addbyte(c, EXTENDED_ARG);
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
723 com_addint(c, extended_arg);
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
724 arg &= 0xffff;
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
725 }
5164
8c277f29b535 Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
Guido van Rossum <guido@python.org>
parents: 5119
diff changeset
726 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
727 com_addint(c, arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
728 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
729
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
730 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
731 com_addfwref(struct compiling *c, int op, int *p_anchor)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
732 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
733 /* Compile a forward reference for backpatching */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
734 int here;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 int anchor;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 com_addbyte(c, op);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
737 here = c->c_nexti;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 anchor = *p_anchor;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
739 *p_anchor = here;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
740 com_addint(c, anchor == 0 ? 0 : here - anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
741 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
742
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
743 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
744 com_backpatch(struct compiling *c, int anchor)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
745 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
746 unsigned char *code = (unsigned char *) PyString_AsString(c->c_code);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
747 int target = c->c_nexti;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
748 int dist;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
749 int prev;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
750 for (;;) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
751 /* Make the JUMP instruction at anchor point to target */
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
752 prev = code[anchor] + (code[anchor+1] << 8);
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
753 dist = target - (anchor+2);
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
754 code[anchor] = dist & 0xff;
14147
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
755 dist >>= 8;
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
756 code[anchor+1] = dist;
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
757 dist >>= 8;
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
758 if (dist) {
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
759 com_error(c, PyExc_SystemError,
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
760 "com_backpatch: offset too large");
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
761 break;
21ec69a56228 Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents: 14117
diff changeset
762 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
763 if (!prev)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
764 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
765 anchor -= prev;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
766 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
767 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
768
544
d0baa8300005 Minor changes.
Guido van Rossum <guido@python.org>
parents: 493
diff changeset
769 /* Handle literals and names uniformly */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
770
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
771 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
772 com_add(struct compiling *c, PyObject *list, PyObject *dict, PyObject *v)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
773 {
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
774 PyObject *w, *t, *np=NULL;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
775 long n;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
776
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
777 t = Py_BuildValue("(OO)", v, v->ob_type);
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
778 if (t == NULL)
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
779 goto fail;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
780 w = PyDict_GetItem(dict, t);
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
781 if (w != NULL) {
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
782 n = PyInt_AsLong(w);
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
783 } else {
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
784 n = PyList_Size(list);
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
785 np = PyInt_FromLong(n);
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
786 if (np == NULL)
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
787 goto fail;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
788 if (PyList_Append(list, v) != 0)
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
789 goto fail;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
790 if (PyDict_SetItem(dict, t, np) != 0)
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
791 goto fail;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
792 Py_DECREF(np);
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
793 }
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
794 Py_DECREF(t);
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
795 return n;
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
796 fail:
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
797 Py_XDECREF(np);
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
798 Py_XDECREF(t);
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
799 c->c_errors++;
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
800 return 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
801 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
802
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
803 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
804 com_addconst(struct compiling *c, PyObject *v)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
805 {
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
806 return com_add(c, c->c_consts, c->c_const_dict, v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
807 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
808
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
809 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
810 com_addname(struct compiling *c, PyObject *v)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
811 {
12522
0c28c9cabbda Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12388
diff changeset
812 return com_add(c, c->c_names, c->c_name_dict, v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
813 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
814
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
815 static int
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
816 mangle(char *p, char *name, char *buffer, size_t maxlen)
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
817 {
4131
6b589334e0e9 Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents: 4130
diff changeset
818 /* Name mangling: __private becomes _classname__private.
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
819 This is independent from how the name is used. */
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
820 size_t nlen, plen;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
821 if (p == NULL || name == NULL || name[0] != '_' || name[1] != '_')
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
822 return 0;
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
823 nlen = strlen(name);
4131
6b589334e0e9 Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents: 4130
diff changeset
824 if (nlen+2 >= maxlen)
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
825 return 0; /* Don't mangle __extremely_long_names */
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
826 if (name[nlen-1] == '_' && name[nlen-2] == '_')
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
827 return 0; /* Don't mangle __whatever__ */
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
828 /* Strip leading underscores from class name */
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
829 while (*p == '_')
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
830 p++;
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
831 if (*p == '\0')
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
832 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
833 plen = strlen(p);
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
834 if (plen + nlen >= maxlen)
4131
6b589334e0e9 Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents: 4130
diff changeset
835 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
836 /* 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
837 buffer[0] = '_';
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
838 strncpy(buffer+1, p, plen);
4131
6b589334e0e9 Afterthough: leave both leading underscores in,
Guido van Rossum <guido@python.org>
parents: 4130
diff changeset
839 strcpy(buffer+1+plen, name);
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
840 /* fprintf(stderr, "mangle %s -> %s\n", name, buffer); */
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
841 return 1;
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
842 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
843
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
844 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
845 com_mangle(struct compiling *c, char *name, char *buffer, size_t maxlen)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
846 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
847 return mangle(c->c_private, name, buffer, maxlen);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
848 }
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
849
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
850 static void
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
851 com_addop_name(struct compiling *c, int op, char *name)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
852 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
853 PyObject *v;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
854 int i;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
855 char buffer[MANGLE_LEN];
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
856 /* fprintf(stderr, "com_addop_name(%s, %d, %s)\n",
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
857 c->c_name, op, name);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
858 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
859 if (com_mangle(c, name, buffer, sizeof(buffer)))
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
860 name = buffer;
5009
402e36c83d20 Intern all names and varnames in newcodeobject(), plus those string
Guido van Rossum <guido@python.org>
parents: 4991
diff changeset
861 if (name == NULL || (v = PyString_InternFromString(name)) == NULL) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
862 c->c_errors++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
863 i = 255;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
864 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
865 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
866 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
867 Py_DECREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
868 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
869 com_addoparg(c, op, i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
870 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
871
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
872 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
873 com_addop_varname(struct compiling *c, int kind, char *name)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
874 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
875 PyObject *v;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
876 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
877 int scope;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
878 int op = STOP_CODE;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
879 char buffer[MANGLE_LEN];
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
880
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
881 if (com_mangle(c, name, buffer, sizeof(buffer)))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
882 name = buffer;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
883 if (name == NULL || (v = PyString_InternFromString(name)) == NULL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
884 c->c_errors++;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
885 i = 255;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
886 goto done;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
887 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
888 scope = NAME_DEFAULT;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
889 if (c->c_symtable->st_cur_type == TYPE_FUNCTION && is_local(c, name)) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
890 scope = NAME_LOCAL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
891 } else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
892 int g = is_global(c, name);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
893 if ((g & EXPLICIT_GLOBAL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
894 || ((c->c_flags & CO_OPTIMIZED) && g))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
895 scope = NAME_GLOBAL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
896 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
897
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
898 /* XXX Test can probably be eliminated once we reach 2.1 beta 1 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
899 if (!(is_local(c, name) || is_global(c, name))) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
900 fprintf(stderr, "name: %s", name);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
901 fprintf(stderr, ", in %s, file '%s', line %d\n",
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
902 c->c_name, c->c_filename, c->c_lineno);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
903 fprintf(stderr, "locals: %s\n",
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
904 PyString_AS_STRING(PyObject_Repr(c->c_locals)));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
905 fprintf(stderr, "globals: %s\n",
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
906 PyString_AS_STRING(PyObject_Repr(c->c_globals)));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
907 Py_FatalError("compiler did not label name as local or global");
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
908 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
909
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
910 i = com_addname(c, v);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
911 if (scope == NAME_LOCAL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
912 PyObject *w = PyDict_GetItem(c->c_locals, v);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
913 if (w == NULL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
914 c->c_errors++;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
915 i = 255;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
916 goto done;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
917 } else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
918 i = PyInt_AsLong(w);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
919 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
920 Py_DECREF(v);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
921
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
922 switch (kind) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
923 case VAR_LOAD:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
924 switch (scope) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
925 case NAME_LOCAL:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
926 op = LOAD_FAST;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
927 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
928 case NAME_GLOBAL:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
929 op = LOAD_GLOBAL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
930 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
931 case NAME_DEFAULT:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
932 op = LOAD_NAME;
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
933 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
934 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
935 case VAR_STORE:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
936 switch (scope) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
937 case NAME_LOCAL:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
938 op = STORE_FAST;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
939 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
940 case NAME_GLOBAL:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
941 op = STORE_GLOBAL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
942 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
943 case NAME_DEFAULT:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
944 op = STORE_NAME;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
945 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
946 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
947 case VAR_DELETE:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
948 switch (scope) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
949 case NAME_LOCAL:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
950 op = DELETE_FAST;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
951 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
952 case NAME_GLOBAL:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
953 op = DELETE_GLOBAL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
954 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
955 case NAME_DEFAULT:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
956 op = DELETE_NAME;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
957 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
958 break;
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
959 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
960 done:
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
961 com_addoparg(c, op, i);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
962 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
963
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
964 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
965 com_addopname(struct compiling *c, int op, node *n)
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
966 {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
967 char *name;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
968 char buffer[1000];
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
969 /* 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
970 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
971 bothered right now */
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
972 if (TYPE(n) == STAR)
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
973 name = "*";
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
974 else if (TYPE(n) == dotted_name) {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
975 char *p = buffer;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
976 int i;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
977 name = buffer;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
978 for (i = 0; i < NCH(n); i += 2) {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
979 char *s = STR(CHILD(n, i));
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
980 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
981 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
982 "dotted_name too long");
2367
915fabec64a3 fix typo (== for =) in assignment
Guido van Rossum <guido@python.org>
parents: 2310
diff changeset
983 name = NULL;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
984 break;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
985 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
986 if (p != buffer)
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
987 *p++ = '.';
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
988 strcpy(p, s);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
989 p = strchr(p, '\0');
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
990 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
991 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
992 else {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
993 REQ(n, NAME);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
994 name = STR(n);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
995 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
996 com_addop_name(c, op, name);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
997 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
998
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
999 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1000 parsenumber(struct compiling *co, char *s)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1001 {
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1002 char *end;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1003 long x;
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5041
diff changeset
1004 double dx;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1005 #ifndef WITHOUT_COMPLEX
3766
516490c8192c Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents: 3366
diff changeset
1006 Py_complex c;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1007 int imflag;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1008 #endif
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1009
176
229168a2fe28 Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents: 160
diff changeset
1010 errno = 0;
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
1011 end = s + strlen(s) - 1;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1012 #ifndef WITHOUT_COMPLEX
3366
c25865884649 only use 'j' for imaginary constants
Guido van Rossum <guido@python.org>
parents: 3349
diff changeset
1013 imflag = *end == 'j' || *end == 'J';
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1014 #endif
744
834dd4a77ee2 fix what lint found
Guido van Rossum <guido@python.org>
parents: 703
diff changeset
1015 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
1016 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
1017 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
1018 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
1019 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1020 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
1021 if (*end == '\0') {
229168a2fe28 Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents: 160
diff changeset
1022 if (errno != 0) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1023 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
1024 "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
1025 return NULL;
229168a2fe28 Added error checking for numeric constants; added local/global variable
Guido van Rossum <guido@python.org>
parents: 160
diff changeset
1026 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1027 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
1028 }
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1029 /* XXX Huge floats may silently fail */
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1030 #ifndef WITHOUT_COMPLEX
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1031 if (imflag) {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1032 c.real = 0.;
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5041
diff changeset
1033 PyFPE_START_PROTECT("atof", return 0)
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1034 c.imag = atof(s);
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5183
diff changeset
1035 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
1036 return PyComplex_FromCComplex(c);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1037 }
6453
c9b139b9c5ff Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents: 6186
diff changeset
1038 else
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1039 #endif
6453
c9b139b9c5ff Fixed for WITHOUT_COMPLEX compilation (Jack)
Guido van Rossum <guido@python.org>
parents: 6186
diff changeset
1040 {
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5041
diff changeset
1041 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
1042 dx = atof(s);
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5183
diff changeset
1043 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
1044 return PyFloat_FromDouble(dx);
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5041
diff changeset
1045 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1046 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1047
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1048 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1049 parsestr(char *s)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1050 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1051 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
1052 size_t len;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1053 char *buf;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1054 char *p;
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1055 char *end;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1056 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
1057 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
1058 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
1059 int rawmode = 0;
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1060 int unicode = 0;
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1061 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
1062 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
1063 quote = *++s;
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1064 unicode = 1;
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1065 }
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1066 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
1067 quote = *++s;
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1068 rawmode = 1;
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1069 }
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1070 }
1364
132602d854d8 Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents: 1354
diff changeset
1071 if (quote != '\'' && quote != '\"') {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1072 PyErr_BadInternalCall();
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1073 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1074 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1075 s++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1076 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
1077 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
1078 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
1079 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
1080 }
1364
132602d854d8 Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents: 1354
diff changeset
1081 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
1082 PyErr_BadInternalCall();
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1083 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1084 }
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1085 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
1086 s += 2;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1087 len -= 2;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1088 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
1089 PyErr_BadInternalCall();
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1090 return NULL;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1091 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1092 }
12538
859e500f0760 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12522
diff changeset
1093 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
1094 if (rawmode)
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1095 return PyUnicode_DecodeRawUnicodeEscape(
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1096 s, len, NULL);
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1097 else
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1098 return PyUnicode_DecodeUnicodeEscape(
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1099 s, len, NULL);
28003afa1a2f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Guido van Rossum <guido@python.org>
parents: 11598
diff changeset
1100 }
14382
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1101 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
1102 return PyString_FromStringAndSize(s, len);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1103 v = PyString_FromStringAndSize((char *)NULL, len);
14382
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1104 if (v == NULL)
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1105 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1106 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
1107 end = s + len;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1108 while (s < end) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1109 if (*s != '\\') {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1110 *p++ = *s++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1111 continue;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1112 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1113 s++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1114 switch (*s++) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1115 /* 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
1116 case '\n': break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1117 case '\\': *p++ = '\\'; break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1118 case '\'': *p++ = '\''; break;
1364
132602d854d8 Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents: 1354
diff changeset
1119 case '\"': *p++ = '\"'; break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1120 case 'b': *p++ = '\b'; break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1121 case 'f': *p++ = '\014'; break; /* FF */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1122 case 't': *p++ = '\t'; break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1123 case 'n': *p++ = '\n'; break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1124 case 'r': *p++ = '\r'; break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1125 case 'v': *p++ = '\013'; break; /* VT */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1126 case 'a': *p++ = '\007'; break; /* BEL, not classic C */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1127 case '0': case '1': case '2': case '3':
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1128 case '4': case '5': case '6': case '7':
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1129 c = s[-1] - '0';
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1130 if ('0' <= *s && *s <= '7') {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1131 c = (c<<3) + *s++ - '0';
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1132 if ('0' <= *s && *s <= '7')
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1133 c = (c<<3) + *s++ - '0';
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1134 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1135 *p++ = c;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1136 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1137 case 'x':
14382
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1138 if (isxdigit(Py_CHARMASK(s[0])) && isxdigit(Py_CHARMASK(s[1]))) {
6501
9ef9cadd978c Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents: 6453
diff changeset
1139 unsigned int x = 0;
14382
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1140 c = Py_CHARMASK(*s);
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1141 s++;
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1142 if (isdigit(c))
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1143 x = c - '0';
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1144 else if (islower(c))
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1145 x = 10 + c - 'a';
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1146 else
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1147 x = 10 + c - 'A';
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1148 x = x << 4;
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1149 c = Py_CHARMASK(*s);
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1150 s++;
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1151 if (isdigit(c))
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1152 x += c - '0';
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1153 else if (islower(c))
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1154 x += 10 + c - 'a';
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1155 else
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1156 x += 10 + c - 'A';
6501
9ef9cadd978c Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
Guido van Rossum <guido@python.org>
parents: 6453
diff changeset
1157 *p++ = x;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1158 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1159 }
14382
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1160 PyErr_SetString(PyExc_ValueError, "invalid \\x escape");
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1161 Py_DECREF(v);
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1162 return NULL;
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1163 default:
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1164 *p++ = '\\';
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1165 *p++ = s[-1];
2d6cf68aa64a changed \x to consume exactly two hex digits. implements PEP-223
Fredrik Lundh <fredrik@pythonware.com>
parents: 14375
diff changeset
1166 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1167 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1168 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1169 _PyString_Resize(&v, (int)(p - buf));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1170 return v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1171 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1172
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1173 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1174 parsestrplus(node *n)
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1175 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1176 PyObject *v;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1177 int i;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1178 REQ(CHILD(n, 0), STRING);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1179 if ((v = parsestr(STR(CHILD(n, 0)))) != NULL) {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1180 /* String literal concatenation */
12388
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1181 for (i = 1; i < NCH(n); i++) {
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1182 PyObject *s;
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1183 s = parsestr(STR(CHILD(n, i)));
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1184 if (s == NULL)
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1185 goto onError;
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1186 if (PyString_Check(v) && PyString_Check(s)) {
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1187 PyString_ConcatAndDel(&v, s);
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1188 if (v == NULL)
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1189 goto onError;
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1190 }
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1191 else {
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1192 PyObject *temp;
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1193 temp = PyUnicode_Concat(v, s);
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1194 Py_DECREF(s);
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1195 if (temp == NULL)
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1196 goto onError;
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1197 Py_DECREF(v);
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1198 v = temp;
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1199 }
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1200 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1201 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1202 return v;
12388
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1203
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1204 onError:
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1205 Py_XDECREF(v);
c48172af13dc M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12333
diff changeset
1206 return NULL;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1207 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1208
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1209 static void
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1210 com_list_for(struct compiling *c, node *n, node *e, char *t)
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1211 {
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1212 PyObject *v;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1213 int anchor = 0;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1214 int save_begin = c->c_begin;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1215
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1216 /* list_iter: for v in expr [list_iter] */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1217 com_node(c, CHILD(n, 3)); /* expr */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1218 v = PyInt_FromLong(0L);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1219 if (v == NULL)
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1220 c->c_errors++;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1221 com_addoparg(c, LOAD_CONST, com_addconst(c, v));
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1222 com_push(c, 1);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1223 Py_XDECREF(v);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1224 c->c_begin = c->c_nexti;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1225 com_addoparg(c, SET_LINENO, n->n_lineno);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1226 com_addfwref(c, FOR_LOOP, &anchor);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1227 com_push(c, 1);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1228 com_assign(c, CHILD(n, 1), OP_ASSIGN, NULL);
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1229 c->c_loops++;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1230 com_list_iter(c, n, e, t);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1231 c->c_loops--;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1232 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1233 c->c_begin = save_begin;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1234 com_backpatch(c, anchor);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1235 com_pop(c, 2); /* FOR_LOOP has popped these */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1236 }
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1237
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1238 static void
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1239 com_list_if(struct compiling *c, node *n, node *e, char *t)
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1240 {
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1241 int anchor = 0;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1242 int a = 0;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1243 /* list_iter: 'if' test [list_iter] */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1244 com_addoparg(c, SET_LINENO, n->n_lineno);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1245 com_node(c, CHILD(n, 1));
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1246 com_addfwref(c, JUMP_IF_FALSE, &a);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1247 com_addbyte(c, POP_TOP);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1248 com_pop(c, 1);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1249 com_list_iter(c, n, e, t);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1250 com_addfwref(c, JUMP_FORWARD, &anchor);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1251 com_backpatch(c, a);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1252 /* We jump here with an extra entry which we now pop */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1253 com_addbyte(c, POP_TOP);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1254 com_backpatch(c, anchor);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1255 }
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1256
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1257 static void
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1258 com_list_iter(struct compiling *c,
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1259 node *p, /* parent of list_iter node */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1260 node *e, /* element expression node */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1261 char *t /* name of result list temp local */)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1262 {
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1263 /* list_iter is the last child in a listmaker, list_for, or list_if */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1264 node *n = CHILD(p, NCH(p)-1);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1265 if (TYPE(n) == list_iter) {
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1266 n = CHILD(n, 0);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1267 switch (TYPE(n)) {
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1268 case list_for:
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1269 com_list_for(c, n, e, t);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1270 break;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1271 case list_if:
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1272 com_list_if(c, n, e, t);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1273 break;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1274 default:
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1275 com_error(c, PyExc_SystemError,
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1276 "invalid list_iter node type");
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1277 }
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1278 }
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1279 else {
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
1280 com_addop_varname(c, VAR_LOAD, t);
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1281 com_push(c, 1);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1282 com_node(c, e);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1283 com_addoparg(c, CALL_FUNCTION, 1);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1284 com_addbyte(c, POP_TOP);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1285 com_pop(c, 2);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1286 }
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1287 }
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1288
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1289 static void
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1290 com_list_comprehension(struct compiling *c, node *n)
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1291 {
14117
ac8809959d01 require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents: 14105
diff changeset
1292 /* listmaker: test list_for */
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1293 char tmpname[12];
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
1294 sprintf(tmpname, "[%d]", ++c->c_tmpname);
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1295 com_addoparg(c, BUILD_LIST, 0);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1296 com_addbyte(c, DUP_TOP); /* leave the result on the stack */
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1297 com_push(c, 2);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
1298 com_addop_name(c, LOAD_ATTR, "append");
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
1299 com_addop_varname(c, VAR_STORE, tmpname);
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1300 com_pop(c, 1);
14117
ac8809959d01 require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents: 14105
diff changeset
1301 com_list_for(c, CHILD(n, 1), CHILD(n, 0), tmpname);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
1302 com_addop_varname(c, VAR_DELETE, tmpname);
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1303 --c->c_tmpname;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1304 }
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1305
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1306 static void
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1307 com_listmaker(struct compiling *c, node *n)
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1308 {
14117
ac8809959d01 require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents: 14105
diff changeset
1309 /* listmaker: test ( list_for | (',' test)* [','] ) */
ac8809959d01 require list comprehensions to start with a for clause
Skip Montanaro <skip@pobox.com>
parents: 14105
diff changeset
1310 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for)
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1311 com_list_comprehension(c, n);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1312 else {
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1313 int len = 0;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1314 int i;
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1315 for (i = 0; i < NCH(n); i += 2, len++)
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1316 com_node(c, CHILD(n, i));
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1317 com_addoparg(c, BUILD_LIST, len);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1318 com_pop(c, len-1);
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1319 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1320 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1321
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1322 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1323 com_dictmaker(struct compiling *c, node *n)
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1324 {
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1325 int i;
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1326 /* dictmaker: test ':' test (',' test ':' value)* [','] */
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1327 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
1328 /* 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
1329 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
1330 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
1331 com_push(c, 1);
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1332 com_node(c, CHILD(n, i+2)); /* value */
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1333 com_addbyte(c, ROT_TWO);
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1334 com_node(c, CHILD(n, i)); /* key */
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1335 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
1336 com_pop(c, 3);
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1337 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1338 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1339
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1340 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1341 com_atom(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1342 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1343 node *ch;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1344 PyObject *v;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1345 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1346 REQ(n, atom);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1347 ch = CHILD(n, 0);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1348 switch (TYPE(ch)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1349 case LPAR:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1350 if (TYPE(CHILD(n, 1)) == RPAR) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1351 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
1352 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
1353 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1354 else
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1355 com_node(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1356 break;
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1357 case LSQB: /* '[' [listmaker] ']' */
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1358 if (TYPE(CHILD(n, 1)) == RSQB) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1359 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
1360 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
1361 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1362 else
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1363 com_listmaker(c, CHILD(n, 1));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1364 break;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1365 case LBRACE: /* '{' [dictmaker] '}' */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1366 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
1367 com_push(c, 1);
13936
25fd9846bd54 list comprehensions. see
Skip Montanaro <skip@pobox.com>
parents: 13930
diff changeset
1368 if (TYPE(CHILD(n, 1)) == dictmaker)
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
1369 com_dictmaker(c, CHILD(n, 1));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1370 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1371 case BACKQUOTE:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1372 com_node(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1373 com_addbyte(c, UNARY_CONVERT);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1374 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1375 case NUMBER:
4315
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
1376 if ((v = parsenumber(c, STR(ch))) == NULL) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1377 i = 255;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1378 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1379 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1380 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
1381 Py_DECREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1382 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1383 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
1384 com_push(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1385 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1386 case STRING:
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1387 v = parsestrplus(n);
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
1388 if (v == NULL) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1389 c->c_errors++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1390 i = 255;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1391 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1392 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1393 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
1394 Py_DECREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1395 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1396 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
1397 com_push(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1398 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1399 case NAME:
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
1400 com_addop_varname(c, VAR_LOAD, STR(ch));
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1401 com_push(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1402 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1403 default:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1404 /* 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
1405 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
1406 "com_atom: unexpected node type");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1407 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1408 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1409
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
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_slice(struct compiling *c, node *n, int op)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1412 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1413 if (NCH(n) == 1) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1414 com_addbyte(c, op);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1415 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1416 else if (NCH(n) == 2) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1417 if (TYPE(CHILD(n, 0)) != COLON) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1418 com_node(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1419 com_addbyte(c, op+1);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1420 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1421 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1422 com_node(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1423 com_addbyte(c, op+2);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1424 }
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1425 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1426 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1427 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1428 com_node(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1429 com_node(c, CHILD(n, 2));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1430 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
1431 com_pop(c, 2);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1432 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1433 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1434
4905
32220c5728f5 Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
1435 static void
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1436 com_augassign_slice(struct compiling *c, node *n, int opcode, node *augn)
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1437 {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1438 if (NCH(n) == 1) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1439 com_addbyte(c, DUP_TOP);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1440 com_push(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1441 com_addbyte(c, SLICE);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1442 com_node(c, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1443 com_addbyte(c, opcode);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1444 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1445 com_addbyte(c, ROT_TWO);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1446 com_addbyte(c, STORE_SLICE);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1447 com_pop(c, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1448 } else if (NCH(n) == 2 && TYPE(CHILD(n, 0)) != COLON) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1449 com_node(c, CHILD(n, 0));
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1450 com_addoparg(c, DUP_TOPX, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1451 com_push(c, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1452 com_addbyte(c, SLICE+1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1453 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1454 com_node(c, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1455 com_addbyte(c, opcode);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1456 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1457 com_addbyte(c, ROT_THREE);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1458 com_addbyte(c, STORE_SLICE+1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1459 com_pop(c, 3);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1460 } else if (NCH(n) == 2) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1461 com_node(c, CHILD(n, 1));
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1462 com_addoparg(c, DUP_TOPX, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1463 com_push(c, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1464 com_addbyte(c, SLICE+2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1465 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1466 com_node(c, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1467 com_addbyte(c, opcode);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1468 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1469 com_addbyte(c, ROT_THREE);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1470 com_addbyte(c, STORE_SLICE+2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1471 com_pop(c, 3);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1472 } else {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1473 com_node(c, CHILD(n, 0));
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1474 com_node(c, CHILD(n, 2));
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1475 com_addoparg(c, DUP_TOPX, 3);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1476 com_push(c, 3);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1477 com_addbyte(c, SLICE+3);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1478 com_pop(c, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1479 com_node(c, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1480 com_addbyte(c, opcode);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1481 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1482 com_addbyte(c, ROT_FOUR);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1483 com_addbyte(c, STORE_SLICE+3);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1484 com_pop(c, 4);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1485 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1486 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1487
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1488 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1489 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
1490 {
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
1491 node *m;
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1492 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
1493 if (NCH(n) == 1) {
4905
32220c5728f5 Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
1494 if (*pkeywords != NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1495 com_error(c, PyExc_SyntaxError,
13993
716e1c4e3f78 When raising a SyntaxError, make a best-effort attempt to set the
Fred Drake <fdrake@acm.org>
parents: 13956
diff changeset
1496 "non-keyword arg after keyword arg");
2813
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2367
diff changeset
1497 }
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
1498 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
1499 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
1500 }
4905
32220c5728f5 Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
1501 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
1502 }
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
1503 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
1504 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
1505 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
1506 } 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
1507 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
1508 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
1509 "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
1510 }
999b5bdc18ce 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value))
Guido van Rossum <guido@python.org>
parents: 2367
diff changeset
1511 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1512 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
1513 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
1514 *pkeywords = PyDict_New();
4905
32220c5728f5 Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
1515 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
1516 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
1517 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1518 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
1519 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
1520 "duplicate keyword argument");
32220c5728f5 Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
1521 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1522 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
1523 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
1524 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
1525 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
1526 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
1527 }
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
1528 }
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
1529 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
1530 }
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
1531
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1532 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1533 com_call_function(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1534 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1535 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
1536 com_addoparg(c, CALL_FUNCTION, 0);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1537 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1538 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1539 PyObject *keywords = NULL;
4905
32220c5728f5 Check for duplicate keyword arguments at compile time.
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
1540 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
1541 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
1542 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
1543 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
1544 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
1545 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
1546 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
1547 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
1548 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
1549 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
1550 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
1551 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
1552 break;
9625
1fe48009d8ea Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents: 9293
diff changeset
1553 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
1554 lineno = ch->n_lineno;
1fe48009d8ea Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents: 9293
diff changeset
1555 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
1556 }
1fe48009d8ea Add more SET_LINENO instructions in long argument lists
Guido van Rossum <guido@python.org>
parents: 9293
diff changeset
1557 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
1558 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
1559 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
1560 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
1561 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
1562 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1563 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
1564 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
1565 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
1566 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
1567 i += 3;
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11974
diff changeset
1568 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
1569 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
1570 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
1571 }
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11974
diff changeset
1572 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
1573 }
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
1574 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
1575 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
1576 "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
1577 }
12082
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11974
diff changeset
1578 if (star_flag || starstar_flag)
12086
96ea1a800b23 remove reference (vestigal) to CALL_FUNCTION_STAR
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12082
diff changeset
1579 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
1580 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
1581 else
603db0d0aed1 slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11974
diff changeset
1582 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
1583 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
1584 com_pop(c, na + 2*nk + star_flag + starstar_flag);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1585 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1586 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1587
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1588 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1589 com_select_member(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1590 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1591 com_addopname(c, LOAD_ATTR, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1592 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1593
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1594 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1595 com_sliceobj(struct compiling *c, node *n)
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1596 {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1597 int i=0;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1598 int ns=2; /* number of slice arguments */
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1599 node *ch;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1600
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1601 /* first argument */
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1602 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
1603 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
1604 com_push(c, 1);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1605 i++;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1606 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1607 else {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1608 com_node(c, CHILD(n,i));
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1609 i++;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1610 REQ(CHILD(n,i),COLON);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1611 i++;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1612 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1613 /* second argument */
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1614 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
1615 com_node(c, CHILD(n,i));
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1616 i++;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1617 }
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1618 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1619 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
1620 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
1621 }
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1622 /* remaining arguments */
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1623 for (; i < NCH(n); i++) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1624 ns++;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1625 ch=CHILD(n,i);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1626 REQ(ch, sliceop);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1627 if (NCH(ch) == 1) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1628 /* 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
1629 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
1630 com_push(c, 1);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1631 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1632 else
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1633 com_node(c, CHILD(ch,1));
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1634 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1635 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
1636 com_pop(c, 1 + (ns == 3));
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1637 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1638
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1639 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1640 com_subscript(struct compiling *c, node *n)
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1641 {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1642 node *ch;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1643 REQ(n, subscript);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1644 ch = CHILD(n,0);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1645 /* 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
1646 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
1647 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
1648 com_push(c, 1);
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1649 }
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1650 else {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1651 /* check for slice */
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1652 if ((TYPE(ch) == COLON || NCH(n) > 1))
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1653 com_sliceobj(c, n);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1654 else {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1655 REQ(ch, test);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1656 com_node(c, ch);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1657 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1658 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1659 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1660
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1661 static void
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1662 com_subscriptlist(struct compiling *c, node *n, int assigning, node *augn)
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1663 {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1664 int i, op;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1665 REQ(n, subscriptlist);
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1666 /* 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
1667 if (NCH(n) == 1) {
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1668 node *sub = CHILD(n, 0); /* subscript */
13873
d014c8ab6a82 Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents: 13658
diff changeset
1669 /* 'Basic' slice, should have exactly one colon. */
d014c8ab6a82 Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents: 13658
diff changeset
1670 if ((TYPE(CHILD(sub, 0)) == COLON
d014c8ab6a82 Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents: 13658
diff changeset
1671 || (NCH(sub) > 1 && TYPE(CHILD(sub, 1)) == COLON))
d014c8ab6a82 Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents: 13658
diff changeset
1672 && (TYPE(CHILD(sub,NCH(sub)-1)) != sliceop))
d014c8ab6a82 Fix some strange indentation and grammar that have been bugging me for
Thomas Wouters <thomas@python.org>
parents: 13658
diff changeset
1673 {
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1674 switch (assigning) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1675 case OP_DELETE:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1676 op = DELETE_SLICE;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1677 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1678 case OP_ASSIGN:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1679 op = STORE_SLICE;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1680 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1681 case OP_APPLY:
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1682 op = SLICE;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1683 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1684 default:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1685 com_augassign_slice(c, sub, assigning, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1686 return;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1687 }
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1688 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
1689 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
1690 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
1691 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
1692 com_pop(c, 1);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1693 return;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1694 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1695 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1696 /* Else normal subscriptlist. Compile each subscript. */
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1697 for (i = 0; i < NCH(n); i += 2)
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1698 com_subscript(c, CHILD(n, i));
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1699 /* 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
1700 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
1701 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
1702 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
1703 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
1704 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1705 switch (assigning) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1706 case OP_DELETE:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1707 op = DELETE_SUBSCR;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1708 i = 2;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1709 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1710 default:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1711 case OP_ASSIGN:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1712 op = STORE_SUBSCR;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1713 i = 3;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1714 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1715 case OP_APPLY:
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1716 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
1717 i = 1;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1718 break;
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1719 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1720 if (assigning > OP_APPLY) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1721 com_addoparg(c, DUP_TOPX, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1722 com_push(c, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1723 com_addbyte(c, BINARY_SUBSCR);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1724 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1725 com_node(c, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1726 com_addbyte(c, assigning);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1727 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1728 com_addbyte(c, ROT_THREE);
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
1729 }
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1730 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
1731 com_pop(c, i);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1732 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1733
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1734 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1735 com_apply_trailer(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1736 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1737 REQ(n, trailer);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1738 switch (TYPE(CHILD(n, 0))) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1739 case LPAR:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1740 com_call_function(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1741 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1742 case DOT:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1743 com_select_member(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1744 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1745 case LSQB:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
1746 com_subscriptlist(c, CHILD(n, 1), OP_APPLY, NULL);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1747 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1748 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1749 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
1750 "com_apply_trailer: unknown trailer type");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1751 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1752 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1753
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1754 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1755 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
1756 {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1757 int i;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1758 REQ(n, power);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1759 com_atom(c, CHILD(n, 0));
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1760 for (i = 1; i < NCH(n); i++) {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1761 if (TYPE(CHILD(n, i)) == DOUBLESTAR) {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1762 com_factor(c, CHILD(n, i+1));
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1763 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
1764 com_pop(c, 1);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1765 break;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1766 }
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1767 else
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1768 com_apply_trailer(c, CHILD(n, i));
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1769 }
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1770 }
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1771
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1772 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1773 com_factor(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1774 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1775 REQ(n, factor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1776 if (TYPE(CHILD(n, 0)) == PLUS) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1777 com_factor(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1778 com_addbyte(c, UNARY_POSITIVE);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1779 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1780 else if (TYPE(CHILD(n, 0)) == MINUS) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1781 com_factor(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1782 com_addbyte(c, UNARY_NEGATIVE);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1783 }
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1784 else if (TYPE(CHILD(n, 0)) == TILDE) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1785 com_factor(c, CHILD(n, 1));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1786 com_addbyte(c, UNARY_INVERT);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1787 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1788 else {
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
1789 com_power(c, CHILD(n, 0));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1790 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1791 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1792
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1793 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1794 com_term(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1795 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1796 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1797 int op;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1798 REQ(n, term);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1799 com_factor(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1800 for (i = 2; i < NCH(n); i += 2) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1801 com_factor(c, CHILD(n, i));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1802 switch (TYPE(CHILD(n, i-1))) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1803 case STAR:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1804 op = BINARY_MULTIPLY;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1805 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1806 case SLASH:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1807 op = BINARY_DIVIDE;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1808 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1809 case PERCENT:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1810 op = BINARY_MODULO;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1811 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1812 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1813 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
1814 "com_term: operator not *, / or %");
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1815 op = 255;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1816 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1817 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
1818 com_pop(c, 1);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1819 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1820 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1821
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1822 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1823 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
1824 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1825 int i;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1826 int op;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1827 REQ(n, arith_expr);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1828 com_term(c, CHILD(n, 0));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1829 for (i = 2; i < NCH(n); i += 2) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1830 com_term(c, CHILD(n, i));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1831 switch (TYPE(CHILD(n, i-1))) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1832 case PLUS:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1833 op = BINARY_ADD;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1834 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1835 case MINUS:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1836 op = BINARY_SUBTRACT;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1837 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1838 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1839 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
1840 "com_arith_expr: operator not + or -");
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1841 op = 255;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1842 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1843 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
1844 com_pop(c, 1);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1845 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1846 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1847
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1848 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1849 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
1850 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1851 int i;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1852 int op;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1853 REQ(n, shift_expr);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1854 com_arith_expr(c, CHILD(n, 0));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1855 for (i = 2; i < NCH(n); i += 2) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1856 com_arith_expr(c, CHILD(n, i));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1857 switch (TYPE(CHILD(n, i-1))) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1858 case LEFTSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1859 op = BINARY_LSHIFT;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1860 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1861 case RIGHTSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1862 op = BINARY_RSHIFT;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1863 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1864 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1865 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
1866 "com_shift_expr: operator not << or >>");
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1867 op = 255;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1868 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1869 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
1870 com_pop(c, 1);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1871 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1872 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1873
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1874 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1875 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
1876 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1877 int i;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1878 int op;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1879 REQ(n, and_expr);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1880 com_shift_expr(c, CHILD(n, 0));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1881 for (i = 2; i < NCH(n); i += 2) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1882 com_shift_expr(c, CHILD(n, i));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1883 if (TYPE(CHILD(n, i-1)) == AMPER) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1884 op = BINARY_AND;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1885 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1886 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1887 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
1888 "com_and_expr: operator not &");
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1889 op = 255;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1890 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1891 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
1892 com_pop(c, 1);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1893 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1894 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1895
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1896 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1897 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
1898 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1899 int i;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1900 int op;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1901 REQ(n, xor_expr);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1902 com_and_expr(c, CHILD(n, 0));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1903 for (i = 2; i < NCH(n); i += 2) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1904 com_and_expr(c, CHILD(n, i));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1905 if (TYPE(CHILD(n, i-1)) == CIRCUMFLEX) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1906 op = BINARY_XOR;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1907 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1908 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1909 com_error(c, PyExc_SystemError,
4315
46d736fb9da3 Added line number to most compile-time error messages.
Guido van Rossum <guido@python.org>
parents: 4131
diff changeset
1910 "com_xor_expr: operator not ^");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1911 op = 255;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1912 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1913 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
1914 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1915 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1916 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1917
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1918 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1919 com_expr(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1920 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1921 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1922 int op;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1923 REQ(n, expr);
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1924 com_xor_expr(c, CHILD(n, 0));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1925 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
1926 com_xor_expr(c, CHILD(n, i));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1927 if (TYPE(CHILD(n, i-1)) == VBAR) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1928 op = BINARY_OR;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1929 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
1930 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1931 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
1932 "com_expr: expr operator not |");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1933 op = 255;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1934 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1935 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
1936 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1937 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1938 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1939
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1940 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
1941 cmp_type(node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1942 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1943 REQ(n, comp_op);
388
31d509e94271 Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents: 336
diff changeset
1944 /* comp_op: '<' | '>' | '=' | '>=' | '<=' | '<>' | '!=' | '=='
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1945 | 'in' | 'not' 'in' | 'is' | 'is' not' */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1946 if (NCH(n) == 1) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1947 n = CHILD(n, 0);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1948 switch (TYPE(n)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1949 case LESS: return LT;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1950 case GREATER: return GT;
388
31d509e94271 Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents: 336
diff changeset
1951 case EQEQUAL: /* == */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1952 case EQUAL: return EQ;
388
31d509e94271 Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents: 336
diff changeset
1953 case LESSEQUAL: return LE;
31d509e94271 Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents: 336
diff changeset
1954 case GREATEREQUAL: return GE;
31d509e94271 Comment out 'abort()' call.
Guido van Rossum <guido@python.org>
parents: 336
diff changeset
1955 case NOTEQUAL: return NE; /* <> or != */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1956 case NAME: if (strcmp(STR(n), "in") == 0) return IN;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1957 if (strcmp(STR(n), "is") == 0) return IS;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1958 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1959 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1960 else if (NCH(n) == 2) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1961 switch (TYPE(CHILD(n, 0))) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1962 case NAME: if (strcmp(STR(CHILD(n, 1)), "in") == 0)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1963 return NOT_IN;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1964 if (strcmp(STR(CHILD(n, 0)), "is") == 0)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1965 return IS_NOT;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1966 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1967 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1968 return BAD;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1969 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1970
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1971 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
1972 com_comparison(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1973 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1974 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1975 enum cmp_op op;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1976 int anchor;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1977 REQ(n, comparison); /* comparison: expr (comp_op expr)* */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1978 com_expr(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1979 if (NCH(n) == 1)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1980 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1981
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1982 /****************************************************************
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1983 The following code is generated for all but the last
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1984 comparison in a chain:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1985
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1986 label: on stack: opcode: jump to:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1987
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1988 a <code to load b>
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1989 a, b DUP_TOP
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1990 a, b, b ROT_THREE
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1991 b, a, b COMPARE_OP
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1992 b, 0-or-1 JUMP_IF_FALSE L1
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1993 b, 1 POP_TOP
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1994 b
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1995
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1996 We are now ready to repeat this sequence for the next
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1997 comparison in the chain.
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1998
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1999 For the last we generate:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2000
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2001 b <code to load c>
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2002 b, c COMPARE_OP
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2003 0-or-1
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2004
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2005 If there were any jumps to L1 (i.e., there was more than one
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2006 comparison), we generate:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2007
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2008 0-or-1 JUMP_FORWARD L2
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2009 L1: b, 0 ROT_TWO
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2010 0, b POP_TOP
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2011 0
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2012 L2: 0-or-1
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2013 ****************************************************************/
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2014
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2015 anchor = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2016
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2017 for (i = 2; i < NCH(n); i += 2) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2018 com_expr(c, CHILD(n, i));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2019 if (i+2 < NCH(n)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2020 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
2021 com_push(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2022 com_addbyte(c, ROT_THREE);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2023 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2024 op = cmp_type(CHILD(n, i-1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2025 if (op == BAD) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2026 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
2027 "com_comparison: unknown comparison op");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2028 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2029 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
2030 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2031 if (i+2 < NCH(n)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2032 com_addfwref(c, JUMP_IF_FALSE, &anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2033 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
2034 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2035 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2036 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2037
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2038 if (anchor) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2039 int anchor2 = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2040 com_addfwref(c, JUMP_FORWARD, &anchor2);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2041 com_backpatch(c, anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2042 com_addbyte(c, ROT_TWO);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2043 com_addbyte(c, POP_TOP);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2044 com_backpatch(c, anchor2);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2045 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2046 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2047
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2048 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2049 com_not_test(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2050 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2051 REQ(n, not_test); /* 'not' not_test | comparison */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2052 if (NCH(n) == 1) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2053 com_comparison(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2054 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2055 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2056 com_not_test(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2057 com_addbyte(c, UNARY_NOT);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2058 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2059 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2060
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2061 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2062 com_and_test(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2063 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2064 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2065 int anchor;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2066 REQ(n, and_test); /* not_test ('and' not_test)* */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2067 anchor = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2068 i = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2069 for (;;) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2070 com_not_test(c, CHILD(n, i));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2071 if ((i += 2) >= NCH(n))
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2072 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2073 com_addfwref(c, JUMP_IF_FALSE, &anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2074 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
2075 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2076 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2077 if (anchor)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2078 com_backpatch(c, anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2079 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2080
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2081 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2082 com_test(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2083 {
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2084 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
2085 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
2086 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
2087 int i;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2088 int ndefs = com_argdefs(c, CHILD(n, 0));
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2089 symtable_enter_scope(c->c_symtable, "lambda", lambdef);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2090 v = (PyObject *) icompile(CHILD(n, 0), c);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2091 symtable_exit_scope(c->c_symtable);
1417
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2092 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
2093 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
2094 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
2095 }
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2096 else {
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2097 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
2098 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
2099 }
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2100 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
2101 com_push(c, 1);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
2102 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
2103 com_pop(c, ndefs);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2104 }
1417
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2105 else {
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2106 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
2107 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
2108 for (;;) {
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2109 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
2110 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
2111 break;
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2112 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
2113 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
2114 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
2115 }
f7edfa6d0dcb change syntactical position of lambdef (was an atom, now is a test)
Guido van Rossum <guido@python.org>
parents: 1415
diff changeset
2116 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
2117 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
2118 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2119 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2120
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2121 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2122 com_list(struct compiling *c, node *n, int toplevel)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2123 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2124 /* exprlist: expr (',' expr)* [',']; likewise for testlist */
482
ee899a81570d New argument passing.
Guido van Rossum <guido@python.org>
parents: 466
diff changeset
2125 if (NCH(n) == 1 && !toplevel) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2126 com_node(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2127 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2128 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2129 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2130 int len;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2131 len = (NCH(n) + 1) / 2;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2132 for (i = 0; i < NCH(n); i += 2)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2133 com_node(c, CHILD(n, i));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2134 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
2135 com_pop(c, len-1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2136 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2137 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2138
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2139
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2140 /* Begin of assignment compilation */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2141
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2142
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2143 static void
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2144 com_augassign_attr(struct compiling *c, node *n, int opcode, node *augn)
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2145 {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2146 com_addbyte(c, DUP_TOP);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2147 com_push(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2148 com_addopname(c, LOAD_ATTR, n);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2149 com_node(c, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2150 com_addbyte(c, opcode);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2151 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2152 com_addbyte(c, ROT_TWO);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2153 com_addopname(c, STORE_ATTR, n);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2154 com_pop(c, 2);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2155 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2156
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2157 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2158 com_assign_attr(struct compiling *c, node *n, int assigning)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2159 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2160 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
2161 com_pop(c, assigning ? 2 : 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2162 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2163
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2164 static void
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2165 com_assign_trailer(struct compiling *c, node *n, int assigning, node *augn)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2166 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2167 REQ(n, trailer);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2168 switch (TYPE(CHILD(n, 0))) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2169 case LPAR: /* '(' [exprlist] ')' */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2170 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
2171 "can't assign to function call");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2172 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2173 case DOT: /* '.' NAME */
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2174 if (assigning > OP_APPLY)
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2175 com_augassign_attr(c, CHILD(n, 1), assigning, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2176 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2177 com_assign_attr(c, CHILD(n, 1), assigning);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2178 break;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
2179 case LSQB: /* '[' subscriptlist ']' */
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2180 com_subscriptlist(c, CHILD(n, 1), assigning, augn);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2181 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2182 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2183 com_error(c, PyExc_SystemError, "unknown trailer type");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2184 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2185 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2186
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2187 static void
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13884
diff changeset
2188 com_assign_sequence(struct compiling *c, node *n, int assigning)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2189 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2190 int i;
14178
dff22d4a48da Fix allowable node-types for assignment, need to add 'listmaker'.
Thomas Wouters <thomas@python.org>
parents: 14163
diff changeset
2191 if (TYPE(n) != testlist && TYPE(n) != listmaker)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2192 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
2193 if (assigning) {
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2194 i = (NCH(n)+1)/2;
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13884
diff changeset
2195 com_addoparg(c, UNPACK_SEQUENCE, i);
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2196 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
2197 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2198 for (i = 0; i < NCH(n); i += 2)
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2199 com_assign(c, CHILD(n, i), assigning, NULL);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2200 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2201
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2202 static void
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2203 com_augassign_name(struct compiling *c, node *n, int opcode, node *augn)
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2204 {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2205 REQ(n, NAME);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2206 com_addop_varname(c, VAR_LOAD, STR(n));
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2207 com_push(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2208 com_node(c, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2209 com_addbyte(c, opcode);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2210 com_pop(c, 1);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2211 com_assign_name(c, n, OP_ASSIGN);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2212 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2213
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2214 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2215 com_assign_name(struct compiling *c, node *n, int assigning)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2216 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2217 REQ(n, NAME);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2218 com_addop_varname(c, assigning ? VAR_STORE : VAR_DELETE, STR(n));
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2219 if (assigning)
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2220 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2221 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2222
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2223 static void
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2224 com_assign(struct compiling *c, node *n, int assigning, node *augn)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2225 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2226 /* Loop to avoid trivial recursion */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2227 for (;;) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2228 switch (TYPE(n)) {
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2229
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2230 case exprlist:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2231 case testlist:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2232 if (NCH(n) > 1) {
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2233 if (assigning > OP_APPLY) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2234 com_error(c, PyExc_SyntaxError,
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2235 "augmented assign to tuple not possible");
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2236 return;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2237 }
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13884
diff changeset
2238 com_assign_sequence(c, n, assigning);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2239 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2240 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2241 n = CHILD(n, 0);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2242 break;
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2243
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2244 case test:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2245 case and_test:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2246 case not_test:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2247 case comparison:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2248 case expr:
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
2249 case xor_expr:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
2250 case and_expr:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
2251 case shift_expr:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
2252 case arith_expr:
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2253 case term:
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
2254 case factor:
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2255 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
2256 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
2257 "can't assign to operator");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2258 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2259 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2260 n = CHILD(n, 0);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2261 break;
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2262
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
2263 case power: /* atom trailer* ('**' power)* */
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
2264 /* ('+'|'-'|'~') factor | atom trailer* */
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
2265 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
2266 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
2267 "can't assign to operator");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2268 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2269 }
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
2270 if (NCH(n) > 1) { /* trailer or exponent present */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2271 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2272 com_node(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2273 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
2274 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
2275 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
2276 "can't assign to operator");
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
2277 return;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
2278 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2279 com_apply_trailer(c, CHILD(n, i));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2280 } /* NB i is still alive */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2281 com_assign_trailer(c,
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2282 CHILD(n, i), assigning, augn);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2283 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2284 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2285 n = CHILD(n, 0);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2286 break;
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2287
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2288 case atom:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2289 switch (TYPE(CHILD(n, 0))) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2290 case LPAR:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2291 n = CHILD(n, 1);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2292 if (TYPE(n) == RPAR) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2293 /* XXX Should allow () = () ??? */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2294 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
2295 "can't assign to ()");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2296 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2297 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2298 if (assigning > OP_APPLY) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2299 com_error(c, PyExc_SyntaxError,
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2300 "augmented assign to tuple not possible");
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2301 return;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2302 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2303 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2304 case LSQB:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2305 n = CHILD(n, 1);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2306 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
2307 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
2308 "can't assign to []");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2309 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2310 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2311 if (assigning > OP_APPLY) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2312 com_error(c, PyExc_SyntaxError,
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2313 "augmented assign to list not possible");
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2314 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2315 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2316 if (NCH(n) > 1
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2317 && TYPE(CHILD(n, 1)) == list_for) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2318 com_error(c, PyExc_SyntaxError,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2319 "can't assign to list comprehension");
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2320 return;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2321 }
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13884
diff changeset
2322 com_assign_sequence(c, n, assigning);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2323 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2324 case NAME:
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2325 if (assigning > OP_APPLY)
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2326 com_augassign_name(c, CHILD(n, 0),
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2327 assigning, augn);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2328 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2329 com_assign_name(c, CHILD(n, 0),
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2330 assigning);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2331 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2332 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2333 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
2334 "can't assign to literal");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2335 return;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2336 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2337 break;
3963
00722990b80c Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2338
00722990b80c Removed unused var; added error check for ``lambda: x=1''.
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
2339 case lambdef:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2340 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
2341 "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
2342 return;
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2343
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2344 default:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2345 /* 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
2346 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
2347 "com_assign: bad node");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2348 return;
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2349
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2350 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2351 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2352 }
5181
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2353
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2354 static void
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2355 com_augassign(struct compiling *c, node *n)
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2356 {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2357 int opcode;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2358
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2359 switch (STR(CHILD(CHILD(n, 1), 0))[0]) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2360 case '+': opcode = INPLACE_ADD; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2361 case '-': opcode = INPLACE_SUBTRACT; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2362 case '/': opcode = INPLACE_DIVIDE; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2363 case '%': opcode = INPLACE_MODULO; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2364 case '<': opcode = INPLACE_LSHIFT; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2365 case '>': opcode = INPLACE_RSHIFT; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2366 case '&': opcode = INPLACE_AND; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2367 case '^': opcode = INPLACE_XOR; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2368 case '|': opcode = INPLACE_OR; break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2369 case '*':
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2370 if (STR(CHILD(CHILD(n, 1), 0))[1] == '*')
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2371 opcode = INPLACE_POWER;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2372 else
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2373 opcode = INPLACE_MULTIPLY;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2374 break;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2375 default:
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2376 com_error(c, PyExc_SystemError, "com_augassign: bad operator");
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2377 return;
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2378 }
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2379 com_assign(c, CHILD(n, 0), opcode, CHILD(n, 2));
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2380 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2381
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2382 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2383 com_expr_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2384 {
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2385 REQ(n, expr_stmt);
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2386 /* testlist (('=' testlist)* | augassign testlist) */
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2387 /* 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
2388 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
2389 return;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2390 if (NCH(n) == 1) {
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2391 com_node(c, CHILD(n, NCH(n)-1));
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2392 if (c->c_interactive)
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2393 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
2394 else
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);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2397 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2398 else if (TYPE(CHILD(n,1)) == augassign)
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2399 com_augassign(c, n);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2400 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2401 int i;
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2402 com_node(c, CHILD(n, NCH(n)-1));
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2403 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
2404 if (i+2 < NCH(n)-2) {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2405 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
2406 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
2407 }
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2408 com_assign(c, CHILD(n, i), OP_ASSIGN, NULL);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2409 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2410 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2411 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2412
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2413 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2414 com_assert_stmt(struct compiling *c, node *n)
5233
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2415 {
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2416 int a = 0, b = 0;
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2417 int i;
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2418 REQ(n, assert_stmt); /* 'assert' test [',' test] */
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2419 /* Generate code like for
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2420
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2421 if __debug__:
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2422 if not <test>:
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2423 raise AssertionError [, <message>]
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2424
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2425 where <message> is the second test, if present.
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2426 */
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2427
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2428 /* XXX should __debug__ and AssertionError get inserted into
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2429 the symbol table? they don't follow the normal rules
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2430 because they are always loaded as globals */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2431
5233
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2432 if (Py_OptimizeFlag)
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2433 return;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2434 com_addop_name(c, LOAD_GLOBAL, "__debug__");
5233
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2435 com_push(c, 1);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2436 com_addfwref(c, JUMP_IF_FALSE, &a);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2437 com_addbyte(c, POP_TOP);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2438 com_pop(c, 1);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2439 com_node(c, CHILD(n, 1));
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2440 com_addfwref(c, JUMP_IF_TRUE, &b);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2441 com_addbyte(c, POP_TOP);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2442 com_pop(c, 1);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2443 /* Raise that exception! */
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2444 com_addop_name(c, LOAD_GLOBAL, "AssertionError");
5233
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2445 com_push(c, 1);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2446 i = NCH(n)/2; /* Either 2 or 4 */
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2447 if (i > 1)
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2448 com_node(c, CHILD(n, 3));
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2449 com_addoparg(c, RAISE_VARARGS, i);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2450 com_pop(c, i);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2451 /* The interpreter does not fall through */
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2452 /* All jumps converge here */
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2453 com_backpatch(c, a);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2454 com_backpatch(c, b);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2455 com_addbyte(c, POP_TOP);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2456 }
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2457
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
2458 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2459 com_print_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2460 {
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2461 int i = 1;
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2462 node* stream = NULL;
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2463
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2464 REQ(n, print_stmt); /* 'print' (test ',')* [test] */
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2465
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2466 /* are we using the extended print form? */
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2467 if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) {
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2468 stream = CHILD(n, 2);
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2469 com_node(c, stream);
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2470 /* stack: [...] => [... stream] */
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2471 com_push(c, 1);
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2472 if (NCH(n) > 3 && TYPE(CHILD(n, 3)) == COMMA)
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2473 i = 4;
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2474 else
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2475 i = 3;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2476 }
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2477 for (; i < NCH(n); i += 2) {
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2478 if (stream != NULL) {
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2479 com_addbyte(c, DUP_TOP);
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2480 /* stack: [stream] => [stream stream] */
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2481 com_push(c, 1);
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2482 com_node(c, CHILD(n, i));
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2483 /* stack: [stream stream] => [stream stream obj] */
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2484 com_addbyte(c, ROT_TWO);
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2485 /* stack: [stream stream obj] => [stream obj stream] */
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2486 com_addbyte(c, PRINT_ITEM_TO);
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2487 /* stack: [stream obj stream] => [stream] */
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2488 com_pop(c, 2);
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2489 }
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2490 else {
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2491 com_node(c, CHILD(n, i));
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2492 /* stack: [...] => [... obj] */
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2493 com_addbyte(c, PRINT_ITEM);
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2494 com_pop(c, 1);
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2495 }
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2496 }
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2497 /* XXX Alternatively, LOAD_CONST '\n' and then PRINT_ITEM */
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2498 if (TYPE(CHILD(n, NCH(n)-1)) == COMMA) {
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2499 if (stream != NULL) {
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2500 /* must pop the extra stream object off the stack */
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2501 com_addbyte(c, POP_TOP);
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2502 /* stack: [... stream] => [...] */
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2503 com_pop(c, 1);
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2504 }
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2505 }
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2506 else {
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2507 if (stream != NULL) {
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2508 /* this consumes the last stream object on stack */
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2509 com_addbyte(c, PRINT_NEWLINE_TO);
14105
d809b9b75b99 com_print_stmt(): Guido rightly points out that the stream expression
Barry Warsaw <barry@python.org>
parents: 14099
diff changeset
2510 /* stack: [... stream] => [...] */
14099
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2511 com_pop(c, 1);
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2512 }
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2513 else
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2514 com_addbyte(c, PRINT_NEWLINE);
468481135c49 PEP 214, Extended print Statement, has been accepted by the BDFL.
Barry Warsaw <barry@python.org>
parents: 14077
diff changeset
2515 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2516 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2517
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2518 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2519 com_return_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2520 {
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2521 REQ(n, return_stmt); /* 'return' [testlist] */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2522 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
2523 com_error(c, PyExc_SyntaxError, "'return' outside function");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2524 }
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2525 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
2526 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
2527 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
2528 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2529 else
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2530 com_node(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2531 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
2532 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2533 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2534
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2535 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2536 com_raise_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2537 {
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2538 int i;
7946
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2539 REQ(n, raise_stmt); /* 'raise' [test [',' test [',' test]]] */
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2540 if (NCH(n) > 1) {
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2541 com_node(c, CHILD(n, 1));
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2542 if (NCH(n) > 3) {
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2543 com_node(c, CHILD(n, 3));
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2544 if (NCH(n) > 5)
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2545 com_node(c, CHILD(n, 5));
ad114620f8c2 Make first raise argument optional
Guido van Rossum <guido@python.org>
parents: 6501
diff changeset
2546 }
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
2547 }
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2548 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
2549 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
2550 com_pop(c, i);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2551 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2552
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2553 static void
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2554 com_from_import(struct compiling *c, node *n)
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2555 {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2556 com_addopname(c, IMPORT_FROM, CHILD(n, 0));
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2557 com_push(c, 1);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2558 if (NCH(n) > 1) {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2559 if (strcmp(STR(CHILD(n, 1)), "as") != 0) {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2560 com_error(c, PyExc_SyntaxError, "invalid syntax");
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2561 return;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2562 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2563 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 2)));
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2564 } else
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2565 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 0)));
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2566 com_pop(c, 1);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2567 }
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2568
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2569 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2570 com_import_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2571 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2572 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2573 REQ(n, import_stmt);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2574 /* 'import' dotted_name (',' dotted_name)* |
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2575 'from' dotted_name 'import' ('*' | NAME (',' NAME)*) */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2576 if (STR(CHILD(n, 0))[0] == 'f') {
15438
433458651eb4 Plug a memory leak in com_import_stmt(): the tuple created to hold the
Guido van Rossum <guido@python.org>
parents: 15408
diff changeset
2577 PyObject *tup;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2578 /* 'from' dotted_name 'import' ... */
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
2579 REQ(CHILD(n, 1), dotted_name);
14232
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2580
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2581 if (TYPE(CHILD(n, 3)) == STAR) {
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2582 tup = Py_BuildValue("(s)", "*");
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2583 } else {
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2584 tup = PyTuple_New((NCH(n) - 2)/2);
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2585 for (i = 3; i < NCH(n); i += 2) {
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2586 PyTuple_SET_ITEM(tup, (i-3)/2,
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2587 PyString_FromString(STR(
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2588 CHILD(CHILD(n, i), 0))));
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2589 }
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2590 }
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2591 com_addoparg(c, LOAD_CONST, com_addconst(c, tup));
15438
433458651eb4 Plug a memory leak in com_import_stmt(): the tuple created to hold the
Guido van Rossum <guido@python.org>
parents: 15408
diff changeset
2592 Py_DECREF(tup);
14232
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2593 com_push(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2594 com_addopname(c, IMPORT_NAME, CHILD(n, 1));
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2595 if (TYPE(CHILD(n, 3)) == STAR)
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2596 com_addbyte(c, IMPORT_STAR);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2597 else {
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2598 for (i = 3; i < NCH(n); i += 2)
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2599 com_from_import(c, CHILD(n, i));
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2600 com_addbyte(c, POP_TOP);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2601 }
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2602 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2603 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2604 else {
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2605 /* 'import' ... */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2606 for (i = 1; i < NCH(n); i += 2) {
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2607 node *subn = CHILD(n, i);
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2608 REQ(subn, dotted_as_name);
14232
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2609 com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None));
1f1a156ed5af Replace the run-time 'future-bytecode-stream-inspection' hack to find out
Thomas Wouters <thomas@python.org>
parents: 14230
diff changeset
2610 com_push(c, 1);
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2611 com_addopname(c, IMPORT_NAME, CHILD(subn, 0));
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2612 if (NCH(subn) > 1) {
14230
31925ab46b23 Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents: 14226
diff changeset
2613 int j;
31925ab46b23 Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents: 14226
diff changeset
2614 if (strcmp(STR(CHILD(subn, 1)), "as") != 0) {
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2615 com_error(c, PyExc_SyntaxError,
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2616 "invalid syntax");
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2617 return;
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2618 }
14230
31925ab46b23 Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents: 14226
diff changeset
2619 for (j=2 ; j < NCH(CHILD(subn, 0)); j += 2)
31925ab46b23 Re-allow 'import mod.submod as s', and change its meaning to what it should
Thomas Wouters <thomas@python.org>
parents: 14226
diff changeset
2620 com_addopname(c, LOAD_ATTR,
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2621 CHILD(CHILD(subn, 0),
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2622 j));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2623 com_addop_varname(c, VAR_STORE,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2624 STR(CHILD(subn, 2)));
14038
18385172fac0 Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents: 13997
diff changeset
2625 } else
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2626 com_addop_varname(c, VAR_STORE,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2627 STR(CHILD(CHILD(subn, 0),
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2628 0)));
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2629 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2630 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2631 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2632 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2633
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2634 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2635 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
2636 {
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2637 REQ(n, exec_stmt);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2638 /* 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
2639 com_node(c, CHILD(n, 1));
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2640 if (NCH(n) >= 4)
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2641 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
2642 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2643 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
2644 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
2645 }
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2646 if (NCH(n) >= 6)
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2647 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
2648 else {
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2649 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
2650 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
2651 }
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2652 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
2653 com_pop(c, 3);
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2654 }
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2655
5181
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2656 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2657 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
2658 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2659 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
2660 int i;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
2661 /* argument c will be NULL when called from symtable_node() */
5181
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2662
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2663 /* 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
2664 next:
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2665 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
2666
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2667 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
2668 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
2669 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
2670 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
2671 }
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2672 /* 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
2673 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
2674 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
2675 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
2676 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
2677 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
2678 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
2679 }
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2680 }
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2681 break;
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2682
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2683 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
2684 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
2685 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
2686 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
2687 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
2688
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2689 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
2690 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
2691 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
2692 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
2693 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
2694 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
2695 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
2696 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
2697 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
2698 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
2699 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
2700 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
2701 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
2702 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
2703 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
2704 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
2705 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
2706 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
2707 }
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2708 break;
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2709
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2710 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
2711 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
2712 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
2713 break;
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2714
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2715 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
2716 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
2717 if (v == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2718 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
2719 break;
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2720 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2721 i = PyObject_IsTrue(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2722 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
2723 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
2724
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2725 case STRING:
5183
636757e812a4 Fix dumb bug calling parsestrplus with wrong node as argument.
Guido van Rossum <guido@python.org>
parents: 5181
diff changeset
2726 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
2727 if (v == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2728 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
2729 break;
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2730 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2731 i = PyObject_IsTrue(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2732 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
2733 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
2734
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2735 }
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2736 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
2737 }
8a0b80dc6e71 Added support for ``if __debug__:'' -- if -O is given, this form is
Guido van Rossum <guido@python.org>
parents: 5164
diff changeset
2738
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2739 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2740 com_if_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2741 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2742 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2743 int anchor = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2744 REQ(n, if_stmt);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2745 /*'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2746 for (i = 0; i+3 < NCH(n); i+=4) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2747 int a = 0;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2748 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
2749 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
2750 continue;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2751 if (i > 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2752 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
2753 com_node(c, ch);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2754 com_addfwref(c, JUMP_IF_FALSE, &a);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2755 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
2756 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2757 com_node(c, CHILD(n, i+3));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2758 com_addfwref(c, JUMP_FORWARD, &anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2759 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
2760 /* We jump here with an extra entry which we now pop */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2761 com_addbyte(c, POP_TOP);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2762 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2763 if (i+2 < NCH(n))
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2764 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
2765 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
2766 com_backpatch(c, anchor);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2767 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2768
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2769 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2770 com_while_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2771 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2772 int break_anchor = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2773 int anchor = 0;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2774 int save_begin = c->c_begin;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2775 REQ(n, while_stmt); /* 'while' test ':' suite ['else' ':' suite] */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2776 com_addfwref(c, SETUP_LOOP, &break_anchor);
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2777 block_push(c, SETUP_LOOP);
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2778 c->c_begin = c->c_nexti;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2779 com_addoparg(c, SET_LINENO, n->n_lineno);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2780 com_node(c, CHILD(n, 1));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2781 com_addfwref(c, JUMP_IF_FALSE, &anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2782 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
2783 com_pop(c, 1);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2784 c->c_loops++;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2785 com_node(c, CHILD(n, 3));
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2786 c->c_loops--;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2787 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin);
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2788 c->c_begin = save_begin;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2789 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
2790 /* We jump here with one entry more on the stack */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2791 com_addbyte(c, POP_TOP);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2792 com_addbyte(c, POP_BLOCK);
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2793 block_pop(c, SETUP_LOOP);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2794 if (NCH(n) > 4)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2795 com_node(c, CHILD(n, 6));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2796 com_backpatch(c, break_anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2797 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2798
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2799 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2800 com_for_stmt(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2801 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
2802 PyObject *v;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2803 int break_anchor = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2804 int anchor = 0;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2805 int save_begin = c->c_begin;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2806 REQ(n, for_stmt);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2807 /* 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2808 com_addfwref(c, SETUP_LOOP, &break_anchor);
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2809 block_push(c, SETUP_LOOP);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2810 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
2811 v = PyInt_FromLong(0L);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2812 if (v == NULL)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2813 c->c_errors++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2814 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
2815 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
2816 Py_XDECREF(v);
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2817 c->c_begin = c->c_nexti;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2818 com_addoparg(c, SET_LINENO, n->n_lineno);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2819 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
2820 com_push(c, 1);
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2821 com_assign(c, CHILD(n, 1), OP_ASSIGN, NULL);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2822 c->c_loops++;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2823 com_node(c, CHILD(n, 5));
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2824 c->c_loops--;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2825 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin);
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2826 c->c_begin = save_begin;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2827 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
2828 com_pop(c, 2); /* FOR_LOOP has popped these */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2829 com_addbyte(c, POP_BLOCK);
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
2830 block_pop(c, SETUP_LOOP);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2831 if (NCH(n) > 8)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2832 com_node(c, CHILD(n, 8));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2833 com_backpatch(c, break_anchor);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2834 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2835
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2836 /* 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
2837
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2838 SETUP_FINALLY L
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2839 <code for S>
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2840 POP_BLOCK
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2841 LOAD_CONST <nil>
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2842 L: <code for Sf>
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2843 END_FINALLY
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2844
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2845 The special instructions use the block stack. Each block
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2846 stack entry contains the instruction that created it (here
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2847 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
2848 block stack entry was created, and a label (here L).
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2849
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2850 SETUP_FINALLY:
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2851 Pushes the current value stack level and the label
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2852 onto the block stack.
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2853 POP_BLOCK:
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2854 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
2855 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
2856 block stack. (The label is ignored.)
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2857 END_FINALLY:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2858 Pops a variable number of entries from the *value* stack
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2859 and re-raises the exception they specify. The number of
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2860 entries popped depends on the (pseudo) exception type.
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2861
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2862 The block stack is unwound when an exception is raised:
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2863 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
2864 onto the value stack (and the exception condition is cleared),
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2865 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
2866 stack.
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2867
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2868 Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...":
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2869 (The contents of the value stack is shown in [], with the top
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2870 at the right; 'tb' is trace-back info, 'val' the exception's
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2871 associated value, and 'exc' the exception.)
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2872
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2873 Value stack Label Instruction Argument
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2874 [] SETUP_EXCEPT L1
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2875 [] <code for S>
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2876 [] POP_BLOCK
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2877 [] JUMP_FORWARD L0
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2878
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2879 [tb, val, exc] L1: DUP )
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2880 [tb, val, exc, exc] <evaluate E1> )
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2881 [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2882 [tb, val, exc, 1-or-0] JUMP_IF_FALSE L2 )
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2883 [tb, val, exc, 1] POP )
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2884 [tb, val, exc] POP
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2885 [tb, val] <assign to V1> (or POP if no V1)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2886 [tb] POP
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2887 [] <code for S1>
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2888 JUMP_FORWARD L0
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2889
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2890 [tb, val, exc, 0] L2: POP
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2891 [tb, val, exc] DUP
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2892 .............................etc.......................
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2893
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2894 [tb, val, exc, 0] Ln+1: POP
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
2895 [tb, val, exc] END_FINALLY # re-raise exception
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2896
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2897 [] L0: <next statement>
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2898
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2899 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
2900 */
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2901
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2902 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2903 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
2904 {
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2905 int except_anchor = 0;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2906 int end_anchor = 0;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2907 int else_anchor = 0;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2908 int i;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2909 node *ch;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2910
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2911 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
2912 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
2913 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
2914 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
2915 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
2916 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
2917 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
2918 for (i = 3;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2919 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
2920 i += 3) {
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2921 /* 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
2922 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
2923 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
2924 "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
2925 break;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2926 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2927 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
2928 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
2929 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
2930 if (NCH(ch) > 1) {
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2931 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
2932 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
2933 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
2934 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
2935 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
2936 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
2937 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
2938 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
2939 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2940 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
2941 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
2942 if (NCH(ch) > 3)
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
2943 com_assign(c, CHILD(ch, 3), OP_ASSIGN, NULL);
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2944 else {
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2945 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
2946 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
2947 }
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2948 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
2949 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
2950 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
2951 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
2952 if (except_anchor) {
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2953 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
2954 /* 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
2955 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
2956 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
2957 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
2958 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2959 }
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
2960 /* 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
2961 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
2962 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
2963 anything. */
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2964 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
2965 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
2966 if (i < NCH(n))
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2967 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
2968 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
2969 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2970
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2971 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2972 com_try_finally(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2973 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2974 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
2975 node *ch;
792
dc3b455f7632 Only * can be used for varargs argument lists
Guido van Rossum <guido@python.org>
parents: 744
diff changeset
2976
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2977 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
2978 block_push(c, SETUP_FINALLY);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2979 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
2980 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
2981 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
2982 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
2983 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
2984 /* 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
2985 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
2986 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
2987 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
2988 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
2989 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
2990 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
2991 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
2992 com_node(c, ch);
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2993 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
2994 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
2995 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
2996 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2997
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
2998 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
2999 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
3000 {
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3001 REQ(n, try_stmt);
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3002 /* '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
3003 | 'try' ':' suite 'finally' ':' suite */
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3004 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
3005 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
3006 else
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3007 com_try_except(c, n);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3008 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3009
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3010 static node *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3011 get_rawdocstring(node *n)
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3012 {
2241
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3013 int i;
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3014
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3015 /* 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
3016 next:
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3017 switch (TYPE(n)) {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3018
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3019 case suite:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3020 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
3021 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
3022 goto next;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3023 }
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3024 /* Fall through */
2241
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3025 case file_input:
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3026 for (i = 0; i < NCH(n); i++) {
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3027 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
3028 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
3029 n = ch;
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3030 goto next;
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3031 }
2241
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3032 }
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3033 break;
fefae37c053c added missing case to get_docstring
Guido van Rossum <guido@python.org>
parents: 2203
diff changeset
3034
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3035 case stmt:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3036 case simple_stmt:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3037 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
3038 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
3039 goto next;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3040
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3041 case expr_stmt:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3042 case testlist:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3043 case test:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3044 case and_test:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3045 case not_test:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3046 case comparison:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3047 case expr:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3048 case xor_expr:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3049 case and_expr:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3050 case shift_expr:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3051 case arith_expr:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3052 case term:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3053 case factor:
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3054 case power:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3055 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
3056 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
3057 goto next;
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3058 }
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3059 break;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3060
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3061 case atom:
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3062 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
3063 return n;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3064 break;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3065
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3066 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3067 return NULL;
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3068 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3069
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3070 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3071 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
3072 {
9987
b7bcc2cda1b3 Implement -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents: 9626
diff changeset
3073 /* 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
3074 if (Py_OptimizeFlag > 1)
b7bcc2cda1b3 Implement -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents: 9626
diff changeset
3075 return NULL;
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3076 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
3077 if (n == NULL)
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3078 return NULL;
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3079 return parsestrplus(n);
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3080 }
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3081
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3082 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3083 com_suite(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3084 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3085 REQ(n, suite);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3086 /* simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3087 if (NCH(n) == 1) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3088 com_node(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3089 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3090 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3091 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3092 for (i = 0; i < NCH(n); i++) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3093 node *ch = CHILD(n, i);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3094 if (TYPE(ch) == stmt)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3095 com_node(c, ch);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3096 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3097 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3098 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3099
744
834dd4a77ee2 fix what lint found
Guido van Rossum <guido@python.org>
parents: 703
diff changeset
3100 /* ARGSUSED */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3101 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3102 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
3103 {
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3104 int i = c->c_nblocks;
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3105 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
3106 com_addoparg(c, JUMP_ABSOLUTE, c->c_begin);
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3107 }
14471
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3108 else if (i <= 0) {
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3109 /* at the outer level */
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3110 com_error(c, PyExc_SyntaxError,
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3111 "'continue' not properly in loop");
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3112 }
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3113 else {
14471
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3114 int j;
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3115 for (j = 0; j <= i; ++j) {
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3116 if (c->c_block[j] == SETUP_LOOP)
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3117 break;
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3118 }
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3119 if (j < i+1) {
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3120 /* there is a loop, but something interferes */
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3121 for (++j; j <= i; ++j) {
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3122 if (c->c_block[i] == SETUP_EXCEPT
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3123 || c->c_block[i] == SETUP_FINALLY) {
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3124 com_error(c, PyExc_SyntaxError,
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3125 "'continue' not supported inside 'try' clause");
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3126 return;
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3127 }
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3128 }
c3c49859e80b com_continue_stmt(): Improve error message when continue is found
Fred Drake <fdrake@acm.org>
parents: 14382
diff changeset
3129 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3130 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
3131 "'continue' not properly in loop");
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3132 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3133 /* XXX Could allow it inside a 'finally' clause
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3134 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
3135 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3136
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3137 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3138 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
3139 {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3140 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
3141 if (TYPE(n) == lambdef) {
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3142 /* lambdef: 'lambda' [varargslist] ':' test */
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3143 n = CHILD(n, 1);
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3144 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3145 else {
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3146 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
3147 n = CHILD(n, 2);
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3148 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
3149 n = CHILD(n, 1);
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3150 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3151 if (TYPE(n) != varargslist)
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3152 return 0;
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3153 /* varargslist:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3154 (fpdef ['=' test] ',')* '*' ....... |
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3155 fpdef ['=' test] (',' fpdef ['=' test])* [','] */
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3156 nch = NCH(n);
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3157 nargs = 0;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3158 ndefs = 0;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3159 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
3160 int t;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3161 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
3162 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
3163 break;
1833
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3164 nargs++;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3165 i++;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3166 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
3167 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
3168 else
e51e17b2d88b fix bug with missing default for last arg (discovered by Tommy Burnette)
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
3169 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
3170 if (t == EQUAL) {
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3171 i++;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3172 ndefs++;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3173 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
3174 i++;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3175 if (i >= nch)
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3176 break;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3177 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
3178 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3179 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
3180 /* 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
3181 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
3182 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
3183 "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
3184 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3185 if (t != COMMA)
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3186 break;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3187 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3188 return ndefs;
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3189 }
39a4c15acb32 * Python/compile.c (com_argdefs, com_arglist): avoid referencing
Guido van Rossum <guido@python.org>
parents: 1417
diff changeset
3190
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3191 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3192 com_funcdef(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3193 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3194 PyObject *v;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3195 int ndefs;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3196 REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3197 ndefs = com_argdefs(c, n);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3198 symtable_enter_scope(c->c_symtable, STR(CHILD(n, 1)), TYPE(n));
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3199 v = (PyObject *)icompile(n, c);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3200 symtable_exit_scope(c->c_symtable);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3201 if (v == NULL)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3202 c->c_errors++;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3203 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3204 int i = com_addconst(c, v);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3205 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
3206 com_push(c, 1);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3207 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
3208 com_pop(c, ndefs);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3209 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 1)));
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3210 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
3211 Py_DECREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3212 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3213 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3214
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3215 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3216 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
3217 {
744
834dd4a77ee2 fix what lint found
Guido van Rossum <guido@python.org>
parents: 703
diff changeset
3218 int i;
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3219 REQ(n, testlist);
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3220 /* testlist: test (',' test)* [','] */
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3221 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
3222 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
3223 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
3224 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
3225 com_pop(c, i-1);
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3226 }
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3227
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3228 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3229 com_classdef(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3230 {
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3231 int i;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3232 PyObject *v;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3233 char *name;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3234
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3235 REQ(n, classdef);
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3236 /* 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
3237 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
3238 c->c_errors++;
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3239 return;
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3240 }
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3241 /* Push the class name on the stack */
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3242 i = com_addconst(c, v);
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3243 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
3244 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
3245 Py_DECREF(v);
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3246 /* 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
3247 if (TYPE(CHILD(n, 2)) != LPAR) {
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3248 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
3249 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
3250 }
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3251 else
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3252 com_bases(c, CHILD(n, 3));
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3253 name = STR(CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3254 symtable_enter_scope(c->c_symtable, name, TYPE(n));
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3255 v = (PyObject *)icompile(n, c);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3256 symtable_exit_scope(c->c_symtable);
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3257 if (v == NULL)
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3258 c->c_errors++;
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3259 else {
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
3260 i = com_addconst(c, v);
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3261 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
3262 com_push(c, 1);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3263 com_addoparg(c, MAKE_FUNCTION, 0);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3264 com_addoparg(c, CALL_FUNCTION, 0);
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3265 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
3266 com_pop(c, 2);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3267 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 1)));
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3268 Py_DECREF(v);
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3269 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3270 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3271
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3272 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3273 com_node(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3274 {
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3275 loop:
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3276 switch (TYPE(n)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3277
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3278 /* Definition nodes */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3279
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3280 case funcdef:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3281 com_funcdef(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3282 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3283 case classdef:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3284 com_classdef(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3285 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3286
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3287 /* Trivial parse tree nodes */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3288
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3289 case stmt:
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3290 case small_stmt:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3291 case flow_stmt:
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3292 n = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3293 goto loop;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3294
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3295 case simple_stmt:
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3296 /* small_stmt (';' small_stmt)* [';'] NEWLINE */
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3297 com_addoparg(c, SET_LINENO, n->n_lineno);
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3298 {
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3299 int i;
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3300 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
3301 com_node(c, CHILD(n, i));
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3302 }
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3303 break;
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3304
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3305 case compound_stmt:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3306 com_addoparg(c, SET_LINENO, n->n_lineno);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3307 n = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3308 goto loop;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3309
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3310 /* Statement nodes */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3311
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3312 case expr_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3313 com_expr_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3314 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3315 case print_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3316 com_print_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3317 break;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3318 case del_stmt: /* 'del' exprlist */
14163
1b9fd0cbd914 Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents: 14147
diff changeset
3319 com_assign(c, CHILD(n, 1), OP_DELETE, NULL);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3320 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3321 case pass_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3322 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3323 case break_stmt:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3324 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
3325 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
3326 "'break' outside loop");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3327 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3328 com_addbyte(c, BREAK_LOOP);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3329 break;
317
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3330 case continue_stmt:
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3331 com_continue_stmt(c, n);
325b40d77235 New syntax: semicolons, continue statement.
Guido van Rossum <guido@python.org>
parents: 303
diff changeset
3332 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3333 case return_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3334 com_return_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3335 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3336 case raise_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3337 com_raise_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3338 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3339 case import_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3340 com_import_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3341 break;
466
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3342 case global_stmt:
90cbcb0b97dc Implement 'global' and new class syntax.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
3343 break;
1354
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3344 case exec_stmt:
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3345 com_exec_stmt(c, n);
fccd415e2eb8 * bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
3346 break;
5233
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
3347 case assert_stmt:
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
3348 com_assert_stmt(c, n);
b749d2dd7582 Added assert statement.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
3349 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3350 case if_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3351 com_if_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3352 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3353 case while_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3354 com_while_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3355 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3356 case for_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3357 com_for_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3358 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3359 case try_stmt:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3360 com_try_stmt(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3361 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3362 case suite:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3363 com_suite(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3364 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3365
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3366 /* Expression nodes */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3367
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3368 case testlist:
482
ee899a81570d New argument passing.
Guido van Rossum <guido@python.org>
parents: 466
diff changeset
3369 com_list(c, n, 0);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3370 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3371 case test:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3372 com_test(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3373 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3374 case and_test:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3375 com_and_test(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3376 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3377 case not_test:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3378 com_not_test(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3379 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3380 case comparison:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3381 com_comparison(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3382 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3383 case exprlist:
482
ee899a81570d New argument passing.
Guido van Rossum <guido@python.org>
parents: 466
diff changeset
3384 com_list(c, n, 0);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3385 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3386 case expr:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3387 com_expr(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3388 break;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3389 case xor_expr:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3390 com_xor_expr(c, n);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3391 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3392 case and_expr:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3393 com_and_expr(c, n);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3394 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3395 case shift_expr:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3396 com_shift_expr(c, n);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3397 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3398 case arith_expr:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3399 com_arith_expr(c, n);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 388
diff changeset
3400 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3401 case term:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3402 com_term(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3403 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3404 case factor:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3405 com_factor(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3406 break;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3407 case power:
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3408 com_power(c, n);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3409 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3410 case atom:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3411 com_atom(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3412 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3413
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3414 default:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3415 /* 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
3416 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
3417 "com_node: unexpected node type");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3418 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3419 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3420
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13330
diff changeset
3421 static void com_fplist(struct compiling *, node *);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3422
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3423 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3424 com_fpdef(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3425 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3426 REQ(n, fpdef); /* fpdef: NAME | '(' fplist ')' */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3427 if (TYPE(CHILD(n, 0)) == LPAR)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3428 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
3429 else {
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3430 com_addop_varname(c, VAR_STORE, STR(CHILD(n, 0)));
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3431 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
3432 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3433 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3434
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3435 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3436 com_fplist(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3437 {
544
d0baa8300005 Minor changes.
Guido van Rossum <guido@python.org>
parents: 493
diff changeset
3438 REQ(n, fplist); /* fplist: fpdef (',' fpdef)* [','] */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3439 if (NCH(n) == 1) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3440 com_fpdef(c, CHILD(n, 0));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3441 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3442 else {
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3443 int i = (NCH(n)+1)/2;
13930
4eaa463c031a Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents: 13884
diff changeset
3444 com_addoparg(c, UNPACK_SEQUENCE, i);
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3445 com_push(c, i-1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3446 for (i = 0; i < NCH(n); i += 2)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3447 com_fpdef(c, CHILD(n, i));
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3448 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3449 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3450
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3451 /* XXX This function could probably be made simpler, because it
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3452 doesn't do anything except generate code for complex arguments.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3453 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3454
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3455 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3456 com_arglist(struct compiling *c, node *n)
584
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3457 {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3458 int nch, i;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3459 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
3460 char nbuf[10];
584
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3461 REQ(n, varargslist);
617
755bb8efcc2d Use strtoul() for oct/hex constants.
Guido van Rossum <guido@python.org>
parents: 584
diff changeset
3462 /* varargslist:
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3463 (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
3464 nch = NCH(n);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3465 /* 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
3466 for (i = 0; i < nch; i++) {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3467 node *ch = CHILD(n, i);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3468 node *fp;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3469 char *name;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3470 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
3471 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3472 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3473 fp = CHILD(ch, 0);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3474 if (TYPE(fp) == NAME)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3475 name = STR(fp);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3476 else {
5754
9ed26afeeaa5 Fix bug reported by Just: anonymous arguments used for tuples should
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
3477 name = nbuf;
9ed26afeeaa5 Fix bug reported by Just: anonymous arguments used for tuples should
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
3478 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
3479 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
3480 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3481 /* all name updates handled by symtable */
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3482 if (++i >= nch)
584
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3483 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3484 ch = CHILD(n, i);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3485 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
3486 i += 2;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3487 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3488 REQ(ch, COMMA);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3489 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3490 /* Handle *arguments */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3491 if (i < nch) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3492 node *ch;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3493 ch = CHILD(n, i);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3494 if (TYPE(ch) != DOUBLESTAR) {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3495 REQ(ch, STAR);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3496 ch = CHILD(n, i+1);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3497 if (TYPE(ch) == NAME) {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3498 i += 3;
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3499 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3500 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3501 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3502 /* Handle **keywords */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3503 if (i < nch) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3504 node *ch;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3505 ch = CHILD(n, i);
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3506 if (TYPE(ch) != DOUBLESTAR) {
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3507 REQ(ch, STAR);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3508 ch = CHILD(n, i+1);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3509 REQ(ch, STAR);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3510 ch = CHILD(n, i+2);
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3511 }
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3512 else
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3513 ch = CHILD(n, i+1);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3514 REQ(ch, NAME);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3515 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3516 if (complex) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3517 /* Generate code for complex arguments only after
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3518 having counted the simple arguments */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3519 int ilocal = 0;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3520 for (i = 0; i < nch; i++) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3521 node *ch = CHILD(n, i);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3522 node *fp;
3324
36920bbd81a8 changes for complex and power (**) operator
Guido van Rossum <guido@python.org>
parents: 3166
diff changeset
3523 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
3524 break;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3525 REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3526 fp = CHILD(ch, 0);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3527 if (TYPE(fp) != NAME) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3528 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
3529 com_push(c, 1);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3530 com_fpdef(c, ch);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3531 }
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3532 ilocal++;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3533 if (++i >= nch)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3534 break;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3535 ch = CHILD(n, i);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3536 if (TYPE(ch) == EQUAL)
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3537 i += 2;
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3538 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3539 REQ(ch, COMMA);
584
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3540 }
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3541 }
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3542 }
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3543
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3544 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3545 com_file_input(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3546 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3547 int i;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3548 PyObject *doc;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3549 REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3550 doc = get_docstring(n);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3551 if (doc != NULL) {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3552 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
3553 Py_DECREF(doc);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3554 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
3555 com_push(c, 1);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3556 com_addop_name(c, STORE_NAME, "__doc__");
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3557 com_pop(c, 1);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3558 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3559 for (i = 0; i < NCH(n); i++) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3560 node *ch = CHILD(n, i);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3561 if (TYPE(ch) != ENDMARKER && TYPE(ch) != NEWLINE)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3562 com_node(c, ch);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3563 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3564 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3565
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3566 /* Top-level compile-node interface */
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3567
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3568 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3569 compile_funcdef(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3570 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3571 PyObject *doc;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3572 node *ch;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3573 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
3574 c->c_name = STR(CHILD(n, 1));
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3575 doc = get_docstring(CHILD(n, 4));
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3576 if (doc != NULL) {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3577 (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
3578 Py_DECREF(doc);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3579 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3580 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3581 (void) com_addconst(c, Py_None); /* No docstring */
584
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3582 ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3583 ch = CHILD(ch, 1); /* ')' | varargslist */
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3584 if (TYPE(ch) == varargslist)
584
37aa67f0867c Added varargs code.
Guido van Rossum <guido@python.org>
parents: 568
diff changeset
3585 com_arglist(c, ch);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3586 c->c_infunction = 1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3587 com_node(c, CHILD(n, 4));
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3588 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
3589 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
3590 com_push(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3591 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
3592 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3593 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3594
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3595 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3596 compile_lambdef(struct compiling *c, node *n)
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1364
diff changeset
3597 {
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
3598 node *ch;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3599 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
3600 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
3601
06570429f062 * import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents: 1405
diff changeset
3602 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
3603 (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
3604 if (TYPE(ch) == varargslist) {
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3605 com_arglist(c, ch);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3606 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
3607 }
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3608 else
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3609 ch = CHILD(n, 2);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3610 com_node(c, ch);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1364
diff changeset
3611 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
3612 com_pop(c, 1);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1364
diff changeset
3613 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1364
diff changeset
3614
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1364
diff changeset
3615 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3616 compile_classdef(struct compiling *c, node *n)
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3617 {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3618 node *ch;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3619 PyObject *doc;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3620 REQ(n, classdef);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3621 /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3622 c->c_name = STR(CHILD(n, 1));
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3623 c->c_private = c->c_name;
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3624 ch = CHILD(n, NCH(n)-1); /* The suite */
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3625 doc = get_docstring(ch);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3626 if (doc != NULL) {
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3627 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
3628 Py_DECREF(doc);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3629 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
3630 com_push(c, 1);
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3631 com_addop_name(c, STORE_NAME, "__doc__");
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3632 com_pop(c, 1);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3633 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3634 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3635 (void) com_addconst(c, Py_None);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3636 com_node(c, ch);
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3637 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
3638 com_push(c, 1);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3639 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
3640 com_pop(c, 1);
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3641 }
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3642
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3643 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3644 compile_node(struct compiling *c, node *n)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3645 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3646 com_addoparg(c, SET_LINENO, n->n_lineno);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3647
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3648 switch (TYPE(n)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3649
120
c9a5fe1660f5 Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
3650 case single_input: /* One interactive command */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3651 /* 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
3652 c->c_interactive++;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3653 n = CHILD(n, 0);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3654 if (TYPE(n) != NEWLINE)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3655 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
3656 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
3657 com_push(c, 1);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3658 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
3659 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
3660 c->c_interactive--;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3661 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3662
120
c9a5fe1660f5 Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
3663 case file_input: /* A whole file, or built-in function exec() */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3664 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
3665 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
3666 com_push(c, 1);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 73
diff changeset
3667 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
3668 com_pop(c, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3669 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3670
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
3671 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
3672 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
3673 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
3674 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
3675 break;
c9a5fe1660f5 Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
3676
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
3677 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
3678 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
3679 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
3680
120
c9a5fe1660f5 Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
3681 case funcdef: /* A function definition */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3682 compile_funcdef(c, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3683 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3684
120
c9a5fe1660f5 Fix bug in input(); add comments to cases in compile().
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
3685 case classdef: /* A class definition */
2089
53aa51433f7f Two independent chages:
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3686 compile_classdef(c, n);
73
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3687 break;
3028acaa56b0 Compile class definitions.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
3688
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3689 default:
4991
8276916e1ea8 Add co_stacksize field to codeobject structure, and stacksize argument
Guido van Rossum <guido@python.org>
parents: 4905
diff changeset
3690 /* 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
3691 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
3692 "compile_node: unexpected node type");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3693 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3694 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3695
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3696 PyCodeObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3697 PyNode_Compile(node *n, char *filename)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3698 {
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3699 return jcompile(n, filename, NULL);
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3700 }
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3701
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3702 static PyCodeObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3703 icompile(node *n, struct compiling *base)
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3704 {
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3705 return jcompile(n, base->c_filename, base);
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3706 }
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3707
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3708 static PyCodeObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3709 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
3710 {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3711 struct compiling sc;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3712 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
3713 if (!com_init(&sc, filename))
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3714 return NULL;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3715 if (base) {
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3716 sc.c_private = base->c_private;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3717 sc.c_symtable = base->c_symtable;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3718 } else {
4129
eedaa59341b9 Name mangling, what the heck!
Guido van Rossum <guido@python.org>
parents: 4003
diff changeset
3719 sc.c_private = NULL;
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3720 if (symtable_build(&sc, n) < 0) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3721 com_free(&sc);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3722 return NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3723 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3724 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3725 co = NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3726 if (symtable_load_symbols(&sc) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3727 goto exit;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3728 compile_node(&sc, n);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3729 com_done(&sc);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1029
diff changeset
3730 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
3731 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
3732 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
3733 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
3734 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
3735 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
3736 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
3737 if (!PyErr_Occurred())
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3738 co = PyCode_New(sc.c_argcount,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3739 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
3740 sc.c_maxstacklevel,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3741 sc.c_flags,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3742 sc.c_code,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3743 consts,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3744 names,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3745 varnames,
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2813
diff changeset
3746 filename,
5041
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3747 name,
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3748 sc.c_firstlineno,
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3749 sc.c_lnotab);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3750 Py_XDECREF(consts);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3751 Py_XDECREF(names);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3752 Py_XDECREF(varnames);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3753 Py_XDECREF(filename);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
3754 Py_XDECREF(name);
266
b5826bf29677 Changed and exported newcodeobject() interface, for ".pyc" files.
Guido van Rossum <guido@python.org>
parents: 238
diff changeset
3755 }
13884
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3756 else if (!PyErr_Occurred()) {
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3757 /* This could happen if someone called PyErr_Clear() after an
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3758 error was reported above. That's not supposed to happen,
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3759 but I just plugged one case and I'm not sure there can't be
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3760 others. In that case, raise SystemError so that at least
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3761 it gets reported instead dumping core. */
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3762 PyErr_SetString(PyExc_SystemError, "lost syntax error");
8eeaff96b4c2 When returning an error from jcompile() (which is passed through by
Guido van Rossum <guido@python.org>
parents: 13873
diff changeset
3763 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3764 exit:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3765 if (base == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3766 symtable_free(sc.c_symtable);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3767 com_free(&sc);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3768 return co;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3769 }
5041
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3770
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3771 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13585
diff changeset
3772 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
3773 {
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3774 int size = PyString_Size(co->co_lnotab) / 2;
11290
ccdf5dc2acf6 Tim Peters writes:
Guido van Rossum <guido@python.org>
parents: 9987
diff changeset
3775 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
3776 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
3777 int addr = 0;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3778 while (--size >= 0) {
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3779 addr += *p++;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3780 if (addr > addrq)
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3781 break;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3782 line += *p++;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3783 }
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3784 return line;
c497929b2371 Instead of emitting SET_LINENO instructions, generate a line number
Guido van Rossum <guido@python.org>
parents: 5011
diff changeset
3785 }
16015
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3786
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3787 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3788 is_local(struct compiling *c, char *name)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3789 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3790 if (PyDict_GetItemString(c->c_locals, name) != NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3791 return 1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3792 else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3793 return 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3794 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3795
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3796 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3797 is_global(struct compiling *c, char *name)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3798 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3799 PyObject *v;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3800 v = PyDict_GetItemString(c->c_globals, name);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3801 if (v == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3802 return 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3803 else if (v == Py_None)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3804 return IMPLICIT_GLOBAL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3805 else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3806 return EXPLICIT_GLOBAL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3807 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3808
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3809 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3810 symtable_build(struct compiling *c, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3811 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3812 if ((c->c_symtable = symtable_init()) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3813 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3814 if (symtable_enter_scope(c->c_symtable, GLOBAL, TYPE(n)) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3815 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3816 symtable_node(c->c_symtable, n);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3817 /* reset for second pass */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3818 c->c_symtable->st_scopes = 1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3819 return 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3820 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3821
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3822 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3823 symtable_load_symbols(struct compiling *c)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3824 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3825 static PyObject *global = NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3826 PyObject *name, *v, *varnames;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3827 int i, info, count, pos;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3828 struct symtable *st = c->c_symtable;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3829
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3830 varnames = PyDict_GetItem(st->st_varnames, st->st_cur_id);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3831 if (varnames == NULL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3832 varnames = PyList_New(0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3833 if (varnames == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3834 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3835 } else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3836 Py_INCREF(varnames);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3837
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3838 c->c_varnames = varnames;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3839 count = PyList_GET_SIZE(varnames);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3840 c->c_argcount = count;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3841 for (i = 0; i < count; ++i) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3842 v = PyInt_FromLong(i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3843 if (PyDict_SetItem(c->c_locals,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3844 PyList_GET_ITEM(varnames, i), v) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3845 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3846 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3847
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3848 /* XXX The cases below define the rules for whether a name is
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3849 local or global. The logic could probably be clearer. */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3850 pos = 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3851 while (PyDict_Next(st->st_cur, &pos, &name, &v)) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3852 info = PyInt_AS_LONG(v);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3853 if (info & DEF_STAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3854 c->c_argcount--;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3855 c->c_flags |= CO_VARARGS;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3856 } else if (info & DEF_DOUBLESTAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3857 c->c_argcount--;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3858 c->c_flags |= CO_VARKEYWORDS;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3859 } else if (info & DEF_INTUPLE)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3860 c->c_argcount--;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3861 else if (info & DEF_GLOBAL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3862 if ((info & DEF_PARAM)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3863 && (PyString_AS_STRING(name)[0] != '.')){
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3864 char buf[500];
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3865 sprintf(buf,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3866 "name '%.400s' is local and global",
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3867 PyString_AS_STRING(name));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3868 com_error(c, PyExc_SyntaxError, buf);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3869 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3870 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3871 if (global == NULL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3872 global = PyInt_FromLong(1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3873 if (global == NULL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3874 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3875 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3876 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3877 if (PyDict_SetItem(c->c_globals, name, global) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3878 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3879 } else if ((info & USE) && !(info & (DEF_LOCAL | DEF_PARAM))) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3880 if (PyDict_SetItem(c->c_globals, name,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3881 Py_None) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3882 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3883 } else if ((info & DEF_LOCAL) && !(info & DEF_PARAM)) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3884 v = PyInt_FromLong(count++);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3885 if (PyDict_SetItem(c->c_locals, name, v) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3886 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3887 if (st->st_cur_type != TYPE_CLASS)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3888 if (PyList_Append(c->c_varnames, name) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3889 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3890 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3891 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3892
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3893 if (st->st_cur_type == TYPE_FUNCTION)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3894 c->c_nlocals = count;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3895
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3896 if (st->st_cur_type != TYPE_MODULE)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3897 c->c_flags |= CO_NEWLOCALS;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3898 if ((st->st_cur_type == TYPE_FUNCTION)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3899 && (PyDict_GetItemString(st->st_cur, NOOPT) == NULL))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3900 c->c_flags |= CO_OPTIMIZED;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3901
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3902 return 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3903 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3904
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3905 static struct symtable *
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3906 symtable_init()
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3907 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3908 struct symtable *st;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3909 PyObject *d;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3910
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3911 st = (struct symtable *)PyMem_Malloc(sizeof(struct symtable));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3912 if (st == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3913 return NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3914 if ((st->st_namespaces = PyList_New(0)) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3915 goto fail;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3916 if ((st->st_types = PyList_New(0)) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3917 goto fail;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3918 if ((st->st_symbols = PyDict_New()) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3919 goto fail;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3920 if ((st->st_varnames = PyDict_New()) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3921 goto fail;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3922 if ((d = PyDict_New()) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3923 goto fail;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3924 if (PyDict_SetItemString(st->st_symbols, GLOBAL, d) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3925 goto fail;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3926 st->st_global = d;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3927 st->st_cur = NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3928 st->st_cur_id = NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3929 st->st_cur_type = 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3930 st->st_scopes = 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3931 st->st_errors = 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3932 st->st_tmpname = 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3933 st->st_private = NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3934 return st;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3935 fail:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3936 symtable_free(st);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3937 return NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3938 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3939
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3940 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3941 symtable_free(struct symtable *st)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3942 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3943 Py_XDECREF(st->st_symbols);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3944 Py_XDECREF(st->st_varnames);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3945 Py_XDECREF(st->st_namespaces);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3946 Py_XDECREF(st->st_types);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3947 Py_XDECREF(st->st_cur_id);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3948 PyMem_Free((void *)st);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3949 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3950
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3951 /* XXX name isn't used ... */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3952
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3953 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3954 symtable_enter_scope(struct symtable *st, char *name, int type)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3955 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3956 PyObject *o;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3957
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3958 o = PyInt_FromLong(st->st_scopes++);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3959 if (o == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3960 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3961 if (PyList_Append(st->st_namespaces, o) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3962 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3963 switch (type) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3964 case funcdef:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3965 case lambdef:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3966 st->st_cur_type = TYPE_FUNCTION;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3967 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3968 case classdef:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3969 st->st_cur_type = TYPE_CLASS;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3970 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3971 case single_input:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3972 case eval_input:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3973 case file_input:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3974 st->st_cur_type = TYPE_MODULE;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3975 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3976 default:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3977 fprintf(stderr, "invalid symtable scope: %d\n", type);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3978 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3979 o = PyInt_FromLong(st->st_cur_type);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3980 if (o == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3981 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3982 if (PyList_Append(st->st_types, o) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3983 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3984 return symtable_update_cur(st);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3985 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3986
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3987 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3988 symtable_exit_scope(struct symtable *st)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3989 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3990 PyObject *o;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3991 int end;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3992
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3993 end = PyList_GET_SIZE(st->st_namespaces) - 1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3994 if (PySequence_DelItem(st->st_namespaces, end) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3995 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3996 if (PySequence_DelItem(st->st_types, end) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3997 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3998 o = PyList_GET_ITEM(st->st_types, end - 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
3999 st->st_cur_type = PyInt_AS_LONG(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4000 return symtable_update_cur(st);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4001 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4002
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4003 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4004 symtable_update_cur(struct symtable *st)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4005 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4006 PyObject *s, *d, *l;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4007 int end;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4008
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4009 end = PyList_GET_SIZE(st->st_namespaces) - 1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4010 s = PyList_GET_ITEM(st->st_namespaces, end);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4011 st->st_cur_id = s;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4012 d = PyDict_GetItem(st->st_symbols, s);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4013 if (d == NULL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4014 if ((d = PyDict_New()) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4015 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4016 if (PyObject_SetItem(st->st_symbols, s, d) < 0) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4017 Py_DECREF(d);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4018 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4019 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4020 if (st->st_cur_type == TYPE_FUNCTION) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4021 if ((l = PyList_New(0)) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4022 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4023 if (PyDict_SetItem(st->st_varnames, s, l) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4024 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4025 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4026 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4027
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4028 st->st_cur = d;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4029 return 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4030 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4031
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4032 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4033 symtable_mangle(struct symtable *st, char *name, char *buffer, size_t maxlen)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4034 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4035 return mangle(st->st_private, name, buffer, maxlen);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4036 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4037
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4038 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4039 symtable_add_def(struct symtable *st, char *name, int scope)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4040 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4041 PyObject *s, *o;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4042 int val;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4043 char buffer[MANGLE_LEN];
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4044
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4045 if (symtable_mangle(st, name, buffer, sizeof(buffer)))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4046 name = buffer;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4047 if ((s = PyString_InternFromString(name)) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4048 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4049 if ((o = PyDict_GetItem(st->st_cur, s))) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4050 val = PyInt_AS_LONG(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4051 if ((scope & DEF_PARAM) && (val & DEF_PARAM)) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4052 PyErr_Format(PyExc_SyntaxError,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4053 "duplicate argument '%s' in function definition",
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4054 name);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4055 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4056 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4057 val |= scope;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4058 } else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4059 val = scope;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4060 o = PyInt_FromLong(val);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4061 if (PyDict_SetItem(st->st_cur, s, o) < 0) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4062 Py_DECREF(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4063 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4064 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4065 Py_DECREF(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4066
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4067 if (scope & DEF_PARAM) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4068 PyObject *l = PyDict_GetItem(st->st_varnames,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4069 st->st_cur_id);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4070 if (l == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4071 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4072 if (PyList_Append(l, s) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4073 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4074 } else if (scope & DEF_GLOBAL) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4075 if ((o = PyDict_GetItem(st->st_global, s))) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4076 val = PyInt_AS_LONG(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4077 val |= scope;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4078 } else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4079 val = scope;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4080 o = PyInt_FromLong(val);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4081 if (PyDict_SetItem(st->st_global, s, o) < 0) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4082 Py_DECREF(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4083 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4084 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4085 Py_DECREF(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4086 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4087 return 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4088 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4089
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4090 static int
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4091 symtable_add_use(struct symtable *st, char *name)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4092 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4093 PyObject *s, *o;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4094 int val;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4095 char buffer[MANGLE_LEN];
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4096
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4097 if (symtable_mangle(st, name, buffer, sizeof(buffer)))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4098 name = buffer;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4099 /* fprintf(stderr, "add_use(%s)\n", name); */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4100 if ((s = PyString_InternFromString(name)) == NULL)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4101 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4102 if ((o = PyDict_GetItem(st->st_cur, s))) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4103 val = PyInt_AS_LONG(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4104 val |= USE;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4105 } else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4106 val = USE;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4107 o = PyInt_FromLong(val);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4108 if (PyDict_SetItem(st->st_cur, s, o) < 0) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4109 Py_DECREF(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4110 return -1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4111 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4112 Py_DECREF(o);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4113 return 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4114 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4115
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4116 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4117 symtable_node(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4118 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4119 int i, start = 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4120
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4121 loop:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4122 switch (TYPE(n)) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4123 case funcdef: {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4124 char *func_name = STR(CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4125 symtable_add_def(st, func_name, DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4126 symtable_default_args(st, CHILD(n, 2));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4127 symtable_enter_scope(st, func_name, TYPE(n));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4128 symtable_funcdef(st, n);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4129 symtable_exit_scope(st);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4130 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4131 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4132 case lambdef:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4133 if (NCH(n) == 4)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4134 symtable_default_args(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4135 symtable_enter_scope(st, "lambda", TYPE(n));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4136 symtable_funcdef(st, n);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4137 symtable_exit_scope(st);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4138 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4139 case classdef: {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4140 char *tmp, *class_name = STR(CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4141 symtable_add_def(st, class_name, DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4142 if (TYPE(CHILD(n, 2)) == LPAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4143 node *bases = CHILD(n, 3);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4144 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4145 for (i = 0; i < NCH(bases); i += 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4146 symtable_node(st, CHILD(bases, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4147 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4148 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4149 symtable_enter_scope(st, class_name, TYPE(n));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4150 tmp = st->st_private;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4151 st->st_private = class_name;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4152 symtable_node(st, CHILD(n, NCH(n) - 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4153 st->st_private = tmp;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4154 symtable_exit_scope(st);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4155 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4156 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4157 case if_stmt:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4158 for (i = 0; i + 3 < NCH(n); i += 4) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4159 if (is_constant_false(NULL, (CHILD(n, i + 1))))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4160 continue;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4161 symtable_node(st, CHILD(n, i + 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4162 symtable_node(st, CHILD(n, i + 3));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4163 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4164 if (i + 2 < NCH(n))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4165 symtable_node(st, CHILD(n, i + 2));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4166 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4167 case global_stmt:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4168 symtable_global(st, n);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4169 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4170 case import_stmt:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4171 symtable_import(st, n);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4172 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4173 case exec_stmt:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4174 if (PyDict_SetItemString(st->st_cur, NOOPT, Py_None) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4175 st->st_errors++;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4176 symtable_node(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4177 if (NCH(n) > 2)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4178 symtable_node(st, CHILD(n, 3));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4179 if (NCH(n) > 4)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4180 symtable_node(st, CHILD(n, 5));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4181 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4182 case except_clause:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4183 if (NCH(n) == 4)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4184 symtable_assign(st, CHILD(n, 3));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4185 if (NCH(n) > 1) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4186 n = CHILD(n, 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4187 goto loop;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4188 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4189 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4190 case del_stmt:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4191 symtable_assign(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4192 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4193 case expr_stmt:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4194 if (NCH(n) == 1)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4195 n = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4196 else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4197 if (TYPE(CHILD(n, 1)) == augassign) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4198 symtable_assign(st, CHILD(n, 0));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4199 symtable_node(st, CHILD(n, 2));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4200 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4201 } else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4202 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4203 for (i = 0; i < NCH(n) - 2; i += 2)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4204 symtable_assign(st, CHILD(n, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4205 n = CHILD(n, NCH(n) - 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4206 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4207 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4208 goto loop;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4209 /* watchout for fall-through logic below */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4210 case listmaker:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4211 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4212 symtable_list_comprehension(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4213 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4214 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4215 case atom:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4216 if (TYPE(n) == atom && TYPE(CHILD(n, 0)) == NAME) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4217 symtable_add_use(st, STR(CHILD(n, 0)));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4218 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4219 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4220 case for_stmt:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4221 if (TYPE(n) == for_stmt) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4222 symtable_assign(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4223 start = 3;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4224 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4225 default:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4226 if (NCH(n) == 1) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4227 n = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4228 goto loop;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4229 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4230 for (i = start; i < NCH(n); ++i)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4231 if (TYPE(CHILD(n, i)) >= single_input)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4232 symtable_node(st, CHILD(n, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4233 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4234 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4235
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4236 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4237 symtable_funcdef(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4238 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4239 node *body;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4240
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4241 if (TYPE(n) == lambdef) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4242 if (NCH(n) == 4)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4243 symtable_params(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4244 } else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4245 symtable_params(st, CHILD(n, 2));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4246 body = CHILD(n, NCH(n) - 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4247 symtable_node(st, body);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4248 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4249
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4250 /* The next two functions parse the argument tuple.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4251 symtable_default_arg() checks for names in the default arguments,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4252 which are references in the defining scope. symtable_params()
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4253 parses the parameter names, which are defined in the function's
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4254 body.
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4255
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4256 varargslist:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4257 (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4258 | fpdef ['=' test] (',' fpdef ['=' test])* [',']
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4259 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4260
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4261 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4262 symtable_default_args(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4263 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4264 node *c;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4265 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4266
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4267 if (TYPE(n) == parameters) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4268 n = CHILD(n, 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4269 if (TYPE(n) == RPAR)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4270 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4271 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4272 REQ(n, varargslist);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4273 for (i = 0; i < NCH(n); i += 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4274 c = CHILD(n, i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4275 if (TYPE(c) == STAR || TYPE(c) == DOUBLESTAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4276 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4277 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4278 if (i > 0 && (TYPE(CHILD(n, i - 1)) == EQUAL))
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4279 symtable_node(st, CHILD(n, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4280 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4281 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4282
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4283 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4284 symtable_params(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4285 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4286 int i, complex = 0, ext = 0;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4287 node *c = NULL;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4288
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4289 if (TYPE(n) == parameters) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4290 n = CHILD(n, 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4291 if (TYPE(n) == RPAR)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4292 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4293 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4294 REQ(n, varargslist);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4295 for (i = 0; i < NCH(n); i += 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4296 c = CHILD(n, i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4297 if (TYPE(c) == STAR || TYPE(c) == DOUBLESTAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4298 ext = 1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4299 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4300 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4301 if (TYPE(c) == test) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4302 continue;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4303 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4304 if (TYPE(CHILD(c, 0)) == NAME)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4305 symtable_add_def(st, STR(CHILD(c, 0)), DEF_PARAM);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4306 else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4307 char nbuf[10];
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4308 sprintf(nbuf, ".%d", i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4309 symtable_add_def(st, nbuf, DEF_PARAM);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4310 complex = 1;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4311 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4312 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4313 if (complex) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4314 int j;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4315 for (j = 0; j < i; j += 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4316 c = CHILD(n, j);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4317 if (TYPE(CHILD(c, 0)) == LPAR)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4318 symtable_params_fplist(st, CHILD(c, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4319 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4320 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4321 if (ext) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4322 c = CHILD(n, i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4323 if (TYPE(c) == STAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4324 i++;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4325 symtable_add_def(st, STR(CHILD(n, i)),
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4326 DEF_PARAM | DEF_STAR);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4327 i += 2;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4328 c = CHILD(n, i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4329 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4330 if (TYPE(c) == DOUBLESTAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4331 i++;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4332 symtable_add_def(st, STR(CHILD(n, i)),
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4333 DEF_PARAM | DEF_DOUBLESTAR);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4334 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4335 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4336 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4337
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4338 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4339 symtable_params_fplist(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4340 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4341 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4342 node *c;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4343
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4344 REQ(n, fplist);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4345 for (i = 0; i < NCH(n); i += 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4346 c = CHILD(n, i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4347 REQ(c, fpdef);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4348 if (NCH(c) == 1)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4349 symtable_add_def(st, STR(CHILD(c, 0)),
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4350 DEF_PARAM | DEF_INTUPLE);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4351 else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4352 symtable_params_fplist(st, CHILD(c, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4353 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4354
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4355 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4356
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4357 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4358 symtable_global(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4359 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4360 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4361
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4362 for (i = 1; i < NCH(n); i += 2)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4363 symtable_add_def(st, STR(CHILD(n, i)), DEF_GLOBAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4364 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4365
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4366 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4367 symtable_list_comprehension(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4368 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4369 char tmpname[12];
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4370
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4371 sprintf(tmpname, "[%d]", ++st->st_tmpname);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4372 symtable_add_def(st, tmpname, DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4373 symtable_assign(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4374 symtable_node(st, CHILD(n, 3));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4375 if (NCH(n) == 5)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4376 symtable_node(st, CHILD(n, 4));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4377 --st->st_tmpname;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4378 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4379
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4380 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4381 symtable_import(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4382 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4383 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4384 /*
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4385 import_stmt: 'import' dotted_as_name (',' dotted_as_name)*
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4386 | 'from' dotted_name 'import'
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4387 ('*' | import_as_name (',' import_as_name)*)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4388 import_as_name: NAME [NAME NAME]
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4389 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4390
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4391 if (STR(CHILD(n, 0))[0] == 'f') { /* from */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4392 if (TYPE(CHILD(n, 3)) == STAR) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4393 if (PyDict_SetItemString(st->st_cur, NOOPT,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4394 Py_None) < 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4395 st->st_errors++;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4396 } else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4397 for (i = 3; i < NCH(n); i += 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4398 node *c = CHILD(n, i);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4399 if (NCH(c) > 1) /* import as */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4400 symtable_assign(st, CHILD(c, 2));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4401 else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4402 symtable_assign(st, CHILD(c, 0));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4403 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4404 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4405 } else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4406 for (i = 1; i < NCH(n); i += 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4407 symtable_assign(st, CHILD(n, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4408 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4409 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4410 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4411
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4412 static void
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4413 symtable_assign(struct symtable *st, node *n)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4414 {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4415 node *tmp;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4416 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4417
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4418 for (;;) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4419 /* fprintf(stderr, "symtable_assign(%d, %d)\n",
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4420 TYPE(n), NCH(n));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4421 */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4422
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4423 switch (TYPE(n)) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4424 case power:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4425 /* not sure that NCH(n) > 1 always means that
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4426 none of the left-hand side names are
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4427 targets of assignments */
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4428 if (NCH(n) > 2) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4429 for (i = 2; i < NCH(n); ++i)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4430 if (TYPE(CHILD(n, i)) != DOUBLESTAR)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4431 symtable_node(st, CHILD(n, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4432 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4433 if (NCH(n) > 1) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4434 symtable_node(st, CHILD(n, 0));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4435 symtable_node(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4436 } else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4437 n = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4438 continue;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4439 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4440 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4441 case listmaker:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4442 if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4443 symtable_list_comprehension(st, CHILD(n, 1));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4444 else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4445 for (i = 0; i < NCH(n); i += 2)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4446 symtable_assign(st, CHILD(n, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4447 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4448 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4449 case exprlist:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4450 case testlist:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4451 if (NCH(n) == 1) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4452 n = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4453 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4454 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4455 else {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4456 int i;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4457 for (i = 0; i < NCH(n); i += 2)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4458 symtable_assign(st, CHILD(n, i));
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4459 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4460 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4461 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4462 case atom:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4463 tmp = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4464 if (TYPE(tmp) == LPAR || TYPE(tmp) == LSQB) {
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4465 n = CHILD(n, 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4466 continue;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4467 } else if (TYPE(tmp) == NAME)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4468 symtable_add_def(st, STR(tmp), DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4469 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4470 case dotted_as_name:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4471 if (NCH(n) == 3)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4472 symtable_add_def(st, STR(CHILD(n, 2)),
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4473 DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4474 else
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4475 symtable_add_def(st,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4476 STR(CHILD(CHILD(n,
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4477 0), 0)),
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4478 DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4479 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4480 case dotted_name:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4481 symtable_add_def(st, STR(CHILD(n, 0)), DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4482 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4483 case NAME:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4484 symtable_add_def(st, STR(n), DEF_LOCAL);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4485 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4486 default:
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4487 if (NCH(n) == 0)
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4488 return;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4489 assert(NCH(n) == 1);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4490 n = CHILD(n, 0);
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4491 break;
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4492 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4493 }
c832ef72499d This patch introduces an extra pass to the compiler that generates a
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16006
diff changeset
4494 }