]> Repositorios git - scryer-prolog.git/commitdiff
mark cyclic lists with ellipses at the head (#2635)
authorMark Thom <[email protected]>
Fri, 11 Apr 2025 05:39:35 +0000 (22:39 -0700)
committerMark Thom <[email protected]>
Fri, 11 Apr 2025 05:40:13 +0000 (22:40 -0700)
src/heap_print.rs

index 3c22f0aec8bcd25984465cbc9a057ca51419b7e1..f6f0c8f3bd142f2fe57da2f9d6837122c8521420 100644 (file)
@@ -874,12 +874,16 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
                                 None => {
                                     if self.max_depth == 0 || *max_depth == 0 {
                                         // otherwise, contract it to an ellipsis.
-                                        push_space_if_amb!(self, "...", {
-                                            append_str!(self, "...");
-                                        });
+                                        self.state_stack.push(TokenOrRedirect::Atom(atom!("...")));
                                     } else {
                                         debug_assert!(cell.is_ref());
 
+                                        let h = cell.get_value() as usize;
+                                        self.iter.push_stack(IterStackLoc::iterable_loc(
+                                            h,
+                                            HeapOrStackTag::Heap,
+                                        ));
+
                                         // as usual, the WAM's
                                         // optimization of the Lis tag
                                         // (conflating the location of
@@ -889,15 +893,17 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
                                         // lest we find ourselves in
                                         // an infinite loop.
                                         if cell.get_tag() == HeapCellValueTag::Lis {
-                                            *max_depth -= 1;
+                                            if self.iter.heap[cell.get_value() as usize]
+                                                .get_forwarding_bit()
+                                            {
+                                                self.state_stack
+                                                    .push(TokenOrRedirect::Atom(atom!("...")));
+                                                return None;
+                                            } else {
+                                                *max_depth -= 1;
+                                            }
                                         }
 
-                                        let h = cell.get_value() as usize;
-                                        self.iter.push_stack(IterStackLoc::iterable_loc(
-                                            h,
-                                            HeapOrStackTag::Heap,
-                                        ));
-
                                         if let Some(cell) = self.iter.next() {
                                             orig_cell = cell;
                                             continue;