@@ -894,7 +894,7 @@ def compute_instr(self, instr: instr_JSON_T, position_to_start_computing: cstack
894
894
seq = []
895
895
896
896
# Decide in which order computations must be done (after computing the subterms)
897
- input_vars = self ._computation_order (instr , cstate )
897
+ input_vars = self ._computation_order (instr , position_to_start_computing , cstate )
898
898
self .debug_logger .debug_message (f"Fixed elements { self .fixed_elements } { cstate } " , depth )
899
899
900
900
for i , stack_var in enumerate (input_vars ):
@@ -917,24 +917,26 @@ def compute_instr(self, instr: instr_JSON_T, position_to_start_computing: cstack
917
917
918
918
return seq
919
919
920
- def _computation_order (self , instr : instr_JSON_T , cstate : SymbolicState ) -> List [var_id_T ]:
920
+ def _computation_order (self , instr : instr_JSON_T , start_position : cstack_pos_T ,
921
+ cstate : SymbolicState ) -> List [var_id_T ]:
921
922
"""
922
923
Decides in which order the arguments of the instruction must be computed
923
924
"""
924
- if instr ['commutative' ]:
925
+ self .debug_logger .debug_message (f"{ start_position } { len (cstate .stack )} " )
926
+ if instr ['commutative' ] and - len (cstate .stack ) <= start_position :
925
927
# If it's commutative, study its dependencies.
926
928
if self .debug_mode :
927
929
assert len (instr ['inpt_sk' ]) == 2 , \
928
930
f'Commutative instruction { instr ["id" ]} has arity != 2'
929
931
930
932
# Condition: the top of the stack can be reused
931
- topmost_element = cstate .top_stack ()
933
+ first_consumed_element = cstate .stack [ start_position ]
932
934
first_arg_instr = self ._var2instr .get (instr ['inpt_sk' ][0 ], None )
933
935
934
936
# Condition1: the topmost element can be reused by the first argument instruction or is the first argument
935
- condition1 = (topmost_element is not None and topmost_element in self ._top_can_be_used [instr ["id" ]] and
936
- first_arg_instr is not None and (first_arg_instr ["outpt_sk" ][0 ] == topmost_element or
937
- topmost_element in self ._top_can_be_used [first_arg_instr ["id" ]]))
937
+ condition1 = (first_consumed_element is not None and first_consumed_element in self ._top_can_be_used [instr ["id" ]] and
938
+ first_arg_instr is not None and (first_arg_instr ["outpt_sk" ][0 ] == first_consumed_element or
939
+ first_consumed_element in self ._top_can_be_used [first_arg_instr ["id" ]]))
938
940
939
941
# Condition2: the first argument just needs to be swapped
940
942
condition2 = cstate .stack_var_copies_needed [instr ['inpt_sk' ][0 ]] == 0
@@ -944,6 +946,7 @@ def _computation_order(self, instr: instr_JSON_T, cstate: SymbolicState) -> List
944
946
input_vars = list (reversed (instr ['inpt_sk' ]))
945
947
else :
946
948
input_vars = list (reversed (instr ['inpt_sk' ]))
949
+
947
950
return input_vars
948
951
949
952
def decide_fixed_elements (self , cstate : SymbolicState , instr : instr_JSON_T ) -> Tuple [int , cstack_pos_T ]:
0 commit comments