]> Repositorios git - scryer-prolog.git/commitdiff
treat functors with PI '.'/2 as lists (#1570)
authorMark Thom <[email protected]>
Sun, 14 Aug 2022 22:14:53 +0000 (16:14 -0600)
committerMark Thom <[email protected]>
Thu, 27 Oct 2022 05:36:07 +0000 (23:36 -0600)
src/indexing.rs
src/machine/dispatch.rs

index ceace331203cd6b6e077e1cc4386c6290d35b695..bad75be4616c0252f4feaa0e9831997add90686c 100644 (file)
@@ -1466,17 +1466,20 @@ impl<I: Indexer> CodeOffsets<I> {
         atom_tbl: &mut AtomTable,
     ) {
         match optimal_arg {
+            &Term::Clause(_, atom!("."), ref terms) if terms.len() == 2 => {
+                clause_index_info.opt_arg_index_key = OptArgIndexKey::List(self.optimal_index, 0);
+                self.index_list(index);
+            }
+            &Term::Cons(..) | &Term::Literal(_, Literal::String(_)) | &Term::PartialString(..) => {
+                clause_index_info.opt_arg_index_key = OptArgIndexKey::List(self.optimal_index, 0);
+                self.index_list(index);
+            }
             &Term::Clause(_, name, ref terms) => {
                 clause_index_info.opt_arg_index_key =
                     OptArgIndexKey::Structure(self.optimal_index, 0, name.clone(), terms.len());
 
                 self.index_structure(name, terms.len(), index);
             }
-            &Term::Cons(..) | &Term::Literal(_, Literal::String(_)) | &Term::PartialString(..) => {
-                clause_index_info.opt_arg_index_key = OptArgIndexKey::List(self.optimal_index, 0);
-
-                self.index_list(index);
-            }
             &Term::Literal(_, constant) => {
                 let overlapping_constants = self.index_constant(atom_tbl, constant, index);
 
index 82ef48264e95e523226423c91cfb354e4fc09233..39afe10ee3bc8f8429593d41aefbf2902c81b419 100644 (file)
@@ -371,8 +371,14 @@ impl Machine {
                             c
                         }
                         (HeapCellValueTag::Str, st) => {
-                            let arity = cell_as_atom_cell!(self.machine_st.heap[st]).get_arity();
-                            if arity == 0 { c } else { s }
+                            let (name, arity) = cell_as_atom_cell!(self.machine_st.heap[st])
+                                .get_name_and_arity();
+
+                            match (name, arity) {
+                                (atom!("."), 2) => l,
+                                (_, 0) => c,
+                                _ => s,
+                            }
                         }
                         (HeapCellValueTag::Cons, ptr) => {
                             match ptr.get_tag() {
@@ -2812,6 +2818,19 @@ impl Machine {
                             self.machine_st.s_offset = 0;
                             self.machine_st.mode = MachineMode::Read;
                         }
+                        (HeapCellValueTag::Str, s) => {
+                            let (name, arity) = cell_as_atom_cell!(self.machine_st.heap[s])
+                                .get_name_and_arity();
+
+                            if name == atom!(".") && arity == 2 {
+                                self.machine_st.s = HeapPtr::HeapCell(s+1);
+                                self.machine_st.s_offset = 0;
+                                self.machine_st.mode = MachineMode::Read;
+                            } else {
+                                self.machine_st.backtrack();
+                                continue;
+                            }
+                        }
                         (HeapCellValueTag::Lis, l) => {
                             self.machine_st.s = HeapPtr::HeapCell(l);
                             self.machine_st.s_offset = 0;