]> Repositorios git - scryer-prolog.git/commitdiff
count cycle lengths in skip_max_list_cycle (#1260)
authorMark Thom <[email protected]>
Tue, 1 Feb 2022 01:23:16 +0000 (18:23 -0700)
committerMark Thom <[email protected]>
Tue, 1 Feb 2022 01:23:16 +0000 (18:23 -0700)
src/machine/system_calls.rs

index a9f1b91fd55acd262f2aabd5c2f0e1cd5b2f488d..4f3ed6517a24286d71321b4e29c0d3d8566e4218 100644 (file)
@@ -462,12 +462,21 @@ impl MachineState {
             hare = step(&self.heap, self.heap[hare]);
         }
 
+        let mut count = 1;
+
         while hare != tortoise {
             hare = step(&self.heap, self.heap[hare]);
             tortoise = step(&self.heap, self.heap[tortoise]);
+
+            count += 1;
         }
 
-        unify!(self, self.registers[4], self.heap[hare]);
+        let target_n = self.store(self.deref(self.registers[1]));
+        self.unify_fixnum(Fixnum::build_with(count), target_n);
+
+        if !self.fail {
+            unify!(self, self.registers[4], self.heap[hare]);
+        }
     }
 
     fn finalize_skip_max_list(&mut self, n: i64, value: HeapCellValue) {