]> Repositorios git - scryer-prolog.git/commitdiff
fix bug in append_compiled_clause, generalize merging indexed subsequences of clauses
authorMark Thom <[email protected]>
Sun, 31 Jan 2021 08:18:45 +0000 (01:18 -0700)
committerMark Thom <[email protected]>
Sun, 31 Jan 2021 08:18:45 +0000 (01:18 -0700)
src/machine/compile.rs

index 7b3fb49f176f7fb2ad0d746ce9d102245a478dcd..5311544b6225a130b8d2520f438f33aa57fd9062 100644 (file)
@@ -1002,7 +1002,25 @@ fn append_compiled_clause(
                 );
 
                 if lower_bound + 1 == target_pos {
-                    set_switch_var_offset(code, index_loc, 1, retraction_info);
+                    let lower_bound_clause_start = find_inner_choice_instr(
+                        code,
+                        skeleton.clauses[lower_bound].clause_start,
+                        index_loc,
+                    );
+
+                    set_switch_var_offset(
+                        code,
+                        index_loc,
+                        lower_bound_clause_start - index_loc,
+                        retraction_info,
+                    );
+
+                    thread_choice_instr_at_to(
+                        code,
+                        lower_bound_clause_start,
+                        skeleton.clauses[target_pos].clause_start,
+                        retraction_info,
+                    );
                 }
 
                 skeleton.clauses[target_pos - 1].clause_start
@@ -1389,6 +1407,12 @@ impl<'a> LoadState<'a> {
                 Some(target_indexing_loc)
                     if mergeable_indexed_subsequences(lower_bound, target_pos, skeleton) =>
                 {
+                    let lower_bound_clause_start = find_inner_choice_instr(
+                        code,
+                        skeleton.clauses[lower_bound].clause_start,
+                        target_indexing_loc,
+                    );
+
                     let result;
 
                     match skeleton.clauses[target_pos + 1].opt_arg_index_key.switch_on_term_loc() {
@@ -1416,7 +1440,7 @@ impl<'a> LoadState<'a> {
                             set_switch_var_offset(
                                 code,
                                 later_indexing_loc,
-                                target_indexing_loc - later_indexing_loc + 1,
+                                lower_bound_clause_start - later_indexing_loc, // target_indexing_loc - later_indexing_loc + 1,
                                 &mut self.retraction_info,
                             );
 
@@ -1440,7 +1464,7 @@ impl<'a> LoadState<'a> {
                             set_switch_var_offset_to_choice_instr_(
                                 code,
                                 target_indexing_loc,
-                                1,
+                                lower_bound_clause_start - target_indexing_loc, //1,
                                 &mut self.retraction_info,
                             );