From 069e132c0ebcc00a063e117d05a2f08cf2a60e15 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sun, 14 Aug 2022 16:14:53 -0600 Subject: [PATCH] treat functors with PI '.'/2 as lists (#1570) --- src/indexing.rs | 13 ++++++++----- src/machine/dispatch.rs | 23 +++++++++++++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/indexing.rs b/src/indexing.rs index ceace331..bad75be4 100644 --- a/src/indexing.rs +++ b/src/indexing.rs @@ -1466,17 +1466,20 @@ impl CodeOffsets { 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); diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 82ef4826..39afe10e 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -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; -- 2.54.0