From 003b4d021876baf0087023357f2d44de624a1f1f Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sat, 22 Feb 2020 00:51:27 -0700 Subject: [PATCH] add comparisons between partial strings and string constants (#263) --- src/prolog/machine/machine_state.rs | 6 +++--- src/prolog/machine/machine_state_impl.rs | 7 +++++++ src/prolog/machine/stack.rs | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/prolog/machine/machine_state.rs b/src/prolog/machine/machine_state.rs index 3a994e9e..3cca9363 100644 --- a/src/prolog/machine/machine_state.rs +++ b/src/prolog/machine/machine_state.rs @@ -538,8 +538,8 @@ pub(crate) trait CallPolicy: Any { attr_var_init_bindings_b, ); - machine_st.stack.truncate(machine_st.b); machine_st.b = machine_st.stack.index_or_frame(b).prelude.b; + machine_st.stack.truncate(b); machine_st.hb = machine_st.heap.h(); machine_st.p += offset; @@ -578,8 +578,8 @@ pub(crate) trait CallPolicy: Any { attr_var_init_bindings_b, ); - machine_st.stack.truncate(machine_st.b); machine_st.b = machine_st.stack.index_or_frame(b).prelude.b; + machine_st.stack.truncate(b); machine_st.hb = machine_st.heap.h(); machine_st.p += 1; @@ -1032,7 +1032,7 @@ impl CWILCallPolicy { pub(crate) trait CutPolicy: Any { // returns true iff we fail or cut redirected the MachineState's p itself - fn cut(&mut self, _: &mut MachineState, _: RegType) -> bool; + fn cut(&mut self, machine_st: &mut MachineState, r: RegType) -> bool; } downcast!(dyn CutPolicy); diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index 998f3252..c6db779b 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -2204,6 +2204,13 @@ impl MachineState { (HeapCellValue::Addr(Addr::PStrLocation(..)), HeapCellValue::Addr(Addr::PStrLocation(..))) => continue, + (HeapCellValue::Addr(Addr::PStrLocation(..)), + HeapCellValue::Addr(Addr::Con(Constant::String(..)))) + | (HeapCellValue::Addr(Addr::Con(Constant::String(..))), + HeapCellValue::Addr(Addr::PStrLocation(..))) + if self.flags.double_quotes.is_chars() => { + continue; + } (HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::Addr(Addr::Lis(_))) => continue, (HeapCellValue::Addr(Addr::Con(Constant::EmptyList)), diff --git a/src/prolog/machine/stack.rs b/src/prolog/machine/stack.rs index 9984dfe1..6e0731d5 100644 --- a/src/prolog/machine/stack.rs +++ b/src/prolog/machine/stack.rs @@ -89,6 +89,8 @@ impl Index for AndFrame { impl IndexMut for AndFrame { fn index_mut(&mut self, index: usize) -> &mut Self::Output { + debug_assert!(self.prelude.univ_prelude.is_or_frame == 0); + let prelude_offset = prelude_size::(); let index_offset = (index - 1) * mem::size_of::(); @@ -143,6 +145,8 @@ impl Index for OrFrame { #[inline] fn index(&self, index: usize) -> &Self::Output { + debug_assert!(self.prelude.univ_prelude.is_or_frame == 1); + let prelude_offset = prelude_size::(); let index_offset = index * mem::size_of::(); @@ -158,6 +162,8 @@ impl Index for OrFrame { impl IndexMut for OrFrame { #[inline] fn index_mut(&mut self, index: usize) -> &mut Self::Output { + debug_assert!(self.prelude.univ_prelude.is_or_frame == 1); + let prelude_offset = prelude_size::(); let index_offset = index * mem::size_of::(); -- 2.54.0