From: Mark Thom Date: Fri, 29 Nov 2019 07:59:31 +0000 (-0700) Subject: clone attribute goals from copy_term/3, fetch attribute goals should be a move X-Git-Tag: v0.8.118~36^2~19 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=34745f6242035c61de6f80604d25c367b5389910;p=scryer-prolog.git clone attribute goals from copy_term/3, fetch attribute goals should be a move --- diff --git a/src/prolog/clause_types.rs b/src/prolog/clause_types.rs index a8246405..e4bae2ae 100644 --- a/src/prolog/clause_types.rs +++ b/src/prolog/clause_types.rs @@ -165,6 +165,7 @@ pub enum SystemClauseType { CallAttributeGoals, CharCode, CharsToNumber, + CloneAttributeGoals, CodesToNumber, CopyTermWithoutAttrVars, CheckCutPoint, @@ -264,6 +265,7 @@ impl SystemClauseType { &SystemClauseType::CallAttributeGoals => clause_name!("$call_attribute_goals"), &SystemClauseType::CharCode => clause_name!("$char_code"), &SystemClauseType::CharsToNumber => clause_name!("$chars_to_number"), + &SystemClauseType::CloneAttributeGoals => clause_name!("$clone_attribute_goals"), &SystemClauseType::CodesToNumber => clause_name!("$codes_to_number"), &SystemClauseType::CopyTermWithoutAttrVars => clause_name!("$copy_term_without_attr_vars"), &SystemClauseType::CheckCutPoint => clause_name!("$check_cp"), @@ -393,6 +395,7 @@ impl SystemClauseType { ("$call_attribute_goals", 2) => Some(SystemClauseType::CallAttributeGoals), ("$char_code", 2) => Some(SystemClauseType::CharCode), ("$chars_to_number", 2) => Some(SystemClauseType::CharsToNumber), + ("$clone_attribute_goals", 1) => Some(SystemClauseType::CloneAttributeGoals), ("$codes_to_number", 2) => Some(SystemClauseType::CodesToNumber), ("$copy_term_without_attr_vars", 2) => Some(SystemClauseType::CopyTermWithoutAttrVars), ("$check_cp", 1) => Some(SystemClauseType::CheckCutPoint), diff --git a/src/prolog/machine/project_attributes.pl b/src/prolog/machine/project_attributes.pl index 60980406..76cccca2 100644 --- a/src/prolog/machine/project_attributes.pl +++ b/src/prolog/machine/project_attributes.pl @@ -88,5 +88,5 @@ copy_term(Source, Dest, Goals) :- term_variables(Source, Vars), gather_modules(Vars, Modules, _), call_attribute_goals(Modules, call_query_var_goals, Vars), - '$fetch_attribute_goals'(Goals0), + '$clone_attribute_goals'(Goals0), '$copy_term_without_attr_vars'([Source | Goals0], [Dest | Goals]). diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index f66ef274..22e9c1ea 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -527,6 +527,16 @@ impl MachineState { Ok(()) } + fn fetch_attribute_goals(&mut self, mut attr_goals: Vec) { + attr_goals.sort_unstable_by(|a1, a2| self.compare_term_test(a1, a2)); + self.term_dedup(&mut attr_goals); + + let attr_goals = Addr::HeapCell(self.heap.to_list(attr_goals.into_iter())); + let target = self[temp_v!(1)].clone(); + + self.unify(attr_goals, target); + } + fn create_instruction_functors(&mut self, code: &Code, first_idx: usize) -> Vec { let mut queue = VecDeque::new(); let mut functors = vec![]; @@ -1105,7 +1115,7 @@ impl MachineState { for i in (arity + 1 .. arity + narity + 1).rev() { self.registers[i] = self.registers[i - arity].clone(); } - + for i in 1 .. arity + 1 { self.registers[i] = self.heap[a + i].as_addr(a + i); } @@ -1118,7 +1128,7 @@ impl MachineState { ); } } - Addr::Con(Constant::Atom(name, _)) => { + Addr::Con(Constant::Atom(name, _)) => { return self.module_lookup(indices, (name, narity), module_name, true) } addr => { @@ -1366,16 +1376,13 @@ impl MachineState { &SystemClauseType::TruncateIfNoLiftedHeapGrowth => { self.truncate_if_no_lifted_heap_diff(|_| Addr::Con(Constant::EmptyList)) } + &SystemClauseType::CloneAttributeGoals => { + let attr_goals = self.attr_var_init.attribute_goals.clone(); + self.fetch_attribute_goals(attr_goals); + } &SystemClauseType::FetchAttributeGoals => { - let mut attr_goals = self.attr_var_init.attribute_goals.clone(); - - attr_goals.sort_unstable_by(|a1, a2| self.compare_term_test(a1, a2)); - self.term_dedup(&mut attr_goals); - - let attr_goals = Addr::HeapCell(self.heap.to_list(attr_goals.into_iter())); - let target = self[temp_v!(1)].clone(); - - self.unify(attr_goals, target); + let attr_goals = mem::replace(&mut self.attr_var_init.attribute_goals, vec![]); + self.fetch_attribute_goals(attr_goals); } &SystemClauseType::GetAttributedVariableList => { let attr_var = self.store(self.deref(self[temp_v!(1)].clone())); @@ -1424,7 +1431,7 @@ impl MachineState { let var_list_addr = Addr::HeapCell(self.heap.to_list(iter)); let list_addr = self[temp_v!(2)].clone(); - + self.unify(var_list_addr, list_addr); } else { self.fail = true; @@ -1909,7 +1916,7 @@ impl MachineState { ContinueResult::ContinueQuery => ';', ContinueResult::Conclude => '.' }; - + let target = self[temp_v!(1)].clone(); self.unify(Addr::Con(Constant::Char(c)), target); }