]> Repositorios git - scryer-prolog.git/commitdiff
add '$unattributed_var' builtin (#1758)
authorMark Thom <[email protected]>
Sun, 19 Mar 2023 05:08:09 +0000 (23:08 -0600)
committerMark Thom <[email protected]>
Sun, 19 Mar 2023 05:08:38 +0000 (23:08 -0600)
build/instructions_template.rs
src/lib/lists.pl
src/machine/dispatch.rs
src/machine/system_calls.rs

index d2cee3bb79bb7a9ff0be98ef9c90a5ae9f65f217..93615dec32072495582f54363c2010c1ad123612 100644 (file)
@@ -574,6 +574,8 @@ enum SystemClauseType {
     DeleteFromAttributedVarList,
     #[strum_discriminants(strum(props(Arity = "1", Name = "$delete_all_attributes_from_var")))]
     DeleteAllAttributesFromVar,
+    #[strum_discriminants(strum(props(Arity = "1", Name = "$unattributed_var")))]
+    UnattributedVar,
     REPL(REPLCodePtr),
 }
 
@@ -1621,7 +1623,7 @@ fn generate_instruction_preface() -> TokenStream {
                     &Instruction::CallMakeDirectoryPath(_) |
                     &Instruction::CallDeleteFile(_) |
                     &Instruction::CallRenameFile(_) |
-                   &Instruction::CallFileCopy(_) |
+                           &Instruction::CallFileCopy(_) |
                     &Instruction::CallWorkingDirectory(_) |
                     &Instruction::CallDeleteDirectory(_) |
                     &Instruction::CallPathCanonical(_) |
@@ -1636,6 +1638,7 @@ fn generate_instruction_preface() -> TokenStream {
                     &Instruction::CallPutToAttributedVarList(_) |
                     &Instruction::CallDeleteFromAttributedVarList(_) |
                     &Instruction::CallDeleteAllAttributesFromVar(_) |
+                    &Instruction::CallUnattributedVar(_) |
                     &Instruction::CallFetchGlobalVar(_) |
                     &Instruction::CallFirstStream(_) |
                     &Instruction::CallFlushOutput(_) |
@@ -1855,6 +1858,7 @@ fn generate_instruction_preface() -> TokenStream {
                     &Instruction::ExecutePutToAttributedVarList(_) |
                     &Instruction::ExecuteDeleteFromAttributedVarList(_) |
                     &Instruction::ExecuteDeleteAllAttributesFromVar(_) |
+                    &Instruction::ExecuteUnattributedVar(_) |
                     &Instruction::ExecuteFetchGlobalVar(_) |
                     &Instruction::ExecuteFirstStream(_) |
                     &Instruction::ExecuteFlushOutput(_) |
index 792c2be245f5c543bc24c1c6e90f6dcf2423abe8..92bc202d12546e97b3e89c12caff615d38125d80 100644 (file)
@@ -92,7 +92,7 @@ length(_, N) :-
 
 length_rundown(Xs, 0) :- !, Xs = [].
 length_rundown(Vs, N) :-
-    \+ \+ '$project_atts':copy_term(Vs,Vs,[]), % unconstrained
+    '$unattributed_var'(Vs), % unconstrained
     !,
     '$det_length_rundown'(Vs, N).
 length_rundown([_|Xs], N) :- % force unification
@@ -100,7 +100,7 @@ length_rundown([_|Xs], N) :- % force unification
     length(Xs, N1). % maybe some new info on Xs
 
 failingvarskip(Xs) :-
-    \+ \+ '$project_atts':copy_term(Xs,Xs,[]), % unconstrained
+    '$unattributed_var'(Xs), % unconstrained
     !.
 failingvarskip([_|Xs0]) :- % force unification
     '$skip_max_list'(_, _, Xs0,Xs),
index e2e144c5b5a71657d5cbdf8b15885303284ab6ab..39ca74c6aaf0aebc7fd35d0047a1ca95b8f4d521 100644 (file)
@@ -5239,6 +5239,14 @@ impl Machine {
                     self.delete_all_attributes_from_var();
                     self.machine_st.p = self.machine_st.cp;
                 }
+                &Instruction::CallUnattributedVar(_) => {
+                    self.machine_st.unattributed_var();
+                    step_or_fail!(self, self.machine_st.p += 1);
+                }
+                &Instruction::ExecuteUnattributedVar(_) => {
+                    self.machine_st.unattributed_var();
+                    step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
+                }
             }
         }
 
index 3931127613163976fa81d2f62a9907b25674c226..a84b78c719e28d5359752ceff48580c145f2a429 100644 (file)
@@ -471,6 +471,25 @@ struct AttrListMatch {
 }
 
 impl MachineState {
+    #[inline(always)]
+    pub(crate) fn unattributed_var(&mut self) {
+        let attr_var = self.store(self.deref(self.registers[1]));
+
+        if !attr_var.is_var() {
+            self.fail = true;
+            return;
+        }
+
+        read_heap_cell!(attr_var,
+            (HeapCellValueTag::AttrVar, h) => {
+                let list_cell = self.store(self.deref(self.heap[h+1]));
+                self.fail = list_cell.get_tag() == HeapCellValueTag::Lis;
+            }
+            _ => {
+            }
+        );
+    }
+
     pub(crate) fn get_attr_var_list(&mut self, attr_var: HeapCellValue) -> Option<usize> {
         read_heap_cell!(attr_var,
             (HeapCellValueTag::AttrVar, h) => {