]> Repositorios git - scryer-prolog.git/commitdiff
report pre-marked values from eager stackful iterator (#2097)
authorMark <[email protected]>
Tue, 10 Oct 2023 17:13:42 +0000 (11:13 -0600)
committerMark <[email protected]>
Tue, 10 Oct 2023 18:56:27 +0000 (12:56 -0600)
src/heap_iter.rs
src/tests/term_variables.pl

index ef5e4ac5bab29c62022e6aa0c0a73d1b84db3eaf..02d87ace9a867987791f26ddf7d7ebe2649fc229 100644 (file)
@@ -59,6 +59,14 @@ impl<'a> EagerStackfulPreOrderHeapIter<'a> {
     fn follow(&mut self) -> Option<HeapCellValue> {
         while let Some(value) = self.iter_stack.pop() {
             if value.get_mark_bit() == self.mark_phase {
+                if value.is_var() {
+                    let h = value.get_value() as usize;
+
+                    if self.heap[h].is_var() && self.heap[h].get_value() as usize == h {
+                        return Some(unmark_cell_bits!(value));
+                    }
+                }
+
                 continue;
             }
 
index 57c55ed19aba85e4e13fea370199bd291f5d0d1c..01dde0d1a4e752443a647aa036e3d0e69f1ddb3d 100644 (file)
@@ -38,6 +38,17 @@ test("term_variables#2063", (
     Vars = [C]
 )).
 
+test("term_variables#2097", (
+    termt(T), term_variables(T,Vs),
+    T = [[[A|B]|A]|A], Vs == [A,B]
+)).
+
+termt(T) :-
+   T = [T1|T2],
+   T1 = [T3|A],
+   T3 = [A|_],
+   T2 = A.
+
 main :-
     findall(test(Name, Goal), test(Name, Goal), Tests),
     run_tests(Tests, Failed),