]> Repositorios git - scryer-prolog.git/commitdiff
do not use self.fail in compare_term_test
authorMark Thom <[email protected]>
Wed, 17 Sep 2025 04:23:23 +0000 (21:23 -0700)
committerMark Thom <[email protected]>
Wed, 17 Sep 2025 04:23:23 +0000 (21:23 -0700)
src/machine/machine_state_impl.rs

index 2432c70255dcb8bcbca865bf11b93c7234f011cf..04fd143f4b5d62768b4253037020741452026949 100644 (file)
@@ -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);
+                                        }
                                     }
                                 }
                                 _ => {