1 #define PYTHON_VERSION "2.5"
2 
3 #include "header.h"
4 #include "opcode25.h"
5 
6 /*
7  * When computing the stack effect for Python,
8  * open up Python-x.x/Python/compile.c and copy
9  * the static function "opcode_stack_effect" below.
10  */
11 /* -----8x-------------8x-------------8x----- */
12 /* PASTE FUNCTION HERE */
13 static int
opcode_stack_effect(int opcode,int oparg)14 opcode_stack_effect(int opcode, int oparg)
15 {
16 	switch (opcode) {
17 		case POP_TOP:
18 			return -1;
19 		case ROT_TWO:
20 		case ROT_THREE:
21 			return 0;
22 		case DUP_TOP:
23 			return 1;
24 		case ROT_FOUR:
25 			return 0;
26 
27 		case UNARY_POSITIVE:
28 		case UNARY_NEGATIVE:
29 		case UNARY_NOT:
30 		case UNARY_CONVERT:
31 		case UNARY_INVERT:
32 			return 0;
33 
34 		case LIST_APPEND:
35 			return -2;
36 
37 		case BINARY_POWER:
38 		case BINARY_MULTIPLY:
39 		case BINARY_DIVIDE:
40 		case BINARY_MODULO:
41 		case BINARY_ADD:
42 		case BINARY_SUBTRACT:
43 		case BINARY_SUBSCR:
44 		case BINARY_FLOOR_DIVIDE:
45 		case BINARY_TRUE_DIVIDE:
46 			return -1;
47 		case INPLACE_FLOOR_DIVIDE:
48 		case INPLACE_TRUE_DIVIDE:
49 			return -1;
50 
51 		case SLICE+0:
52 			return 1;
53 		case SLICE+1:
54 			return 0;
55 		case SLICE+2:
56 			return 0;
57 		case SLICE+3:
58 			return -1;
59 
60 		case STORE_SLICE+0:
61 			return -2;
62 		case STORE_SLICE+1:
63 			return -3;
64 		case STORE_SLICE+2:
65 			return -3;
66 		case STORE_SLICE+3:
67 			return -4;
68 
69 		case DELETE_SLICE+0:
70 			return -1;
71 		case DELETE_SLICE+1:
72 			return -2;
73 		case DELETE_SLICE+2:
74 			return -2;
75 		case DELETE_SLICE+3:
76 			return -3;
77 
78 		case INPLACE_ADD:
79 		case INPLACE_SUBTRACT:
80 		case INPLACE_MULTIPLY:
81 		case INPLACE_DIVIDE:
82 		case INPLACE_MODULO:
83 			return -1;
84 		case STORE_SUBSCR:
85 			return -3;
86 		case DELETE_SUBSCR:
87 			return -2;
88 
89 		case BINARY_LSHIFT:
90 		case BINARY_RSHIFT:
91 		case BINARY_AND:
92 		case BINARY_XOR:
93 		case BINARY_OR:
94 			return -1;
95 		case INPLACE_POWER:
96 			return -1;
97 		case GET_ITER:
98 			return 0;
99 
100 		case PRINT_EXPR:
101 			return -1;
102 		case PRINT_ITEM:
103 			return -1;
104 		case PRINT_NEWLINE:
105 			return 0;
106 		case PRINT_ITEM_TO:
107 			return -2;
108 		case PRINT_NEWLINE_TO:
109 			return -1;
110 		case INPLACE_LSHIFT:
111 		case INPLACE_RSHIFT:
112 		case INPLACE_AND:
113 		case INPLACE_XOR:
114 		case INPLACE_OR:
115 			return -1;
116 		case BREAK_LOOP:
117 			return 0;
118 		case WITH_CLEANUP:
119 			return -1; /* XXX Sometimes more */
120 		case LOAD_LOCALS:
121 			return 1;
122 		case RETURN_VALUE:
123 			return -1;
124 		case IMPORT_STAR:
125 			return -1;
126 		case EXEC_STMT:
127 			return -3;
128 		case YIELD_VALUE:
129 			return 0;
130 
131 		case POP_BLOCK:
132 			return 0;
133 		case END_FINALLY:
134 			return -1; /* or -2 or -3 if exception occurred */
135 		case BUILD_CLASS:
136 			return -2;
137 
138 		case STORE_NAME:
139 			return -1;
140 		case DELETE_NAME:
141 			return 0;
142 		case UNPACK_SEQUENCE:
143 			return oparg-1;
144 		case FOR_ITER:
145 			return 1;
146 
147 		case STORE_ATTR:
148 			return -2;
149 		case DELETE_ATTR:
150 			return -1;
151 		case STORE_GLOBAL:
152 			return -1;
153 		case DELETE_GLOBAL:
154 			return 0;
155 		case DUP_TOPX:
156 			return oparg;
157 		case LOAD_CONST:
158 			return 1;
159 		case LOAD_NAME:
160 			return 1;
161 		case BUILD_TUPLE:
162 		case BUILD_LIST:
163 			return 1-oparg;
164 		case BUILD_MAP:
165 			return 1;
166 		case LOAD_ATTR:
167 			return 0;
168 		case COMPARE_OP:
169 			return -1;
170 		case IMPORT_NAME:
171 			return 0;
172 		case IMPORT_FROM:
173 			return 1;
174 
175 		case JUMP_FORWARD:
176 		case JUMP_IF_FALSE:
177 		case JUMP_IF_TRUE:
178 		case JUMP_ABSOLUTE:
179 			return 0;
180 
181 		case LOAD_GLOBAL:
182 			return 1;
183 
184 		case CONTINUE_LOOP:
185 			return 0;
186 		case SETUP_LOOP:
187 			return 0;
188 		case SETUP_EXCEPT:
189 		case SETUP_FINALLY:
190 			return 3; /* actually pushed by an exception */
191 
192 		case LOAD_FAST:
193 			return 1;
194 		case STORE_FAST:
195 			return -1;
196 		case DELETE_FAST:
197 			return 0;
198 
199 		case RAISE_VARARGS:
200 			return -oparg;
201 #define NARGS(o) (((o) % 256) + 2*((o) / 256))
202 		case CALL_FUNCTION:
203 			return -NARGS(oparg);
204 		case CALL_FUNCTION_VAR:
205 		case CALL_FUNCTION_KW:
206 			return -NARGS(oparg)-1;
207 		case CALL_FUNCTION_VAR_KW:
208 			return -NARGS(oparg)-2;
209 #undef NARGS
210 		case MAKE_FUNCTION:
211 			return -oparg;
212 		case BUILD_SLICE:
213 			if (oparg == 3)
214 				return -2;
215 			else
216 				return -1;
217 
218 		case MAKE_CLOSURE:
219 			return -oparg;
220 		case LOAD_CLOSURE:
221 			return 1;
222 		case LOAD_DEREF:
223 			return 1;
224 		case STORE_DEREF:
225 			return -1;
226 		default:
227 			fprintf(stderr, "opcode = %d\n", opcode);
228 			Py_FatalError("opcode_stack_effect()");
229 
230 	}
231 	return 0; /* not reachable */
232 }
233 /* -----8x-------------8x-------------8x----- */
234 #include "main.h"
235