@@ -32,6 +32,7 @@ def skip_if_different_mount_drives():
3232 import analysis
3333 import formatting
3434 from parsing import StackEffect
35+ import tier1_generator
3536
3637
3738def handle_stderr ():
@@ -108,13 +109,12 @@ def run_cases_test(self, input: str, expected: str):
108109 temp_input .write (analysis .END_MARKER )
109110 temp_input .flush ()
110111
111- a = generate_cases .Generator ([self .temp_input_filename ])
112112 with handle_stderr ():
113- a . parse ()
114- a . analyze ()
115- if a . errors :
116- raise RuntimeError ( f"Found { a . errors } errors" )
117- a . write_instructions ( self . temp_output_filename , False )
113+ tier1_generator . generate_tier1_from_files (
114+ [ self . temp_input_filename ],
115+ self . temp_output_filename ,
116+ False
117+ )
118118
119119 with open (self .temp_output_filename ) as temp_output :
120120 lines = temp_output .readlines ()
@@ -163,7 +163,7 @@ def test_inst_one_pop(self):
163163 PyObject *value;
164164 value = stack_pointer[-1];
165165 spam();
166- STACK_SHRINK(1) ;
166+ stack_pointer += -1 ;
167167 DISPATCH();
168168 }
169169 """
@@ -182,8 +182,8 @@ def test_inst_one_push(self):
182182 INSTRUCTION_STATS(OP);
183183 PyObject *res;
184184 spam();
185- STACK_GROW(1) ;
186- stack_pointer[-1] = res ;
185+ stack_pointer[0] = res ;
186+ stack_pointer += 1 ;
187187 DISPATCH();
188188 }
189189 """
@@ -227,8 +227,8 @@ def test_binary_op(self):
227227 right = stack_pointer[-1];
228228 left = stack_pointer[-2];
229229 spam();
230- STACK_SHRINK(1) ;
231- stack_pointer[-1] = res ;
230+ stack_pointer[-2] = res ;
231+ stack_pointer += -1 ;
232232 DISPATCH();
233233 }
234234 """
@@ -273,7 +273,6 @@ def test_predictions_and_eval_breaker(self):
273273 next_instr += 1;
274274 INSTRUCTION_STATS(OP1);
275275 PREDICTED(OP1);
276- static_assert(INLINE_CACHE_ENTRIES_OP1 == 0, "incorrect cache size");
277276 PyObject *arg;
278277 PyObject *rest;
279278 arg = stack_pointer[-1];
@@ -285,6 +284,7 @@ def test_predictions_and_eval_breaker(self):
285284 frame->instr_ptr = next_instr;
286285 next_instr += 1;
287286 INSTRUCTION_STATS(OP3);
287+ static_assert(INLINE_CACHE_ENTRIES_OP1 == 0, "incorrect cache size");
288288 PyObject *arg;
289289 PyObject *res;
290290 arg = stack_pointer[-1];
@@ -325,6 +325,7 @@ def test_error_if_plain_with_comment(self):
325325 next_instr += 1;
326326 INSTRUCTION_STATS(OP);
327327 if (cond) goto label;
328+ // Comment is ok
328329 DISPATCH();
329330 }
330331 """
@@ -347,8 +348,8 @@ def test_error_if_pop(self):
347348 right = stack_pointer[-1];
348349 left = stack_pointer[-2];
349350 if (cond) goto pop_2_label;
350- STACK_SHRINK(1) ;
351- stack_pointer[-1] = res ;
351+ stack_pointer[-2] = res ;
352+ stack_pointer += -1 ;
352353 DISPATCH();
353354 }
354355 """
@@ -368,7 +369,7 @@ def test_cache_effect(self):
368369 value = stack_pointer[-1];
369370 uint16_t counter = read_u16(&this_instr[1].cache);
370371 uint32_t extra = read_u32(&this_instr[2].cache);
371- STACK_SHRINK(1) ;
372+ stack_pointer += -1 ;
372373 DISPATCH();
373374 }
374375 """
@@ -411,26 +412,26 @@ def test_macro_instruction(self):
411412 INSTRUCTION_STATS(OP);
412413 PREDICTED(OP);
413414 _Py_CODEUNIT *this_instr = next_instr - 6;
414- static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
415415 PyObject *right;
416416 PyObject *left;
417417 PyObject *arg2;
418418 PyObject *res;
419- // OP1
419+ // _OP1
420420 right = stack_pointer[-1];
421421 left = stack_pointer[-2];
422422 {
423423 uint16_t counter = read_u16(&this_instr[1].cache);
424424 op1(left, right);
425425 }
426+ /* Skip 2 cache entries */
426427 // OP2
427428 arg2 = stack_pointer[-3];
428429 {
429430 uint32_t extra = read_u32(&this_instr[4].cache);
430431 res = op2(arg2, left, right);
431432 }
432- STACK_SHRINK(2) ;
433- stack_pointer[-1] = res ;
433+ stack_pointer[-3] = res ;
434+ stack_pointer += -2 ;
434435 DISPATCH();
435436 }
436437
@@ -451,6 +452,7 @@ def test_macro_instruction(self):
451452 frame->instr_ptr = next_instr;
452453 next_instr += 6;
453454 INSTRUCTION_STATS(OP3);
455+ static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
454456 PyObject *right;
455457 PyObject *left;
456458 PyObject *arg2;
@@ -459,8 +461,24 @@ def test_macro_instruction(self):
459461 left = stack_pointer[-2];
460462 arg2 = stack_pointer[-3];
461463 res = op3(arg2, left, right);
462- STACK_SHRINK(2);
463- stack_pointer[-1] = res;
464+ stack_pointer[-3] = res;
465+ stack_pointer += -2;
466+ DISPATCH();
467+ }
468+ """
469+ self .run_cases_test (input , output )
470+ def test_unused_caches (self ):
471+ input = """
472+ inst(OP, (unused/1, unused/2 --)) {
473+ body();
474+ }
475+ """
476+ output = """
477+ TARGET(OP) {
478+ frame->instr_ptr = next_instr;
479+ next_instr += 4;
480+ INSTRUCTION_STATS(OP);
481+ body();
464482 DISPATCH();
465483 }
466484 """
@@ -519,11 +537,10 @@ def test_array_input(self):
519537 PyObject **values;
520538 PyObject *below;
521539 above = stack_pointer[-1];
522- values = stack_pointer - 1 - oparg*2;
540+ values = & stack_pointer[- 1 - oparg*2] ;
523541 below = stack_pointer[-2 - oparg*2];
524542 spam();
525- STACK_SHRINK(oparg*2);
526- STACK_SHRINK(2);
543+ stack_pointer += -2 - oparg*2;
527544 DISPATCH();
528545 }
529546 """
@@ -543,11 +560,11 @@ def test_array_output(self):
543560 PyObject *below;
544561 PyObject **values;
545562 PyObject *above;
546- values = stack_pointer - 1 ;
563+ values = & stack_pointer[-1] ;
547564 spam(values, oparg);
548- STACK_GROW(oparg*3) ;
549- stack_pointer[-2 - oparg*3] = below ;
550- stack_pointer[-1] = above ;
565+ stack_pointer[-2] = below ;
566+ stack_pointer[-1 + oparg*3] = above ;
567+ stack_pointer += oparg*3 ;
551568 DISPATCH();
552569 }
553570 """
@@ -566,10 +583,10 @@ def test_array_input_output(self):
566583 INSTRUCTION_STATS(OP);
567584 PyObject **values;
568585 PyObject *above;
569- values = stack_pointer - oparg;
586+ values = & stack_pointer[- oparg] ;
570587 spam(values, oparg);
571- STACK_GROW(1) ;
572- stack_pointer[-1] = above ;
588+ stack_pointer[0] = above ;
589+ stack_pointer += 1 ;
573590 DISPATCH();
574591 }
575592 """
@@ -588,11 +605,10 @@ def test_array_error_if(self):
588605 INSTRUCTION_STATS(OP);
589606 PyObject **values;
590607 PyObject *extra;
591- values = stack_pointer - oparg;
608+ values = & stack_pointer[- oparg] ;
592609 extra = stack_pointer[-1 - oparg];
593- if (oparg == 0) { STACK_SHRINK(oparg); goto pop_1_somewhere; }
594- STACK_SHRINK(oparg);
595- STACK_SHRINK(1);
610+ if (oparg == 0) { stack_pointer += -1 - oparg; goto somewhere; }
611+ stack_pointer += -1 - oparg;
596612 DISPATCH();
597613 }
598614 """
@@ -616,14 +632,13 @@ def test_cond_effect(self):
616632 PyObject *output = NULL;
617633 PyObject *zz;
618634 cc = stack_pointer[-1];
619- if ((oparg & 1) == 1) { input = stack_pointer[-1 - ((oparg & 1) == 1 ? 1 : 0)]; }
620- aa = stack_pointer[-2 - ((oparg & 1) == 1 ? 1 : 0)];
635+ if ((oparg & 1) == 1) { input = stack_pointer[-1 - (((( oparg & 1) == 1) ? 1 : 0) )]; }
636+ aa = stack_pointer[-2 - (((( oparg & 1) == 1) ? 1 : 0) )];
621637 output = spam(oparg, input);
622- STACK_SHRINK((((oparg & 1) == 1) ? 1 : 0));
623- STACK_GROW(((oparg & 2) ? 1 : 0));
624- stack_pointer[-2 - (oparg & 2 ? 1 : 0)] = xx;
625- if (oparg & 2) { stack_pointer[-1 - (oparg & 2 ? 1 : 0)] = output; }
626- stack_pointer[-1] = zz;
638+ stack_pointer[-2 - ((((oparg & 1) == 1) ? 1 : 0))] = xx;
639+ if (oparg & 2) stack_pointer[-1 - ((((oparg & 1) == 1) ? 1 : 0))] = output;
640+ stack_pointer[-1 - ((((oparg & 1) == 1) ? 1 : 0)) + (((oparg & 2) ? 1 : 0))] = zz;
641+ stack_pointer += -((((oparg & 1) == 1) ? 1 : 0)) + (((oparg & 2) ? 1 : 0));
627642 DISPATCH();
628643 }
629644 """
@@ -661,11 +676,10 @@ def test_macro_cond_effect(self):
661676 {
662677 # Body of B
663678 }
664- STACK_SHRINK(1);
665- STACK_GROW((oparg ? 1 : 0));
666- stack_pointer[-2 - (oparg ? 1 : 0)] = deep;
667- if (oparg) { stack_pointer[-1 - (oparg ? 1 : 0)] = extra; }
668- stack_pointer[-1] = res;
679+ stack_pointer[-3] = deep;
680+ if (oparg) stack_pointer[-2] = extra;
681+ stack_pointer[-2 + (((oparg) ? 1 : 0))] = res;
682+ stack_pointer += -1 + (((oparg) ? 1 : 0));
669683 DISPATCH();
670684 }
671685 """
@@ -696,9 +710,9 @@ def test_macro_push_push(self):
696710 {
697711 val2 = spam();
698712 }
699- STACK_GROW(2) ;
700- stack_pointer[-2 ] = val1 ;
701- stack_pointer[-1] = val2 ;
713+ stack_pointer[0] = val1 ;
714+ stack_pointer[1 ] = val2 ;
715+ stack_pointer += 2 ;
702716 DISPATCH();
703717 }
704718 """
0 commit comments