From: Mark Thom Date: Wed, 17 Sep 2025 04:23:23 +0000 (-0700) Subject: do not use self.fail in compare_term_test X-Git-Tag: v0.10.0~6 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=012e3de3a16941b97e88578ba6894e4fde0d47d7;p=scryer-prolog.git do not use self.fail in compare_term_test --- diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index 2432c702..04fd143f 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -593,26 +593,30 @@ impl MachineState { self.pdl.push(char_as_cell!(c)); self.pdl.push(heap_loc_as_cell!(l2)); } - (HeapCellValueTag::Str, s) => { - if tabu_list.contains(&(l1, s)) { + (HeapCellValueTag::Str, s2) => { + if tabu_list.contains(&(l1, s2)) { continue; } - let (name, arity) = cell_as_atom_cell!(self.heap[s]) - .get_name_and_arity(); + tabu_list.insert((l1, s2)); - if name == atom!(".") && arity == 2 { - tabu_list.insert((l1, s)); + let (n2, a2) = cell_as_atom_cell!(self.heap[s2]) + .get_name_and_arity(); - let (c, succ_cell) = self.heap.last_str_char_and_tail(l1); + match (2, atom!(".")).cmp(&(a2,n2)) { + Ordering::Equal => { + let (c, succ_cell) = self.heap.last_str_char_and_tail(l1); - self.pdl.push(heap_loc_as_cell!(s+2)); - self.pdl.push(succ_cell); + self.pdl.push(heap_loc_as_cell!(s2+2)); + self.pdl.push(succ_cell); - self.pdl.push(heap_loc_as_cell!(s+1)); - self.pdl.push(char_as_cell!(c)); - } else { - self.fail = true; + self.pdl.push(heap_loc_as_cell!(s2+1)); + self.pdl.push(char_as_cell!(c)); + } + ordering => { + self.pdl.clear(); + return Some(ordering); + } } } _ => { @@ -673,19 +677,23 @@ impl MachineState { } } (HeapCellValueTag::PStrLoc, l2) => { - let (name, arity) = cell_as_atom_cell!(self.heap[s1]) + let (n1, a1) = cell_as_atom_cell!(self.heap[s1]) .get_name_and_arity(); - if name == atom!(".") && arity == 2 { - let (c, succ_cell) = self.heap.last_str_char_and_tail(l2); + match (a1,n1).cmp(&(2, atom!("."))) { + Ordering::Equal => { + let (c, succ_cell) = self.heap.last_str_char_and_tail(l2); - self.pdl.push(succ_cell); - self.pdl.push(heap_loc_as_cell!(s1+2)); + self.pdl.push(succ_cell); + self.pdl.push(heap_loc_as_cell!(s1+2)); - self.pdl.push(char_as_cell!(c)); - self.pdl.push(heap_loc_as_cell!(s1+1)); - } else { - self.fail = true; + self.pdl.push(char_as_cell!(c)); + self.pdl.push(heap_loc_as_cell!(s1+1)); + } + ordering => { + self.pdl.clear(); + return Some(ordering); + } } } _ => {