From: Mark Thom Date: Tue, 9 Apr 2024 21:58:17 +0000 (-0600) Subject: correct offsets around max_steps in skip_max_list (#2381) X-Git-Tag: v0.10.0~143 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=77e90ca7254e99ca9512ee55c3efe56ab0abd899;p=scryer-prolog.git correct offsets around max_steps in skip_max_list (#2381) --- diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index b1f3aa9e..f4dc1f65 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -247,9 +247,9 @@ impl BrentAlgState { self.pstr_chars += num_chars; Some(CycleSearchResult::ProperList(self.num_steps())) } else { - let offset = self.num_steps() + num_chars - self.max_steps as usize; - self.pstr_chars += offset; - Some(CycleSearchResult::PStrLocation(self.max_steps as usize, h, offset)) + let char_offset = self.num_steps() + num_chars - self.max_steps as usize; + self.pstr_chars += char_offset; + Some(CycleSearchResult::PStrLocation(self.max_steps as usize, h, char_offset + offset)) } } (HeapCellValueTag::PStr, pstr_atom) => { @@ -260,9 +260,9 @@ impl BrentAlgState { self.pstr_chars += num_chars - 1; self.step(h+1) } else { - let offset = self.num_steps() + num_chars - self.max_steps as usize; - self.pstr_chars += offset; - Some(CycleSearchResult::PStrLocation(self.max_steps as usize, h, offset)) + let char_offset = self.num_steps() + num_chars - self.max_steps as usize; + self.pstr_chars += char_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; if heap[h].get_tag() == HeapCellValueTag::PStrOffset { - debug_assert!(heap[h].get_tag() == HeapCellValueTag::PStrOffset); - if heap[h_offset].get_tag() == HeapCellValueTag::CStr { return if pstr_chars < max_steps { CycleSearchResult::ProperList(pstr_chars + 1) } 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 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