@@ -43,7 +43,8 @@ def run_cases_test(input: str, expected: str):
43
43
temp_input .write (generate_cases .END_MARKER )
44
44
temp_input .flush ()
45
45
temp_output = tempfile .NamedTemporaryFile ("w+" )
46
- a = generate_cases .Analyzer (temp_input .name , temp_output .name )
46
+ temp_metadata = tempfile .NamedTemporaryFile ("w+" )
47
+ a = generate_cases .Analyzer ([temp_input .name ], temp_output .name , temp_metadata .name )
47
48
a .parse ()
48
49
a .analyze ()
49
50
if a .errors :
@@ -84,7 +85,7 @@ def test_inst_one_pop():
84
85
"""
85
86
output = """
86
87
TARGET(OP) {
87
- PyObject *value = PEEK(1) ;
88
+ PyObject *value = stack_pointer[-1] ;
88
89
spam();
89
90
STACK_SHRINK(1);
90
91
DISPATCH();
@@ -103,7 +104,7 @@ def test_inst_one_push():
103
104
PyObject *res;
104
105
spam();
105
106
STACK_GROW(1);
106
- POKE(1, res) ;
107
+ stack_pointer[-1] = res;
107
108
DISPATCH();
108
109
}
109
110
"""
@@ -117,10 +118,10 @@ def test_inst_one_push_one_pop():
117
118
"""
118
119
output = """
119
120
TARGET(OP) {
120
- PyObject *value = PEEK(1) ;
121
+ PyObject *value = stack_pointer[-1] ;
121
122
PyObject *res;
122
123
spam();
123
- POKE(1, res) ;
124
+ stack_pointer[-1] = res;
124
125
DISPATCH();
125
126
}
126
127
"""
@@ -134,12 +135,12 @@ def test_binary_op():
134
135
"""
135
136
output = """
136
137
TARGET(OP) {
137
- PyObject *right = PEEK(1) ;
138
- PyObject *left = PEEK(2) ;
138
+ PyObject *right = stack_pointer[-1] ;
139
+ PyObject *left = stack_pointer[-2] ;
139
140
PyObject *res;
140
141
spam();
141
142
STACK_SHRINK(1);
142
- POKE(1, res) ;
143
+ stack_pointer[-1] = res;
143
144
DISPATCH();
144
145
}
145
146
"""
@@ -153,11 +154,11 @@ def test_overlap():
153
154
"""
154
155
output = """
155
156
TARGET(OP) {
156
- PyObject *right = PEEK(1) ;
157
- PyObject *left = PEEK(2) ;
157
+ PyObject *right = stack_pointer[-1] ;
158
+ PyObject *left = stack_pointer[-2] ;
158
159
PyObject *result;
159
160
spam();
160
- POKE(1, result) ;
161
+ stack_pointer[-1] = result;
161
162
DISPATCH();
162
163
}
163
164
"""
@@ -167,11 +168,8 @@ def test_predictions_and_eval_breaker():
167
168
input = """
168
169
inst(OP1, (--)) {
169
170
}
170
- inst(OP2, (--)) {
171
- }
172
171
inst(OP3, (arg -- res)) {
173
172
DEOPT_IF(xxx, OP1);
174
- PREDICT(OP2);
175
173
CHECK_EVAL_BREAKER();
176
174
}
177
175
"""
@@ -181,17 +179,11 @@ def test_predictions_and_eval_breaker():
181
179
DISPATCH();
182
180
}
183
181
184
- TARGET(OP2) {
185
- PREDICTED(OP2);
186
- DISPATCH();
187
- }
188
-
189
182
TARGET(OP3) {
190
- PyObject *arg = PEEK(1) ;
183
+ PyObject *arg = stack_pointer[-1] ;
191
184
PyObject *res;
192
185
DEOPT_IF(xxx, OP1);
193
- POKE(1, res);
194
- PREDICT(OP2);
186
+ stack_pointer[-1] = res;
195
187
CHECK_EVAL_BREAKER();
196
188
DISPATCH();
197
189
}
@@ -234,12 +226,12 @@ def test_error_if_pop():
234
226
"""
235
227
output = """
236
228
TARGET(OP) {
237
- PyObject *right = PEEK(1) ;
238
- PyObject *left = PEEK(2) ;
229
+ PyObject *right = stack_pointer[-1] ;
230
+ PyObject *left = stack_pointer[-2] ;
239
231
PyObject *res;
240
232
if (cond) goto pop_2_label;
241
233
STACK_SHRINK(1);
242
- POKE(1, res) ;
234
+ stack_pointer[-1] = res;
243
235
DISPATCH();
244
236
}
245
237
"""
@@ -252,11 +244,11 @@ def test_cache_effect():
252
244
"""
253
245
output = """
254
246
TARGET(OP) {
255
- PyObject *value = PEEK(1) ;
247
+ PyObject *value = stack_pointer[-1] ;
256
248
uint16_t counter = read_u16(&next_instr[0].cache);
257
249
uint32_t extra = read_u32(&next_instr[1].cache);
258
250
STACK_SHRINK(1);
259
- JUMPBY(3) ;
251
+ next_instr += 3 ;
260
252
DISPATCH();
261
253
}
262
254
"""
@@ -275,59 +267,6 @@ def test_suppress_dispatch():
275
267
"""
276
268
run_cases_test (input , output )
277
269
278
- def test_super_instruction ():
279
- # TODO: Test cache effect
280
- input = """
281
- inst(OP1, (counter/1, arg --)) {
282
- op1();
283
- }
284
- inst(OP2, (extra/2, arg --)) {
285
- op2();
286
- }
287
- super(OP) = OP1 + OP2;
288
- """
289
- output = """
290
- TARGET(OP1) {
291
- PyObject *arg = PEEK(1);
292
- uint16_t counter = read_u16(&next_instr[0].cache);
293
- op1();
294
- STACK_SHRINK(1);
295
- JUMPBY(1);
296
- DISPATCH();
297
- }
298
-
299
- TARGET(OP2) {
300
- PyObject *arg = PEEK(1);
301
- uint32_t extra = read_u32(&next_instr[0].cache);
302
- op2();
303
- STACK_SHRINK(1);
304
- JUMPBY(2);
305
- DISPATCH();
306
- }
307
-
308
- TARGET(OP) {
309
- PyObject *_tmp_1 = PEEK(1);
310
- PyObject *_tmp_2 = PEEK(2);
311
- {
312
- PyObject *arg = _tmp_1;
313
- uint16_t counter = read_u16(&next_instr[0].cache);
314
- op1();
315
- }
316
- JUMPBY(1);
317
- NEXTOPARG();
318
- JUMPBY(1);
319
- {
320
- PyObject *arg = _tmp_2;
321
- uint32_t extra = read_u32(&next_instr[0].cache);
322
- op2();
323
- }
324
- JUMPBY(2);
325
- STACK_SHRINK(2);
326
- DISPATCH();
327
- }
328
- """
329
- run_cases_test (input , output )
330
-
331
270
def test_macro_instruction ():
332
271
input = """
333
272
inst(OP1, (counter/1, left, right -- left, right)) {
@@ -344,18 +283,18 @@ def test_macro_instruction():
344
283
"""
345
284
output = """
346
285
TARGET(OP1) {
347
- PyObject *right = PEEK(1) ;
348
- PyObject *left = PEEK(2) ;
286
+ PyObject *right = stack_pointer[-1] ;
287
+ PyObject *left = stack_pointer[-2] ;
349
288
uint16_t counter = read_u16(&next_instr[0].cache);
350
289
op1(left, right);
351
- JUMPBY(1) ;
290
+ next_instr += 1 ;
352
291
DISPATCH();
353
292
}
354
293
355
294
TARGET(OP) {
356
- PyObject *_tmp_1 = PEEK(1) ;
357
- PyObject *_tmp_2 = PEEK(2) ;
358
- PyObject *_tmp_3 = PEEK(3) ;
295
+ PyObject *_tmp_1 = stack_pointer[-1] ;
296
+ PyObject *_tmp_2 = stack_pointer[-2] ;
297
+ PyObject *_tmp_3 = stack_pointer[-3] ;
359
298
{
360
299
PyObject *right = _tmp_1;
361
300
PyObject *left = _tmp_2;
@@ -373,22 +312,22 @@ def test_macro_instruction():
373
312
res = op2(arg2, left, right);
374
313
_tmp_3 = res;
375
314
}
376
- JUMPBY(5) ;
315
+ next_instr += 5 ;
377
316
static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
378
317
STACK_SHRINK(2);
379
- POKE(1, _tmp_3) ;
318
+ stack_pointer[-1] = _tmp_3;
380
319
DISPATCH();
381
320
}
382
321
383
322
TARGET(OP3) {
384
- PyObject *right = PEEK(1) ;
385
- PyObject *left = PEEK(2) ;
386
- PyObject *arg2 = PEEK(3) ;
323
+ PyObject *right = stack_pointer[-1] ;
324
+ PyObject *left = stack_pointer[-2] ;
325
+ PyObject *arg2 = stack_pointer[-3] ;
387
326
PyObject *res;
388
327
res = op3(arg2, left, right);
389
328
STACK_SHRINK(2);
390
- POKE(1, res) ;
391
- JUMPBY(5) ;
329
+ stack_pointer[-1] = res;
330
+ next_instr += 5 ;
392
331
DISPATCH();
393
332
}
394
333
"""
@@ -402,9 +341,9 @@ def test_array_input():
402
341
"""
403
342
output = """
404
343
TARGET(OP) {
405
- PyObject *above = PEEK(1) ;
406
- PyObject **values = &PEEK( 1 + oparg*2);
407
- PyObject *below = PEEK (2 + oparg*2);
344
+ PyObject *above = stack_pointer[-1] ;
345
+ PyObject **values = (stack_pointer - ( 1 + oparg*2) );
346
+ PyObject *below = stack_pointer[- (2 + oparg*2)] ;
408
347
spam();
409
348
STACK_SHRINK(oparg*2);
410
349
STACK_SHRINK(2);
@@ -426,8 +365,8 @@ def test_array_output():
426
365
PyObject *above;
427
366
spam(values, oparg);
428
367
STACK_GROW(oparg*3);
429
- POKE(1, above) ;
430
- POKE (2 + oparg*3, below) ;
368
+ stack_pointer[-1] = above;
369
+ stack_pointer[- (2 + oparg*3)] = below;
431
370
DISPATCH();
432
371
}
433
372
"""
@@ -441,11 +380,11 @@ def test_array_input_output():
441
380
"""
442
381
output = """
443
382
TARGET(OP) {
444
- PyObject **values = &PEEK( oparg);
383
+ PyObject **values = (stack_pointer - oparg);
445
384
PyObject *above;
446
385
spam(values, oparg);
447
386
STACK_GROW(1);
448
- POKE(1, above) ;
387
+ stack_pointer[-1] = above;
449
388
DISPATCH();
450
389
}
451
390
"""
@@ -459,8 +398,8 @@ def test_array_error_if():
459
398
"""
460
399
output = """
461
400
TARGET(OP) {
462
- PyObject **values = &PEEK( oparg);
463
- PyObject *extra = PEEK (1 + oparg);
401
+ PyObject **values = (stack_pointer - oparg);
402
+ PyObject *extra = stack_pointer[- (1 + oparg)] ;
464
403
if (oparg == 0) { STACK_SHRINK(oparg); goto pop_1_somewhere; }
465
404
STACK_SHRINK(oparg);
466
405
STACK_SHRINK(1);
@@ -469,26 +408,6 @@ def test_array_error_if():
469
408
"""
470
409
run_cases_test (input , output )
471
410
472
- def test_register ():
473
- input = """
474
- register inst(OP, (counter/1, left, right -- result)) {
475
- result = op(left, right);
476
- }
477
- """
478
- output = """
479
- TARGET(OP) {
480
- PyObject *left = REG(oparg1);
481
- PyObject *right = REG(oparg2);
482
- PyObject *result;
483
- uint16_t counter = read_u16(&next_instr[0].cache);
484
- result = op(left, right);
485
- Py_XSETREF(REG(oparg3), result);
486
- JUMPBY(1);
487
- DISPATCH();
488
- }
489
- """
490
- run_cases_test (input , output )
491
-
492
411
def test_cond_effect ():
493
412
input = """
494
413
inst(OP, (aa, input if ((oparg & 1) == 1), cc -- xx, output if (oparg & 2), zz)) {
@@ -497,18 +416,18 @@ def test_cond_effect():
497
416
"""
498
417
output = """
499
418
TARGET(OP) {
500
- PyObject *cc = PEEK(1) ;
501
- PyObject *input = ((oparg & 1) == 1) ? PEEK (1 + (((oparg & 1) == 1) ? 1 : 0)) : NULL;
502
- PyObject *aa = PEEK (2 + (((oparg & 1) == 1) ? 1 : 0));
419
+ PyObject *cc = stack_pointer[-1] ;
420
+ PyObject *input = ((oparg & 1) == 1) ? stack_pointer[- (1 + (((oparg & 1) == 1) ? 1 : 0))] : NULL;
421
+ PyObject *aa = stack_pointer[- (2 + (((oparg & 1) == 1) ? 1 : 0))] ;
503
422
PyObject *xx;
504
423
PyObject *output = NULL;
505
424
PyObject *zz;
506
425
output = spam(oparg, input);
507
426
STACK_SHRINK((((oparg & 1) == 1) ? 1 : 0));
508
427
STACK_GROW(((oparg & 2) ? 1 : 0));
509
- POKE(1, zz) ;
510
- if (oparg & 2) { POKE (1 + ((oparg & 2) ? 1 : 0), output) ; }
511
- POKE (2 + ((oparg & 2) ? 1 : 0), xx) ;
428
+ stack_pointer[-1] = zz ;
429
+ if (oparg & 2) { stack_pointer[- (1 + ((oparg & 2) ? 1 : 0))] = output; }
430
+ stack_pointer[- (2 + ((oparg & 2) ? 1 : 0))] = xx ;
512
431
DISPATCH();
513
432
}
514
433
"""
0 commit comments