@@ -15,9 +15,8 @@ def skip_if_different_mount_drives():
15
15
root_drive = os .path .splitroot (ROOT )[0 ]
16
16
cwd_drive = os .path .splitroot (os .getcwd ())[0 ]
17
17
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).
21
20
raise unittest .SkipTest (
22
21
f"the current working directory and the Python source code "
23
22
f"directory have different mount drives "
@@ -28,10 +27,9 @@ def skip_if_different_mount_drives():
28
27
29
28
test_tools .skip_if_missing ('cases_generator' )
30
29
with 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
35
33
import tier1_generator
36
34
37
35
@@ -43,37 +41,24 @@ def handle_stderr():
43
41
44
42
class TestEffects (unittest .TestCase ):
45
43
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" ),
50
49
]
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 " ),
55
54
]
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" )
77
62
78
63
79
64
class TestGeneratedCases (unittest .TestCase ):
@@ -104,9 +89,9 @@ def tearDown(self) -> None:
104
89
105
90
def run_cases_test (self , input : str , expected : str ):
106
91
with open (self .temp_input_filename , "w+" ) as temp_input :
107
- temp_input .write (analysis .BEGIN_MARKER )
92
+ temp_input .write (parser .BEGIN_MARKER )
108
93
temp_input .write (input )
109
- temp_input .write (analysis .END_MARKER )
94
+ temp_input .write (parser .END_MARKER )
110
95
temp_input .flush ()
111
96
112
97
with handle_stderr ():
@@ -636,13 +621,13 @@ def test_cond_effect(self):
636
621
PyObject *output = NULL;
637
622
PyObject *zz;
638
623
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)];
641
626
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);
646
631
DISPATCH();
647
632
}
648
633
"""
@@ -682,8 +667,8 @@ def test_macro_cond_effect(self):
682
667
}
683
668
stack_pointer[-3] = deep;
684
669
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);
687
672
DISPATCH();
688
673
}
689
674
"""
0 commit comments