]> Repositorios git - scryer-prolog.git/commitdiff
add AttrVar variant to Addr
authorMark Thom <[email protected]>
Sun, 27 Jan 2019 03:46:37 +0000 (20:46 -0700)
committerMark Thom <[email protected]>
Sun, 27 Jan 2019 03:46:37 +0000 (20:46 -0700)
src/prolog/copier.rs
src/prolog/heap_iter.rs
src/prolog/instructions.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/write.rs

index 1988c350f3b0ad0329cfaee59ac8e1363c3d5729..1e08424659b76fd51cf0d1e3f3f905ebdc55ecbf 100644 (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;
                                 },
index 4bdb382f3187bf287a17e6f602767d705f687622..2b96ff6931578d7e99388a70e28469b9963756bd 100644 (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.
         }
     }
index 5d81c514e2839348fc87ede3f8f32c761e53de93..88a707a2e1760db102a60522c1c67d63b9370dcb 100644 (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)
         }
     }
index 62f3241c61e17b7d032ae8ff88f60cd4512850b3..dae948059806715737cd1f360b31d7141c3cd78a 100644 (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()));
 
index 76fb48fd897540be3502aa5e1ec18f6c2ff4f224..9b5004b21c771a5834593cc43cdcd632c5d74c1b 100644 (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)