]> Repositorios git - scryer-prolog.git/commitdiff
fix list index offset bug (#314)
authorMark Thom <[email protected]>
Mon, 6 Apr 2020 22:15:36 +0000 (16:15 -0600)
committerMark Thom <[email protected]>
Mon, 6 Apr 2020 22:15:36 +0000 (16:15 -0600)
src/prolog/indexing.rs
src/prolog/instructions.rs
src/prolog/machine/machine_state_impl.rs

index 59e83a78c04981b240e6b23a1295e88590a922e4..239c5dbd042c448605607db4089451efa49e6478 100644 (file)
@@ -258,12 +258,11 @@ impl CodeOffsets {
     fn switch_on_lst_offset_from(
         lst_loc: IntIndex,
         prelude_len: usize,
-        lst_offset: usize,
     ) -> usize {
         match lst_loc {
             IntIndex::External(o) => o + prelude_len + 1,
             IntIndex::Fail => 0,
-            IntIndex::Internal(_) => prelude_len - lst_offset + 1,
+            IntIndex::Internal(_) => 1, // this internal is always 0.
         }
     }
 
@@ -276,8 +275,6 @@ impl CodeOffsets {
         let mut prelude = VecDeque::new();
 
         let lst_loc = Self::switch_on_list(self.lists, &mut prelude);
-        let lst_offset = prelude.len();
-
         let str_loc = Self::switch_on_structure(self.structures, &mut prelude);
         let con_loc = Self::switch_on_constant(self.constants, &mut prelude);
 
@@ -285,18 +282,19 @@ impl CodeOffsets {
 
         for (index, line) in prelude.iter_mut().enumerate() {
             match line {
-                &mut Line::IndexedChoice(IndexedChoiceInstruction::Try(ref mut i))
-              | &mut Line::IndexedChoice(IndexedChoiceInstruction::Retry(ref mut i))
-              | &mut Line::IndexedChoice(IndexedChoiceInstruction::Trust(ref mut i)) => {
-                    *i += prelude_length - index
+                &mut Line::IndexedChoice(IndexedChoiceInstruction::Try(ref mut i)) |
+                &mut Line::IndexedChoice(IndexedChoiceInstruction::Retry(ref mut i)) |
+                &mut Line::IndexedChoice(IndexedChoiceInstruction::Trust(ref mut i)) => {
+                    *i += prelude_length - index;
+                }
+                _ => {
                 }
-                _ => {}
             }
         }
 
         let str_loc = Self::switch_on_str_offset_from(str_loc, prelude.len(), con_loc);
         let con_loc = Self::switch_on_con_offset_from(con_loc, prelude.len());
-        let lst_loc = Self::switch_on_lst_offset_from(lst_loc, prelude.len(), lst_offset);
+        let lst_loc = Self::switch_on_lst_offset_from(lst_loc, prelude.len());
 
         let switch_instr =
             IndexingInstruction::SwitchOnTerm(prelude.len() + 1, con_loc, lst_loc, str_loc);
index 903fbd3cf17759e84e65bd9432b831aa8d6ef1d9..d12cb7521571a8960345013be31e48368a38d795 100644 (file)
@@ -438,9 +438,9 @@ impl IndexingInstruction {
                 functor!(
                     "switch_on_term",
                     [integer(vars),
-                      integer(constants),
-                      integer(lists),
-                      integer(structures)]
+                     integer(constants),
+                     integer(lists),
+                     integer(structures)]
                 )
             }
             &IndexingInstruction::SwitchOnConstant(constants, _) => {
index 120e39f8acc9935078d5982e81cc360c9984c320..0768a5eba6c3b8e63a52c828f7d0eb308f181c23 100644 (file)
@@ -1308,7 +1308,7 @@ impl MachineState {
                     Addr::HeapCell(_) | Addr::StackCell(..) |
                     Addr::AttrVar(..) | Addr::Stream(_) => {
                       v
-                  }
+                    }
                     Addr::PStrLocation(..) => {
                         if !self.flags.double_quotes.is_atom() {
                             l