@@ -995,15 +995,19 @@ def test_conditional_jump_forward_non_const_condition(self):
995
995
('LOAD_CONST' , 2 , 13 ),
996
996
lbl ,
997
997
('LOAD_CONST' , 3 , 14 ),
998
+ ('RETURN_VALUE' , 14 ),
998
999
]
999
- expected = [
1000
+ expected_insts = [
1000
1001
('LOAD_NAME' , 1 , 11 ),
1001
1002
('POP_JUMP_IF_TRUE' , lbl := self .Label (), 12 ),
1002
- ('LOAD_CONST' , 2 , 13 ),
1003
+ ('LOAD_CONST' , 1 , 13 ),
1003
1004
lbl ,
1004
- ('LOAD_CONST ' , 3 , 14 )
1005
+ ('RETURN_CONST ' , 2 , 14 ),
1005
1006
]
1006
- self .cfg_optimization_test (insts , expected , consts = list (range (5 )))
1007
+ self .cfg_optimization_test (insts ,
1008
+ expected_insts ,
1009
+ consts = [0 , 1 , 2 , 3 , 4 ],
1010
+ expected_consts = [0 , 2 , 3 ])
1007
1011
1008
1012
def test_conditional_jump_forward_const_condition (self ):
1009
1013
# The unreachable branch of the jump is removed, the jump
@@ -1015,43 +1019,50 @@ def test_conditional_jump_forward_const_condition(self):
1015
1019
('LOAD_CONST' , 2 , 13 ),
1016
1020
lbl ,
1017
1021
('LOAD_CONST' , 3 , 14 ),
1022
+ ('RETURN_VALUE' , 14 ),
1018
1023
]
1019
- expected = [
1020
- ('NOP' , None , 11 ),
1021
- ('NOP' , None , 12 ),
1022
- ('LOAD_CONST ' , 3 , 14 )
1024
+ expected_insts = [
1025
+ ('NOP' , 11 ),
1026
+ ('NOP' , 12 ),
1027
+ ('RETURN_CONST ' , 1 , 14 ),
1023
1028
]
1024
- self .cfg_optimization_test (insts , expected , consts = list (range (5 )))
1029
+ self .cfg_optimization_test (insts ,
1030
+ expected_insts ,
1031
+ consts = [0 , 1 , 2 , 3 , 4 ],
1032
+ expected_consts = [0 , 3 ])
1025
1033
1026
1034
def test_conditional_jump_backward_non_const_condition (self ):
1027
1035
insts = [
1028
1036
lbl1 := self .Label (),
1029
1037
('LOAD_NAME' , 1 , 11 ),
1030
1038
('POP_JUMP_IF_TRUE' , lbl1 , 12 ),
1031
- ('LOAD_CONST' , 2 , 13 ),
1039
+ ('LOAD_NAME' , 2 , 13 ),
1040
+ ('RETURN_VALUE' , 13 ),
1032
1041
]
1033
1042
expected = [
1034
1043
lbl := self .Label (),
1035
1044
('LOAD_NAME' , 1 , 11 ),
1036
1045
('POP_JUMP_IF_TRUE' , lbl , 12 ),
1037
- ('LOAD_CONST' , 2 , 13 )
1046
+ ('LOAD_NAME' , 2 , 13 ),
1047
+ ('RETURN_VALUE' , 13 ),
1038
1048
]
1039
1049
self .cfg_optimization_test (insts , expected , consts = list (range (5 )))
1040
1050
1041
1051
def test_conditional_jump_backward_const_condition (self ):
1042
1052
# The unreachable branch of the jump is removed
1043
1053
insts = [
1044
1054
lbl1 := self .Label (),
1045
- ('LOAD_CONST' , 1 , 11 ),
1055
+ ('LOAD_CONST' , 3 , 11 ),
1046
1056
('POP_JUMP_IF_TRUE' , lbl1 , 12 ),
1047
1057
('LOAD_CONST' , 2 , 13 ),
1058
+ ('RETURN_VALUE' , 13 ),
1048
1059
]
1049
- expected = [
1060
+ expected_insts = [
1050
1061
lbl := self .Label (),
1051
- ('NOP' , None , 11 ),
1052
- ('JUMP' , lbl , 12 )
1062
+ ('NOP' , 11 ),
1063
+ ('JUMP' , lbl , 12 ),
1053
1064
]
1054
- self .cfg_optimization_test (insts , expected , consts = list (range (5 )))
1065
+ self .cfg_optimization_test (insts , expected_insts , consts = list (range (5 )))
1055
1066
1056
1067
1057
1068
if __name__ == "__main__" :
0 commit comments