refactor copier.rs

This commit is contained in:
Mark Thom
2019-02-19 22:00:13 -07:00
parent 2467f6c711
commit b710112df2
3 changed files with 183 additions and 153 deletions

View File

@@ -33,17 +33,17 @@ impl Ball {
}
}
pub(super) struct DuplicateTerm<'a> {
pub(super) struct CopyTerm<'a> {
state: &'a mut MachineState
}
impl<'a> DuplicateTerm<'a> {
impl<'a> CopyTerm<'a> {
pub(super) fn new(state: &'a mut MachineState) -> Self {
DuplicateTerm { state: state }
CopyTerm { state: state }
}
}
impl<'a> Index<usize> for DuplicateTerm<'a> {
impl<'a> Index<usize> for CopyTerm<'a> {
type Output = HeapCellValue;
fn index(&self, index: usize) -> &Self::Output {
@@ -51,14 +51,14 @@ impl<'a> Index<usize> for DuplicateTerm<'a> {
}
}
impl<'a> IndexMut<usize> for DuplicateTerm<'a> {
impl<'a> IndexMut<usize> for CopyTerm<'a> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.state.heap[index]
}
}
// the ordinary, heap term copier, used by duplicate_term.
impl<'a> CopierTarget for DuplicateTerm<'a> {
impl<'a> CopierTarget for CopyTerm<'a> {
fn source(&self) -> usize {
self.state.heap.h
}
@@ -84,19 +84,19 @@ impl<'a> CopierTarget for DuplicateTerm<'a> {
}
}
pub(super) struct DuplicateBallTerm<'a> {
pub(super) struct CopyBallTerm<'a> {
state: &'a mut MachineState,
heap_boundary: usize
}
impl<'a> DuplicateBallTerm<'a> {
impl<'a> CopyBallTerm<'a> {
pub(super) fn new(state: &'a mut MachineState) -> Self {
let hb = state.heap.len();
DuplicateBallTerm { state, heap_boundary: hb }
CopyBallTerm { state, heap_boundary: hb }
}
}
impl<'a> Index<usize> for DuplicateBallTerm<'a> {
impl<'a> Index<usize> for CopyBallTerm<'a> {
type Output = HeapCellValue;
fn index(&self, index: usize) -> &Self::Output {
@@ -109,7 +109,7 @@ impl<'a> Index<usize> for DuplicateBallTerm<'a> {
}
}
impl<'a> IndexMut<usize> for DuplicateBallTerm<'a> {
impl<'a> IndexMut<usize> for CopyBallTerm<'a> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
if index < self.heap_boundary {
&mut self.state.heap[index]
@@ -121,7 +121,7 @@ impl<'a> IndexMut<usize> for DuplicateBallTerm<'a> {
}
// the ordinary, heap term copier, used by duplicate_term.
impl<'a> CopierTarget for DuplicateBallTerm<'a> {
impl<'a> CopierTarget for CopyBallTerm<'a> {
fn source(&self) -> usize {
self.heap_boundary
}

View File

@@ -182,7 +182,8 @@ impl MachineState {
-> Outputter
where Outputter: HCValueOutputter
{
let printer = HCPrinter::from_heap_locs(&self, output, var_dict);
let mut printer = HCPrinter::from_heap_locs(&self, output, var_dict);
printer.see_all_locs();
printer.print(addr)
}
@@ -1348,8 +1349,8 @@ impl MachineState {
let addr = self[temp_v!(1)].clone();
self.ball.boundary = self.heap.h;
let mut duplicator = DuplicateBallTerm::new(self);
duplicator.duplicate_term(addr);
let duplicator = CopyBallTerm::new(self);
copy_term(duplicator, addr);
}
pub(super) fn setup_call_n(&mut self, arity: usize) -> Option<PredicateKey>
@@ -2031,8 +2032,8 @@ impl MachineState {
// drop the mutable references contained in gadget
// once the term has been duplicated.
{
let mut gadget = DuplicateTerm::new(self);
gadget.duplicate_term(a1);
let gadget = CopyTerm::new(self);
copy_term(gadget, a1);
}
self.unify(Addr::HeapCell(old_h), a2);