]> Repositorios git - scryer-prolog.git/commitdiff
clone attribute goals from copy_term/3, fetch attribute goals should be a move
authorMark Thom <[email protected]>
Fri, 29 Nov 2019 07:59:31 +0000 (00:59 -0700)
committerMark Thom <[email protected]>
Fri, 29 Nov 2019 07:59:31 +0000 (00:59 -0700)
src/prolog/clause_types.rs
src/prolog/machine/project_attributes.pl
src/prolog/machine/system_calls.rs

index a82464056020ab7e0531f09a26ce729b399cf150..e4bae2ae0b64fed40400ff7369b0519f0f50f32d 100644 (file)
@@ -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),
index 60980406b22be1f1d3d816931d0126ec3c2248a6..76cccca2583f5baf5497e4e1174a06d426ea9745 100644 (file)
@@ -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]).
index f66ef2749705d3547f4d86511d77d92749b56ca9..22e9c1ea77066b9d21a5faccd6b7e25fc04bcfc0 100644 (file)
@@ -527,6 +527,16 @@ impl MachineState {
         Ok(())
     }
 
+    fn fetch_attribute_goals(&mut self, mut attr_goals: Vec<Addr>) {
+        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<Addr> {
         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);
             }