@@ -77,171 +77,6 @@ def test_effect_sizes(self):
77
77
self .assertEqual (stack .top_offset .to_c (), "1 - oparg - oparg*2 + oparg*4" )
78
78
79
79
80
- class TestGenerateMaxStackEffect (unittest .TestCase ):
81
- def check (self , input , output ):
82
- analysis = analyze_forest (parse_src (input ))
83
- buf = StringIO ()
84
- writer = CWriter (buf , 0 , False )
85
- opcode_metadata_generator .generate_max_stack_effect_function (analysis , writer )
86
- buf .seek (0 )
87
- generated = buf .read ()
88
- matches = re .search (r"(case OP: {[^}]+})" , generated )
89
- if matches is None :
90
- self .fail (f"Couldn't find case statement for OP in:\n { generated } " )
91
- self .assertEqual (output .strip (), matches .group (1 ))
92
-
93
- def test_push_one (self ):
94
- input = """
95
- inst(OP, (a -- b, c)) {
96
- SPAM();
97
- }
98
- """
99
- output = """
100
- case OP: {
101
- *effect = 1;
102
- return 0;
103
- }
104
- """
105
- self .check (input , output )
106
-
107
- def test_cond_push (self ):
108
- input = """
109
- inst(OP, (a -- b, c if (oparg))) {
110
- SPAM();
111
- }
112
- """
113
- output = """
114
- case OP: {
115
- *effect = ((oparg) ? 1 : 0);
116
- return 0;
117
- }
118
- """
119
- self .check (input , output )
120
-
121
- def test_ops_pass_two (self ):
122
- input = """
123
- op(A, (-- val1)) {
124
- val1 = SPAM();
125
- }
126
- op(B, (-- val2)) {
127
- val2 = SPAM();
128
- }
129
- op(C, (val1, val2 --)) {
130
- }
131
- macro(OP) = A + B + C;
132
- """
133
- output = """
134
- case OP: {
135
- *effect = 2;
136
- return 0;
137
- }
138
- """
139
- self .check (input , output )
140
-
141
- def test_ops_pass_two_cond_push (self ):
142
- input = """
143
- op(A, (-- val1, val2)) {
144
- val1 = 0;
145
- val2 = 1;
146
- }
147
- op(B, (val1, val2 -- val1, val2, val3 if (oparg))) {
148
- val3 = SPAM();
149
- }
150
- macro(OP) = A + B;
151
- """
152
- output = """
153
- case OP: {
154
- *effect = Py_MAX(2, 2 + ((oparg) ? 1 : 0));
155
- return 0;
156
- }
157
- """
158
- self .check (input , output )
159
-
160
- def test_pop_push_array (self ):
161
- input = """
162
- inst(OP, (values[oparg] -- values[oparg], above)) {
163
- SPAM(values, oparg);
164
- above = 0;
165
- }
166
- """
167
- output = """
168
- case OP: {
169
- *effect = 1;
170
- return 0;
171
- }
172
- """
173
- self .check (input , output )
174
-
175
- def test_family (self ):
176
- input = """
177
- op(A, (-- val1, val2)) {
178
- val1 = 0;
179
- val2 = 1;
180
- }
181
- op(B, (val1, val2 -- val3)) {
182
- val3 = 2;
183
- }
184
- macro(OP1) = A + B;
185
-
186
- inst(OP, (-- val)) {
187
- val = 0;
188
- }
189
-
190
- family(OP, 0) = { OP1 };
191
- """
192
- output = """
193
- case OP: {
194
- *effect = 2;
195
- return 0;
196
- }
197
- """
198
- self .check (input , output )
199
-
200
- def test_family_intermediate_array (self ):
201
- input = """
202
- op(A, (-- values[oparg])) {
203
- val1 = 0;
204
- val2 = 1;
205
- }
206
- op(B, (values[oparg] -- val3)) {
207
- val3 = 2;
208
- }
209
- macro(OP1) = A + B;
210
-
211
- inst(OP, (-- val)) {
212
- val = 0;
213
- }
214
-
215
- family(OP, 0) = { OP1 };
216
- """
217
- output = """
218
- case OP: {
219
- *effect = Py_MAX(1, oparg);
220
- return 0;
221
- }
222
- """
223
- self .check (input , output )
224
-
225
- def test_negative_effect (self ):
226
- input = """
227
- op(A, (val1 -- )) {
228
- }
229
- op(B, (val2 --)) {
230
- }
231
- op(C, (val3 --)) {
232
- }
233
-
234
- macro(OP) = A + B + C;
235
- """
236
- output = """
237
- case OP: {
238
- *effect = -1;
239
- return 0;
240
- }
241
- """
242
- self .check (input , output )
243
-
244
-
245
80
class TestGeneratedCases (unittest .TestCase ):
246
81
def setUp (self ) -> None :
247
82
super ().setUp ()
@@ -287,12 +122,6 @@ def run_cases_test(self, input: str, expected: str):
287
122
_ , labels_with_postlude = labels_with_prelude_and_postlude .split (tier1_generator .LABEL_START_MARKER )
288
123
labels , _ = labels_with_postlude .split (tier1_generator .LABEL_END_MARKER )
289
124
actual = instructions .strip () + "\n \n " + labels .strip ()
290
- # if actual.strip() != expected.strip():
291
- # print("Actual:")
292
- # print(actual)
293
- # print("Expected:")
294
- # print(expected)
295
- # print("End")
296
125
297
126
self .assertEqual (actual .strip (), expected .strip ())
298
127
0 commit comments