add access to HeapVarDict to the printer.
This commit is contained in:
@@ -184,6 +184,14 @@ pub struct HCDerefAcyclicIterator<HCIter> {
|
|||||||
seen: HashSet<Addr>
|
seen: HashSet<Addr>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type HCDerefAcyclicPreOrderIterator<'a> = HCDerefAcyclicIterator<HCPreOrderIterator<'a>>;
|
||||||
|
|
||||||
|
impl<'a> HCPreOrderIterator<'a> {
|
||||||
|
pub fn deref_acyclic_iter(self) -> HCDerefAcyclicPreOrderIterator<'a> {
|
||||||
|
HCDerefAcyclicIterator::new(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<HCIter: MutStackHCIterator> HCDerefAcyclicIterator<HCIter>
|
impl<HCIter: MutStackHCIterator> HCDerefAcyclicIterator<HCIter>
|
||||||
{
|
{
|
||||||
pub fn new(iter: HCIter) -> Self {
|
pub fn new(iter: HCIter) -> Self {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use prolog::ast::*;
|
use prolog::ast::*;
|
||||||
use prolog::heap_iter::*;
|
use prolog::heap_iter::*;
|
||||||
|
use prolog::machine::machine_state::MachineState;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
@@ -143,7 +144,7 @@ impl HCValueFormatter for TermFormatter {
|
|||||||
pub struct HCPrinter<'a, Formatter, Outputter> {
|
pub struct HCPrinter<'a, Formatter, Outputter> {
|
||||||
formatter: Formatter,
|
formatter: Formatter,
|
||||||
outputter: Outputter,
|
outputter: Outputter,
|
||||||
iter: HCPreOrderIterator<'a>,
|
iter: HCDerefAcyclicPreOrderIterator<'a>,
|
||||||
state_stack: Vec<TokenOrRedirect>,
|
state_stack: Vec<TokenOrRedirect>,
|
||||||
heap_locs: Cow<'a, HeapVarDict>
|
heap_locs: Cow<'a, HeapVarDict>
|
||||||
}
|
}
|
||||||
@@ -151,22 +152,26 @@ pub struct HCPrinter<'a, Formatter, Outputter> {
|
|||||||
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>, fmt: Formatter, output: Outputter) -> Self
|
pub fn new(machine_st: &'a MachineState, addr: Addr, fmt: Formatter, output: Outputter) -> Self
|
||||||
{
|
{
|
||||||
|
let iter = HCPreOrderIterator::new(&machine_st, addr);
|
||||||
|
|
||||||
HCPrinter { formatter: fmt,
|
HCPrinter { formatter: fmt,
|
||||||
outputter: output,
|
outputter: output,
|
||||||
iter,
|
iter: iter.deref_acyclic_iter(),
|
||||||
state_stack: vec![],
|
state_stack: vec![],
|
||||||
heap_locs: Cow::default() }
|
heap_locs: Cow::default() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_heap_locs(iter: HCPreOrderIterator<'a>, fmt: Formatter,
|
pub fn from_heap_locs(machine_st: &'a MachineState, addr: Addr, fmt: Formatter,
|
||||||
output: Outputter, heap_locs: &'a HeapVarDict)
|
output: Outputter, heap_locs: &'a HeapVarDict)
|
||||||
-> Self
|
-> Self
|
||||||
{
|
{
|
||||||
|
let iter = HCPreOrderIterator::new(&machine_st, addr);
|
||||||
|
|
||||||
HCPrinter { formatter: fmt,
|
HCPrinter { formatter: fmt,
|
||||||
outputter: output,
|
outputter: output,
|
||||||
iter,
|
iter: iter.deref_acyclic_iter(),
|
||||||
state_stack: vec![],
|
state_stack: vec![],
|
||||||
heap_locs: Cow::Borrowed(heap_locs) }
|
heap_locs: Cow::Borrowed(heap_locs) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,12 +93,34 @@ impl MachineState {
|
|||||||
self.trail(r1);
|
self.trail(r1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn print_term<Fmt, Outputter>(&self, a: Addr, fmt: Fmt, output: Outputter) -> Outputter
|
pub(super)
|
||||||
|
fn print_var_eq<Fmt, Outputter>(&self, var: Rc<Var>, addr: Addr, var_dir: &HeapVarDict,
|
||||||
|
fmt: Fmt, mut output: Outputter)
|
||||||
|
-> Outputter
|
||||||
|
where Fmt: HCValueFormatter, Outputter: HCValueOutputter
|
||||||
|
{
|
||||||
|
let orig_len = output.len();
|
||||||
|
|
||||||
|
output.begin_new_var();
|
||||||
|
|
||||||
|
output.append(var.as_str());
|
||||||
|
output.append(" = ");
|
||||||
|
|
||||||
|
let printer = HCPrinter::from_heap_locs(&self, addr, fmt, output, var_dir);
|
||||||
|
let mut output = printer.print();
|
||||||
|
|
||||||
|
if output.ends_with(var.as_str()) {
|
||||||
|
output.truncate(orig_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super)
|
||||||
|
fn print_term<Fmt, Outputter>(&self, addr: Addr, fmt: Fmt, output: Outputter) -> Outputter
|
||||||
where Fmt: HCValueFormatter, Outputter: HCValueOutputter
|
where Fmt: HCValueFormatter, Outputter: HCValueOutputter
|
||||||
{
|
{
|
||||||
let iter = HCPreOrderIterator::new(&self, a);
|
let printer = HCPrinter::new(&self, addr, fmt, output);
|
||||||
let printer = HCPrinter::new(iter, fmt, output);
|
|
||||||
|
|
||||||
printer.print()
|
printer.print()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use prolog::heap_print::*;
|
|||||||
use prolog::tabled_rc::*;
|
use prolog::tabled_rc::*;
|
||||||
|
|
||||||
mod machine_errors;
|
mod machine_errors;
|
||||||
pub(crate) mod machine_state;
|
pub(super) mod machine_state;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod machine_state_impl;
|
mod machine_state_impl;
|
||||||
|
|
||||||
@@ -427,12 +427,8 @@ impl Machine {
|
|||||||
where Outputter: HCValueOutputter
|
where Outputter: HCValueOutputter
|
||||||
{
|
{
|
||||||
for (var, addr) in var_dir {
|
for (var, addr) in var_dir {
|
||||||
output.begin_new_var();
|
let fmt = TermFormatter {};
|
||||||
|
output = self.ms.print_var_eq(var.clone(), addr.clone(), var_dir, fmt, output);
|
||||||
output.append(var.as_str());
|
|
||||||
output.append(" = ");
|
|
||||||
|
|
||||||
output = self.ms.print_term(addr.clone(), TermFormatter {}, output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output
|
output
|
||||||
|
|||||||
Reference in New Issue
Block a user