]> Repositorios git - scryer-prolog.git/commitdiff
fix list copying
authorMark Thom <[email protected]>
Sun, 1 Dec 2019 22:28:47 +0000 (15:28 -0700)
committerMark Thom <[email protected]>
Sun, 1 Dec 2019 22:28:47 +0000 (15:28 -0700)
src/prolog/machine/copier.rs

index 34c1bfe6dd5823e213d1d9dea86194ba3c323af7..328c504a3d17e874e792be6cad4c30e3b0ad25aa 100644 (file)
@@ -71,13 +71,31 @@ impl<T: CopierTarget> CopyTermState<T> {
         *self.value_at_scan() = HeapCellValue::Addr(Addr::Lis(threshold));
 
         let hcv = self.target[addr].clone();
-        self.target.push(hcv);
 
+        let ra = hcv.as_addr(threshold);
+        let rd = self.target.store(self.target.deref(ra));
+
+        self.target.push(hcv);
+        
         let hcv = self.target[addr + 1].clone();
         self.target.push(hcv);
 
-        self.trail.push((Ref::HeapCell(addr), self.target[addr].clone()));
-        self.target[addr] = HeapCellValue::Addr(Addr::Lis(threshold));
+        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(..) => {
+                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.target[addr] = HeapCellValue::Addr(Addr::Lis(threshold))
+            }
+        };
 
         self.scan += 1;
     }