set up heap_var Cow in heap_print.rs
This commit is contained in:
@@ -179,6 +179,37 @@ where HCIter: Iterator<Item=HeapCellValue> + MutStackHCIterator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct HCDerefAcyclicIterator<HCIter> {
|
||||||
|
iter: HCIter,
|
||||||
|
seen: HashSet<Addr>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<HCIter: MutStackHCIterator> HCDerefAcyclicIterator<HCIter>
|
||||||
|
{
|
||||||
|
pub fn new(iter: HCIter) -> Self {
|
||||||
|
HCDerefAcyclicIterator { iter, seen: HashSet::new() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<HCIter> Iterator for HCDerefAcyclicIterator<HCIter>
|
||||||
|
where HCIter: Iterator<Item=HeapCellValue> + MutStackHCIterator
|
||||||
|
{
|
||||||
|
type Item = HeapCellValue;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
loop {
|
||||||
|
match self.iter.next() {
|
||||||
|
Some(HeapCellValue::Addr(addr)) =>
|
||||||
|
if !self.seen.contains(&addr) {
|
||||||
|
self.seen.insert(addr.clone());
|
||||||
|
return Some(HeapCellValue::Addr(addr));
|
||||||
|
},
|
||||||
|
item => return item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct HCZippedAcyclicIterator<HCIter> {
|
pub struct HCZippedAcyclicIterator<HCIter> {
|
||||||
i1: HCIter,
|
i1: HCIter,
|
||||||
i2: HCIter,
|
i2: HCIter,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use prolog::ast::*;
|
use prolog::ast::*;
|
||||||
use prolog::heap_iter::*;
|
use prolog::heap_iter::*;
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@@ -143,16 +144,31 @@ pub struct HCPrinter<'a, Formatter, Outputter> {
|
|||||||
formatter: Formatter,
|
formatter: Formatter,
|
||||||
outputter: Outputter,
|
outputter: Outputter,
|
||||||
iter: HCPreOrderIterator<'a>,
|
iter: HCPreOrderIterator<'a>,
|
||||||
state_stack: Vec<TokenOrRedirect>
|
state_stack: Vec<TokenOrRedirect>,
|
||||||
|
heap_locs: Cow<'a, HeapVarDict>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
|
impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
|
||||||
HCPrinter<'a, Formatter, Outputter>
|
HCPrinter<'a, Formatter, Outputter>
|
||||||
{
|
{
|
||||||
pub fn new(iter: HCPreOrderIterator<'a>, formatter: Formatter, outputter: Outputter)
|
pub fn new(iter: HCPreOrderIterator<'a>, fmt: Formatter, output: Outputter) -> Self
|
||||||
|
{
|
||||||
|
HCPrinter { formatter: fmt,
|
||||||
|
outputter: output,
|
||||||
|
iter,
|
||||||
|
state_stack: vec![],
|
||||||
|
heap_locs: Cow::default() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_heap_locs(iter: HCPreOrderIterator<'a>, fmt: Formatter,
|
||||||
|
output: Outputter, heap_locs: &'a HeapVarDict)
|
||||||
-> Self
|
-> Self
|
||||||
{
|
{
|
||||||
HCPrinter { formatter, outputter, iter, state_stack: vec![] }
|
HCPrinter { formatter: fmt,
|
||||||
|
outputter: output,
|
||||||
|
iter,
|
||||||
|
state_stack: vec![],
|
||||||
|
heap_locs: Cow::Borrowed(heap_locs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_heap_term(&mut self, heap_val: HeapCellValue) {
|
fn handle_heap_term(&mut self, heap_val: HeapCellValue) {
|
||||||
|
|||||||
Reference in New Issue
Block a user