From 335202b9d905b6318d82001b84db81c007e19f50 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Thu, 28 Nov 2019 19:08:08 -0700 Subject: [PATCH] reset attributed variable state between toplevel queries (#242) --- src/prolog/clause_types.rs | 3 +++ src/prolog/machine/attributed_variables.rs | 2 +- src/prolog/machine/system_calls.rs | 3 +++ src/prolog/toplevel.pl | 3 ++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/prolog/clause_types.rs b/src/prolog/clause_types.rs index bf17531c..82bd8cde 100644 --- a/src/prolog/clause_types.rs +++ b/src/prolog/clause_types.rs @@ -179,6 +179,7 @@ pub enum SystemClauseType { FetchGlobalVar, FetchGlobalVarWithOffset, GetChar, + ResetAttrVarState, TruncateIfNoLiftedHeapGrowthDiff, TruncateIfNoLiftedHeapGrowth, GetAttributedVariableList, @@ -289,6 +290,7 @@ impl SystemClauseType { clause_name!("$fetch_global_var_with_offset") } &SystemClauseType::GetChar => clause_name!("$get_char"), + &SystemClauseType::ResetAttrVarState => clause_name!("$reset_attr_var_state"), &SystemClauseType::TruncateIfNoLiftedHeapGrowth => { clause_name!("$truncate_if_no_lh_growth") } @@ -408,6 +410,7 @@ impl SystemClauseType { ("$fetch_global_var", 2) => Some(SystemClauseType::FetchGlobalVar), ("$fetch_global_var_with_offset", 3) => Some(SystemClauseType::FetchGlobalVarWithOffset), ("$get_char", 1) => Some(SystemClauseType::GetChar), + ("$reset_attr_var_state", 0) => Some(SystemClauseType::ResetAttrVarState), ("$truncate_if_no_lh_growth", 1) => { Some(SystemClauseType::TruncateIfNoLiftedHeapGrowth) } diff --git a/src/prolog/machine/attributed_variables.rs b/src/prolog/machine/attributed_variables.rs index 992ba98d..50a101b9 100644 --- a/src/prolog/machine/attributed_variables.rs +++ b/src/prolog/machine/attributed_variables.rs @@ -32,9 +32,9 @@ impl AttrVarInitializer { #[inline] pub(super) fn reset(&mut self) { + self.attribute_goals.clear(); self.attr_var_queue.clear(); self.bindings.clear(); - self.attribute_goals.clear(); } } diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index fd3e31a5..e168849b 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -1680,6 +1680,9 @@ impl MachineState { } }; }, + &SystemClauseType::ResetAttrVarState => { + self.attr_var_init.reset(); + } &SystemClauseType::RemoveCallPolicyCheck => { let restore_default = match call_policy.downcast_mut::().ok() { Some(call_policy) => { diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 63433554..51eb93fa 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -44,7 +44,8 @@ ), ( '$get_b_value'(B), call(Term), '$write_eqs_and_read_input'(B, VarList), ! ; write('false.'), nl - ). + ), + '$reset_attr_var_state'. '$needs_bracketing'(Value, Op) :- catch((functor(Value, F, _), -- 2.54.0