From: Mark Thom Date: Mon, 27 Aug 2018 02:50:12 +0000 (-0600) Subject: unify matching strings with different cursors. X-Git-Tag: v0.8.110~420 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=b418e63a89c8a71c677b50e66f62b6b57aed6c1e;p=scryer-prolog.git unify matching strings with different cursors. --- diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index ee68a2e5..1bd939db 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -214,6 +214,24 @@ impl MachineState { pdl.push(Addr::HeapCell(a1 + 1)); pdl.push(Addr::HeapCell(a2 + 1)); }, + (Addr::Con(Constant::String(ref s1)), Addr::Con(Constant::String(ref s2))) => { + if let Some(c1) = s1.head() { + if let Some(c2) = s2.head() { + if c1 == c2 { + pdl.push(Addr::Con(Constant::String(s1.tail()))); + pdl.push(Addr::Con(Constant::String(s2.tail()))); + + continue; + } + } + } else { + if s2.head().is_none() { + continue; + } + } + + self.fail = true; + }, (Addr::Con(ref c1), Addr::Con(ref c2)) => if c1 != c2 { self.fail = true; diff --git a/src/prolog/string_list.rs b/src/prolog/string_list.rs index d4f8e35e..b4676765 100644 --- a/src/prolog/string_list.rs +++ b/src/prolog/string_list.rs @@ -46,7 +46,7 @@ impl Ord for StringList { impl PartialEq for StringList { fn eq(&self, other: &Self) -> bool { - self.body == other.body + self.body == other.body && self.cursor == other.cursor && self.expandable == other.expandable } }