correct offsets around max_steps in skip_max_list (#2381)

This commit is contained in:
Mark Thom
2024-04-09 15:58:17 -06:00
parent f734c273ca
commit 77e90ca725

View File

@@ -247,9 +247,9 @@ impl BrentAlgState {
self.pstr_chars += num_chars; self.pstr_chars += num_chars;
Some(CycleSearchResult::ProperList(self.num_steps())) Some(CycleSearchResult::ProperList(self.num_steps()))
} else { } else {
let offset = self.num_steps() + num_chars - self.max_steps as usize; let char_offset = self.num_steps() + num_chars - self.max_steps as usize;
self.pstr_chars += offset; self.pstr_chars += char_offset;
Some(CycleSearchResult::PStrLocation(self.max_steps as usize, h, offset)) Some(CycleSearchResult::PStrLocation(self.max_steps as usize, h, char_offset + offset))
} }
} }
(HeapCellValueTag::PStr, pstr_atom) => { (HeapCellValueTag::PStr, pstr_atom) => {
@@ -260,9 +260,9 @@ impl BrentAlgState {
self.pstr_chars += num_chars - 1; self.pstr_chars += num_chars - 1;
self.step(h+1) self.step(h+1)
} else { } else {
let offset = self.num_steps() + num_chars - self.max_steps as usize; let char_offset = self.num_steps() + num_chars - self.max_steps as usize;
self.pstr_chars += offset; self.pstr_chars += char_offset;
Some(CycleSearchResult::PStrLocation(self.max_steps as usize, h, offset)) Some(CycleSearchResult::PStrLocation(self.max_steps as usize, h, char_offset + offset))
} }
} }
_ => { _ => {
@@ -429,14 +429,12 @@ impl BrentAlgState {
pstr_chars = pstr.as_str_from(n).chars().count() - 1; pstr_chars = pstr.as_str_from(n).chars().count() - 1;
if heap[h].get_tag() == HeapCellValueTag::PStrOffset { if heap[h].get_tag() == HeapCellValueTag::PStrOffset {
debug_assert!(heap[h].get_tag() == HeapCellValueTag::PStrOffset);
if heap[h_offset].get_tag() == HeapCellValueTag::CStr { if heap[h_offset].get_tag() == HeapCellValueTag::CStr {
return if pstr_chars < max_steps { return if pstr_chars < max_steps {
CycleSearchResult::ProperList(pstr_chars + 1) CycleSearchResult::ProperList(pstr_chars + 1)
} else { } else {
CycleSearchResult::UntouchedCStr(pstr.into(), max_steps) CycleSearchResult::PStrLocation(max_steps, h_offset, n)
}; }
} }
} }
@@ -689,6 +687,7 @@ impl MachineState {
let cell = if offset > 0 { let cell = if offset > 0 {
let h = self.heap.len(); let h = self.heap.len();
let (pstr_loc, _) = pstr_loc_and_offset(&self.heap, pstr_loc);
self.heap.push(pstr_offset_as_cell!(pstr_loc)); self.heap.push(pstr_offset_as_cell!(pstr_loc));
self.heap self.heap