fix list index offset bug (#314)

This commit is contained in:
Mark Thom
2020-04-06 16:15:36 -06:00
parent 6299d41cda
commit a3c3afba48
3 changed files with 12 additions and 14 deletions

View File

@@ -258,12 +258,11 @@ impl CodeOffsets {
fn switch_on_lst_offset_from( fn switch_on_lst_offset_from(
lst_loc: IntIndex, lst_loc: IntIndex,
prelude_len: usize, prelude_len: usize,
lst_offset: usize,
) -> usize { ) -> usize {
match lst_loc { match lst_loc {
IntIndex::External(o) => o + prelude_len + 1, IntIndex::External(o) => o + prelude_len + 1,
IntIndex::Fail => 0, 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 mut prelude = VecDeque::new();
let lst_loc = Self::switch_on_list(self.lists, &mut prelude); 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 str_loc = Self::switch_on_structure(self.structures, &mut prelude);
let con_loc = Self::switch_on_constant(self.constants, &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() { for (index, line) in prelude.iter_mut().enumerate() {
match line { match line {
&mut Line::IndexedChoice(IndexedChoiceInstruction::Try(ref mut i)) &mut Line::IndexedChoice(IndexedChoiceInstruction::Try(ref mut i)) |
| &mut Line::IndexedChoice(IndexedChoiceInstruction::Retry(ref mut i)) &mut Line::IndexedChoice(IndexedChoiceInstruction::Retry(ref mut i)) |
| &mut Line::IndexedChoice(IndexedChoiceInstruction::Trust(ref mut i)) => { &mut Line::IndexedChoice(IndexedChoiceInstruction::Trust(ref mut i)) => {
*i += prelude_length - index *i += prelude_length - index;
}
_ => {
} }
_ => {}
} }
} }
let str_loc = Self::switch_on_str_offset_from(str_loc, prelude.len(), con_loc); 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 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 = let switch_instr =
IndexingInstruction::SwitchOnTerm(prelude.len() + 1, con_loc, lst_loc, str_loc); IndexingInstruction::SwitchOnTerm(prelude.len() + 1, con_loc, lst_loc, str_loc);

View File

@@ -438,9 +438,9 @@ impl IndexingInstruction {
functor!( functor!(
"switch_on_term", "switch_on_term",
[integer(vars), [integer(vars),
integer(constants), integer(constants),
integer(lists), integer(lists),
integer(structures)] integer(structures)]
) )
} }
&IndexingInstruction::SwitchOnConstant(constants, _) => { &IndexingInstruction::SwitchOnConstant(constants, _) => {

View File

@@ -1308,7 +1308,7 @@ impl MachineState {
Addr::HeapCell(_) | Addr::StackCell(..) | Addr::HeapCell(_) | Addr::StackCell(..) |
Addr::AttrVar(..) | Addr::Stream(_) => { Addr::AttrVar(..) | Addr::Stream(_) => {
v v
} }
Addr::PStrLocation(..) => { Addr::PStrLocation(..) => {
if !self.flags.double_quotes.is_atom() { if !self.flags.double_quotes.is_atom() {
l l