From 70939331d113dedbca48f0b3b1345cf0d10533a5 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sun, 16 Sep 2018 02:32:29 -0600 Subject: [PATCH] correct copier. --- src/prolog/copier.rs | 25 ++++++++----------------- src/prolog/heap_iter.rs | 6 ++---- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/prolog/copier.rs b/src/prolog/copier.rs index 7d15cb5d..6b206abb 100644 --- a/src/prolog/copier.rs +++ b/src/prolog/copier.rs @@ -3,20 +3,12 @@ use prolog::instructions::*; use std::ops::IndexMut; -//type ListTrail = HashMap; type Trail = Vec<(Ref, HeapCellValue)>; pub(crate) struct RedirectInfo { - //list_trail: ListTrail, trail: Trail } -/* -impl RedirectInfo { - fn new() -> Self { - RedirectInfo { list_trail: ListTrail::new(), trail: Trail::new() } - } -} -*/ + pub(crate) trait CopierTarget { fn source(&self) -> usize; @@ -50,16 +42,15 @@ pub(crate) trait CopierTarget self.stack()[fr][sc] = Addr::HeapCell(scan); trail.push((Ref::StackCell(fr, sc), HeapCellValue::Addr(Addr::StackCell(fr, sc)))); - } + } } - + // duplicate_term_impl(L1, L2) uses Cheney's algorithm to copy the term // at L1 to L2. trail is kept to restore the innards of L1 after // it's been copied to L2. fn duplicate_term_impl(&mut self, addr: Addr) -> RedirectInfo where Self: IndexMut { - // let mut redirect_info = RedirectInfo::new(); let mut trail = Trail::new(); let mut scan = self.source(); let old_h = self.threshold(); @@ -83,13 +74,13 @@ pub(crate) trait CopierTarget let threshold = self.threshold(); self[scan] = HeapCellValue::Addr(Addr::Lis(threshold)); - + let hcv = self[a].clone(); - self.push(hcv.clone()); - + self.push(hcv.clone()); + let ra = hcv.as_addr(threshold); let rd = self.store(self.deref(ra)); - + match rd.clone() { Addr::HeapCell(hc) if hc >= old_h => { self[threshold] = HeapCellValue::Addr(rd); @@ -108,7 +99,7 @@ pub(crate) trait CopierTarget trail.push((Ref::HeapCell(a), self[a].clone())); self[a] = HeapCellValue::Addr(Addr::Lis(threshold)) } - }; + }; let hcv = self[a+1].clone(); self.push(hcv); diff --git a/src/prolog/heap_iter.rs b/src/prolog/heap_iter.rs index 1428edf3..30d78a96 100644 --- a/src/prolog/heap_iter.rs +++ b/src/prolog/heap_iter.rs @@ -60,10 +60,8 @@ impl<'a> HCPreOrderIterator<'a> { da }, - Addr::HeapCell(_) | Addr::StackCell(_, _) => - da, - Addr::Str(s) => - self.follow_heap(s) // record terms of structure. + Addr::HeapCell(_) | Addr::StackCell(_, _) => da, + Addr::Str(s) => self.follow_heap(s) // record terms of structure. } } } -- 2.54.0