6
6
7
7
test_tools .skip_if_missing ('cases_generator' )
8
8
with test_tools .imports_under_tool ('cases_generator' ):
9
+ import generate_cases
9
10
import analysis
10
11
import formatting
11
- import generate_cases
12
12
from parsing import StackEffect
13
13
14
14
@@ -46,28 +46,11 @@ def test_effect_sizes(self):
46
46
(2 , "(oparg<<1)" ),
47
47
)
48
48
49
- self .assertEqual (
50
- formatting .string_effect_size (
51
- formatting .list_effect_size (input_effects ),
52
- ), "1 + oparg + oparg*2" ,
53
- )
54
- self .assertEqual (
55
- formatting .string_effect_size (
56
- formatting .list_effect_size (output_effects ),
57
- ),
58
- "2 + oparg*4" ,
59
- )
60
- self .assertEqual (
61
- formatting .string_effect_size (
62
- formatting .list_effect_size (other_effects ),
63
- ),
64
- "2 + (oparg<<1)" ,
65
- )
66
-
67
49
68
50
class TestGeneratedCases (unittest .TestCase ):
69
51
def setUp (self ) -> None :
70
52
super ().setUp ()
53
+ self .maxDiff = None
71
54
72
55
self .temp_dir = tempfile .gettempdir ()
73
56
self .temp_input_filename = os .path .join (self .temp_dir , "input.txt" )
@@ -140,7 +123,8 @@ def test_inst_one_pop(self):
140
123
"""
141
124
output = """
142
125
TARGET(OP) {
143
- PyObject *value = stack_pointer[-1];
126
+ PyObject *value;
127
+ value = stack_pointer[-1];
144
128
spam();
145
129
STACK_SHRINK(1);
146
130
DISPATCH();
@@ -173,8 +157,9 @@ def test_inst_one_push_one_pop(self):
173
157
"""
174
158
output = """
175
159
TARGET(OP) {
176
- PyObject *value = stack_pointer[-1] ;
160
+ PyObject *value;
177
161
PyObject *res;
162
+ value = stack_pointer[-1];
178
163
spam();
179
164
stack_pointer[-1] = res;
180
165
DISPATCH();
@@ -190,9 +175,11 @@ def test_binary_op(self):
190
175
"""
191
176
output = """
192
177
TARGET(OP) {
193
- PyObject *right = stack_pointer[-1] ;
194
- PyObject *left = stack_pointer[-2] ;
178
+ PyObject *right;
179
+ PyObject *left;
195
180
PyObject *res;
181
+ right = stack_pointer[-1];
182
+ left = stack_pointer[-2];
196
183
spam();
197
184
STACK_SHRINK(1);
198
185
stack_pointer[-1] = res;
@@ -209,9 +196,11 @@ def test_overlap(self):
209
196
"""
210
197
output = """
211
198
TARGET(OP) {
212
- PyObject *right = stack_pointer[-1] ;
213
- PyObject *left = stack_pointer[-2] ;
199
+ PyObject *right;
200
+ PyObject *left;
214
201
PyObject *result;
202
+ right = stack_pointer[-1];
203
+ left = stack_pointer[-2];
215
204
spam();
216
205
stack_pointer[-1] = result;
217
206
DISPATCH();
@@ -235,8 +224,9 @@ def test_predictions_and_eval_breaker(self):
235
224
}
236
225
237
226
TARGET(OP3) {
238
- PyObject *arg = stack_pointer[-1] ;
227
+ PyObject *arg;
239
228
PyObject *res;
229
+ arg = stack_pointer[-1];
240
230
DEOPT_IF(xxx, OP1);
241
231
stack_pointer[-1] = res;
242
232
CHECK_EVAL_BREAKER();
@@ -281,9 +271,11 @@ def test_error_if_pop(self):
281
271
"""
282
272
output = """
283
273
TARGET(OP) {
284
- PyObject *right = stack_pointer[-1] ;
285
- PyObject *left = stack_pointer[-2] ;
274
+ PyObject *right;
275
+ PyObject *left;
286
276
PyObject *res;
277
+ right = stack_pointer[-1];
278
+ left = stack_pointer[-2];
287
279
if (cond) goto pop_2_label;
288
280
STACK_SHRINK(1);
289
281
stack_pointer[-1] = res;
@@ -299,7 +291,8 @@ def test_cache_effect(self):
299
291
"""
300
292
output = """
301
293
TARGET(OP) {
302
- PyObject *value = stack_pointer[-1];
294
+ PyObject *value;
295
+ value = stack_pointer[-1];
303
296
uint16_t counter = read_u16(&next_instr[0].cache);
304
297
uint32_t extra = read_u32(&next_instr[1].cache);
305
298
STACK_SHRINK(1);
@@ -338,47 +331,49 @@ def test_macro_instruction(self):
338
331
"""
339
332
output = """
340
333
TARGET(OP1) {
341
- PyObject *right = stack_pointer[-1];
342
- PyObject *left = stack_pointer[-2];
334
+ PyObject *right;
335
+ PyObject *left;
336
+ right = stack_pointer[-1];
337
+ left = stack_pointer[-2];
343
338
uint16_t counter = read_u16(&next_instr[0].cache);
344
339
op1(left, right);
345
340
next_instr += 1;
346
341
DISPATCH();
347
342
}
348
343
349
344
TARGET(OP) {
350
- PyObject *_tmp_1 = stack_pointer[-1];
351
- PyObject *_tmp_2 = stack_pointer[-2];
352
- PyObject *_tmp_3 = stack_pointer[-3];
345
+ static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
346
+ PyObject *right;
347
+ PyObject *left;
348
+ PyObject *arg2;
349
+ PyObject *res;
350
+ // OP1
351
+ right = stack_pointer[-1];
352
+ left = stack_pointer[-2];
353
353
{
354
- PyObject *right = _tmp_1;
355
- PyObject *left = _tmp_2;
356
354
uint16_t counter = read_u16(&next_instr[0].cache);
357
355
op1(left, right);
358
- _tmp_2 = left;
359
- _tmp_1 = right;
360
356
}
357
+ // OP2
358
+ arg2 = stack_pointer[-3];
361
359
{
362
- PyObject *right = _tmp_1;
363
- PyObject *left = _tmp_2;
364
- PyObject *arg2 = _tmp_3;
365
- PyObject *res;
366
360
uint32_t extra = read_u32(&next_instr[3].cache);
367
361
res = op2(arg2, left, right);
368
- _tmp_3 = res;
369
362
}
370
- next_instr += 5;
371
- static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
372
363
STACK_SHRINK(2);
373
- stack_pointer[-1] = _tmp_3;
364
+ stack_pointer[-1] = res;
365
+ next_instr += 5;
374
366
DISPATCH();
375
367
}
376
368
377
369
TARGET(OP3) {
378
- PyObject *right = stack_pointer[-1] ;
379
- PyObject *left = stack_pointer[-2] ;
380
- PyObject *arg2 = stack_pointer[-3] ;
370
+ PyObject *right;
371
+ PyObject *left;
372
+ PyObject *arg2;
381
373
PyObject *res;
374
+ right = stack_pointer[-1];
375
+ left = stack_pointer[-2];
376
+ arg2 = stack_pointer[-3];
382
377
res = op3(arg2, left, right);
383
378
STACK_SHRINK(2);
384
379
stack_pointer[-1] = res;
@@ -396,9 +391,12 @@ def test_array_input(self):
396
391
"""
397
392
output = """
398
393
TARGET(OP) {
399
- PyObject *above = stack_pointer[-1];
400
- PyObject **values = (stack_pointer - (1 + oparg*2));
401
- PyObject *below = stack_pointer[-(2 + oparg*2)];
394
+ PyObject *above;
395
+ PyObject **values;
396
+ PyObject *below;
397
+ above = stack_pointer[-1];
398
+ values = stack_pointer - 1 - oparg*2;
399
+ below = stack_pointer[-2 - oparg*2];
402
400
spam();
403
401
STACK_SHRINK(oparg*2);
404
402
STACK_SHRINK(2);
@@ -416,12 +414,13 @@ def test_array_output(self):
416
414
output = """
417
415
TARGET(OP) {
418
416
PyObject *below;
419
- PyObject **values = stack_pointer - (2) + 1 ;
417
+ PyObject **values;
420
418
PyObject *above;
419
+ values = stack_pointer - 1;
421
420
spam(values, oparg);
422
421
STACK_GROW(oparg*3);
422
+ stack_pointer[-2 - oparg*3] = below;
423
423
stack_pointer[-1] = above;
424
- stack_pointer[-(2 + oparg*3)] = below;
425
424
DISPATCH();
426
425
}
427
426
"""
@@ -435,8 +434,9 @@ def test_array_input_output(self):
435
434
"""
436
435
output = """
437
436
TARGET(OP) {
438
- PyObject **values = (stack_pointer - oparg) ;
437
+ PyObject **values;
439
438
PyObject *above;
439
+ values = stack_pointer - oparg;
440
440
spam(values, oparg);
441
441
STACK_GROW(1);
442
442
stack_pointer[-1] = above;
@@ -453,8 +453,10 @@ def test_array_error_if(self):
453
453
"""
454
454
output = """
455
455
TARGET(OP) {
456
- PyObject **values = (stack_pointer - oparg);
457
- PyObject *extra = stack_pointer[-(1 + oparg)];
456
+ PyObject **values;
457
+ PyObject *extra;
458
+ values = stack_pointer - oparg;
459
+ extra = stack_pointer[-1 - oparg];
458
460
if (oparg == 0) { STACK_SHRINK(oparg); goto pop_1_somewhere; }
459
461
STACK_SHRINK(oparg);
460
462
STACK_SHRINK(1);
@@ -471,18 +473,21 @@ def test_cond_effect(self):
471
473
"""
472
474
output = """
473
475
TARGET(OP) {
474
- PyObject *cc = stack_pointer[-1] ;
475
- PyObject *input = ((oparg & 1) == 1) ? stack_pointer[-(1 + (((oparg & 1) == 1) ? 1 : 0))] : NULL;
476
- PyObject *aa = stack_pointer[-(2 + (((oparg & 1) == 1) ? 1 : 0))] ;
476
+ PyObject *cc;
477
+ PyObject *input = NULL;
478
+ PyObject *aa;
477
479
PyObject *xx;
478
480
PyObject *output = NULL;
479
481
PyObject *zz;
482
+ cc = stack_pointer[-1];
483
+ if ((oparg & 1) == 1) { input = stack_pointer[-1 - ((oparg & 1) == 1 ? 1 : 0)]; }
484
+ aa = stack_pointer[-2 - ((oparg & 1) == 1 ? 1 : 0)];
480
485
output = spam(oparg, input);
481
486
STACK_SHRINK((((oparg & 1) == 1) ? 1 : 0));
482
487
STACK_GROW(((oparg & 2) ? 1 : 0));
488
+ stack_pointer[-2 - (oparg & 2 ? 1 : 0)] = xx;
489
+ if (oparg & 2) { stack_pointer[-1 - (oparg & 2 ? 1 : 0)] = output; }
483
490
stack_pointer[-1] = zz;
484
- if (oparg & 2) { stack_pointer[-(1 + ((oparg & 2) ? 1 : 0))] = output; }
485
- stack_pointer[-(2 + ((oparg & 2) ? 1 : 0))] = xx;
486
491
DISPATCH();
487
492
}
488
493
"""
@@ -500,29 +505,28 @@ def test_macro_cond_effect(self):
500
505
"""
501
506
output = """
502
507
TARGET(M) {
503
- PyObject *_tmp_1 = stack_pointer[-1];
504
- PyObject *_tmp_2 = stack_pointer[-2];
505
- PyObject *_tmp_3 = stack_pointer[-3];
508
+ PyObject *right;
509
+ PyObject *middle;
510
+ PyObject *left;
511
+ PyObject *deep;
512
+ PyObject *extra = NULL;
513
+ PyObject *res;
514
+ // A
515
+ right = stack_pointer[-1];
516
+ middle = stack_pointer[-2];
517
+ left = stack_pointer[-3];
506
518
{
507
- PyObject *right = _tmp_1;
508
- PyObject *middle = _tmp_2;
509
- PyObject *left = _tmp_3;
510
519
# Body of A
511
520
}
521
+ // B
512
522
{
513
- PyObject *deep;
514
- PyObject *extra = NULL;
515
- PyObject *res;
516
523
# Body of B
517
- _tmp_3 = deep;
518
- if (oparg) { _tmp_2 = extra; }
519
- _tmp_1 = res;
520
524
}
521
525
STACK_SHRINK(1);
522
526
STACK_GROW((oparg ? 1 : 0));
523
- stack_pointer[-1 ] = _tmp_1 ;
524
- if (oparg) { stack_pointer[-2 ] = _tmp_2 ; }
525
- stack_pointer[-3 ] = _tmp_3 ;
527
+ stack_pointer[-2 - (oparg ? 1 : 0) ] = deep ;
528
+ if (oparg) { stack_pointer[-1 - (oparg ? 1 : 0) ] = extra ; }
529
+ stack_pointer[-1 ] = res ;
526
530
DISPATCH();
527
531
}
528
532
"""
0 commit comments