]> Repositorios git - scryer-prolog.git/commitdiff
another big refactor
authorMark Thom <[email protected]>
Fri, 12 Jan 2018 03:56:04 +0000 (20:56 -0700)
committerMark Thom <[email protected]>
Fri, 12 Jan 2018 03:56:04 +0000 (20:56 -0700)
Cargo.lock
src/prolog/arithmetic.rs
src/prolog/ast.rs
src/prolog/copier.rs
src/prolog/heapview.rs
src/prolog/iterators.rs
src/prolog/machine.rs
src/prolog/macros.rs

index a8c0944230a71b4795d9b04409fa6bb44c98ed5b..966a4013a8773999e7a9d9292340f899087cc992 100644 (file)
@@ -1,14 +1,3 @@
-[root]
-name = "rusty-wam"
-version = "0.7.4"
-dependencies = [
- "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
- "ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "regex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
 [[package]]
 name = "aho-corasick"
 version = "0.6.4"
@@ -180,6 +169,17 @@ name = "rustc-serialize"
 version = "0.3.24"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "rusty-wam"
+version = "0.7.4"
+dependencies = [
+ "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "termion"
 version = "1.5.1"
index 5ccb7972d92e91458f4bba23541191c197602151..4d16c4f7623e0bb2d8c399694d2b16dc7a64637f 100644 (file)
@@ -5,14 +5,14 @@ use std::cmp::{min, max};
 use std::vec::Vec;
 
 pub struct ArithExprIterator<'a> {
-    state_stack: Vec<IteratorState<'a>>
+    state_stack: Vec<TermIterState<'a>>
 }
 
 pub type ArithCont = (Code, Option<ArithmeticTerm>);
 
 impl<'a> ArithExprIterator<'a> {
     fn push_subterm(&mut self, lvl: Level, term: &'a Term) {
-        self.state_stack.push(IteratorState::to_state(lvl, term));
+        self.state_stack.push(TermIterState::to_state(lvl, term));
     }
 
     fn new(term: &'a Term) -> Result<Self, ArithmeticError> {
@@ -20,13 +20,13 @@ impl<'a> ArithExprIterator<'a> {
             &Term::AnonVar =>
                 return Err(ArithmeticError::InvalidTerm),
             &Term::Clause(_, _, ref terms) =>
-                IteratorState::Clause(0, ClauseType::Root, terms),
+                TermIterState::Clause(0, ClauseType::Root, terms),
             &Term::Constant(ref cell, ref cons) =>
-                IteratorState::Constant(Level::Shallow, cell, cons),
+                TermIterState::Constant(Level::Shallow, cell, cons),
             &Term::Cons(_, _, _) =>
                 return Err(ArithmeticError::InvalidTerm),
             &Term::Var(ref cell, ref var) =>
-                IteratorState::Var(Level::Shallow, cell, var)
+                TermIterState::Var(Level::Shallow, cell, var)
         };
 
         Ok(ArithExprIterator { state_stack: vec![state] })
@@ -45,26 +45,26 @@ impl<'a> Iterator for ArithExprIterator<'a> {
     fn next(&mut self) -> Option<Self::Item> {
         while let Some(iter_state) = self.state_stack.pop() {
             match iter_state {
-                IteratorState::AnonVar(lvl) =>
+                TermIterState::AnonVar(lvl) =>
                     return Some(TermRef::AnonVar(lvl)),
-                IteratorState::Clause(child_num, ct, child_terms) => {
+                TermIterState::Clause(child_num, ct, child_terms) => {
                     if child_num == child_terms.len() {
                         return Some(TermRef::Clause(ct, child_terms));
                     } else {
-                        self.state_stack.push(IteratorState::Clause(child_num + 1, ct, child_terms));
+                        self.state_stack.push(TermIterState::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.state_stack.push(IteratorState::FinalCons(lvl, cell, head, tail));
+                TermIterState::InitialCons(lvl, cell, head, tail) => {
+                    self.state_stack.push(TermIterState::FinalCons(lvl, cell, head, tail));
                     self.push_subterm(Level::Deep, tail);
                     self.push_subterm(Level::Deep, head);
                 },
-                IteratorState::FinalCons(lvl, cell, head, tail) =>
+                TermIterState::FinalCons(lvl, cell, head, tail) =>
                     return Some(TermRef::Cons(lvl, cell, head, tail)),
-                IteratorState::Constant(lvl, cell, constant) =>
+                TermIterState::Constant(lvl, cell, constant) =>
                     return Some(TermRef::Constant(lvl, cell, constant)),
-                IteratorState::Var(lvl, cell, var) =>
+                TermIterState::Var(lvl, cell, var) =>
                     return Some(TermRef::Var(lvl, cell, var))
             };
         }
index 7cc9ed0edb7a190ae3d41e6837b459354bac685e..a53f40e24ce07121366ba0d2b5c4ed5fc7e5c141 100644 (file)
@@ -862,8 +862,18 @@ impl Addr {
             _ => false
         }
     }
-    
+   
     pub fn as_ref(&self) -> Option<Ref> {
+        match self {
+            &Addr::HeapCell(hc) => Some(Ref::HeapCell(hc)),
+            &Addr::StackCell(fr, sc) => Some(Ref::StackCell(fr, sc)),
+            &Addr::Lis(hc) => Some(Ref::HeapCell(hc)),
+            &Addr::Str(hc) => Some(Ref::HeapCell(hc)),
+            _ => None
+        }
+    }
+    
+    pub fn as_var(&self) -> Option<Ref> {
         match self {
             &Addr::HeapCell(hc) => Some(Ref::HeapCell(hc)),
             &Addr::StackCell(fr, sc) => Some(Ref::StackCell(fr, sc)),
@@ -896,37 +906,14 @@ pub enum Ref {
 
 #[derive(Clone, PartialEq)]
 pub enum HeapCellValue {
-    Con(Constant),
-    Lis(usize),
-    NamedStr(usize, Rc<Atom>),
-    Ref(Ref),
-    Str(usize)
-}
-
-impl From<Addr> for HeapCellValue {
-    fn from(addr: Addr) -> HeapCellValue {
-        match addr {
-            Addr::Con(constant) =>
-                HeapCellValue::Con(constant),
-            Addr::HeapCell(hc) =>
-                HeapCellValue::Ref(Ref::HeapCell(hc)),
-            Addr::Lis(a) =>
-                HeapCellValue::Lis(a),
-            Addr::StackCell(fr, sc) =>
-                HeapCellValue::Ref(Ref::StackCell(fr, sc)),
-            Addr::Str(hc) =>
-                HeapCellValue::Str(hc)
-        }
-    }
+    Addr(Addr),
+    NamedStr(usize, Rc<Atom>), // arity, name.
 }
 
 impl HeapCellValue {
     pub fn as_addr(&self, focus: usize) -> Addr {
         match self {
-            &HeapCellValue::Con(ref c) => Addr::Con(c.clone()),
-            &HeapCellValue::Lis(a) => Addr::Lis(a),
-            &HeapCellValue::Ref(r) => Addr::from(r),
-            &HeapCellValue::Str(s) => Addr::Str(s),
+            &HeapCellValue::Addr(ref a)    => a.clone(),
             &HeapCellValue::NamedStr(_, _) => Addr::Str(focus)
         }
     }
@@ -1064,7 +1051,7 @@ impl Term {
     }
 }
 
-pub enum IteratorState<'a> {
+pub enum TermIterState<'a> {
     AnonVar(Level),
     Clause(usize, ClauseType<'a>, &'a Vec<Box<Term>>),
     Constant(Level, &'a Cell<RegType>, &'a Constant),
@@ -1073,19 +1060,19 @@ pub enum IteratorState<'a> {
     Var(Level, &'a Cell<VarReg>, &'a Var)
 }
 
-impl<'a> IteratorState<'a> {
-    pub fn to_state(lvl: Level, term: &'a Term) -> IteratorState<'a> {
+impl<'a> TermIterState<'a> {
+    pub fn to_state(lvl: Level, term: &'a Term) -> TermIterState<'a> {
         match term {
             &Term::AnonVar =>
-                IteratorState::AnonVar(lvl),
+                TermIterState::AnonVar(lvl),
             &Term::Clause(ref cell, ref atom, ref child_terms) =>
-                IteratorState::Clause(0, ClauseType::Deep(lvl, cell, atom), child_terms),
+                TermIterState::Clause(0, ClauseType::Deep(lvl, cell, atom), child_terms),
             &Term::Cons(ref cell, ref head, ref tail) =>
-                IteratorState::InitialCons(lvl, cell, head.as_ref(), tail.as_ref()),
+                TermIterState::InitialCons(lvl, cell, head.as_ref(), tail.as_ref()),
             &Term::Constant(ref cell, ref constant) =>
-                IteratorState::Constant(lvl, cell, constant),
+                TermIterState::Constant(lvl, cell, constant),
             &Term::Var(ref cell, ref var) =>
-                IteratorState::Var(lvl, cell, var)
+                TermIterState::Var(lvl, cell, var)
         }
     }
 }
index f108d15c9c38bf937aae46aa9cd0dc07668b64d5..cdf7e19204f82f9d96c7482ac320de3eaa74adb8 100644 (file)
@@ -17,81 +17,87 @@ pub trait CopierTarget
     // after it's been copied to L2.
     fn duplicate_term(&mut self, a: Addr) where Self: IndexMut<usize, Output=HeapCellValue>
     {
-        let mut forward_trail: Vec<(Ref, HeapCellValue)>= Vec::new();
+        let mut trail: Vec<(Ref, HeapCellValue)>= Vec::new();
         let mut scan = self.source();
         let old_h = self.threshold();
 
-        self.push(HeapCellValue::from(a));
+        self.push(HeapCellValue::Addr(a));
 
         while scan < self.threshold() {
             match self[scan].clone() {
-                HeapCellValue::Con(_) | HeapCellValue::NamedStr(_, _) =>
+                HeapCellValue::NamedStr(_, _) =>
                     scan += 1,
-                HeapCellValue::Lis(a) => {
-                    self[scan] = HeapCellValue::Lis(self.threshold());
+                HeapCellValue::Addr(a) =>
+                    match a.clone() {
+                        Addr::Lis(a) => {
+                            self[scan] = HeapCellValue::Addr(Addr::Lis(self.threshold()));
 
-                    let hcv = self[a].clone();
-                    self.push(hcv);
+                            let hcv = self[a].clone();
+                            self.push(hcv);
 
-                    let hcv = self[a+1].clone();
-                    self.push(hcv);
+                            let hcv = self[a+1].clone();
+                            self.push(hcv);
 
-                    scan += 1;
-                },
-                HeapCellValue::Ref(r) => {
-                    let ra = Addr::from(r);
-                    let rd = self.store(self.deref(ra.clone()));
-
-                    match rd {
-                        Addr::HeapCell(hc) if hc >= old_h => {
-                            self[scan] = HeapCellValue::Ref(Ref::HeapCell(hc));
                             scan += 1;
                         },
-                        _ if ra == rd => {
-                            self[scan] = HeapCellValue::Ref(Ref::HeapCell(scan));
-
-                            match r {
-                                Ref::HeapCell(hc) =>
-                                    self[hc] = HeapCellValue::Ref(Ref::HeapCell(scan)),
-                                Ref::StackCell(fr, sc) =>
-                                    self.stack()[fr][sc] = Addr::HeapCell(scan)
+                        Addr::HeapCell(_) | Addr::StackCell(_, _) => {
+                            let ra = a;
+                            let rd = self.store(self.deref(ra.clone()));
+
+                            match rd.clone() {
+                                Addr::HeapCell(hc) if hc >= old_h => {
+                                    self[scan] = HeapCellValue::Addr(rd);
+                                    scan += 1;
+                                },
+                                _ if ra == rd => {
+                                    self[scan] = HeapCellValue::Addr(Addr::HeapCell(scan));
+
+                                    if let Addr::HeapCell(hc) = ra.clone() {
+                                        self[hc] = HeapCellValue::Addr(Addr::HeapCell(scan));
+                                        trail.push((Ref::HeapCell(hc),
+                                                    HeapCellValue::Addr(Addr::HeapCell(hc))));
+                                    } else if let Addr::StackCell(fr, sc) = ra {
+                                        self.stack()[fr][sc] = Addr::HeapCell(scan);
+                                        trail.push((Ref::StackCell(fr, sc),
+                                                    HeapCellValue::Addr(Addr::StackCell(fr, sc))));
+                                    }
+
+                                    scan += 1;
+                                },
+                                _ => self[scan] = HeapCellValue::Addr(rd)
                             };
+                        },
+                        Addr::Str(s) => {
+                            match self[s].clone() {
+                                HeapCellValue::NamedStr(arity, name) => {
+                                    let threshold = self.threshold();
+
+                                    self[scan] = HeapCellValue::Addr(Addr::Str(threshold));
+                                    self[s] = HeapCellValue::Addr(Addr::Str(threshold));
+
+                                    trail.push((Ref::HeapCell(s),
+                                                        HeapCellValue::NamedStr(arity, name.clone())));
+
+                                    self.push(HeapCellValue::NamedStr(arity, name));
+
+                                    for i in 0 .. arity {
+                                        let hcv = self[s + 1 + i].clone();
+                                        self.push(hcv);
+                                    }
+                                },
+                                HeapCellValue::Addr(Addr::Str(o)) =>
+                                    self[scan] = HeapCellValue::Addr(Addr::Str(o)),
+                                _ => {}
+                            }
 
-                            forward_trail.push((r, HeapCellValue::Ref(r)));
                             scan += 1;
                         },
-                        _ => self[scan] = HeapCellValue::from(rd)
+                        Addr::Con(_) => scan += 1
                     }
-                },
-                HeapCellValue::Str(s) => {
-                    match self[s].clone() {
-                        HeapCellValue::NamedStr(arity, name) => {
-                            let threshold = self.threshold();
-
-                            self[scan] = HeapCellValue::Str(threshold);
-                            self[s] = HeapCellValue::Str(threshold);
-
-                            forward_trail.push((Ref::HeapCell(s),
-                                                HeapCellValue::NamedStr(arity, name.clone())));
-
-                            self.push(HeapCellValue::NamedStr(arity, name));
-
-                            for i in 0 .. arity {
-                                let hcv = self[s + 1 + i].clone();
-                                self.push(hcv);
-                            }
-                        },
-                        HeapCellValue::Str(o) =>
-                            self[scan] = HeapCellValue::Str(o),
-                        _ => {}
-                    };
-
-                    scan += 1;
-                }
-            };
+            }
         }
 
-        for (r, hcv) in forward_trail {
+        for (r, hcv) in trail {
             match r {
                 Ref::HeapCell(hc) => self[hc] = hcv,
                 Ref::StackCell(fr, sc) => self.stack()[fr][sc] = hcv.as_addr(0)
index 52ed0747231046db24d8ae53c11d10a139df2fe5..f46fe65c28a08d480e1e1c615d144d828e03bab7 100644 (file)
@@ -128,10 +128,6 @@ impl<'a> HeapCellViewer<'a>
     fn from_heap(&mut self, mut focus: usize) -> CellView<'a> {
         loop {
             match &self.heap[focus] {
-                &HeapCellValue::Con(ref c) =>
-                    return CellView::Con(c),
-                &HeapCellValue::Lis(a) =>
-                    return self.handle_list(a),                
                 &HeapCellValue::NamedStr(arity, ref name) => {
                     self.state_stack.push(CellRef::TToken(TToken::RRBracket));
 
@@ -145,21 +141,29 @@ impl<'a> HeapCellViewer<'a>
 
                     return CellView::Str(arity, name);
                 },
-                &HeapCellValue::Ref(Ref::HeapCell(hc)) =>
-                    if focus == hc {
-                        return CellView::HeapVar(hc);
-                    } else {
-                        focus = hc;
-                    },                
-                &HeapCellValue::Ref(Ref::StackCell(fr, sc)) =>
-                    match self.deref_cell(&self.and_stack[fr][sc]) {
-                        CellRef::Lis(hc)         => return self.handle_list(hc),
-                        CellRef::View(cell_view) => return cell_view,
-                        CellRef::Redirect(hc)    => focus = hc,
-                        CellRef::TToken(token)   => return CellView::TToken(token)
-                    },                
-                &HeapCellValue::Str(cell_num) =>
-                    focus = cell_num,
+                &HeapCellValue::Addr(ref a) =>
+                    match a {
+                        &Addr::Con(ref c) =>
+                            return CellView::Con(c),
+                        &Addr::Lis(a) =>
+                            return self.handle_list(a),                                
+                        &Addr::HeapCell(hc) =>
+                            if focus == hc {
+                                return CellView::HeapVar(hc);
+                            } else {
+                                focus = hc;
+                            },                
+                        &Addr::StackCell(fr, sc) =>
+                            match self.deref_cell(&self.and_stack[fr][sc]) {
+                                CellRef::Lis(hc)         => return self.handle_list(hc),
+                                CellRef::View(cell_view) => return cell_view,
+                                CellRef::Redirect(hc)    => focus = hc,
+                                CellRef::TToken(token)   => return CellView::TToken(token)
+                            },                
+                        &Addr::Str(cell_num) =>
+                            focus = cell_num,
+                    },
+                
             }
         }
     }
index e5cf2d3511bec544def43bb127089071d545d87e..26a7c0fafed934d96405c23d0fdd18c79036bcce 100644 (file)
@@ -5,12 +5,12 @@ use std::iter::*;
 use std::vec::Vec;
 
 pub struct QueryIterator<'a> {
-    state_stack: Vec<IteratorState<'a>>
+    state_stack: Vec<TermIterState<'a>>
 }
 
 impl<'a> QueryIterator<'a> {
     fn push_subterm(&mut self, lvl: Level, term: &'a Term) {
-        self.state_stack.push(IteratorState::to_state(lvl, term));
+        self.state_stack.push(TermIterState::to_state(lvl, term));
     }
 
     fn from_term(term: &'a Term) -> Self {
@@ -18,13 +18,13 @@ impl<'a> QueryIterator<'a> {
             &Term::AnonVar =>
                 return QueryIterator { state_stack: vec![] },
             &Term::Clause(_, _, ref terms) =>
-                IteratorState::Clause(0, ClauseType::Root, terms),
+                TermIterState::Clause(0, ClauseType::Root, terms),
             &Term::Cons(_, _, _) =>
                 return QueryIterator { state_stack: vec![] },
             &Term::Constant(_, _) =>
                 return QueryIterator { state_stack: vec![] },
             &Term::Var(ref cell, ref var) =>
-                IteratorState::Var(Level::Shallow, cell, var)
+                TermIterState::Var(Level::Shallow, cell, var)
         };
 
         QueryIterator { state_stack: vec![state] }
@@ -33,21 +33,21 @@ impl<'a> QueryIterator<'a> {
     fn new(term: &'a QueryTerm) -> Self {
         match term {
             &QueryTerm::CallN(ref terms) => {
-                let state = IteratorState::Clause(1, ClauseType::CallN, terms);
+                let state = TermIterState::Clause(1, ClauseType::CallN, terms);
                 QueryIterator { state_stack: vec![state] }
             },
             &QueryTerm::Catch(ref terms) => {
-                let state = IteratorState::Clause(0, ClauseType::Catch, terms);
+                let state = TermIterState::Clause(0, ClauseType::Catch, terms);
                 QueryIterator { state_stack: vec![state] }
             },
             &QueryTerm::Arg(ref terms)
           | &QueryTerm::Functor(ref terms) => {
-                let state = IteratorState::Clause(0, ClauseType::Root, terms);
+                let state = TermIterState::Clause(0, ClauseType::Root, terms);
                 QueryIterator { state_stack: vec![state] }
             },
             &QueryTerm::Inlined(InlinedQueryTerm::CompareNumber(_, ref terms))
           | &QueryTerm::Is(ref terms) => {
-                    let state = IteratorState::Clause(0, ClauseType::Is, terms);
+                    let state = TermIterState::Clause(0, ClauseType::Is, terms);
                     QueryIterator { state_stack: vec![state] }
                 },
             &QueryTerm::Inlined(InlinedQueryTerm::IsAtomic(ref terms))
@@ -57,7 +57,7 @@ impl<'a> QueryIterator<'a> {
             &QueryTerm::Term(ref term) =>
                 Self::from_term(term),
             &QueryTerm::Throw(ref term) => {
-                let state = IteratorState::Clause(0, ClauseType::Throw, term);
+                let state = TermIterState::Clause(0, ClauseType::Throw, term);
                 QueryIterator { state_stack: vec![state] }
             },
             &QueryTerm::Cut => QueryIterator { state_stack: vec![] }
@@ -77,9 +77,9 @@ impl<'a> Iterator for QueryIterator<'a> {
     fn next(&mut self) -> Option<Self::Item> {
         while let Some(iter_state) = self.state_stack.pop() {
             match iter_state {
-                IteratorState::AnonVar(lvl) =>
+                TermIterState::AnonVar(lvl) =>
                     return Some(TermRef::AnonVar(lvl)),
-                IteratorState::Clause(child_num, ct, child_terms) => {
+                TermIterState::Clause(child_num, ct, child_terms) => {
                     if child_num == child_terms.len() {
                         match ct {
                             ClauseType::CallN =>
@@ -90,20 +90,20 @@ impl<'a> Iterator for QueryIterator<'a> {
                                 return None
                         };
                     } else {
-                        self.state_stack.push(IteratorState::Clause(child_num + 1, ct, child_terms));
+                        self.state_stack.push(TermIterState::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.state_stack.push(IteratorState::FinalCons(lvl, cell, head, tail));
+                TermIterState::InitialCons(lvl, cell, head, tail) => {
+                    self.state_stack.push(TermIterState::FinalCons(lvl, cell, head, tail));
                     self.push_subterm(Level::Deep, tail);
                     self.push_subterm(Level::Deep, head);
                 },
-                IteratorState::FinalCons(lvl, cell, head, tail) =>
+                TermIterState::FinalCons(lvl, cell, head, tail) =>
                     return Some(TermRef::Cons(lvl, cell, head, tail)),
-                IteratorState::Constant(lvl, cell, constant) =>
+                TermIterState::Constant(lvl, cell, constant) =>
                     return Some(TermRef::Constant(lvl, cell, constant)),
-                IteratorState::Var(lvl, cell, var) =>
+                TermIterState::Var(lvl, cell, var) =>
                     return Some(TermRef::Var(lvl, cell, var))
             };
         }
@@ -113,29 +113,29 @@ impl<'a> Iterator for QueryIterator<'a> {
 }
 
 pub struct FactIterator<'a> {
-    state_queue: VecDeque<IteratorState<'a>>,
+    state_queue: VecDeque<TermIterState<'a>>,
 }
 
 impl<'a> FactIterator<'a> {
     fn push_subterm(&mut self, lvl: Level, term: &'a Term) {
-        self.state_queue.push_back(IteratorState::to_state(lvl, term));
+        self.state_queue.push_back(TermIterState::to_state(lvl, term));
     }
 
     fn new(term: &'a Term) -> FactIterator<'a> {
         let states = match term {
             &Term::AnonVar =>
-                vec![IteratorState::AnonVar(Level::Shallow)],
+                vec![TermIterState::AnonVar(Level::Shallow)],
             &Term::Clause(_, _, ref terms) =>
-                vec![IteratorState::Clause(0, ClauseType::Root, terms)],
+                vec![TermIterState::Clause(0, ClauseType::Root, terms)],
             &Term::Cons(ref cell, ref head, ref tail) =>
-                vec![IteratorState::InitialCons(Level::Shallow,
+                vec![TermIterState::InitialCons(Level::Shallow,
                                                 cell,
                                                 head.as_ref(),
                                                 tail.as_ref())],
             &Term::Constant(ref cell, ref constant) =>
-                vec![IteratorState::Constant(Level::Shallow, cell, constant)],
+                vec![TermIterState::Constant(Level::Shallow, cell, constant)],
             &Term::Var(ref cell, ref var) =>
-                vec![IteratorState::Var(Level::Shallow, cell, var)]
+                vec![TermIterState::Var(Level::Shallow, cell, var)]
         };
 
         FactIterator { state_queue: VecDeque::from(states) }
@@ -148,9 +148,9 @@ impl<'a> Iterator for FactIterator<'a> {
     fn next(&mut self) -> Option<Self::Item> {
         while let Some(state) = self.state_queue.pop_front() {
             match state {
-                IteratorState::AnonVar(lvl) =>
+                TermIterState::AnonVar(lvl) =>
                     return Some(TermRef::AnonVar(lvl)),
-                IteratorState::Clause(_, ct, child_terms) => {
+                TermIterState::Clause(_, ct, child_terms) => {
                     for child_term in child_terms {
                         self.push_subterm(ct.level_of_subterms(), child_term);
                     }
@@ -162,15 +162,15 @@ impl<'a> Iterator for FactIterator<'a> {
                             continue
                     };
                 },
-                IteratorState::InitialCons(lvl, cell, head, tail) => {
+                TermIterState::InitialCons(lvl, cell, head, tail) => {
                     self.push_subterm(Level::Deep, head);
                     self.push_subterm(Level::Deep, tail);
 
                     return Some(TermRef::Cons(lvl, cell, head, tail));
                 },
-                IteratorState::Constant(lvl, cell, constant) =>
+                TermIterState::Constant(lvl, cell, constant) =>
                     return Some(TermRef::Constant(lvl, cell, constant)),
-                IteratorState::Var(lvl, cell, var) =>
+                TermIterState::Var(lvl, cell, var) =>
                     return Some(TermRef::Var(lvl, cell, var)),
                 _ => {}
             }
index 314bc71084d8ff9c4112d5d0bbde6eeae1d068d0..f426c33d4bb25a793f9337eb87e9a00924e940e7 100644 (file)
@@ -535,7 +535,7 @@ impl Machine {
                     result += cell_num.to_string().as_str();
                 },
                 CellView::StackVar(_, cell_num) => {
-                        result += "s_";
+                    result += "s_";
                     result += cell_num.to_string().as_str();
                 },
                 CellView::Str(_, ref name) =>
@@ -669,7 +669,7 @@ impl MachineState {
             Ref::StackCell(fr, sc) =>
                 self.and_stack[fr][sc] = t2,
             Ref::HeapCell(hc) =>
-                self.heap[hc] = HeapCellValue::from(t2)
+                self.heap[hc] = HeapCellValue::Addr(t2)
         };
 
         self.trail(r1);
@@ -764,7 +764,7 @@ impl MachineState {
         for i in a1 .. a2 {
             match self.trail[i] {
                 Ref::HeapCell(r) =>
-                    self.heap[r] = HeapCellValue::Ref(Ref::HeapCell(r)),
+                    self.heap[r] = HeapCellValue::Addr(Addr::HeapCell(r)),
                 Ref::StackCell(fr, sc) =>
                     self.and_stack[fr][sc] = Addr::StackCell(fr, sc)
             }
@@ -818,7 +818,7 @@ impl MachineState {
 
         match self.store(addr) {
             Addr::HeapCell(hc) => {
-                self.heap[hc] = HeapCellValue::Con(c.clone());
+                self.heap[hc] = HeapCellValue::Addr(Addr::Con(c.clone()));
                 self.trail(Ref::HeapCell(hc));
             },
             Addr::StackCell(fr, sc) => {
@@ -1142,7 +1142,7 @@ impl MachineState {
                     Addr::HeapCell(hc) => {
                         let h = self.heap.h;
 
-                        self.heap.push(HeapCellValue::Lis(h+1));
+                        self.heap.push(HeapCellValue::Addr(Addr::Lis(h+1)));
                         self.bind(Ref::HeapCell(hc), Addr::HeapCell(h));
 
                         self.mode = MachineMode::Write;
@@ -1150,7 +1150,7 @@ impl MachineState {
                     Addr::StackCell(fr, sc) => {
                         let h = self.heap.h;
 
-                        self.heap.push(HeapCellValue::Lis(h+1));
+                        self.heap.push(HeapCellValue::Addr(Addr::Lis(h+1)));
                         self.bind(Ref::StackCell(fr, sc), Addr::HeapCell(h));
 
                         self.mode = MachineMode::Write;
@@ -1181,10 +1181,10 @@ impl MachineState {
                     Addr::HeapCell(_) | Addr::StackCell(_, _) => {
                         let h = self.heap.h;
 
-                        self.heap.push(HeapCellValue::Str(h + 1));
+                        self.heap.push(HeapCellValue::Addr(Addr::Str(h + 1)));
                         self.heap.push(HeapCellValue::NamedStr(arity, name.clone()));
 
-                        self.bind(addr.as_ref().unwrap(), Addr::HeapCell(h));
+                        self.bind(addr.as_var().unwrap(), Addr::HeapCell(h));
 
                         self.mode = MachineMode::Write;
                     },
@@ -1206,7 +1206,7 @@ impl MachineState {
                         self.write_constant_to_var(addr, c.clone());
                     },
                     MachineMode::Write => {
-                        self.heap.push(HeapCellValue::Con(c.clone()));
+                        self.heap.push(HeapCellValue::Addr(Addr::Con(c.clone())));
                     }
                 };
 
@@ -1219,7 +1219,7 @@ impl MachineState {
                     MachineMode::Write => {
                         let h = self.heap.h;
 
-                        self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+                        self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
                         self[reg] = Addr::HeapCell(h);
                     }
                 };
@@ -1249,7 +1249,7 @@ impl MachineState {
                             }
                         }
 
-                        self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+                        self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
                         self.bind(Ref::HeapCell(h), addr);
                     }
                 };
@@ -1266,7 +1266,7 @@ impl MachineState {
                     },
                     MachineMode::Write => {
                         let heap_val = self.store(self[reg].clone());
-                        self.heap.push(HeapCellValue::from(heap_val));
+                        self.heap.push(HeapCellValue::Addr(heap_val));
                     }
                 };
 
@@ -1280,7 +1280,7 @@ impl MachineState {
                         let h = self.heap.h;
 
                         for i in h .. h + n {
-                            self.heap.push(HeapCellValue::Ref(Ref::HeapCell(i)));
+                            self.heap.push(HeapCellValue::Addr(Addr::HeapCell(i)));
                         }
                     }
                 };
@@ -1374,7 +1374,7 @@ impl MachineState {
                 } else {
                     let h = self.heap.h;
 
-                    self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+                    self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
                     self.bind(Ref::HeapCell(h), addr);
 
                     self.registers[arg] = self.heap[h].as_addr(h);
@@ -1392,15 +1392,15 @@ impl MachineState {
                     },
                     RegType::Temp(_) => {
                         let h = self.heap.h;
-                        self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+                        self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
 
                         self[norm] = Addr::HeapCell(h);
                         self.registers[arg] = Addr::HeapCell(h);
                     }
                 };
             },
-            &QueryInstruction::SetConstant(ref constant) => {
-                self.heap.push(HeapCellValue::Con(constant.clone()));
+            &QueryInstruction::SetConstant(ref c) => {
+                self.heap.push(HeapCellValue::Addr(Addr::Con(c.clone())));
             },
             &QueryInstruction::SetLocalValue(reg) => {
                 let addr = self.deref(self[reg].clone());
@@ -1408,28 +1408,28 @@ impl MachineState {
 
                 if let Addr::HeapCell(hc) = addr {
                     if hc < h {
-                        self.heap.push(HeapCellValue::from(addr));
+                        self.heap.push(HeapCellValue::Addr(addr));
                         return;
                     }
                 }
 
-                self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+                self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
                 self.bind(Ref::HeapCell(h), addr);
             },
             &QueryInstruction::SetVariable(reg) => {
                 let h = self.heap.h;
-                self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+                self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
                 self[reg] = Addr::HeapCell(h);
             },
             &QueryInstruction::SetValue(reg) => {
                 let heap_val = self[reg].clone();
-                self.heap.push(HeapCellValue::from(heap_val));
+                self.heap.push(HeapCellValue::Addr(heap_val));
             },
             &QueryInstruction::SetVoid(n) => {
                 let h = self.heap.h;
 
                 for i in h .. h + n {
-                    self.heap.push(HeapCellValue::Ref(Ref::HeapCell(i)));
+                    self.heap.push(HeapCellValue::Addr(Addr::HeapCell(i)));
                 }
             }
         }
@@ -1539,7 +1539,7 @@ impl MachineState {
                 self.throw_exception(functor!("type_error",
                                               2,
                                               [atom!("callable"),
-                                               HeapCellValue::from(addr)]));
+                                               HeapCellValue::Addr(addr)]));
                 return None;
             }
         };
@@ -1552,11 +1552,11 @@ impl MachineState {
 
         for heap_value in self.ball.1.iter().cloned() {
             self.heap.push(match heap_value {
-                HeapCellValue::Con(c) => HeapCellValue::Con(c),
-                HeapCellValue::Lis(a) => HeapCellValue::Lis(a - diff),
-                HeapCellValue::Ref(Ref::HeapCell(hc)) =>
-                    HeapCellValue::Ref(Ref::HeapCell(hc - diff)),
-                HeapCellValue::Str(s) => HeapCellValue::Str(s - diff),
+                HeapCellValue::Addr(Addr::Con(c)) => HeapCellValue::Addr(Addr::Con(c)),
+                HeapCellValue::Addr(Addr::Lis(a)) => HeapCellValue::Addr(Addr::Lis(a - diff)),
+                HeapCellValue::Addr(Addr::HeapCell(hc)) =>
+                    HeapCellValue::Addr(Addr::HeapCell(hc - diff)),
+                HeapCellValue::Addr(Addr::Str(s)) => HeapCellValue::Addr(Addr::Str(s - diff)),
                 _ => heap_value
             });
         }
@@ -1658,7 +1658,7 @@ impl MachineState {
 
                 let ball = self.heap[h].as_addr(h);
 
-                match addr.as_ref() {
+                match addr.as_var() {
                     Some(r) => {
                         self.bind(r, ball);
                         self.p += 1;
@@ -1822,7 +1822,7 @@ impl MachineState {
 
                         for _ in 0 .. arity {
                             let h = self.heap.h;
-                            self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+                            self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
                         }
                                                 
                         self.unify(a1, f_a);                                                
index 3ac2f46a2e31d9fde6e884d100f27ef7bc8220da..91e0bc234bcc2eaa77a8685976f418779b704d9d 100644 (file)
@@ -53,7 +53,7 @@ macro_rules! functor {
 
 macro_rules! atom {
     ($name:expr) => (
-        HeapCellValue::Con(Constant::Atom(Rc::new(String::from($name))))
+        HeapCellValue::Addr(Addr::Con(Constant::Atom(Rc::new(String::from($name)))))
     )
 }