abbreviate names in heap_iter.rs
This commit is contained in:
@@ -4,15 +4,15 @@ use prolog::machine::machine_state::MachineState;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
pub struct HeapCellPreOrderIterator<'a> {
|
pub struct HCPreOrderIterator<'a> {
|
||||||
machine_st: &'a MachineState,
|
machine_st: &'a MachineState,
|
||||||
state_stack: Vec<Addr>
|
state_stack: Vec<Addr>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> HeapCellPreOrderIterator<'a> {
|
impl<'a> HCPreOrderIterator<'a> {
|
||||||
pub fn new(machine_st: &'a MachineState, a: Addr) -> Self
|
pub fn new(machine_st: &'a MachineState, a: Addr) -> Self
|
||||||
{
|
{
|
||||||
HeapCellPreOrderIterator {
|
HCPreOrderIterator {
|
||||||
machine_st, state_stack: vec![a]
|
machine_st, state_stack: vec![a]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ impl<'a> HeapCellPreOrderIterator<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for HeapCellPreOrderIterator<'a> {
|
impl<'a> Iterator for HCPreOrderIterator<'a> {
|
||||||
type Item = HeapCellValue;
|
type Item = HeapCellValue;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
@@ -72,21 +72,21 @@ impl<'a> Iterator for HeapCellPreOrderIterator<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HeapCellPostOrderIterator<'a> {
|
pub struct HCPostOrderIterator<'a> {
|
||||||
pre_iter: HeapCellPreOrderIterator<'a>,
|
pre_iter: HCPreOrderIterator<'a>,
|
||||||
parent_stack: Vec<(usize, HeapCellValue)> // number of children, parent node.
|
parent_stack: Vec<(usize, HeapCellValue)> // number of children, parent node.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> HeapCellPostOrderIterator<'a> {
|
impl<'a> HCPostOrderIterator<'a> {
|
||||||
pub fn new(pre_iter: HeapCellPreOrderIterator<'a>) -> Self {
|
pub fn new(pre_iter: HCPreOrderIterator<'a>) -> Self {
|
||||||
HeapCellPostOrderIterator {
|
HCPostOrderIterator {
|
||||||
pre_iter,
|
pre_iter,
|
||||||
parent_stack: vec![]
|
parent_stack: vec![]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for HeapCellPostOrderIterator<'a> {
|
impl<'a> Iterator for HCPostOrderIterator<'a> {
|
||||||
type Item = HeapCellValue;
|
type Item = HeapCellValue;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
@@ -117,53 +117,52 @@ impl<'a> Iterator for HeapCellPostOrderIterator<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MachineState {
|
impl MachineState {
|
||||||
pub fn pre_order_iter<'a>(&'a self, a: Addr) -> HeapCellPreOrderIterator<'a> {
|
pub fn pre_order_iter<'a>(&'a self, a: Addr) -> HCPreOrderIterator<'a> {
|
||||||
HeapCellPreOrderIterator::new(self, a)
|
HCPreOrderIterator::new(self, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post_order_iter<'a>(&'a self, a: Addr) -> HeapCellPostOrderIterator<'a> {
|
pub fn post_order_iter<'a>(&'a self, a: Addr) -> HCPostOrderIterator<'a> {
|
||||||
HeapCellPostOrderIterator::new(HeapCellPreOrderIterator::new(self, a))
|
HCPostOrderIterator::new(HCPreOrderIterator::new(self, a))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn acyclic_pre_order_iter<'a>(&'a self, a: Addr)
|
pub fn acyclic_pre_order_iter<'a>(&'a self, a: Addr)
|
||||||
-> HeapCellAcyclicIterator<HeapCellPreOrderIterator<'a>>
|
-> HCAcyclicIterator<HCPreOrderIterator<'a>>
|
||||||
{
|
{
|
||||||
HeapCellAcyclicIterator::new(HeapCellPreOrderIterator::new(self, a))
|
HCAcyclicIterator::new(HCPreOrderIterator::new(self, a))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn zipped_acyclic_pre_order_iter<'a>(&'a self, a1: Addr, a2: Addr)
|
pub fn zipped_acyclic_pre_order_iter<'a>(&'a self, a1: Addr, a2: Addr)
|
||||||
-> HeapCellZippedAcyclicIterator<HeapCellPreOrderIterator<'a>>
|
-> HCZippedAcyclicIterator<HCPreOrderIterator<'a>>
|
||||||
{
|
{
|
||||||
HeapCellZippedAcyclicIterator::new(HeapCellPreOrderIterator::new(self, a1),
|
HCZippedAcyclicIterator::new(HCPreOrderIterator::new(self, a1),
|
||||||
HeapCellPreOrderIterator::new(self, a2))
|
HCPreOrderIterator::new(self, a2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MutStackHeapCellIterator {
|
pub trait MutStackHCIterator {
|
||||||
fn stack(&mut self) -> &mut Vec<Addr>;
|
fn stack(&mut self) -> &mut Vec<Addr>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MutStackHeapCellIterator for HeapCellPreOrderIterator<'a> {
|
impl<'a> MutStackHCIterator for HCPreOrderIterator<'a> {
|
||||||
fn stack(&mut self) -> &mut Vec<Addr> {
|
fn stack(&mut self) -> &mut Vec<Addr> {
|
||||||
&mut self.state_stack
|
&mut self.state_stack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HeapCellAcyclicIterator<HeapCellIter> {
|
pub struct HCAcyclicIterator<HCIter> {
|
||||||
iter: HeapCellIter,
|
iter: HCIter,
|
||||||
seen: HashSet<Addr>
|
seen: HashSet<Addr>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<HeapCellIter: MutStackHeapCellIterator> HeapCellAcyclicIterator<HeapCellIter>
|
impl<HCIter: MutStackHCIterator> HCAcyclicIterator<HCIter>
|
||||||
{
|
{
|
||||||
pub fn new(iter: HeapCellIter) -> Self {
|
pub fn new(iter: HCIter) -> Self {
|
||||||
HeapCellAcyclicIterator { iter, seen: HashSet::new() }
|
HCAcyclicIterator { iter, seen: HashSet::new() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<HeapCellIter> Iterator for HeapCellAcyclicIterator<HeapCellIter>
|
impl<HCIter> Iterator for HCAcyclicIterator<HCIter>
|
||||||
where HeapCellIter: Iterator<Item=HeapCellValue>
|
where HCIter: Iterator<Item=HeapCellValue> + MutStackHCIterator
|
||||||
+ MutStackHeapCellIterator
|
|
||||||
{
|
{
|
||||||
type Item = HeapCellValue;
|
type Item = HeapCellValue;
|
||||||
|
|
||||||
@@ -180,22 +179,21 @@ impl<HeapCellIter> Iterator for HeapCellAcyclicIterator<HeapCellIter>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HeapCellZippedAcyclicIterator<HeapCellIter> {
|
pub struct HCZippedAcyclicIterator<HCIter> {
|
||||||
i1: HeapCellIter,
|
i1: HCIter,
|
||||||
i2: HeapCellIter,
|
i2: HCIter,
|
||||||
seen: HashSet<(Addr, Addr)>
|
seen: HashSet<(Addr, Addr)>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<HeapCellIter: MutStackHeapCellIterator> HeapCellZippedAcyclicIterator<HeapCellIter>
|
impl<HCIter: MutStackHCIterator> HCZippedAcyclicIterator<HCIter>
|
||||||
{
|
{
|
||||||
pub fn new(i1: HeapCellIter, i2: HeapCellIter) -> Self {
|
pub fn new(i1: HCIter, i2: HCIter) -> Self {
|
||||||
HeapCellZippedAcyclicIterator { i1, i2, seen: HashSet::new() }
|
HCZippedAcyclicIterator { i1, i2, seen: HashSet::new() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<HeapCellIter> Iterator for HeapCellZippedAcyclicIterator<HeapCellIter>
|
impl<HCIter> Iterator for HCZippedAcyclicIterator<HCIter>
|
||||||
where HeapCellIter: Iterator<Item=HeapCellValue>
|
where HCIter: Iterator<Item=HeapCellValue> + MutStackHCIterator
|
||||||
+ MutStackHeapCellIterator
|
|
||||||
{
|
{
|
||||||
type Item = (HeapCellValue, HeapCellValue);
|
type Item = (HeapCellValue, HeapCellValue);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub enum TokenOrRedirect {
|
|||||||
Space
|
Space
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HeapCellValueFormatter {
|
pub trait HCValueFormatter {
|
||||||
// this function belongs to the display predicate formatter, which it uses
|
// this function belongs to the display predicate formatter, which it uses
|
||||||
// to format all clauses.
|
// to format all clauses.
|
||||||
fn format_struct(&self, arity: usize, name: ClauseName, state_stack: &mut Vec<TokenOrRedirect>)
|
fn format_struct(&self, arity: usize, name: ClauseName, state_stack: &mut Vec<TokenOrRedirect>)
|
||||||
@@ -40,7 +40,7 @@ pub trait HeapCellValueFormatter {
|
|||||||
fn format_clause(&self, usize, ClauseType, &mut Vec<TokenOrRedirect>);
|
fn format_clause(&self, usize, ClauseType, &mut Vec<TokenOrRedirect>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HeapCellValueOutputter {
|
pub trait HCValueOutputter {
|
||||||
type Output;
|
type Output;
|
||||||
|
|
||||||
fn new() -> Self;
|
fn new() -> Self;
|
||||||
@@ -56,7 +56,7 @@ pub struct PrinterOutputter {
|
|||||||
contents: String
|
contents: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeapCellValueOutputter for PrinterOutputter {
|
impl HCValueOutputter for PrinterOutputter {
|
||||||
type Output = String;
|
type Output = String;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
@@ -93,7 +93,7 @@ impl HeapCellValueOutputter for PrinterOutputter {
|
|||||||
// the 'classic' display corresponding to the display predicate.
|
// the 'classic' display corresponding to the display predicate.
|
||||||
pub struct DisplayFormatter {}
|
pub struct DisplayFormatter {}
|
||||||
|
|
||||||
impl HeapCellValueFormatter for DisplayFormatter {
|
impl HCValueFormatter for DisplayFormatter {
|
||||||
fn format_clause(&self, arity: usize, ct: ClauseType, state_stack: &mut Vec<TokenOrRedirect>)
|
fn format_clause(&self, arity: usize, ct: ClauseType, state_stack: &mut Vec<TokenOrRedirect>)
|
||||||
{
|
{
|
||||||
if ct.fixity().is_some() {
|
if ct.fixity().is_some() {
|
||||||
@@ -110,7 +110,7 @@ impl HeapCellValueFormatter for DisplayFormatter {
|
|||||||
|
|
||||||
pub struct TermFormatter {}
|
pub struct TermFormatter {}
|
||||||
|
|
||||||
impl HeapCellValueFormatter for TermFormatter {
|
impl HCValueFormatter for TermFormatter {
|
||||||
fn format_clause(&self, arity: usize, ct: ClauseType, state_stack: &mut Vec<TokenOrRedirect>)
|
fn format_clause(&self, arity: usize, ct: ClauseType, state_stack: &mut Vec<TokenOrRedirect>)
|
||||||
{
|
{
|
||||||
if let Some(fixity) = ct.fixity() {
|
if let Some(fixity) = ct.fixity() {
|
||||||
@@ -139,20 +139,20 @@ impl HeapCellValueFormatter for TermFormatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HeapCellPrinter<'a, Formatter, Outputter> {
|
pub struct HCPrinter<'a, Formatter, Outputter> {
|
||||||
formatter: Formatter,
|
formatter: Formatter,
|
||||||
outputter: Outputter,
|
outputter: Outputter,
|
||||||
iter: HeapCellPreOrderIterator<'a>,
|
iter: HCPreOrderIterator<'a>,
|
||||||
state_stack: Vec<TokenOrRedirect>
|
state_stack: Vec<TokenOrRedirect>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Formatter: HeapCellValueFormatter, Outputter: HeapCellValueOutputter>
|
impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
|
||||||
HeapCellPrinter<'a, Formatter, Outputter>
|
HCPrinter<'a, Formatter, Outputter>
|
||||||
{
|
{
|
||||||
pub fn new(iter: HeapCellPreOrderIterator<'a>, formatter: Formatter, outputter: Outputter)
|
pub fn new(iter: HCPreOrderIterator<'a>, formatter: Formatter, outputter: Outputter)
|
||||||
-> Self
|
-> Self
|
||||||
{
|
{
|
||||||
HeapCellPrinter { formatter, outputter, iter, state_stack: vec![] }
|
HCPrinter { formatter, outputter, iter, state_stack: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_heap_term(&mut self, heap_val: HeapCellValue) {
|
fn handle_heap_term(&mut self, heap_val: HeapCellValue) {
|
||||||
|
|||||||
@@ -94,10 +94,10 @@ impl MachineState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn print_term<Fmt, Outputter>(&self, a: Addr, fmt: Fmt, output: Outputter) -> Outputter
|
pub(super) fn print_term<Fmt, Outputter>(&self, a: Addr, fmt: Fmt, output: Outputter) -> Outputter
|
||||||
where Fmt: HeapCellValueFormatter, Outputter: HeapCellValueOutputter
|
where Fmt: HCValueFormatter, Outputter: HCValueOutputter
|
||||||
{
|
{
|
||||||
let iter = HeapCellPreOrderIterator::new(&self, a);
|
let iter = HCPreOrderIterator::new(&self, a);
|
||||||
let printer = HeapCellPrinter::new(iter, fmt, output);
|
let printer = HCPrinter::new(iter, fmt, output);
|
||||||
|
|
||||||
printer.print()
|
printer.print()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn heap_view<Outputter>(&self, var_dir: &HeapVarDict, mut output: Outputter) -> Outputter
|
pub fn heap_view<Outputter>(&self, var_dir: &HeapVarDict, mut output: Outputter) -> Outputter
|
||||||
where Outputter: HeapCellValueOutputter
|
where Outputter: HCValueOutputter
|
||||||
{
|
{
|
||||||
for (var, addr) in var_dir {
|
for (var, addr) in var_dir {
|
||||||
output.begin_new_var();
|
output.begin_new_var();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ impl TestOutputter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeapCellValueOutputter for TestOutputter {
|
impl HCValueOutputter for TestOutputter {
|
||||||
type Output = Vec<HashSet<String>>;
|
type Output = Vec<HashSet<String>>;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user