-[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"
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"
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> {
&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] })
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))
};
}
_ => 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)),
#[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)
}
}
}
}
-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),
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)
}
}
}
// 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)
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));
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,
+ },
+
}
}
}
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 {
&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] }
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))
&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![] }
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 =>
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))
};
}
}
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) }
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);
}
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)),
_ => {}
}
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) =>
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);
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)
}
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) => {
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;
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;
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;
},
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())));
}
};
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);
}
};
}
}
- self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
+ self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
self.bind(Ref::HeapCell(h), addr);
}
};
},
MachineMode::Write => {
let heap_val = self.store(self[reg].clone());
- self.heap.push(HeapCellValue::from(heap_val));
+ self.heap.push(HeapCellValue::Addr(heap_val));
}
};
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)));
}
}
};
} 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);
},
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());
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)));
}
}
}
self.throw_exception(functor!("type_error",
2,
[atom!("callable"),
- HeapCellValue::from(addr)]));
+ HeapCellValue::Addr(addr)]));
return None;
}
};
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
});
}
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;
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);
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)))))
)
}