fix read_s logic around HeapPtr::PStrLoc (#2894)
This commit is contained in:
@@ -345,8 +345,8 @@ impl MachineState {
|
|||||||
pub(crate) fn read_s(&mut self) -> HeapCellValue {
|
pub(crate) fn read_s(&mut self) -> HeapCellValue {
|
||||||
match self.s {
|
match self.s {
|
||||||
HeapPtr::HeapCell(h) => self.deref(self.heap[h + self.s_offset]),
|
HeapPtr::HeapCell(h) => self.deref(self.heap[h + self.s_offset]),
|
||||||
HeapPtr::PStr(h) => {
|
HeapPtr::PStr(byte_index) => {
|
||||||
let mut char_iter = self.heap.char_iter(h);
|
let mut char_iter = self.heap.char_iter(byte_index);
|
||||||
|
|
||||||
if self.s_offset == 0 {
|
if self.s_offset == 0 {
|
||||||
// read the car of the list
|
// read the car of the list
|
||||||
@@ -354,10 +354,9 @@ impl MachineState {
|
|||||||
char_as_cell!(c)
|
char_as_cell!(c)
|
||||||
} else {
|
} else {
|
||||||
// read the (self.s_offset)^{th} cdr of the list
|
// read the (self.s_offset)^{th} cdr of the list
|
||||||
let byte_offset: usize =
|
// self.s_offset is the number of bytes offset into the PStr
|
||||||
char_iter.take(self.s_offset).map(|c| c.len_utf8()).sum();
|
// in this context, *not* the number of heap cells.
|
||||||
let new_h = h + byte_offset;
|
let new_h = byte_index + self.s_offset;
|
||||||
|
|
||||||
self.s_offset = 0;
|
self.s_offset = 0;
|
||||||
|
|
||||||
if self.heap.char_iter(new_h).next().is_some() {
|
if self.heap.char_iter(new_h).next().is_some() {
|
||||||
|
|||||||
Reference in New Issue
Block a user