]> Repositorios git - scryer-prolog.git/commitdiff
simply post order iterators.
authorMark Thom <[email protected]>
Sun, 12 Nov 2017 08:36:19 +0000 (01:36 -0700)
committerMark Thom <[email protected]>
Sun, 12 Nov 2017 08:36:19 +0000 (01:36 -0700)
src/prolog/arithmetic.rs
src/prolog/iterators.rs

index 8a93ed3fcf34505d6377209d844969a04ba88d25..52a2a89a87d90c7c2160cb0f3e54ee3359741774 100644 (file)
@@ -3,7 +3,6 @@ use prolog::fixtures::*;
 use prolog::num::{BigInt, Zero};
 use prolog::ordered_float::{OrderedFloat};
 
-use std::cell::Cell;
 use std::cmp::{min, max};
 use std::vec::Vec;
 
@@ -12,20 +11,10 @@ pub struct ArithExprIterator<'a> {
 }
 
 impl<'a> ArithExprIterator<'a> {
-    fn push_clause(&mut self, child_num: usize, ct: ClauseType<'a>, child_terms: &'a Vec<Box<Term>>)
-    {
-        self.state_stack.push(IteratorState::Clause(child_num, ct, child_terms));
-    }
-
     fn push_subterm(&mut self, lvl: Level, term: &'a Term) {
         self.state_stack.push(IteratorState::to_state(lvl, term));
     }
 
-    fn push_final_cons(&mut self, lvl: Level, cell: &'a Cell<RegType>, head: &'a Term, tail: &'a Term)
-    {
-        self.state_stack.push(IteratorState::FinalCons(lvl, cell, head, tail));
-    }
-
     fn new(term: &'a Term) -> Result<Self, ArithmeticError> {
         let state = match term {
             &Term::AnonVar =>
@@ -62,12 +51,12 @@ impl<'a> Iterator for ArithExprIterator<'a> {
                     if child_num == child_terms.len() {
                         return Some(TermRef::Clause(ct, child_terms));
                     } else {
-                        self.push_clause(child_num + 1, ct, child_terms);
+                        self.state_stack.push(IteratorState::Clause(child_num + 1, ct, child_terms));
                         self.push_subterm(ct.level_of_subterms(), child_terms[child_num].as_ref());
                     }
                 },
                 IteratorState::InitialCons(lvl, cell, head, tail) => {
-                    self.push_final_cons(lvl, cell, head, tail);
+                    self.state_stack.push(IteratorState::FinalCons(lvl, cell, head, tail));
                     self.push_subterm(Level::Deep, tail);
                     self.push_subterm(Level::Deep, head);
                 },
index e61a6d5fd4a6849f42020f6ecdf041831265a825..a2a96976e5e038a8884426375be99c58cf9f6cea 100644 (file)
@@ -1,6 +1,5 @@
 use prolog::ast::*;
 
-use std::cell::Cell;
 use std::collections::VecDeque;
 use std::iter::*;
 use std::vec::Vec;
@@ -10,20 +9,10 @@ pub struct QueryIterator<'a> {
 }
 
 impl<'a> QueryIterator<'a> {
-    fn push_clause(&mut self, child_num: usize, ct: ClauseType<'a>, child_terms: &'a Vec<Box<Term>>)
-    {
-        self.state_stack.push(IteratorState::Clause(child_num, ct, child_terms));
-    }
-
     fn push_subterm(&mut self, lvl: Level, term: &'a Term) {
         self.state_stack.push(IteratorState::to_state(lvl, term));
     }
 
-    fn push_final_cons(&mut self, lvl: Level, cell: &'a Cell<RegType>, head: &'a Term, tail: &'a Term)
-    {
-        self.state_stack.push(IteratorState::FinalCons(lvl, cell, head, tail));
-    }
-
     fn from_term(term: &'a Term) -> Self {
         let state = match term {
             &Term::AnonVar =>
@@ -76,7 +65,7 @@ impl QueryTerm {
 
 impl<'a> Iterator for QueryIterator<'a> {
     type Item = TermRef<'a>;
-
+    
     fn next(&mut self) -> Option<Self::Item> {
         while let Some(iter_state) = self.state_stack.pop() {
             match iter_state {
@@ -93,12 +82,12 @@ impl<'a> Iterator for QueryIterator<'a> {
                                 return None
                         };
                     } else {
-                        self.push_clause(child_num + 1, ct, child_terms);
+                        self.state_stack.push(IteratorState::Clause(child_num + 1, ct, child_terms));
                         self.push_subterm(ct.level_of_subterms(), child_terms[child_num].as_ref());
                     }
                 },
                 IteratorState::InitialCons(lvl, cell, head, tail) => {
-                    self.push_final_cons(lvl, cell, head, tail);
+                    self.state_stack.push(IteratorState::FinalCons(lvl, cell, head, tail));
                     self.push_subterm(Level::Deep, tail);
                     self.push_subterm(Level::Deep, head);
                 },
@@ -111,7 +100,7 @@ impl<'a> Iterator for QueryIterator<'a> {
             };
         }
 
-        None
+        None        
     }
 }