Format code using 'cargo fmt'

This commit is contained in:
Atul Bhosale
2019-09-23 19:35:37 +07:00
parent 8207fdea40
commit 1273e2d52d
36 changed files with 8738 additions and 6375 deletions

View File

@@ -5,8 +5,7 @@ use std::ops::IndexMut;
type Trail = Vec<(Ref, HeapCellValue)>;
pub(crate) trait CopierTarget: IndexMut<usize, Output=HeapCellValue>
{
pub(crate) trait CopierTarget: IndexMut<usize, Output = HeapCellValue> {
fn threshold(&self) -> usize;
fn push(&mut self, HeapCellValue);
fn store(&self, Addr) -> Addr;
@@ -14,9 +13,7 @@ pub(crate) trait CopierTarget: IndexMut<usize, Output=HeapCellValue>
fn stack(&mut self) -> &mut AndStack;
}
pub(crate)
fn copy_term<T: CopierTarget>(target: T, addr: Addr)
{
pub(crate) fn copy_term<T: CopierTarget>(target: T, addr: Addr) {
let mut copy_term_state = CopyTermState::new(target);
copy_term_state.copy_term_impl(addr);
}
@@ -25,16 +22,16 @@ struct CopyTermState<T: CopierTarget> {
trail: Trail,
scan: usize,
old_h: usize,
target: T
target: T,
}
impl<T: CopierTarget> CopyTermState<T> {
fn new(target: T) -> Self {
CopyTermState {
trail: vec![],
scan: 0,
scan: 0,
old_h: target.threshold(),
target
target,
}
}
@@ -44,24 +41,28 @@ impl<T: CopierTarget> CopyTermState<T> {
&mut self.target[scan]
}
fn reinstantiate_var(&mut self, addr: Addr, threshold: usize)
{
fn reinstantiate_var(&mut self, addr: Addr, threshold: usize) {
match addr {
Addr::HeapCell(h) => {
self.target[threshold] = HeapCellValue::Addr(Addr::HeapCell(threshold));
self.target[h] = HeapCellValue::Addr(Addr::HeapCell(threshold));
self.trail.push((Ref::HeapCell(h), HeapCellValue::Addr(Addr::HeapCell(h))));
},
self.trail
.push((Ref::HeapCell(h), HeapCellValue::Addr(Addr::HeapCell(h))));
}
Addr::StackCell(fr, sc) => {
self.target[threshold] = HeapCellValue::Addr(Addr::HeapCell(threshold));
self.target.stack()[fr][sc] = Addr::HeapCell(threshold);
self.trail.push((Ref::StackCell(fr, sc), HeapCellValue::Addr(Addr::StackCell(fr, sc))));
},
self.trail.push((
Ref::StackCell(fr, sc),
HeapCellValue::Addr(Addr::StackCell(fr, sc)),
));
}
Addr::AttrVar(h) => {
self.target[threshold] = HeapCellValue::Addr(Addr::AttrVar(threshold));
self.target[h] = HeapCellValue::Addr(Addr::AttrVar(threshold));
self.trail.push((Ref::AttrVar(h), HeapCellValue::Addr(Addr::AttrVar(h))));
},
self.trail
.push((Ref::AttrVar(h), HeapCellValue::Addr(Addr::AttrVar(h))));
}
_ => {}
}
}
@@ -93,16 +94,19 @@ impl<T: CopierTarget> CopyTermState<T> {
let rd = self.target.store(self.target.deref(ra));
match rd.clone() {
Addr::AttrVar(h) | Addr::HeapCell(h) if h >= self.old_h =>
self.target[threshold] = HeapCellValue::Addr(rd),
ra @ Addr::AttrVar(_) | ra @ Addr::HeapCell(..) | ra @ Addr::StackCell(..) =>
Addr::AttrVar(h) | Addr::HeapCell(h) if h >= self.old_h => {
self.target[threshold] = HeapCellValue::Addr(rd)
}
ra @ Addr::AttrVar(_) | ra @ Addr::HeapCell(..) | ra @ Addr::StackCell(..) => {
if ra == rd {
self.reinstantiate_var(ra, threshold);
} else {
self.target[threshold] = HeapCellValue::Addr(ra);
},
}
}
_ => {
self.trail.push((Ref::HeapCell(addr), self.target[addr].clone()));
self.trail
.push((Ref::HeapCell(addr), self.target[addr].clone()));
self.target[addr] = HeapCellValue::Addr(Addr::Lis(threshold))
}
};
@@ -120,23 +124,24 @@ impl<T: CopierTarget> CopyTermState<T> {
Addr::AttrVar(h) | Addr::HeapCell(h) if h >= self.old_h => {
*self.value_at_scan() = HeapCellValue::Addr(rd);
self.scan += 1;
},
}
Addr::AttrVar(h) if addr == rd => {
let threshold = self.target.threshold();
self.target.push(HeapCellValue::Addr(Addr::AttrVar(threshold)));
self.target
.push(HeapCellValue::Addr(Addr::AttrVar(threshold)));
let list_val = self.target[h + 1].clone();
self.target.push(list_val);
self.reinstantiate_var(addr, threshold);
*self.value_at_scan() = HeapCellValue::Addr(Addr::AttrVar(threshold));
},
}
_ if addr == rd => {
let scan = self.scan;
self.reinstantiate_var(addr, scan);
self.scan += 1;
},
_ => *self.value_at_scan() = HeapCellValue::Addr(rd)
}
_ => *self.value_at_scan() = HeapCellValue::Addr(rd),
}
}
@@ -148,18 +153,22 @@ impl<T: CopierTarget> CopyTermState<T> {
*self.value_at_scan() = HeapCellValue::Addr(Addr::Str(threshold));
self.target[addr] = HeapCellValue::Addr(Addr::Str(threshold));
self.trail.push((Ref::HeapCell(addr),
HeapCellValue::NamedStr(arity, name.clone(), fixity.clone())));
self.trail.push((
Ref::HeapCell(addr),
HeapCellValue::NamedStr(arity, name.clone(), fixity.clone()),
));
self.target.push(HeapCellValue::NamedStr(arity, name, fixity));
self.target
.push(HeapCellValue::NamedStr(arity, name, fixity));
for i in 0 .. arity {
for i in 0..arity {
let hcv = self.target[addr + 1 + i].clone();
self.target.push(hcv);
}
},
HeapCellValue::Addr(Addr::Str(addr)) =>
*self.value_at_scan() = HeapCellValue::Addr(Addr::Str(addr)),
}
HeapCellValue::Addr(Addr::Str(addr)) => {
*self.value_at_scan() = HeapCellValue::Addr(Addr::Str(addr))
}
_ => {}
}
@@ -172,21 +181,15 @@ impl<T: CopierTarget> CopyTermState<T> {
while self.scan < self.target.threshold() {
match self.value_at_scan().clone() {
HeapCellValue::NamedStr(..) =>
self.scan += 1,
HeapCellValue::Addr(addr) =>
match addr {
Addr::Lis(addr) =>
self.copy_list(addr),
addr @ Addr::AttrVar(_)
| addr @ Addr::HeapCell(_)
| addr @ Addr::StackCell(..) =>
self.copy_var(addr),
Addr::Str(addr) =>
self.copy_structure(addr),
Addr::Con(_) | Addr::DBRef(_) =>
self.scan += 1
}
HeapCellValue::NamedStr(..) => self.scan += 1,
HeapCellValue::Addr(addr) => match addr {
Addr::Lis(addr) => self.copy_list(addr),
addr @ Addr::AttrVar(_)
| addr @ Addr::HeapCell(_)
| addr @ Addr::StackCell(..) => self.copy_var(addr),
Addr::Str(addr) => self.copy_structure(addr),
Addr::Con(_) | Addr::DBRef(_) => self.scan += 1,
},
}
}
@@ -194,12 +197,10 @@ impl<T: CopierTarget> CopyTermState<T> {
}
fn unwind_trail(&mut self) {
for (r, value) in self.trail.drain(0 ..) {
for (r, value) in self.trail.drain(0..) {
match r {
Ref::AttrVar(h) | Ref::HeapCell(h) =>
self.target[h] = value,
Ref::StackCell(fr, sc) =>
self.target.stack()[fr][sc] = value.as_addr(0)
Ref::AttrVar(h) | Ref::HeapCell(h) => self.target[h] = value,
Ref::StackCell(fr, sc) => self.target.stack()[fr][sc] = value.as_addr(0),
}
}
}