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; scan += 1;
}, },
Addr::HeapCell(_) | Addr::StackCell(_, _) => { Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(_, _) => {
let ra = a; let ra = a;
let rd = self.store(self.deref(ra.clone())); let rd = self.store(self.deref(ra.clone()));
match rd.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); self[scan] = HeapCellValue::Addr(rd);
scan += 1; scan += 1;
}, },

View File

@@ -65,7 +65,7 @@ impl<'a> HCPreOrderIterator<'a> {
da da
}, },
Addr::HeapCell(_) | Addr::StackCell(_, _) => da, Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(_, _) => da,
Addr::Str(s) => self.follow_heap(s) // record terms of structure. 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)] #[derive(Clone, PartialEq, Eq, Hash)]
pub enum Addr { pub enum Addr {
AttrVar(usize),
Con(Constant), Con(Constant),
Lis(usize), Lis(usize),
HeapCell(usize), HeapCell(usize),
@@ -776,8 +777,9 @@ impl Add<usize> for Addr {
fn add(self, rhs: usize) -> Self::Output { fn add(self, rhs: usize) -> Self::Output {
match self { match self {
Addr::AttrVar(a) => Addr::AttrVar(a + rhs),
Addr::Lis(a) => Addr::Lis(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), Addr::Str(s) => Addr::Str(s + rhs),
_ => self _ => self
} }
@@ -789,8 +791,9 @@ impl Sub<usize> for Addr {
fn sub(self, rhs: usize) -> Self::Output { fn sub(self, rhs: usize) -> Self::Output {
match self { match self {
Addr::AttrVar(a) => Addr::AttrVar(a - rhs),
Addr::Lis(a) => Addr::Lis(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), Addr::Str(s) => Addr::Str(s - rhs),
_ => self _ => self
} }
@@ -800,7 +803,7 @@ impl Sub<usize> for Addr {
impl From<Ref> for Addr { impl From<Ref> for Addr {
fn from(r: Ref) -> Self { fn from(r: Ref) -> Self {
match r { match r {
Ref::HeapCell(hc) => Addr::HeapCell(hc), Ref::HeapCell(h) => Addr::HeapCell(h),
Ref::StackCell(fr, sc) => Addr::StackCell(fr, sc) Ref::StackCell(fr, sc) => Addr::StackCell(fr, sc)
} }
} }

View File

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