add AttrVar variant to Addr

This commit is contained in:
Mark Thom
2019-01-26 20:46:37 -07:00
parent 6e735bc2d4
commit 4f87fb8535
5 changed files with 26 additions and 17 deletions

View File

@@ -100,12 +100,12 @@ pub(crate) trait CopierTarget: IndexMut<usize, Output=HeapCellValue>
scan += 1;
},
Addr::HeapCell(_) | Addr::StackCell(_, _) => {
Addr::AttrVar(_) | 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 => {
Addr::AttrVar(h) | Addr::HeapCell(h) if h >= old_h => {
self[scan] = HeapCellValue::Addr(rd);
scan += 1;
},

View File

@@ -65,7 +65,7 @@ impl<'a> HCPreOrderIterator<'a> {
da
},
Addr::HeapCell(_) | Addr::StackCell(_, _) => da,
Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(_, _) => da,
Addr::Str(s) => self.follow_heap(s) // record terms of structure.
}
}

View File

@@ -708,6 +708,7 @@ pub type CodeDeque = VecDeque<Line>;
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum Addr {
AttrVar(usize),
Con(Constant),
Lis(usize),
HeapCell(usize),
@@ -776,8 +777,9 @@ impl Add<usize> for Addr {
fn add(self, rhs: usize) -> Self::Output {
match self {
Addr::AttrVar(a) => Addr::AttrVar(a + rhs),
Addr::Lis(a) => Addr::Lis(a + rhs),
Addr::HeapCell(hc) => Addr::HeapCell(hc + rhs),
Addr::HeapCell(h) => Addr::HeapCell(h + rhs),
Addr::Str(s) => Addr::Str(s + rhs),
_ => self
}
@@ -789,8 +791,9 @@ impl Sub<usize> for Addr {
fn sub(self, rhs: usize) -> Self::Output {
match self {
Addr::AttrVar(a) => Addr::AttrVar(a - rhs),
Addr::Lis(a) => Addr::Lis(a - rhs),
Addr::HeapCell(hc) => Addr::HeapCell(hc - rhs),
Addr::HeapCell(h) => Addr::HeapCell(h - rhs),
Addr::Str(s) => Addr::Str(s - rhs),
_ => self
}
@@ -800,7 +803,7 @@ impl Sub<usize> for Addr {
impl From<Ref> for Addr {
fn from(r: Ref) -> Self {
match r {
Ref::HeapCell(hc) => Addr::HeapCell(hc),
Ref::HeapCell(h) => Addr::HeapCell(h),
Ref::StackCell(fr, sc) => Addr::StackCell(fr, sc)
}
}

View File

@@ -78,7 +78,8 @@ impl MachineState {
pub(crate) fn store(&self, a: Addr) -> Addr {
match a {
Addr::HeapCell(r) => self.heap[r].as_addr(r),
Addr::AttrVar(h) => self.heap[h+1].as_addr(h+1),
Addr::HeapCell(h) => self.heap[h].as_addr(h),
Addr::StackCell(fr, sc) => self.and_stack[fr][sc].clone(),
addr => addr
}
@@ -219,10 +220,14 @@ impl MachineState {
if d1 != d2 {
match (self.store(d1.clone()), self.store(d2.clone())) {
(Addr::HeapCell(hc), _) =>
self.bind(Ref::HeapCell(hc), d2),
(_, Addr::HeapCell(hc)) =>
self.bind(Ref::HeapCell(hc), d1),
(Addr::AttrVar(h), addr) | (addr, Addr::AttrVar(h)) => {
pdl.push(Addr::HeapCell(h+1));
pdl.push(addr);
},
(Addr::HeapCell(h), _) =>
self.bind(Ref::HeapCell(h), d2),
(_, Addr::HeapCell(h)) =>
self.bind(Ref::HeapCell(h), d1),
(Addr::StackCell(fr, sc), _) =>
self.bind(Ref::StackCell(fr, sc), d2),
(_, Addr::StackCell(fr, sc)) =>
@@ -481,10 +486,10 @@ impl MachineState {
}
pub(super) fn write_constant_to_var(&mut self, addr: Addr, c: Constant) {
match self.store(self.deref(addr)) {
Addr::HeapCell(hc) => {
self.heap[hc] = HeapCellValue::Addr(Addr::Con(c.clone()));
self.trail(TrailRef::HeapCell(hc));
match self.store(self.deref(addr)) {
Addr::HeapCell(h) => {
self.heap[h] = HeapCellValue::Addr(Addr::Con(c.clone()));
self.trail(TrailRef::HeapCell(h));
},
Addr::StackCell(fr, sc) => {
self.and_stack[fr][sc] = Addr::Con(c.clone());
@@ -1163,7 +1168,7 @@ impl MachineState {
let addr = self.store(self.deref(a1));
let offset = match addr {
Addr::HeapCell(_) | Addr::StackCell(_, _) => v,
Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(_, _) => v,
Addr::Con(Constant::String(_)) if self.flags.double_quotes.is_chars() => l,
Addr::Con(_) => c,
Addr::Lis(_) => l,
@@ -1839,7 +1844,7 @@ impl MachineState {
},
Addr::Lis(_) =>
self.try_functor_compound_case(clause_name!("."), 2),
Addr::HeapCell(_) | Addr::StackCell(_, _) => {
Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(..) => {
let name = self.store(self.deref(self[temp_v!(2)].clone()));
let arity = self.store(self.deref(self[temp_v!(3)].clone()));

View File

@@ -146,6 +146,7 @@ impl fmt::Display for Addr {
match self {
&Addr::Con(ref c) => write!(f, "Addr::Con({})", c),
&Addr::Lis(l) => write!(f, "Addr::Lis({})", l),
&Addr::AttrVar(h) => write!(f, "Addr::AttrVar({})", h),
&Addr::HeapCell(h) => write!(f, "Addr::HeapCell({})", h),
&Addr::StackCell(fr, sc)=> write!(f, "Addr::StackCell({}, {})", fr, sc),
&Addr::Str(s) => write!(f, "Addr::Str({})", s)