]> Repositorios git - scryer-prolog.git/commitdiff
change '$delete_all_attributes' to '$delete_all_attributes_from_var'
authorMark Thom <[email protected]>
Sat, 18 Feb 2023 21:12:07 +0000 (14:12 -0700)
committerMark Thom <[email protected]>
Mon, 20 Feb 2023 08:11:52 +0000 (01:11 -0700)
build/instructions_template.rs
src/machine/dispatch.rs
src/machine/project_attributes.pl
src/machine/system_calls.rs

index 6e21c1659d3c9a713ab7004cef33897a573cc9d0..0ea3fa59fc74c7ca76bdd8f91fb67a28df36bdef 100644 (file)
@@ -566,8 +566,8 @@ enum SystemClauseType {
     PutToAttributedVarList,
     #[strum_discriminants(strum(props(Arity = "3", Name = "$del_from_attr_list")))]
     DeleteFromAttributedVarList,
-    #[strum_discriminants(strum(props(Arity = "1", Name = "$delete_all_attributes")))]
-    DeleteAllAttributes,
+    #[strum_discriminants(strum(props(Arity = "1", Name = "$delete_all_attributes_from_var")))]
+    DeleteAllAttributesFromVar,
     REPL(REPLCodePtr),
 }
 
@@ -1629,7 +1629,7 @@ fn generate_instruction_preface() -> TokenStream {
                     &Instruction::CallGetFromAttributedVarList(_) |
                     &Instruction::CallPutToAttributedVarList(_) |
                     &Instruction::CallDeleteFromAttributedVarList(_) |
-                    &Instruction::CallDeleteAllAttributes(_) |
+                    &Instruction::CallDeleteAllAttributesFromVar(_) |
                     &Instruction::CallFetchGlobalVar(_) |
                     &Instruction::CallFirstStream(_) |
                     &Instruction::CallFlushOutput(_) |
@@ -1845,7 +1845,7 @@ fn generate_instruction_preface() -> TokenStream {
                     &Instruction::ExecuteGetFromAttributedVarList(_) |
                     &Instruction::ExecutePutToAttributedVarList(_) |
                     &Instruction::ExecuteDeleteFromAttributedVarList(_) |
-                    &Instruction::ExecuteDeleteAllAttributes(_) |
+                    &Instruction::ExecuteDeleteAllAttributesFromVar(_) |
                     &Instruction::ExecuteFetchGlobalVar(_) |
                     &Instruction::ExecuteFirstStream(_) |
                     &Instruction::ExecuteFlushOutput(_) |
index e15e804810d352e0fbdc7244a718e13a6f3fb51b..f0ed046966b55f799886ed37094e3ace5607f4d1 100644 (file)
@@ -5207,12 +5207,12 @@ impl Machine {
                     self.delete_from_attributed_variable_list();
                     step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
                 }
-                &Instruction::CallDeleteAllAttributes(_) => {
-                    self.delete_all_attributes();
+                &Instruction::CallDeleteAllAttributesFromVar(_) => {
+                    self.delete_all_attributes_from_var();
                     self.machine_st.p += 1;
                 }
-                &Instruction::ExecuteDeleteAllAttributes(_) => {
-                    self.delete_all_attributes();
+                &Instruction::ExecuteDeleteAllAttributesFromVar(_) => {
+                    self.delete_all_attributes_from_var();
                     self.machine_st.p = self.machine_st.cp;
                 }
             }
index 968859cda8fdf070166f8206ccec4420d1598e34..0c51096ea370c99ff1c2f52de9d8e83cbe1228a9 100644 (file)
@@ -1,8 +1,9 @@
 :- module('$project_atts', [copy_term/3]).
 
 :- use_module(library(dcgs)).
+:- use_module(library(error), [can_be/2]).
 :- use_module(library(lambda)).
-:- use_module(library(lists), [foldl/4]).
+:- use_module(library(lists), [foldl/4, maplist/2]).
 
 project_attributes(QueryVars, AttrVars) :-
     phrase(gather_attr_modules(AttrVars), Modules0),
@@ -97,12 +98,13 @@ gather_residual_goals([V|Vs]) -->
     foldl(V+\M^phrase(M:attribute_goals(V)), Modules),
     gather_residual_goals(Vs).
 
-delete_all_attributes(Term) :- '$delete_all_attributes'(Term).
+delete_all_attributes_from_var(V) :- '$delete_all_attributes_from_var'(V).
 
 copy_term(Term, Copy, Gs) :-
-        '$term_attributed_variables'(Term, Vs),
-        findall(Term-Gs,
-                ( phrase(gather_residual_goals(Vs), Gs),
-                  delete_all_attributes(Term)
-                ),
-                [Copy-Gs]).
+   can_be(list, Gs),
+   findall(Term-Rs, term_residual_goals(Term,Rs), [Copy-Gs]).
+
+term_residual_goals(Term,Rs) :-
+   '$term_attributed_variables'(Term, Vs),
+   phrase(gather_residual_goals(Vs), Rs),
+   maplist(delete_all_attributes_from_var, Vs).
index 402bcac73511b93e653e28df8d2cc7c0c3bee27a..e39f3d22e1951a71450ded0e357819b5e94c9655 100644 (file)
@@ -1037,23 +1037,13 @@ impl MachineState {
 
 impl Machine {
     #[inline(always)]
-    pub(crate) fn delete_all_attributes(&mut self) {
-        let h = self.machine_st.heap.len();
-
-        self.machine_st.heap.push(heap_loc_as_cell!(h));
-        self.machine_st.registers[2] = heap_loc_as_cell!(h);
-
-        self.term_attributed_variables();
-
-        let mut list_of_attr_vars = self.deref_register(2);
-
-        while let HeapCellValueTag::Lis = list_of_attr_vars.get_tag() {
-            let attr_var_loc = list_of_attr_vars.get_value();
+    pub(crate) fn delete_all_attributes_from_var(&mut self) {
+        let attr_var = self.deref_register(1);
 
+        if let HeapCellValueTag::AttrVar = attr_var.get_tag() {
+            let attr_var_loc = attr_var.get_value();
             self.machine_st.heap[attr_var_loc] = heap_loc_as_cell!(attr_var_loc);
             self.machine_st.trail(TrailRef::Ref(Ref::attr_var(attr_var_loc)));
-
-            list_of_attr_vars = self.machine_st.heap[attr_var_loc + 1];
         }
     }