From: Mark Thom Date: Fri, 6 Dec 2019 19:22:28 +0000 (-0400) Subject: resolve panic caused by lingering attribute goals (#253) X-Git-Tag: v0.8.118~36^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=5ccd334555dc2074c2f0566623f4f31eabbfc2ea;p=scryer-prolog.git resolve panic caused by lingering attribute goals (#253) --- diff --git a/src/prolog/clause_types.rs b/src/prolog/clause_types.rs index 37f9ada9..006ea3d4 100644 --- a/src/prolog/clause_types.rs +++ b/src/prolog/clause_types.rs @@ -166,6 +166,7 @@ pub enum SystemClauseType { CharCode, CharsToNumber, ClearAttrVarBindings, + ClearAttributeGoals, CloneAttributeGoals, CodesToNumber, CopyTermWithoutAttrVars, @@ -266,6 +267,7 @@ impl SystemClauseType { &SystemClauseType::CallAttributeGoals => clause_name!("$call_attribute_goals"), &SystemClauseType::CharCode => clause_name!("$char_code"), &SystemClauseType::CharsToNumber => clause_name!("$chars_to_number"), + &SystemClauseType::ClearAttributeGoals => clause_name!("$clear_attribute_goals"), &SystemClauseType::CloneAttributeGoals => clause_name!("$clone_attribute_goals"), &SystemClauseType::CodesToNumber => clause_name!("$codes_to_number"), &SystemClauseType::CopyTermWithoutAttrVars => clause_name!("$copy_term_without_attr_vars"), @@ -398,6 +400,7 @@ impl SystemClauseType { ("$char_code", 2) => Some(SystemClauseType::CharCode), ("$chars_to_number", 2) => Some(SystemClauseType::CharsToNumber), ("$clear_attr_var_bindings", 0) => Some(SystemClauseType::ClearAttrVarBindings), + ("$clear_attribute_goals", 0) => Some(SystemClauseType::ClearAttributeGoals), ("$clone_attribute_goals", 1) => Some(SystemClauseType::CloneAttributeGoals), ("$codes_to_number", 2) => Some(SystemClauseType::CodesToNumber), ("$copy_term_without_attr_vars", 2) => Some(SystemClauseType::CopyTermWithoutAttrVars), diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 11eb193e..2fb652d4 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -1376,6 +1376,9 @@ impl MachineState { &SystemClauseType::TruncateIfNoLiftedHeapGrowth => { self.truncate_if_no_lifted_heap_diff(|_| Addr::Con(Constant::EmptyList)) } + &SystemClauseType::ClearAttributeGoals => { + self.attr_var_init.attribute_goals.clear(); + } &SystemClauseType::CloneAttributeGoals => { let attr_goals = self.attr_var_init.attribute_goals.clone(); self.fetch_attribute_goals(attr_goals); diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 74df6a6f..cf561645 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -44,7 +44,9 @@ ), ( '$get_b_value'(B), call(Term), '$write_eqs_and_read_input'(B, VarList), ! - ; write('false.'), nl + % clear attribute goal lists, which may be populated by + % copy_term/3 prior to failure. + ; '$clear_attribute_goals', write('false.'), nl ). '$needs_bracketing'(Value, Op) :- @@ -144,7 +146,7 @@ ). '$gather_query_vars'([], []). -'$is_a_different_variable'([Var = Binding | Pairs], Value) :- +'$is_a_different_variable'([_ = Binding | Pairs], Value) :- ( Value == Binding, ! ; '$is_a_different_variable'(Pairs, Value) ).