]> Repositorios git - scryer-prolog.git/commitdiff
update toplevel comments, add mutable stack to zipped acyclic iterators
authorMark Thom <[email protected]>
Sun, 19 Apr 2020 22:01:35 +0000 (16:01 -0600)
committerMark Thom <[email protected]>
Sun, 19 Apr 2020 22:01:35 +0000 (16:01 -0600)
src/prolog/heap_iter.rs
src/prolog/machine/machine_errors.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/toplevel.pl

index 8a3ce4926b6c6eb34f214c7648491b17534895f8..1815ee199a07ee8f486320043eebcf7919bf492a 100644 (file)
@@ -120,10 +120,11 @@ impl<'a> Iterator for HCPreOrderIterator<'a> {
     }
 }
 
-pub trait MutStackHCIterator
-where Self: Iterator<Item = Addr>
+pub trait MutStackHCIterator<'b> where Self: Iterator
 {
-    fn stack(&mut self) -> &mut Vec<Addr>;
+    type MutStack;
+
+    fn stack(&'b mut self) -> Self::MutStack;
 }
 
 pub struct HCPostOrderIterator<'a> {
@@ -220,8 +221,10 @@ impl MachineState {
     }
 }
 
-impl<'a> MutStackHCIterator for HCPreOrderIterator<'a> {
-    fn stack(&mut self) -> &mut Vec<Addr> {
+impl<'b, 'a: 'b> MutStackHCIterator<'b> for HCPreOrderIterator<'a> {
+    type MutStack = &'b mut Vec<Addr>;
+
+    fn stack(&'b mut self) -> Self::MutStack {
         &mut self.state_stack
     }
 }
@@ -273,6 +276,14 @@ pub struct HCZippedAcyclicIterator<'a> {
     pub first_to_expire: Ordering,
 }
 
+impl<'b, 'a: 'b> MutStackHCIterator<'b> for HCZippedAcyclicIterator<'a> {
+    type MutStack = (&'b mut Vec<Addr>, &'b mut Vec<Addr>);
+
+    fn stack(&'b mut self) -> Self::MutStack {
+        (self.i1.stack(), self.i2.stack())
+    }
+}
+
 impl<'a> HCZippedAcyclicIterator<'a> {
     pub fn new(i1: HCPreOrderIterator<'a>, i2: HCPreOrderIterator<'a>) -> Self {
         HCZippedAcyclicIterator {
@@ -293,6 +304,7 @@ impl<'a> Iterator for HCZippedAcyclicIterator<'a>
             if !self.seen.contains(&(a1.clone(), a2.clone())) {
                 self.i1.stack().push(a1.clone());
                 self.i2.stack().push(a2.clone());
+
                 self.seen.insert((a1, a2));
 
                 break;
index 68b7a3ff87731a64d61ebb3c478468898541b273..9948787cb8e205208fc45e1da2665a2770bede5d 100644 (file)
@@ -158,7 +158,7 @@ impl MachineError {
     pub(super)
     fn interrupt_error() -> Self {
         let stub = functor!("$interrupt_thrown");
-        
+
         MachineError {
             stub,
             location: None,
index dfcb08be401fcad05594b12178ef96b27d27c80c..188b3673d30a9acf85ae4ad38a741524bf247eb8 100644 (file)
@@ -1969,7 +1969,8 @@ impl MachineState {
         iter.first_to_expire != Ordering::Equal
     }
 
-    pub(super) fn compare_term_test(&self, a1: &Addr, a2: &Addr) -> Option<Ordering> {
+    pub(super)
+    fn compare_term_test(&self, a1: &Addr, a2: &Addr) -> Option<Ordering> {
         let mut iter = self.zipped_acyclic_pre_order_iter(*a1, *a2);
 
         while let Some((v1, v2)) = iter.next() {
index 099bc9f973fe1d17676670d3f2321e18b6e26c51..edd13ce0ae6fe48d065faba3d1abc15596f3fc35 100644 (file)
@@ -214,7 +214,10 @@ gather_goals([Var = Value | Pairs], VarList, Goals) :-
     ).
 
 print_exception(E) :-
-    (  E == error('$interrupt_thrown', repl) -> nl % print the exception on a newline to evade "^C".
+    (  E == error('$interrupt_thrown', repl) -> nl % print the
+                                                   % exception on a
+                                                   % newline to evade
+                                                   % "^C".
     ;  true
     ),
     write_term('caught: ', [quoted(false), max_depth(20)]),