correctly increment s_offset for partial strings (#2897)
This commit is contained in:
@@ -272,55 +272,6 @@ impl MachineState {
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline(always)]
|
||||
pub(crate) fn constant_to_literal(&self, addr: HeapCellValue) -> Literal {
|
||||
read_heap_cell!(addr,
|
||||
(HeapCellValueTag::Char, c) => {
|
||||
Literal::Char(c)
|
||||
}
|
||||
(HeapCellValueTag::Fixnum, n) => {
|
||||
Literal::Fixnum(n)
|
||||
}
|
||||
(HeapCellValueTag::F64, f) => {
|
||||
Literal::Float(f.as_offset())
|
||||
}
|
||||
(HeapCellValueTag::Atom, (atom, arity)) => {
|
||||
debug_assert_eq!(arity, 0);
|
||||
Literal::Atom(atom)
|
||||
}
|
||||
(HeapCellValueTag::Str, s) => {
|
||||
Literal::Atom(cell_as_atom_cell!(self.heap[s]).get_name())
|
||||
}
|
||||
(HeapCellValueTag::Cons, cons_ptr) => {
|
||||
match_untyped_arena_ptr!(cons_ptr,
|
||||
(ArenaHeaderTag::Rational, r) => {
|
||||
Literal::Rational(r)
|
||||
}
|
||||
(ArenaHeaderTag::Integer, n) => {
|
||||
let result = (&*n).try_into();
|
||||
|
||||
match result {
|
||||
Ok(fixnum) => if let Ok(n) = Fixnum::build_with_checked(fixnum) {
|
||||
Literal::Fixnum(n)
|
||||
} else {
|
||||
Literal::Integer(n)
|
||||
},
|
||||
Err(_) => Literal::Integer(n)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
)
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn select_switch_on_structure_index(
|
||||
&self,
|
||||
@@ -3004,14 +2955,14 @@ impl Machine {
|
||||
&Instruction::UnifyConstant(v) => {
|
||||
match self.machine_st.mode {
|
||||
MachineMode::Read => {
|
||||
let addr = self.machine_st.read_s();
|
||||
let (addr, s_offset_incr) = self.machine_st.read_s();
|
||||
unify!(&mut self.machine_st, addr, v);
|
||||
|
||||
if self.machine_st.fail {
|
||||
self.machine_st.backtrack();
|
||||
continue;
|
||||
} else {
|
||||
self.machine_st.s_offset += 1;
|
||||
self.machine_st.s_offset += s_offset_incr;
|
||||
}
|
||||
}
|
||||
MachineMode::Write => {
|
||||
@@ -3025,7 +2976,7 @@ impl Machine {
|
||||
match self.machine_st.mode {
|
||||
MachineMode::Read => {
|
||||
let reg_addr = self.machine_st[reg];
|
||||
let value = self.machine_st.read_s();
|
||||
let (value, s_offset_incr) = self.machine_st.read_s();
|
||||
|
||||
unify_fn!(&mut self.machine_st, reg_addr, value);
|
||||
|
||||
@@ -3033,7 +2984,7 @@ impl Machine {
|
||||
self.machine_st.backtrack();
|
||||
continue;
|
||||
} else {
|
||||
self.machine_st.s_offset += 1;
|
||||
self.machine_st.s_offset += s_offset_incr;
|
||||
}
|
||||
}
|
||||
MachineMode::Write => {
|
||||
@@ -3066,13 +3017,12 @@ impl Machine {
|
||||
&Instruction::UnifyVariable(reg) => {
|
||||
match self.machine_st.mode {
|
||||
MachineMode::Read => {
|
||||
let value = self.machine_st.read_s();
|
||||
let (value, s_offset_incr) = self.machine_st.read_s();
|
||||
self.machine_st[reg] = value;
|
||||
self.machine_st.s_offset += 1;
|
||||
self.machine_st.s_offset += s_offset_incr;
|
||||
}
|
||||
MachineMode::Write => {
|
||||
let h = self.machine_st.heap.cell_len();
|
||||
|
||||
push_cell!(self.machine_st, heap_loc_as_cell!(h));
|
||||
self.machine_st[reg] = heap_loc_as_cell!(h);
|
||||
}
|
||||
@@ -3084,7 +3034,7 @@ impl Machine {
|
||||
match self.machine_st.mode {
|
||||
MachineMode::Read => {
|
||||
let reg_addr = self.machine_st[reg];
|
||||
let value = self.machine_st.read_s();
|
||||
let (value, s_offset_incr) = self.machine_st.read_s();
|
||||
|
||||
unify_fn!(&mut self.machine_st, reg_addr, value);
|
||||
|
||||
@@ -3092,7 +3042,7 @@ impl Machine {
|
||||
self.machine_st.backtrack();
|
||||
continue;
|
||||
} else {
|
||||
self.machine_st.s_offset += 1;
|
||||
self.machine_st.s_offset += s_offset_incr;
|
||||
}
|
||||
}
|
||||
MachineMode::Write => {
|
||||
|
||||
@@ -342,16 +342,16 @@ impl MachineState {
|
||||
}
|
||||
|
||||
// return the read value and the succeeding HeapPtr
|
||||
pub(crate) fn read_s(&mut self) -> HeapCellValue {
|
||||
pub(crate) fn read_s(&mut self) -> (HeapCellValue, usize) {
|
||||
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]), 1),
|
||||
HeapPtr::PStr(byte_index) => {
|
||||
let mut char_iter = self.heap.char_iter(byte_index);
|
||||
|
||||
if self.s_offset == 0 {
|
||||
// read the car of the list
|
||||
let c = char_iter.next().unwrap();
|
||||
char_as_cell!(c)
|
||||
(char_as_cell!(c), c.len_utf8())
|
||||
} else {
|
||||
// read the (self.s_offset)^{th} cdr of the list
|
||||
// self.s_offset is the number of bytes offset into the PStr
|
||||
@@ -361,11 +361,11 @@ impl MachineState {
|
||||
|
||||
if self.heap.char_iter(new_h).next().is_some() {
|
||||
self.s = HeapPtr::PStr(new_h);
|
||||
pstr_loc_as_cell!(new_h)
|
||||
(pstr_loc_as_cell!(new_h), 0)
|
||||
} else {
|
||||
let h = Heap::pstr_tail_idx(new_h);
|
||||
self.s = HeapPtr::HeapCell(h);
|
||||
self.deref(heap_loc_as_cell!(h))
|
||||
(self.deref(heap_loc_as_cell!(h)), 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user