annotate Python/ceval.c @ 1282:e0464e7115ca legacy-trunk

* pythonrun.c: Print exception type+arg *after* stack trace instead of before it. * ceval.c, object.c: moved testbool() to object.c (now extern visible) * stringobject.c: fix bugs in and rationalize string resize in formatstring() * tokenizer.[ch]: fix non-working code for lines longer than BUFSIZ
author Guido van Rossum <guido@python.org>
date Wed, 12 May 1993 08:24:20 +0000
parents 69a066b6b1ff
children 9fed5726a36d
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: 119
diff changeset
1 /***********************************************************
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1181
diff changeset
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1181
diff changeset
3 Amsterdam, The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
6
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
8 documentation for any purpose and without fee is hereby granted,
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
9 provided that the above copyright notice appear in all copies and that
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
10 both that copyright notice and this permission notice appear in
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
13 distribution of the software without specific, written prior permission.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
14
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
22
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
23 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 119
diff changeset
24
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
25 /* Execute compiled code */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
27 #include "allobjects.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
28
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 #include "import.h"
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #include "sysmodule.h"
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #include "compile.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
32 #include "frameobject.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
33 #include "eval.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
34 #include "ceval.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include "opcode.h"
119
9fee1ca6c8fe File name shortening.
Guido van Rossum <guido@python.org>
parents: 88
diff changeset
36 #include "bltinmodule.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
37 #include "traceback.h"
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
39 /* Turn this on if your compiler chokes on the big switch: */
1273
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
40 /* #define CASE_TOO_BIG 1 /**/
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
41
1273
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
42 /* Turn this on if you want to debug the interpreter: */
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
43 /* (This can be on even if NDEBUG is defined) */
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
44 /* #define DEBUG 1 /**/
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
45
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
46 #if defined(DEBUG) || !defined(NDEBUG)
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
47 /* For debugging the interpreter: */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
48 #define LLTRACE 1 /* Low-level trace feature */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
49 #define CHECKEXC 1 /* Double-check exception checking */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 #endif
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
52
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
53 /* Forward declarations */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
54
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
55 #ifdef LLTRACE
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
56 static int prtrace PROTO((object *, char *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
57 #endif
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
58 static void call_exc_trace PROTO((object **, object**, frameobject *));
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
59 static int call_trace
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
60 PROTO((object **, object **, frameobject *, char *, object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
61 static object *add PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
62 static object *sub PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
63 static object *mul PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
64 static object *divide PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
65 static object *rem PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
66 static object *neg PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
67 static object *pos PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
68 static object *not PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
69 static object *invert PROTO((object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
70 static object *lshift PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
71 static object *rshift PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
72 static object *and PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
73 static object *xor PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
74 static object *or PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
75 static object *call_builtin PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
76 static object *call_function PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
77 static object *apply_subscript PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
78 static object *loop_subscript PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
79 static int slice_index PROTO((object *, int, int *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
80 static object *apply_slice PROTO((object *, object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
81 static int assign_subscript PROTO((object *, object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
82 static int assign_slice PROTO((object *, object *, object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
83 static int cmp_exception PROTO((object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
84 static int cmp_member PROTO((object *, object *));
802
3d6541a2eca5 Arg of cmp_outcome becomes an int for portability to the Mac
Guido van Rossum <guido@python.org>
parents: 789
diff changeset
85 static object *cmp_outcome PROTO((int, object *, object *));
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
86 static int import_from PROTO((object *, object *, object *));
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
87 static object *build_class PROTO((object *, object *));
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
88 static void locals_2_fast PROTO((frameobject *, int));
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
89 static void fast_2_locals PROTO((frameobject *));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
90
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
91
746
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
92 /* Pointer to current frame, used to link new frames to */
6c0f16008bd9 lint (added prototypes for all static fns)
Guido van Rossum <guido@python.org>
parents: 708
diff changeset
93
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
94 static frameobject *current_frame;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
95
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
96 #ifdef USE_THREAD
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
97
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
98 #include <errno.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
99 #include "thread.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
100
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
101 static type_lock interpreter_lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
102
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
103 void
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
104 init_save_thread()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
105 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
106 if (interpreter_lock)
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1132
diff changeset
107 return;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
108 interpreter_lock = allocate_lock();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
109 acquire_lock(interpreter_lock, 1);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
110 }
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
111
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
112 #endif
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
113
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
114 /* Functions save_thread and restore_thread are always defined so
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
115 dynamically loaded modules needn't be compiled separately for use
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
116 with and without threads: */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
117
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
118 object *
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
119 save_thread()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
120 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
121 #ifdef USE_THREAD
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
122 if (interpreter_lock) {
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
123 object *res;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
124 res = (object *)current_frame;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
125 current_frame = NULL;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
126 release_lock(interpreter_lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
127 return res;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
128 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
129 #endif
1271
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1263
diff changeset
130 return NULL;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
131 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
132
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
133 void
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
134 restore_thread(x)
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
135 object *x;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
136 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
137 #ifdef USE_THREAD
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
138 if (interpreter_lock) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
139 int err;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
140 err = errno;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
141 acquire_lock(interpreter_lock, 1);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
142 errno = err;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
143 current_frame = (frameobject *)x;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
144 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
145 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
146 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
147
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
148
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
149 /* Status code for main loop (reason for stack unwind) */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
150
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
151 enum why_code {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
152 WHY_NOT, /* No error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
153 WHY_EXCEPTION, /* Exception occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
154 WHY_RERAISE, /* Exception re-raised by 'finally' */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
155 WHY_RETURN, /* 'return' statement */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
156 WHY_BREAK /* 'break' statement */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
157 };
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
158
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
159
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
160 /* Interpreter main loop */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
161
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
162 object *
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
163 eval_code(co, globals, locals, arg)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
164 codeobject *co;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
165 object *globals;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
166 object *locals;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
167 object *arg;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
168 {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
169 register unsigned char *next_instr;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
170 register int opcode; /* Current opcode */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
171 register int oparg; /* Current opcode argument, if any */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
172 register object **stack_pointer;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
173 register enum why_code why; /* Reason for block stack unwind */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
174 register int err; /* Error status -- nonzero if error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
175 register object *x; /* Result object -- NULL if error */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
176 register object *v; /* Temporary objects popped off stack */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
177 register object *w;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
178 register object *u;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
179 register object *t;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
180 register frameobject *f; /* Current frame */
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
181 register listobject *fastlocals = NULL;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
182 object *trace = NULL; /* Trace function or NULL */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
183 object *retval; /* Return value iff why == WHY_RETURN */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
184 char *name; /* Name used by some instructions */
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
185 int needmerge = 0;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
186 #ifdef LLTRACE
1273
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
187 int lltrace;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
188 #endif
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
189 #ifdef DEBUG
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
190 /* Make it easier to find out where we are with dbx */
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
191 char *filename = getstringvalue(co->co_filename);
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
192 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
193
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
194 /* Code access macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
195
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
196 #define GETCONST(i) Getconst(f, i)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
197 #define GETNAME(i) Getname(f, i)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
198 #define GETNAMEV(i) Getnamev(f, i)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
199 #define FIRST_INSTR() (GETUSTRINGVALUE(f->f_code->co_code))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
200 #define INSTR_OFFSET() (next_instr - FIRST_INSTR())
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
201 #define NEXTOP() (*next_instr++)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
202 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
203 #define JUMPTO(x) (next_instr = FIRST_INSTR() + (x))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
204 #define JUMPBY(x) (next_instr += (x))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
205
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
206 /* Stack manipulation macros */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
207
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
208 #define STACK_LEVEL() (stack_pointer - f->f_valuestack)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
209 #define EMPTY() (STACK_LEVEL() == 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
210 #define TOP() (stack_pointer[-1])
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
211 #define BASIC_PUSH(v) (*stack_pointer++ = (v))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
212 #define BASIC_POP() (*--stack_pointer)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
213
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
214 #define CHECK_STACK(n) (STACK_LEVEL() + (n) < f->f_nvalues || \
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
215 (stack_pointer = extend_stack(f, STACK_LEVEL(), n)))
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
216
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
217 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
218 #define PUSH(v) (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push"))
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
219 #define POP() (lltrace && prtrace(TOP(), "pop"), BASIC_POP())
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
220 #else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
221 #define PUSH(v) BASIC_PUSH(v)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
222 #define POP() BASIC_POP()
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
223 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
224
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
225 if (globals == NULL) {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
226 globals = getglobals();
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
227 if (locals == NULL) {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
228 locals = getlocals();
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
229 needmerge = 1;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
230 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
231 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
232 else {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
233 if (locals == NULL)
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
234 locals = globals;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
235 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
236
1273
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
237 #ifdef LLTRACE
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
238 lltrace = dictlookup(globals, "__lltrace__") != NULL;
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
239 #endif
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
240
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
241 f = newframeobject(
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
242 current_frame, /*back*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
243 co, /*code*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
244 globals, /*globals*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
245 locals, /*locals*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
246 50, /*nvalues*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
247 20); /*nblocks*/
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
248 if (f == NULL)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
249 return NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
250
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
251 current_frame = f;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
252
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
253 if (sys_trace != NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
254 /* sys_trace, if defined, is a function that will
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
255 be called on *every* entry to a code block.
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
256 Its return value, if not None, is a function that
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
257 will be called at the start of each executed line
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
258 of code. (Actually, the function must return
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
259 itself in order to continue tracing.)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
260 The trace functions are called with three arguments:
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
261 a pointer to the current frame, a string indicating
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
262 why the function is called, and an argument which
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
263 depends on the situation. The global trace function
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
264 (sys.trace) is also called whenever an exception
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
265 is detected. */
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
266 if (call_trace(&sys_trace, &trace, f, "call", arg)) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
267 /* Trace function raised an error */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
268 current_frame = f->f_back;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
269 DECREF(f);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
270 return NULL;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
271 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
272 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
273
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
274 if (sys_profile != NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
275 /* Similar for sys_profile, except it needn't return
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
276 itself and isn't called for "line" events */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
277 if (call_trace(&sys_profile, (object**)0, f, "call", arg)) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
278 current_frame = f->f_back;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
279 DECREF(f);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
280 return NULL;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
281 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
282 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
283
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
284 next_instr = GETUSTRINGVALUE(f->f_code->co_code);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
285 stack_pointer = f->f_valuestack;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
286
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
287 if (arg != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
288 INCREF(arg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
289 PUSH(arg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
290 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
291
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
292 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
293 err = 0;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
294 x = None; /* Not a reference, just anything non-NULL */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
295
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
296 for (;;) {
237
16f467717d7a Declare ticker as int; made testbool generic for all numeric types
Guido van Rossum <guido@python.org>
parents: 224
diff changeset
297 static int ticker;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
298
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
299 /* Do periodic things.
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
300 Doing this every time through the loop would add
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
301 too much overhead (a function call per instruction).
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
302 So we do it only every tenth instruction. */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
303
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
304 if (--ticker < 0) {
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
305 ticker = 10;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
306 if (intrcheck()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
307 err_set(KeyboardInterrupt);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
308 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
309 goto on_error;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
310 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
311
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
312 #ifdef USE_THREAD
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
313 if (interpreter_lock) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
314 /* Give another thread a chance */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
315
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
316 current_frame = NULL;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
317 release_lock(interpreter_lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
318
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
319 /* Other threads may run now */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
320
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
321 acquire_lock(interpreter_lock, 1);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
322 current_frame = f;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
323 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
324 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
325 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents: 815
diff changeset
326
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
327 /* Extract opcode and argument */
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
328
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
329 #ifdef DEBUG
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
330 f->f_lasti = INSTR_OFFSET();
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
331 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
332
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
333 opcode = NEXTOP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
334 if (HAS_ARG(opcode))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
335 oparg = NEXTARG();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
336
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
337 #ifdef LLTRACE
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
338 /* Instruction tracing */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
339
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
340 if (lltrace) {
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
341 if (HAS_ARG(opcode)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
342 printf("%d: %d, %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
343 (int) (INSTR_OFFSET() - 3),
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
344 opcode, oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
345 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
346 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
347 printf("%d: %d\n",
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
348 (int) (INSTR_OFFSET() - 1), opcode);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
349 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
350 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
351 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
352
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
353 if (!CHECK_STACK(3)) {
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
354 x = NULL;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
355 break;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
356 }
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
357
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
358 /* Main switch on opcode */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
359
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
360 switch (opcode) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
361
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
362 /* BEWARE!
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
363 It is essential that any operation that fails sets either
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
364 x to NULL, err to nonzero, or why to anything but WHY_NOT,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
365 and that no operation that succeeds does this! */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
366
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
367 /* case STOP_CODE: this is an error! */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
368
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
369 case POP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
370 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
371 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
372 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
373
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
374 case ROT_TWO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
375 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
376 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
377 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
378 PUSH(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
379 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
380
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
381 case ROT_THREE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
382 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
383 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
384 x = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
385 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
386 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
387 PUSH(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
388 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
389
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
390 case DUP_TOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
391 v = TOP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
392 INCREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
393 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
394 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
395
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
396 case UNARY_POSITIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
397 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
398 x = pos(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
399 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
400 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
401 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
402
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
403 case UNARY_NEGATIVE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
404 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
405 x = neg(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
406 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
407 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
408 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
409
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
410 case UNARY_NOT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
411 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
412 x = not(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
413 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
414 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
415 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
416
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
417 case UNARY_CONVERT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
418 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
419 x = reprobject(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
420 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
421 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
422 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
423
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
424 case UNARY_CALL:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
425 v = POP();
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
426 f->f_lasti = INSTR_OFFSET() - 1; /* For tracing */
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
427 x = call_object(v, (object *)NULL);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
428 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
429 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
430 break;
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
431
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
432 case UNARY_INVERT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
433 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
434 x = invert(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
435 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
436 PUSH(x);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
437 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
438
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
439 case BINARY_MULTIPLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
440 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
441 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
442 x = mul(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
443 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
444 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
445 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
446 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
447
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
448 case BINARY_DIVIDE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
449 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
450 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
451 x = divide(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
452 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
453 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
454 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
455 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
456
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
457 case BINARY_MODULO:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
458 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
459 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
460 x = rem(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
461 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
462 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
463 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
464 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
465
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
466 case BINARY_ADD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
467 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
468 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
469 x = add(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
470 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
471 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
472 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
473 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
474
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
475 case BINARY_SUBTRACT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
476 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
477 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
478 x = sub(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
479 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
480 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
481 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
482 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
483
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
484 case BINARY_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
485 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
486 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
487 x = apply_subscript(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
488 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
489 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
490 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
491 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
492
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
493 case BINARY_CALL:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
494 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
495 v = POP();
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
496 f->f_lasti = INSTR_OFFSET() - 1; /* For tracing */
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
497 x = call_object(v, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
498 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
499 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
500 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
501 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
502
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
503 case BINARY_LSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
504 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
505 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
506 x = lshift(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
507 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
508 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
509 PUSH(x);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
510 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
511
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
512 case BINARY_RSHIFT:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
513 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
514 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
515 x = rshift(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
516 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
517 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
518 PUSH(x);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
519 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
520
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
521 case BINARY_AND:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
522 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
523 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
524 x = and(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
525 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
526 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
527 PUSH(x);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
528 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
529
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
530 case BINARY_XOR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
531 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
532 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
533 x = xor(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
534 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
535 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
536 PUSH(x);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
537 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
538
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
539 case BINARY_OR:
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
540 w = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
541 v = POP();
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
542 x = or(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
543 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
544 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
545 PUSH(x);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
546 break;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
547
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
548 case SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
549 case SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
550 case SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
551 case SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
552 if ((opcode-SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
553 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
554 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
555 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
556 if ((opcode-SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
557 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
558 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
559 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
560 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
561 x = apply_slice(u, v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
562 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
563 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
564 XDECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
565 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
566 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
567
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
568 case STORE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
569 case STORE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
570 case STORE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
571 case STORE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
572 if ((opcode-STORE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
573 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
574 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
575 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
576 if ((opcode-STORE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
577 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
578 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
579 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
580 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
581 t = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
582 err = assign_slice(u, v, w, t); /* u[v:w] = t */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
583 DECREF(t);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
584 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
585 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
586 XDECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
587 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
588
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
589 case DELETE_SLICE+0:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
590 case DELETE_SLICE+1:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
591 case DELETE_SLICE+2:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
592 case DELETE_SLICE+3:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
593 if ((opcode-DELETE_SLICE) & 2)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
594 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
595 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
596 w = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
597 if ((opcode-DELETE_SLICE) & 1)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
598 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
599 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
600 v = NULL;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
601 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
602 err = assign_slice(u, v, w, (object *)NULL);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
603 /* del u[v:w] */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
604 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
605 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
606 XDECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
607 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
608
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
609 case STORE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
610 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
611 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
612 u = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
613 /* v[w] = u */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
614 err = assign_subscript(v, w, u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
615 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
616 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
617 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
618 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
619
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
620 case DELETE_SUBSCR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
621 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
622 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
623 /* del v[w] */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
624 err = assign_subscript(v, w, (object *)NULL);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
625 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
626 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
627 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
628
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
629 case PRINT_EXPR:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
630 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
631 /* Print value except if procedure result */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
632 if (v != None) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
633 flushline();
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
634 x = sysget("stdout");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
635 softspace(x, 1);
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
636 err = writeobject(v, x, 0);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
637 flushline();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
638 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
639 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
640 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
641
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
642 case PRINT_ITEM:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
643 v = POP();
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
644 w = sysget("stdout");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
645 if (softspace(w, 1))
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
646 writestring(" ", w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
647 if (is_stringobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
648 char *s = getstringvalue(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
649 int len = getstringsize(v);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
650 err = writeobject(v, w, PRINT_RAW);
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
651 if (err == 0 && len > 0 && s[len-1] == '\n')
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
652 softspace(w, 0);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
653 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
654 else {
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
655 err = writeobject(v, w, 0);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
656 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
657 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
658 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
659
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
660 case PRINT_NEWLINE:
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
661 x = sysget("stdout");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
662 if (x == NULL)
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
663 err_setstr(RuntimeError, "lost sys.stdout");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
664 else {
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
665 writestring("\n", x);
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
666 softspace(x, 0);
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
667 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
668 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
669
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
670 case BREAK_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
671 why = WHY_BREAK;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
672 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
673
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
674 case RAISE_EXCEPTION:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
675 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
676 w = POP();
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
677 /* A tuple is equivalent to its first element here */
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
678 while (is_tupleobject(w)) {
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
679 u = w;
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
680 w = gettupleitem(u, 0);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
681 DECREF(u);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
682 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
683 if (!is_stringobject(w))
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
684 err_setstr(TypeError,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
685 "exceptions must be strings");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
686 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
687 err_setval(w, v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
688 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
689 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
690 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
691 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
692
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
693 case LOAD_LOCALS:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
694 v = f->f_locals;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
695 INCREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
696 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
697 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
698
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
699 case RETURN_VALUE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
700 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
701 why = WHY_RETURN;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
702 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
703
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
704 case BUILD_FUNCTION:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
705 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
706 x = newfuncobject(v, f->f_globals);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
707 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
708 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
709 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
710
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
711 case POP_BLOCK:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
712 {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
713 block *b = pop_block(f);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
714 while (STACK_LEVEL() > b->b_level) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
715 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
716 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
717 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
718 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
719 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
720
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
721 case END_FINALLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
722 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
723 if (is_intobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
724 why = (enum why_code) getintvalue(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
725 if (why == WHY_RETURN)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
726 retval = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
727 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
728 else if (is_stringobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
729 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
730 err_setval(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
731 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
732 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
733 tb_store(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
734 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
735 why = WHY_RERAISE;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
736 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
737 else if (v != None) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
738 err_setstr(SystemError,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
739 "'finally' pops bad exception");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
740 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
741 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
742 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
743 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
744
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
745 case BUILD_CLASS:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
746 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
747 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
748 x = build_class(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
749 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
750 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
751 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
752 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
753
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
754 case STORE_NAME:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
755 w = GETNAMEV(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
756 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
757 err = dict2insert(f->f_locals, w, v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
758 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
759 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
760
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
761 case DELETE_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
762 w = GETNAMEV(oparg);
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
763 if ((err = dict2remove(f->f_locals, w)) != 0)
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
764 err_setstr(NameError, getstringvalue(w));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
765 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
766
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
767 #ifdef CASE_TOO_BIG
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
768 default: switch (opcode) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
769 #endif
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
770
581
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
771 case UNPACK_VARARG:
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
772 if (EMPTY()) {
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
773 err_setstr(TypeError,
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
774 "no argument list");
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
775 why = WHY_EXCEPTION;
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
776 break;
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
777 }
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
778 v = POP();
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
779 if (!is_tupleobject(v)) {
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
780 err_setstr(TypeError,
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
781 "bad argument list");
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
782 why = WHY_EXCEPTION;
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
783 }
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
784 else if (gettuplesize(v) < oparg) {
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
785 err_setstr(TypeError,
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
786 "not enough arguments");
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
787 why = WHY_EXCEPTION;
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
788 }
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
789 else if (oparg == 0) {
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
790 PUSH(v);
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
791 break;
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
792 }
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
793 else {
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
794 x = gettupleslice(v, oparg, gettuplesize(v));
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
795 if (x != NULL) {
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
796 PUSH(x);
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
797 if (!CHECK_STACK(oparg)) {
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
798 x = NULL;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
799 break;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
800 }
581
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
801 for (; --oparg >= 0; ) {
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
802 w = gettupleitem(v, oparg);
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
803 INCREF(w);
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
804 PUSH(w);
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
805 }
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
806 }
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
807 }
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
808 DECREF(v);
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
809 break;
bae1494f2ec8 Added UNPACK_VARARG code.
Guido van Rossum <guido@python.org>
parents: 567
diff changeset
810
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
811 case UNPACK_ARG:
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
812 {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
813 int n;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
814 if (EMPTY()) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
815 err_setstr(TypeError,
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
816 "no argument list");
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
817 why = WHY_EXCEPTION;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
818 break;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
819 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
820 v = POP();
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
821 if (!is_tupleobject(v)) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
822 err_setstr(TypeError,
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
823 "bad argument list");
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
824 why = WHY_EXCEPTION;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
825 break;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
826 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
827 n = gettuplesize(v);
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
828 #ifdef COMPAT_HACKS
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
829 /* Implement various compatibility hacks (for 0.9.4 or earlier):
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
830 (a) f(a,b,...) accepts f((1,2,...))
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
831 (b) f((a,b,...)) accepts f(1,2,...)
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
832 (c) f(self,(a,b,...)) accepts f(x,1,2,...)
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
833 */
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
834 if (n == 1 && oparg != 1) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
835 /* Rule (a) */
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
836 w = gettupleitem(v, 0);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
837 if (is_tupleobject(w)) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
838 INCREF(w);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
839 DECREF(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
840 v = w;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
841 n = gettuplesize(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
842 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
843 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
844 else if (n != 1 && oparg == 1) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
845 /* Rule (b) */
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
846 PUSH(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
847 break;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
848 /* Don't fall through */
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
849 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
850 else if (n > 2 && oparg == 2) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
851 /* Rule (c) */
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
852 int i;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
853 w = newtupleobject(n-1);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
854 u = newtupleobject(2);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
855 if (u == NULL || w == NULL) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
856 XDECREF(w);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
857 XDECREF(u);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
858 DECREF(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
859 why = WHY_EXCEPTION;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
860 break;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
861 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
862 t = gettupleitem(v, 0);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
863 INCREF(t);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
864 settupleitem(u, 0, t);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
865 for (i = 1; i < n; i++) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
866 t = gettupleitem(v, i);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
867 INCREF(t);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
868 settupleitem(w, i-1, t);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
869 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
870 settupleitem(u, 1, w);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
871 DECREF(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
872 v = u;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
873 n = 2;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
874 }
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents: 1096
diff changeset
875 #endif /* Disabled compatibility hacks */
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
876 if (n != oparg) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
877 err_setstr(TypeError,
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
878 "arg count mismatch");
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
879 why = WHY_EXCEPTION;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
880 DECREF(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
881 break;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
882 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
883 PUSH(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
884 }
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
885 /* Fall through */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
886 case UNPACK_TUPLE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
887 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
888 if (!is_tupleobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
889 err_setstr(TypeError, "unpack non-tuple");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
890 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
891 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
892 else if (gettuplesize(v) != oparg) {
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
893 err_setstr(ValueError,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
894 "unpack tuple of wrong size");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
895 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
896 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
897 else {
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
898 if (!CHECK_STACK(oparg)) {
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
899 x = NULL;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
900 break;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
901 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
902 for (; --oparg >= 0; ) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
903 w = gettupleitem(v, oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
904 INCREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
905 PUSH(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
906 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
907 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
908 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
909 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
910
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
911 case UNPACK_LIST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
912 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
913 if (!is_listobject(v)) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
914 err_setstr(TypeError, "unpack non-list");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
915 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
916 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
917 else if (getlistsize(v) != oparg) {
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
918 err_setstr(ValueError,
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
919 "unpack list of wrong size");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
920 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
921 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
922 else {
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
923 if (!CHECK_STACK(oparg)) {
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
924 x = NULL;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
925 break;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
926 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
927 for (; --oparg >= 0; ) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
928 w = getlistitem(v, oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
929 INCREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
930 PUSH(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
931 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
932 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
933 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
934 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
935
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
936 case STORE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
937 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
938 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
939 u = POP();
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
940 err = setattro(v, w, u); /* v.w = u */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
941 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
942 DECREF(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
943 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
944
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
945 case DELETE_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
946 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
947 v = POP();
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
948 err = setattro(v, w, (object *)NULL); /* del v.w */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
949 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
950 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
951
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
952 case STORE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
953 w = GETNAMEV(oparg);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
954 v = POP();
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
955 err = dict2insert(f->f_globals, w, v);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
956 DECREF(v);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
957 break;
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
958
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
959 case DELETE_GLOBAL:
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
960 w = GETNAMEV(oparg);
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
961 if ((err = dict2remove(f->f_globals, w)) != 0)
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
962 err_setstr(NameError, getstringvalue(w));
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
963 break;
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
964
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
965 case LOAD_CONST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
966 x = GETCONST(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
967 INCREF(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
968 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
969 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
970
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
971 case LOAD_NAME:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
972 w = GETNAMEV(oparg);
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
973 x = dict2lookup(f->f_locals, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
974 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
975 err_clear();
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
976 x = dict2lookup(f->f_globals, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
977 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
978 err_clear();
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
979 x = getbuiltin(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
980 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
981 err_setstr(NameError,
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
982 getstringvalue(w));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
983 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
984 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
985 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
986 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
987 INCREF(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
988 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
989 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
990
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
991 case LOAD_GLOBAL:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
992 w = GETNAMEV(oparg);
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
993 x = dict2lookup(f->f_globals, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
994 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
995 err_clear();
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
996 x = getbuiltin(w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
997 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
998 err_setstr(NameError,
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
999 getstringvalue(w));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1000 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1001 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1002 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1003 INCREF(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1004 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1005 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1006
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1007 case LOAD_LOCAL:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1008 w = GETNAMEV(oparg);
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1009 x = dict2lookup(f->f_locals, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1010 if (x == NULL) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1011 err_setstr(NameError, getstringvalue(w));
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1012 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1013 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1014 INCREF(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1015 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1016 break;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1017
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1018 case RESERVE_FAST:
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1019 x = GETCONST(oparg);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1020 if (x == None)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1021 break;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1022 if (x == NULL || !is_dictobject(x)) {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1023 fatal("bad RESERVE_FAST");
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1024 err_setstr(SystemError, "bad RESERVE_FAST");
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1025 x = NULL;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1026 break;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1027 }
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1028 XDECREF(f->f_fastlocals);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1029 XDECREF(f->f_localmap);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1030 INCREF(x);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1031 f->f_localmap = x;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1032 f->f_fastlocals = x = newlistobject(
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1033 x->ob_type->tp_as_mapping->mp_length(x));
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1034 fastlocals = (listobject *) x;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1035 break;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1036
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1037 case LOAD_FAST:
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1038 x = GETLISTITEM(fastlocals, oparg);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1039 if (x == NULL) {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1040 err_setstr(NameError,
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1041 "undefined local variable");
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1042 break;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1043 }
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1044 INCREF(x);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1045 PUSH(x);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1046 break;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1047
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1048 case STORE_FAST:
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1049 w = GETLISTITEM(fastlocals, oparg);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1050 XDECREF(w);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1051 w = POP();
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1052 GETLISTITEM(fastlocals, oparg) = w;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1053 break;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1054
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1055 case DELETE_FAST:
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1056 x = GETLISTITEM(fastlocals, oparg);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1057 if (x == NULL) {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1058 err_setstr(NameError,
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1059 "undefined local variable");
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1060 break;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1061 }
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1062 DECREF(x);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1063 GETLISTITEM(fastlocals, oparg) = NULL;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1064 break;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1065
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1066 case BUILD_TUPLE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1067 x = newtupleobject(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1068 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1069 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1070 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1071 err = settupleitem(x, oparg, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1072 if (err != 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1073 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1074 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1075 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1076 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1077 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1078
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1079 case BUILD_LIST:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1080 x = newlistobject(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1081 if (x != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1082 for (; --oparg >= 0;) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1083 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1084 err = setlistitem(x, oparg, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1085 if (err != 0)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1086 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1087 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1088 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1089 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1090 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1091
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1092 case BUILD_MAP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1093 x = newdictobject();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1094 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1095 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1096
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1097 case LOAD_ATTR:
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1098 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1099 v = POP();
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1100 x = getattro(v, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1101 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1102 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1103 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1104
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1105 case COMPARE_OP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1106 w = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1107 v = POP();
802
3d6541a2eca5 Arg of cmp_outcome becomes an int for portability to the Mac
Guido van Rossum <guido@python.org>
parents: 789
diff changeset
1108 x = cmp_outcome(oparg, v, w);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1109 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1110 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1111 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1112 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1113
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1114 case IMPORT_NAME:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1115 name = GETNAME(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1116 x = import_module(name);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1117 XINCREF(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1118 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1119 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1120
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1121 case IMPORT_FROM:
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1122 w = GETNAMEV(oparg);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1123 v = TOP();
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
1124 err = import_from(f->f_locals, v, w);
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1125 locals_2_fast(f, 0);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1126 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1127
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1128 case JUMP_FORWARD:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1129 JUMPBY(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1130 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1131
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1132 case JUMP_IF_FALSE:
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1133 err = testbool(TOP());
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1134 if (err > 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1135 err = 0;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1136 else if (err == 0)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1137 JUMPBY(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1138 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1139
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1140 case JUMP_IF_TRUE:
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1141 err = testbool(TOP());
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1142 if (err > 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1143 err = 0;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1144 JUMPBY(oparg);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1145 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1146 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1147
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1148 case JUMP_ABSOLUTE:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1149 JUMPTO(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1150 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1151
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1152 case FOR_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1153 /* for v in s: ...
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1154 On entry: stack contains s, i.
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1155 On exit: stack contains s, i+1, s[i];
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1156 but if loop exhausted:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1157 s, i are popped, and we jump */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1158 w = POP(); /* Loop index */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1159 v = POP(); /* Sequence object */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1160 u = loop_subscript(v, w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1161 if (u != NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1162 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1163 x = newintobject(getintvalue(w)+1);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1164 PUSH(x);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1165 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1166 PUSH(u);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1167 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1168 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1169 DECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1170 DECREF(w);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1171 /* A NULL can mean "s exhausted"
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1172 but also an error: */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1173 if (err_occurred())
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1174 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1175 else
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1176 JUMPBY(oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1177 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1178 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1179
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1180 case SETUP_LOOP:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1181 case SETUP_EXCEPT:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1182 case SETUP_FINALLY:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1183 setup_block(f, opcode, INSTR_OFFSET() + oparg,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1184 STACK_LEVEL());
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1185 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1186
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1187 case SET_LINENO:
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1188 #ifdef LLTRACE
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1189 if (lltrace)
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1190 printf("--- Line %d ---\n", oparg);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1191 #endif
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1192 f->f_lineno = oparg;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1193 if (trace != NULL) {
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1194 /* Trace each line of code reached */
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1195 f->f_lasti = INSTR_OFFSET();
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1196 err = call_trace(&trace, &trace,
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1197 f, "line", None);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1198 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1199 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1200
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1201 default:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1202 fprintf(stderr,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1203 "XXX lineno: %d, opcode: %d\n",
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1204 f->f_lineno, opcode);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1205 err_setstr(SystemError, "eval_code: unknown opcode");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1206 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1207 break;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1208
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1209 #ifdef CASE_TOO_BIG
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1210 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1211 #endif
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1212
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1213 } /* switch */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1214
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1215 on_error:
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1216
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1217 /* Quickly continue if no error occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1218
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1219 if (why == WHY_NOT) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1220 if (err == 0 && x != NULL)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1221 continue; /* Normal, fast path */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1222 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1223 x = None;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1224 err = 0;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1225 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1226
814
f08d34499269 reverse sense of test for CHECKEXC
Guido van Rossum <guido@python.org>
parents: 802
diff changeset
1227 #ifdef CHECKEXC
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1228 /* Double-check exception status */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1229
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1230 if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1231 if (!err_occurred()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1232 fprintf(stderr, "XXX ghost error\n");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1233 err_setstr(SystemError, "ghost error");
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1234 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1235 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1236 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1237 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1238 if (err_occurred()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1239 fprintf(stderr, "XXX undetected error\n");
1016
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
1240 abort();
a41e3ba5b47d Add some debugging features if DEBUG defined
Guido van Rossum <guido@python.org>
parents: 974
diff changeset
1241 /* NOTREACHED */
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1242 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1243 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1244 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1245 #endif
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1246
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1247 /* Log traceback info if this is a real exception */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1248
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1249 if (why == WHY_EXCEPTION) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1250 f->f_lasti = INSTR_OFFSET() - 1;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1251 if (HAS_ARG(opcode))
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1252 f->f_lasti -= 2;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1253 tb_here(f);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1254
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1255 if (trace)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1256 call_exc_trace(&trace, &trace, f);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1257 if (sys_profile)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1258 call_exc_trace(&sys_profile, (object**)0, f);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1259 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1260
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1261 /* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1262
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1263 if (why == WHY_RERAISE)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1264 why = WHY_EXCEPTION;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1265
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1266 /* Unwind stacks if a (pseudo) exception occurred */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1267
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1268 while (why != WHY_NOT && f->f_iblock > 0) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1269 block *b = pop_block(f);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1270 while (STACK_LEVEL() > b->b_level) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1271 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1272 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1273 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1274 if (b->b_type == SETUP_LOOP && why == WHY_BREAK) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1275 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1276 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1277 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1278 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1279 if (b->b_type == SETUP_FINALLY ||
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1280 b->b_type == SETUP_EXCEPT &&
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1281 why == WHY_EXCEPTION) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1282 if (why == WHY_EXCEPTION) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1283 object *exc, *val;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1284 err_get(&exc, &val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1285 if (val == NULL) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1286 val = None;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1287 INCREF(val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1288 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1289 v = tb_fetch();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1290 /* Make the raw exception data
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1291 available to the handler,
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1292 so a program can emulate the
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1293 Python main loop. Don't do
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1294 this for 'finally'. */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1295 if (b->b_type == SETUP_EXCEPT) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1296 sysset("exc_traceback", v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1297 sysset("exc_value", val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1298 sysset("exc_type", exc);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1299 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1300 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1301 PUSH(val);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1302 PUSH(exc);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1303 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1304 else {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1305 if (why == WHY_RETURN)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1306 PUSH(retval);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1307 v = newintobject((long)why);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1308 PUSH(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1309 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1310 why = WHY_NOT;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1311 JUMPTO(b->b_handler);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1312 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1313 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1314 } /* unwind stack */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1315
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1316 /* End the loop if we still have an error (or return) */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1317
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1318 if (why != WHY_NOT)
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1319 break;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1320
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1321 } /* main loop */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1322
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1323 /* Pop remaining stack entries */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1324
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1325 while (!EMPTY()) {
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1326 v = POP();
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1327 XDECREF(v);
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1328 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1329
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1330 if (why != WHY_RETURN)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1331 retval = NULL;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1332
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1333 if (trace) {
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1334 if (why == WHY_RETURN) {
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1335 if (call_trace(&trace, &trace, f, "return", retval)) {
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1336 XDECREF(retval);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1337 retval = NULL;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1338 why = WHY_EXCEPTION;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1339 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1340 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1341 XDECREF(trace);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1342 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1343
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1344 if (sys_profile && why == WHY_RETURN) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1345 if (call_trace(&sys_profile, (object**)0,
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1346 f, "return", retval)) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1347 XDECREF(retval);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1348 retval = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1349 why = WHY_EXCEPTION;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1350 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1351 }
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1352
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1353 if (fastlocals && (f->ob_refcnt > 1 || f->f_locals->ob_refcnt > 2))
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1354 fast_2_locals(f);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1355
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1356 /* Restore previous frame and release the current one */
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1357
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1358 current_frame = f->f_back;
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1359 DECREF(f);
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1360
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1361 if (needmerge)
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1362 locals_2_fast(current_frame, 1);
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1363
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1364 return retval;
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1365 }
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1366
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1367 #ifdef LLTRACE
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1368 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1369 prtrace(v, str)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1370 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1371 char *str;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1372 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1373 printf("%s ", str);
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 260
diff changeset
1374 if (printobject(v, stdout, 0) != 0)
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 260
diff changeset
1375 err_clear(); /* Don't know what else to do */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1376 printf("\n");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1377 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1378 #endif
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1379
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1380 static void
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1381 call_exc_trace(p_trace, p_newtrace, f)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1382 object **p_trace, **p_newtrace;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1383 frameobject *f;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1384 {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1385 object *type, *value, *traceback, *arg;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1386 int err;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1387 err_get(&type, &value);
815
6508c93f9472 Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 814
diff changeset
1388 if (value == NULL) {
6508c93f9472 Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 814
diff changeset
1389 value = None;
6508c93f9472 Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 814
diff changeset
1390 INCREF(value);
6508c93f9472 Test for NULL coming out of err_get() in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 814
diff changeset
1391 }
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1392 traceback = tb_fetch();
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1393 arg = newtupleobject(3);
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1394 if (arg == NULL)
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1395 goto cleanup;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1396 settupleitem(arg, 0, type);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1397 settupleitem(arg, 1, value);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1398 settupleitem(arg, 2, traceback);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1399 err = call_trace(p_trace, p_newtrace, f, "exception", arg);
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1400 if (!err) {
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1401 cleanup:
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1402 /* Restore original exception */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1403 err_setval(type, value);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1404 tb_store(traceback);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1405 }
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1406 XDECREF(arg);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1407 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1408
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1409 static int
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1410 call_trace(p_trace, p_newtrace, f, msg, arg)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1411 object **p_trace; /* in/out; may not be NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1412 may not point to NULL variable initially */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1413 object **p_newtrace; /* in/out; may be NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1414 may point to NULL variable;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1415 may be same variable as p_newtrace */
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1416 frameobject *f;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1417 char *msg;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1418 object *arg;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1419 {
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1420 object *arglist, *what;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1421 object *res = NULL;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1422 static int tracing = 0;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1423
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1424 if (tracing) {
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1425 /* Don't do recursive traces */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1426 if (p_newtrace) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1427 XDECREF(*p_newtrace);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1428 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1429 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1430 return 0;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1431 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1432
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1433 arglist = newtupleobject(3);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1434 if (arglist == NULL)
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1435 goto cleanup;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1436 what = newstringobject(msg);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1437 if (what == NULL)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1438 goto cleanup;
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1439 INCREF(f);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1440 settupleitem(arglist, 0, (object *)f);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1441 settupleitem(arglist, 1, what);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1442 if (arg == NULL)
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1443 arg = None;
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1444 INCREF(arg);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1445 settupleitem(arglist, 2, arg);
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1446 tracing++;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1447 fast_2_locals(f);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1448 res = call_object(*p_trace, arglist);
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1449 locals_2_fast(f, 1);
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1450 tracing--;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1451 cleanup:
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1452 XDECREF(arglist);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1453 if (res == NULL) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1454 /* The trace proc raised an exception */
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1455 tb_here(f);
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1456 DECREF(*p_trace);
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1457 *p_trace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1458 if (p_newtrace) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1459 XDECREF(*p_newtrace);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1460 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1461 }
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1462 return -1;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1463 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1464 else {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1465 if (p_newtrace) {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1466 XDECREF(*p_newtrace);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1467 if (res == None)
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1468 *p_newtrace = NULL;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1469 else {
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1470 INCREF(res);
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1471 *p_newtrace = res;
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1472 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1473 }
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1474 DECREF(res);
789
f565cf7f9aba (Hopefully) fix bug in reference count in call_exc_trace()
Guido van Rossum <guido@python.org>
parents: 746
diff changeset
1475 return 0;
708
8bcb50f436fa New trace implementation; and profile (in a similat vein).
Guido van Rossum <guido@python.org>
parents: 688
diff changeset
1476 }
567
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1477 }
8c179d023583 User trace feature.
Guido van Rossum <guido@python.org>
parents: 565
diff changeset
1478
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1479 static void
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1480 fast_2_locals(f)
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1481 frameobject *f;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1482 {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1483 /* Merge f->f_fastlocals into f->f_locals */
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1484 object *locals, *fast, *map;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1485 object *error_type, *error_value;
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1486 int i;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1487 if (f == NULL)
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1488 return;
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1489 locals = f->f_locals;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1490 fast = f->f_fastlocals;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1491 map = f->f_localmap;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1492 if (locals == NULL || fast == NULL || map == NULL)
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1493 return;
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1494 if (!is_dictobject(locals) || !is_listobject(fast) ||
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1495 !is_dictobject(map))
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1496 return;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1497 err_get(&error_type, &error_value);
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1498 i = getdictsize(map);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1499 while (--i >= 0) {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1500 object *key;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1501 object *value;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1502 int j;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1503 key = getdict2key(map, i);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1504 if (key == NULL)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1505 continue;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1506 value = dict2lookup(map, key);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1507 if (value == NULL || !is_intobject(value))
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1508 continue;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1509 j = getintvalue(value);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1510 value = getlistitem(fast, j);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1511 if (value == NULL) {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1512 err_clear();
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1513 if (dict2remove(locals, key) != 0)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1514 err_clear();
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1515 }
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1516 else {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1517 if (dict2insert(locals, key, value) != 0)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1518 err_clear();
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1519 }
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1520 }
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1521 err_setval(error_type, error_value);
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1522 }
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1523
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1524 static void
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1525 locals_2_fast(f, clear)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1526 frameobject *f;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1527 int clear;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1528 {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1529 /* Merge f->f_locals into f->f_fastlocals */
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1530 object *locals, *fast, *map;
1273
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
1531 object *error_type, *error_value;
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1532 int i;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1533 if (f == NULL)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1534 return;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1535 locals = f->f_locals;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1536 fast = f->f_fastlocals;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1537 map = f->f_localmap;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1538 if (locals == NULL || fast == NULL || map == NULL)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1539 return;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1540 if (!is_dictobject(locals) || !is_listobject(fast) ||
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1541 !is_dictobject(map))
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1542 return;
1273
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
1543 err_get(&error_type, &error_value);
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1544 i = getdictsize(map);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1545 while (--i >= 0) {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1546 object *key;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1547 object *value;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1548 int j;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1549 key = getdict2key(map, i);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1550 if (key == NULL)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1551 continue;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1552 value = dict2lookup(map, key);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1553 if (value == NULL || !is_intobject(value))
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1554 continue;
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1555 j = getintvalue(value);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1556 value = dict2lookup(locals, key);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1557 if (value == NULL)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1558 err_clear();
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1559 else
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1560 INCREF(value);
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1561 if (value != NULL || clear)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1562 if (setlistitem(fast, j, value) != 0)
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1563 err_clear();
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1564 }
1273
69a066b6b1ff (I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
1565 err_setval(error_type, error_value);
1262
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1566 }
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1567
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1568 void
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1569 mergelocals()
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1570 {
f820e6917f07 Changes to speed up local variables enormously, by avoiding dictionary
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
1571 locals_2_fast(current_frame, 1);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1572 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1573
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1574 object *
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1575 getlocals()
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1576 {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1577 if (current_frame == NULL)
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1578 return NULL;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1579 fast_2_locals(current_frame);
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1580 return current_frame->f_locals;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1581 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1582
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
1583 object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1584 getglobals()
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1585 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1586 if (current_frame == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1587 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1588 else
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1589 return current_frame->f_globals;
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
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1592 void
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
1593 printtraceback(f)
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
1594 object *f;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1595 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1596 object *v = tb_fetch();
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1597 if (v != NULL) {
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
1598 writestring("Stack backtrace (innermost last):\n", f);
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
1599 tb_print(v, f);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1600 DECREF(v);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1601 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1602 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1603
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1604
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1605 void
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1606 flushline()
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1607 {
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
1608 object *f = sysget("stdout");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
1609 if (softspace(f, 0))
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1016
diff changeset
1610 writestring("\n", f);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1611 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1612
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1613
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1614 static object *
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1615 or(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1616 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1617 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1618 if (v->ob_type->tp_as_number != NULL) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1619 object *x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1620 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1621 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1622 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1623 if ((f = v->ob_type->tp_as_number->nb_or) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1624 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1625 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1626 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1627 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1628 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1629 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1630 err_setstr(TypeError, "bad operand type(s) for |");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1631 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1632 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1633
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1634 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1635 xor(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1636 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1637 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1638 if (v->ob_type->tp_as_number != NULL) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1639 object *x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1640 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1641 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1642 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1643 if ((f = v->ob_type->tp_as_number->nb_xor) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1644 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1645 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1646 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1647 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1648 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1649 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1650 err_setstr(TypeError, "bad operand type(s) for ^");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1651 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1652 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1653
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1654 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1655 and(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1656 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1657 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1658 if (v->ob_type->tp_as_number != NULL) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1659 object *x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1660 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1661 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1662 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1663 if ((f = v->ob_type->tp_as_number->nb_and) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1664 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1665 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1666 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1667 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1668 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1669 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1670 err_setstr(TypeError, "bad operand type(s) for &");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1671 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1672 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1673
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1674 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1675 lshift(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1676 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1677 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1678 if (v->ob_type->tp_as_number != NULL) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1679 object *x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1680 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1681 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1682 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1683 if ((f = v->ob_type->tp_as_number->nb_lshift) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1684 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1685 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1686 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1687 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1688 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1689 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1690 err_setstr(TypeError, "bad operand type(s) for <<");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1691 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1692 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1693
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1694 static object *
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1695 rshift(v, w)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1696 object *v, *w;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1697 {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1698 if (v->ob_type->tp_as_number != NULL) {
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1699 object *x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1700 object * (*f) FPROTO((object *, object *));
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1701 if (coerce(&v, &w) != 0)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1702 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1703 if ((f = v->ob_type->tp_as_number->nb_rshift) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1704 x = (*f)(v, w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1705 DECREF(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1706 DECREF(w);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1707 if (f != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1708 return x;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1709 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1710 err_setstr(TypeError, "bad operand type(s) for >>");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1711 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1712 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1713
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1714 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1715 add(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1716 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1717 {
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1718 if (v->ob_type->tp_as_sequence != NULL)
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1719 return (*v->ob_type->tp_as_sequence->sq_concat)(v, w);
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1720 else if (v->ob_type->tp_as_number != NULL) {
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1721 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1722 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1723 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1724 x = (*v->ob_type->tp_as_number->nb_add)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1725 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1726 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1727 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1728 }
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1181
diff changeset
1729 err_setstr(TypeError, "bad operand type(s) for +");
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1181
diff changeset
1730 return NULL;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1731 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1732
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1733 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1734 sub(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1735 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1736 {
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1737 if (v->ob_type->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1738 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1739 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1740 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1741 x = (*v->ob_type->tp_as_number->nb_subtract)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1742 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1743 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1744 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1745 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1746 err_setstr(TypeError, "bad operand type(s) for -");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1747 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1748 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1749
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1750 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1751 mul(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1752 object *v, *w;
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 typeobject *tp;
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1755 tp = v->ob_type;
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1756 if (tp->tp_as_number != NULL &&
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1757 w->ob_type->tp_as_sequence != NULL &&
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1758 !is_instanceobject(v)) {
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1759 /* number*sequence -- swap v and w */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1760 object *tmp = v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1761 v = w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1762 w = tmp;
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1763 tp = v->ob_type;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1764 }
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1765 if (tp->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1766 object *x;
955
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1767 if (is_instanceobject(v)) {
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1768 /* Instances of user-defined classes get their
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1769 other argument uncoerced, so they may
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1770 implement sequence*number as well as
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1771 number*number. */
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1772 INCREF(v);
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1773 INCREF(w);
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1774 }
03de67080c95 * classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents: 944
diff changeset
1775 else if (coerce(&v, &w) != 0)
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1776 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1777 x = (*v->ob_type->tp_as_number->nb_multiply)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1778 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1779 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1780 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1781 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1782 if (tp->tp_as_sequence != NULL) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1783 if (!is_intobject(w)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1784 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1785 "can't multiply sequence with non-int");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1786 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1787 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1788 return (*tp->tp_as_sequence->sq_repeat)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1789 (v, (int)getintvalue(w));
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1790 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1791 err_setstr(TypeError, "bad operand type(s) for *");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1792 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1793 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1794
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1795 static object *
88
16e8c5d16493 Change div() into divide(); div() is a Standard C function.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
1796 divide(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1797 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1798 {
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1799 if (v->ob_type->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1800 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1801 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1802 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1803 x = (*v->ob_type->tp_as_number->nb_divide)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1804 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1805 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1806 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1807 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1808 err_setstr(TypeError, "bad operand type(s) for /");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1809 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1810 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1811
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1812 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1813 rem(v, w)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1814 object *v, *w;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1815 {
302
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1816 if (v->ob_type->tp_as_number != NULL) {
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1817 object *x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1818 if (coerce(&v, &w) != 0)
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1819 return NULL;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1820 x = (*v->ob_type->tp_as_number->nb_remainder)(v, w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1821 DECREF(v);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1822 DECREF(w);
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1823 return x;
d19a665904df Call coerce() in arithmetic operations, to support mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
1824 }
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1207
diff changeset
1825 if (is_stringobject(v)) {
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1207
diff changeset
1826 return formatstring(v, w);
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1207
diff changeset
1827 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1828 err_setstr(TypeError, "bad operand type(s) for %");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1829 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1830 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1831
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1832 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1833 neg(v)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1834 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1835 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1836 if (v->ob_type->tp_as_number != NULL)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1837 return (*v->ob_type->tp_as_number->nb_negative)(v);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1838 err_setstr(TypeError, "bad operand type(s) for unary -");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1839 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1840 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1841
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1842 static object *
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1843 pos(v)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1844 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1845 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1846 if (v->ob_type->tp_as_number != NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1847 return (*v->ob_type->tp_as_number->nb_positive)(v);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1848 err_setstr(TypeError, "bad operand type(s) for unary +");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1849 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1850 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1851
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1852 static object *
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1853 invert(v)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1854 object *v;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1855 {
671
10002e1bc526 Use correct prototype for invert().
Guido van Rossum <guido@python.org>
parents: 661
diff changeset
1856 object * (*f) FPROTO((object *));
409
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1857 if (v->ob_type->tp_as_number != NULL &&
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1858 (f = v->ob_type->tp_as_number->nb_invert) != NULL)
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1859 return (*f)(v);
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1860 err_setstr(TypeError, "bad operand type(s) for unary ~");
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1861 return NULL;
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1862 }
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1863
b5fe6482072f Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents: 401
diff changeset
1864 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1865 not(v)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1866 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1867 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1868 int outcome = testbool(v);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1869 object *w;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1870 if (outcome < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1871 return NULL;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1872 if (outcome == 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1873 w = True;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1874 else
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1875 w = False;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1876 INCREF(w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1877 return w;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1878 }
314
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1879 /* External interface to call any callable object. The arg may be NULL. */
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1880
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1881 object *
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1882 call_object(func, arg)
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1883 object *func;
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1884 object *arg;
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1885 {
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1886 if (is_instancemethodobject(func) || is_funcobject(func))
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1887 return call_function(func, arg);
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1888 else
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1889 return call_builtin(func, arg);
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1890 }
e83852d1a5e2 Add interface to call a Python function (or other callable) object
Guido van Rossum <guido@python.org>
parents: 312
diff changeset
1891
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1892 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1893 call_builtin(func, arg)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1894 object *func;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1895 object *arg;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1896 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1897 if (is_methodobject(func)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1898 method meth = getmethod(func);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1899 object *self = getself(func);
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1900 if (!getvarargs(func) && arg != NULL && is_tupleobject(arg)) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1901 int size = gettuplesize(arg);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1902 if (size == 1)
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1903 arg = gettupleitem(arg, 0);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1904 else if (size == 0)
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1905 arg = NULL;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1906 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1907 return (*meth)(self, arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1908 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1909 if (is_classobject(func)) {
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1910 if (arg != NULL &&
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1911 !(is_tupleobject(arg) &&
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1912 gettuplesize(arg) == 0)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1913 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1914 "classobject() allows no arguments");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1915 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1916 }
173
4656452436e1 Moved support functions after main function; added prototypes;
Guido van Rossum <guido@python.org>
parents: 159
diff changeset
1917 return newinstanceobject(func);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1918 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1919 err_setstr(TypeError, "call of non-function");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1920 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1921 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1922
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1923 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1924 call_function(func, arg)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1925 object *func;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1926 object *arg;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1927 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1928 object *newarg = NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1929 object *newlocals, *newglobals;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1930 object *co, *v;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1931
224
e71b6fec86e5 Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents: 173
diff changeset
1932 if (is_instancemethodobject(func)) {
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1933 int argcount;
224
e71b6fec86e5 Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents: 173
diff changeset
1934 object *self = instancemethodgetself(func);
e71b6fec86e5 Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents: 173
diff changeset
1935 func = instancemethodgetfunc(func);
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1936 if (arg == NULL)
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1937 argcount = 0;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1938 else if (is_tupleobject(arg))
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1939 argcount = gettuplesize(arg);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1940 else
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1941 argcount = 1;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1942 newarg = newtupleobject(argcount + 1);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1943 if (newarg == NULL)
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1944 return NULL;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1945 INCREF(self);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1946 settupleitem(newarg, 0, self);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1947 if (arg != NULL && !is_tupleobject(arg)) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1948 INCREF(arg);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1949 settupleitem(newarg, 1, arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1950 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1951 else {
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1952 int i;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1953 object *v;
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1954 for (i = 0; i < argcount; i++) {
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1955 v = gettupleitem(arg, i);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1956 XINCREF(v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1957 settupleitem(newarg, i+1, v);
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1958 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1959 }
481
dc0463453a64 New argument passing mechanism.
Guido van Rossum <guido@python.org>
parents: 464
diff changeset
1960 arg = newarg;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1961 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1962 else {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1963 if (!is_funcobject(func)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1964 err_setstr(TypeError, "call of non-function");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1965 return NULL;
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
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1969 co = getfunccode(func);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1970 if (co == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1971 XDECREF(newarg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1972 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1973 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1974 if (!is_codeobject(co)) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1975 fprintf(stderr, "XXX Bad code\n");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1976 abort();
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1977 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1978 newlocals = newdictobject();
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1979 if (newlocals == NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1980 XDECREF(newarg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1981 return NULL;
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
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1984 newglobals = getfuncglobals(func);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1985 INCREF(newglobals);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1986
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1987 v = eval_code((codeobject *)co, newglobals, newlocals, arg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1988
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1989 DECREF(newlocals);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1990 DECREF(newglobals);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1991
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1992 XDECREF(newarg);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1993
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1994 return v;
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
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1997 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
1998 apply_subscript(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1999 object *v, *w;
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 typeobject *tp = v->ob_type;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2002 if (tp->tp_as_sequence == NULL && tp->tp_as_mapping == NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2003 err_setstr(TypeError, "unsubscriptable object");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2004 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2005 }
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2006 if (tp->tp_as_mapping != NULL) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2007 return (*tp->tp_as_mapping->mp_subscript)(v, w);
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2008 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2009 else {
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2010 int i;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2011 if (!is_intobject(w)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2012 err_setstr(TypeError, "sequence subscript not int");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2013 return NULL;
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 i = getintvalue(w);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2016 if (i < 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2017 int len = (*tp->tp_as_sequence->sq_length)(v);
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2018 if (len < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2019 return NULL;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2020 i += len;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2021 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2022 return (*tp->tp_as_sequence->sq_item)(v, i);
69
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 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2025
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2026 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2027 loop_subscript(v, w)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2028 object *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2029 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2030 sequence_methods *sq = v->ob_type->tp_as_sequence;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2031 int i, n;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2032 if (sq == NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2033 err_setstr(TypeError, "loop over non-sequence");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2034 return NULL;
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 i = getintvalue(w);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2037 n = (*sq->sq_length)(v);
1096
ce718457b172 * classobject.c: in instance_lenth, test result of call_object
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
2038 if (n < 0)
ce718457b172 * classobject.c: in instance_lenth, test result of call_object
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
2039 return NULL; /* Exception */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2040 if (i >= n)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2041 return NULL; /* End of loop */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2042 return (*sq->sq_item)(v, i);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2043 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2044
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2045 static int
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2046 slice_index(v, isize, pi)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2047 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2048 int isize;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2049 int *pi;
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 if (v != NULL) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2052 if (!is_intobject(v)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2053 err_setstr(TypeError, "slice index must be int");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2054 return -1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2055 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2056 *pi = getintvalue(v);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2057 if (*pi < 0)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2058 *pi += isize;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2059 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2060 return 0;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2061 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2062
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2063 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2064 apply_slice(u, v, w) /* return u[v:w] */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2065 object *u, *v, *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2066 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2067 typeobject *tp = u->ob_type;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2068 int ilow, ihigh, isize;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2069 if (tp->tp_as_sequence == NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2070 err_setstr(TypeError, "only sequences can be sliced");
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2071 return NULL;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2072 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2073 ilow = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2074 isize = ihigh = (*tp->tp_as_sequence->sq_length)(u);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2075 if (isize < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2076 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2077 if (slice_index(v, isize, &ilow) != 0)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2078 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2079 if (slice_index(w, isize, &ihigh) != 0)
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2080 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2081 return (*tp->tp_as_sequence->sq_slice)(u, ilow, ihigh);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2082 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2083
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2084 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2085 assign_subscript(w, key, v) /* w[key] = v */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2086 object *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2087 object *key;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2088 object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2089 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2090 typeobject *tp = w->ob_type;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2091 sequence_methods *sq;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2092 mapping_methods *mp;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2093 int (*func)();
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2094 if ((mp = tp->tp_as_mapping) != NULL &&
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2095 (func = mp->mp_ass_subscript) != NULL) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2096 return (*func)(w, key, v);
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2097 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2098 else if ((sq = tp->tp_as_sequence) != NULL &&
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2099 (func = sq->sq_ass_item) != NULL) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2100 if (!is_intobject(key)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2101 err_setstr(TypeError,
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2102 "sequence subscript must be integer (assign or del)");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2103 return -1;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2104 }
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2105 else {
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2106 int i = getintvalue(key);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2107 if (i < 0) {
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2108 int len = (*sq->sq_length)(w);
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2109 if (len < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2110 return -1;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2111 i += len;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2112 }
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2113 return (*func)(w, i, v);
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2114 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2115 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2116 else {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2117 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2118 "can't assign to this subscripted object");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2119 return -1;
69
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 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2122
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2123 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2124 assign_slice(u, v, w, x) /* u[v:w] = x */
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2125 object *u, *v, *w, *x;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2126 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2127 sequence_methods *sq = u->ob_type->tp_as_sequence;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2128 int ilow, ihigh, isize;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2129 if (sq == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2130 err_setstr(TypeError, "assign to slice of non-sequence");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2131 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2132 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2133 if (sq == NULL || sq->sq_ass_slice == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2134 err_setstr(TypeError, "unassignable slice");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2135 return -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 ilow = 0;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2138 isize = ihigh = (*sq->sq_length)(u);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2139 if (isize < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2140 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2141 if (slice_index(v, isize, &ilow) != 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2142 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2143 if (slice_index(w, isize, &ihigh) != 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2144 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2145 return (*sq->sq_ass_slice)(u, ilow, ihigh, x);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2146 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2147
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2148 static int
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2149 cmp_exception(err, v)
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2150 object *err, *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2151 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2152 if (is_tupleobject(v)) {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2153 int i, n;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2154 n = gettuplesize(v);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2155 for (i = 0; i < n; i++) {
464
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
2156 /* Test recursively */
90300ca21200 Added STORE_GLOBAL and DELETE_GLOBAL.
Guido van Rossum <guido@python.org>
parents: 409
diff changeset
2157 if (cmp_exception(err, gettupleitem(v, i)))
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2158 return 1;
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 return 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2161 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2162 return err == v;
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
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2165 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2166 cmp_member(v, w)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2167 object *v, *w;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2168 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2169 int i, n, cmp;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2170 object *x;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2171 sequence_methods *sq;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2172 /* Special case for char in string */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2173 if (is_stringobject(w)) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2174 register char *s, *end;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2175 register char c;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2176 if (!is_stringobject(v) || getstringsize(v) != 1) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2177 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2178 "string member test needs char left operand");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2179 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2180 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2181 c = getstringvalue(v)[0];
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2182 s = getstringvalue(w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2183 end = s + getstringsize(w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2184 while (s < end) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2185 if (c == *s++)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2186 return 1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2187 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2188 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2189 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2190 sq = w->ob_type->tp_as_sequence;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2191 if (sq == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2192 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2193 "'in' or 'not in' needs sequence right argument");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2194 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2195 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2196 n = (*sq->sq_length)(w);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2197 if (n < 0)
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2198 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2199 for (i = 0; i < n; i++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2200 x = (*sq->sq_item)(w, i);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2201 cmp = cmpobject(v, x);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2202 XDECREF(x);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2203 if (cmp == 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2204 return 1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2205 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2206 return 0;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2207 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2208
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2209 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2210 cmp_outcome(op, v, w)
802
3d6541a2eca5 Arg of cmp_outcome becomes an int for portability to the Mac
Guido van Rossum <guido@python.org>
parents: 789
diff changeset
2211 int op;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2212 register object *v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2213 register object *w;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2214 {
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2215 register int cmp;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2216 register int res = 0;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2217 switch (op) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2218 case IS:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2219 case IS_NOT:
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2220 res = (v == w);
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2221 if (op == (int) IS_NOT)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2222 res = !res;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2223 break;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2224 case IN:
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2225 case NOT_IN:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2226 res = cmp_member(v, w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2227 if (res < 0)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2228 return NULL;
944
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
2229 if (op == (int) NOT_IN)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2230 res = !res;
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2231 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2232 case EXC_MATCH:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2233 res = cmp_exception(v, w);
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2234 break;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2235 default:
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2236 cmp = cmpobject(v, w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2237 switch (op) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2238 case LT: res = cmp < 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2239 case LE: res = cmp <= 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2240 case EQ: res = cmp == 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2241 case NE: res = cmp != 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2242 case GT: res = cmp > 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2243 case GE: res = cmp >= 0; break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2244 /* XXX no default? (res is initialized to 0 though) */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2245 }
69
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2246 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2247 v = res ? True : False;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2248 INCREF(v);
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2249 return v;
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2250 }
cccd534f2280 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2251
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2252 static int
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2253 import_from(locals, v, name)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2254 object *locals;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2255 object *v;
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2256 object *name;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2257 {
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2258 object *w, *x;
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2259 w = getmoduledict(v);
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2260 if (getstringvalue(name)[0] == '*') {
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2261 int i;
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2262 int n = getdictsize(w);
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2263 for (i = 0; i < n; i++) {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2264 name = getdict2key(w, i);
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2265 if (name == NULL || getstringvalue(name)[0] == '_')
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2266 continue;
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2267 x = dict2lookup(w, name);
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2268 if (x == NULL) {
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2269 /* XXX can't happen? */
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2270 err_setstr(SystemError, getstringvalue(name));
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2271 return -1;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2272 }
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2273 if (dict2insert(locals, name, x) != 0)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2274 return -1;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2275 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2276 return 0;
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2277 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2278 else {
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2279 x = dict2lookup(w, name);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2280 if (x == NULL) {
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2281 char buf[250];
661
7e5f4d9aee77 Limit length of name passed to sprintf.
Guido van Rossum <guido@python.org>
parents: 607
diff changeset
2282 sprintf(buf, "cannot import name %.230s",
506
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2283 getstringvalue(name));
9f7161db5669 Negative subscript are now allowed as in slices.
Guido van Rossum <guido@python.org>
parents: 481
diff changeset
2284 err_setstr(ImportError, buf);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2285 return -1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2286 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2287 else
334
449f5e5d9af6 Changed many calls to dict stufff to dict2 variants.
Guido van Rossum <guido@python.org>
parents: 314
diff changeset
2288 return dict2insert(locals, name, x);
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2289 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2290 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2291
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2292 static object *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2293 build_class(v, w)
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2294 object *v; /* None or tuple containing base classes */
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2295 object *w; /* dictionary */
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2296 {
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2297 if (is_tupleobject(v)) {
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2298 int i;
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2299 for (i = gettuplesize(v); --i >= 0; ) {
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2300 object *x = gettupleitem(v, i);
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2301 if (!is_classobject(x)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2302 err_setstr(TypeError,
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2303 "base is not a class object");
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2304 return NULL;
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2305 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2306 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2307 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2308 else {
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2309 v = NULL;
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2310 }
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2311 if (!is_dictobject(w)) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 72
diff changeset
2312 err_setstr(SystemError, "build_class with non-dictionary");
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2313 return NULL;
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2314 }
401
0c5e4e137de6 newclassobject() gets a third argument
Guido van Rossum <guido@python.org>
parents: 334
diff changeset
2315 return newclassobject(v, w, (object *) NULL);
72
5e8a0b40a4bd Free parse tree after compiling.
Guido van Rossum <guido@python.org>
parents: 69
diff changeset
2316 }