@@ -15,9 +15,8 @@ def skip_if_different_mount_drives():
1515 root_drive = os .path .splitroot (ROOT )[0 ]
1616 cwd_drive = os .path .splitroot (os .getcwd ())[0 ]
1717 if root_drive != cwd_drive :
18- # generate_cases.py uses relpath() which raises ValueError if ROOT
19- # and the current working different have different mount drives
20- # (on Windows).
18+ # May raise ValueError if ROOT and the current working
19+ # different have different mount drives (on Windows).
2120 raise unittest .SkipTest (
2221 f"the current working directory and the Python source code "
2322 f"directory have different mount drives "
@@ -28,10 +27,9 @@ def skip_if_different_mount_drives():
2827
2928test_tools .skip_if_missing ('cases_generator' )
3029with test_tools .imports_under_tool ('cases_generator' ):
31- import generate_cases
32- import analysis
33- import formatting
34- from parsing import StackEffect
30+ from analyzer import StackItem
31+ import parser
32+ from stack import Stack
3533 import tier1_generator
3634
3735
@@ -43,37 +41,24 @@ def handle_stderr():
4341
4442class TestEffects (unittest .TestCase ):
4543 def test_effect_sizes (self ):
46- input_effects = [
47- x := StackEffect ("x" , "" , "" , "" ),
48- y := StackEffect ("y" , "" , "" , "oparg" ),
49- z := StackEffect ("z" , "" , "" , "oparg*2" ),
44+ stack = Stack ()
45+ inputs = [
46+ x := StackItem ("x" , None , "" , "1" ),
47+ y := StackItem ("y" , None , "" , "oparg" ),
48+ z := StackItem ("z" , None , "" , "oparg*2" ),
5049 ]
51- output_effects = [
52- StackEffect ( "a " , "" , "" , "" ),
53- StackEffect ("b" , "" , "" , "oparg*4" ),
54- StackEffect ("c" , "" , "" , "" ),
50+ outputs = [
51+ StackItem ( "x " , None , "" , "1 " ),
52+ StackItem ("b" , None , "" , "oparg*4" ),
53+ StackItem ("c" , None , "" , "1 " ),
5554 ]
56- other_effects = [
57- StackEffect ("p" , "" , "" , "oparg<<1" ),
58- StackEffect ("q" , "" , "" , "" ),
59- StackEffect ("r" , "" , "" , "" ),
60- ]
61- self .assertEqual (formatting .effect_size (x ), (1 , "" ))
62- self .assertEqual (formatting .effect_size (y ), (0 , "oparg" ))
63- self .assertEqual (formatting .effect_size (z ), (0 , "oparg*2" ))
64-
65- self .assertEqual (
66- formatting .list_effect_size (input_effects ),
67- (1 , "oparg + oparg*2" ),
68- )
69- self .assertEqual (
70- formatting .list_effect_size (output_effects ),
71- (2 , "oparg*4" ),
72- )
73- self .assertEqual (
74- formatting .list_effect_size (other_effects ),
75- (2 , "(oparg<<1)" ),
76- )
55+ stack .pop (z )
56+ stack .pop (y )
57+ stack .pop (x )
58+ for out in outputs :
59+ stack .push (out )
60+ self .assertEqual (stack .base_offset .to_c (), "-1 - oparg*2 - oparg" )
61+ self .assertEqual (stack .top_offset .to_c (), "1 - oparg*2 - oparg + oparg*4" )
7762
7863
7964class TestGeneratedCases (unittest .TestCase ):
@@ -104,9 +89,9 @@ def tearDown(self) -> None:
10489
10590 def run_cases_test (self , input : str , expected : str ):
10691 with open (self .temp_input_filename , "w+" ) as temp_input :
107- temp_input .write (analysis .BEGIN_MARKER )
92+ temp_input .write (parser .BEGIN_MARKER )
10893 temp_input .write (input )
109- temp_input .write (analysis .END_MARKER )
94+ temp_input .write (parser .END_MARKER )
11095 temp_input .flush ()
11196
11297 with handle_stderr ():
@@ -636,13 +621,13 @@ def test_cond_effect(self):
636621 PyObject *output = NULL;
637622 PyObject *zz;
638623 cc = stack_pointer[-1];
639- if ((oparg & 1) == 1) { input = stack_pointer[-1 - (((( oparg & 1) == 1) ? 1 : 0) )]; }
640- aa = stack_pointer[-2 - (((( oparg & 1) == 1) ? 1 : 0) )];
624+ if ((oparg & 1) == 1) { input = stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)]; }
625+ aa = stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)];
641626 output = spam(oparg, input);
642- stack_pointer[-2 - (((( oparg & 1) == 1) ? 1 : 0) )] = xx;
643- if (oparg & 2) stack_pointer[-1 - (((( oparg & 1) == 1) ? 1 : 0) )] = output;
644- stack_pointer[-1 - (((( oparg & 1) == 1) ? 1 : 0)) + ((( oparg & 2) ? 1 : 0) )] = zz;
645- stack_pointer += -(((( oparg & 1) == 1) ? 1 : 0)) + ((( oparg & 2) ? 1 : 0) );
627+ stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)] = xx;
628+ if (oparg & 2) stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)] = output;
629+ stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0)] = zz;
630+ stack_pointer += -(((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0);
646631 DISPATCH();
647632 }
648633 """
@@ -682,8 +667,8 @@ def test_macro_cond_effect(self):
682667 }
683668 stack_pointer[-3] = deep;
684669 if (oparg) stack_pointer[-2] = extra;
685- stack_pointer[-2 + ((( oparg) ? 1 : 0) )] = res;
686- stack_pointer += -1 + ((( oparg) ? 1 : 0) );
670+ stack_pointer[-2 + ((oparg) ? 1 : 0)] = res;
671+ stack_pointer += -1 + ((oparg) ? 1 : 0);
687672 DISPATCH();
688673 }
689674 """
0 commit comments