From: Mark Thom Date: Sat, 5 May 2018 01:43:43 +0000 (-0600) Subject: abbreviate names in heap_iter.rs X-Git-Tag: v0.8.110~473 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=2df82e6b01e759f1b49d1fee7e44a1f460076a56;p=scryer-prolog.git abbreviate names in heap_iter.rs --- diff --git a/src/prolog/heap_iter.rs b/src/prolog/heap_iter.rs index a070dfdf..367daace 100644 --- a/src/prolog/heap_iter.rs +++ b/src/prolog/heap_iter.rs @@ -4,15 +4,15 @@ use prolog::machine::machine_state::MachineState; use std::collections::HashSet; use std::vec::Vec; -pub struct HeapCellPreOrderIterator<'a> { +pub struct HCPreOrderIterator<'a> { machine_st: &'a MachineState, state_stack: Vec } -impl<'a> HeapCellPreOrderIterator<'a> { +impl<'a> HCPreOrderIterator<'a> { pub fn new(machine_st: &'a MachineState, a: Addr) -> Self { - HeapCellPreOrderIterator { + HCPreOrderIterator { 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; fn next(&mut self) -> Option { @@ -72,21 +72,21 @@ impl<'a> Iterator for HeapCellPreOrderIterator<'a> { } } -pub struct HeapCellPostOrderIterator<'a> { - pre_iter: HeapCellPreOrderIterator<'a>, +pub struct HCPostOrderIterator<'a> { + pre_iter: HCPreOrderIterator<'a>, parent_stack: Vec<(usize, HeapCellValue)> // number of children, parent node. } -impl<'a> HeapCellPostOrderIterator<'a> { - pub fn new(pre_iter: HeapCellPreOrderIterator<'a>) -> Self { - HeapCellPostOrderIterator { +impl<'a> HCPostOrderIterator<'a> { + pub fn new(pre_iter: HCPreOrderIterator<'a>) -> Self { + HCPostOrderIterator { pre_iter, parent_stack: vec![] } } } -impl<'a> Iterator for HeapCellPostOrderIterator<'a> { +impl<'a> Iterator for HCPostOrderIterator<'a> { type Item = HeapCellValue; fn next(&mut self) -> Option { @@ -117,53 +117,52 @@ impl<'a> Iterator for HeapCellPostOrderIterator<'a> { } impl MachineState { - pub fn pre_order_iter<'a>(&'a self, a: Addr) -> HeapCellPreOrderIterator<'a> { - HeapCellPreOrderIterator::new(self, a) + pub fn pre_order_iter<'a>(&'a self, a: Addr) -> HCPreOrderIterator<'a> { + HCPreOrderIterator::new(self, a) } - pub fn post_order_iter<'a>(&'a self, a: Addr) -> HeapCellPostOrderIterator<'a> { - HeapCellPostOrderIterator::new(HeapCellPreOrderIterator::new(self, a)) + pub fn post_order_iter<'a>(&'a self, a: Addr) -> HCPostOrderIterator<'a> { + HCPostOrderIterator::new(HCPreOrderIterator::new(self, a)) } pub fn acyclic_pre_order_iter<'a>(&'a self, a: Addr) - -> HeapCellAcyclicIterator> + -> HCAcyclicIterator> { - 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) - -> HeapCellZippedAcyclicIterator> + -> HCZippedAcyclicIterator> { - HeapCellZippedAcyclicIterator::new(HeapCellPreOrderIterator::new(self, a1), - HeapCellPreOrderIterator::new(self, a2)) + HCZippedAcyclicIterator::new(HCPreOrderIterator::new(self, a1), + HCPreOrderIterator::new(self, a2)) } } -pub trait MutStackHeapCellIterator { +pub trait MutStackHCIterator { fn stack(&mut self) -> &mut Vec; } -impl<'a> MutStackHeapCellIterator for HeapCellPreOrderIterator<'a> { +impl<'a> MutStackHCIterator for HCPreOrderIterator<'a> { fn stack(&mut self) -> &mut Vec { &mut self.state_stack } } -pub struct HeapCellAcyclicIterator { - iter: HeapCellIter, +pub struct HCAcyclicIterator { + iter: HCIter, seen: HashSet } -impl HeapCellAcyclicIterator +impl HCAcyclicIterator { - pub fn new(iter: HeapCellIter) -> Self { - HeapCellAcyclicIterator { iter, seen: HashSet::new() } + pub fn new(iter: HCIter) -> Self { + HCAcyclicIterator { iter, seen: HashSet::new() } } } -impl Iterator for HeapCellAcyclicIterator - where HeapCellIter: Iterator - + MutStackHeapCellIterator +impl Iterator for HCAcyclicIterator +where HCIter: Iterator + MutStackHCIterator { type Item = HeapCellValue; @@ -180,22 +179,21 @@ impl Iterator for HeapCellAcyclicIterator } } -pub struct HeapCellZippedAcyclicIterator { - i1: HeapCellIter, - i2: HeapCellIter, +pub struct HCZippedAcyclicIterator { + i1: HCIter, + i2: HCIter, seen: HashSet<(Addr, Addr)> } -impl HeapCellZippedAcyclicIterator +impl HCZippedAcyclicIterator { - pub fn new(i1: HeapCellIter, i2: HeapCellIter) -> Self { - HeapCellZippedAcyclicIterator { i1, i2, seen: HashSet::new() } + pub fn new(i1: HCIter, i2: HCIter) -> Self { + HCZippedAcyclicIterator { i1, i2, seen: HashSet::new() } } } -impl Iterator for HeapCellZippedAcyclicIterator - where HeapCellIter: Iterator - + MutStackHeapCellIterator +impl Iterator for HCZippedAcyclicIterator +where HCIter: Iterator + MutStackHCIterator { type Item = (HeapCellValue, HeapCellValue); diff --git a/src/prolog/heap_print.rs b/src/prolog/heap_print.rs index 0bc8b0d9..f901a5e4 100644 --- a/src/prolog/heap_print.rs +++ b/src/prolog/heap_print.rs @@ -17,7 +17,7 @@ pub enum TokenOrRedirect { Space } -pub trait HeapCellValueFormatter { +pub trait HCValueFormatter { // this function belongs to the display predicate formatter, which it uses // to format all clauses. fn format_struct(&self, arity: usize, name: ClauseName, state_stack: &mut Vec) @@ -40,7 +40,7 @@ pub trait HeapCellValueFormatter { fn format_clause(&self, usize, ClauseType, &mut Vec); } -pub trait HeapCellValueOutputter { +pub trait HCValueOutputter { type Output; fn new() -> Self; @@ -56,7 +56,7 @@ pub struct PrinterOutputter { contents: String } -impl HeapCellValueOutputter for PrinterOutputter { +impl HCValueOutputter for PrinterOutputter { type Output = String; fn new() -> Self { @@ -93,7 +93,7 @@ impl HeapCellValueOutputter for PrinterOutputter { // the 'classic' display corresponding to the display predicate. pub struct DisplayFormatter {} -impl HeapCellValueFormatter for DisplayFormatter { +impl HCValueFormatter for DisplayFormatter { fn format_clause(&self, arity: usize, ct: ClauseType, state_stack: &mut Vec) { if ct.fixity().is_some() { @@ -110,7 +110,7 @@ impl HeapCellValueFormatter for DisplayFormatter { pub struct TermFormatter {} -impl HeapCellValueFormatter for TermFormatter { +impl HCValueFormatter for TermFormatter { fn format_clause(&self, arity: usize, ct: ClauseType, state_stack: &mut Vec) { 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, outputter: Outputter, - iter: HeapCellPreOrderIterator<'a>, + iter: HCPreOrderIterator<'a>, state_stack: Vec } -impl<'a, Formatter: HeapCellValueFormatter, Outputter: HeapCellValueOutputter> - HeapCellPrinter<'a, Formatter, Outputter> +impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter> + 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 { - HeapCellPrinter { formatter, outputter, iter, state_stack: vec![] } + HCPrinter { formatter, outputter, iter, state_stack: vec![] } } fn handle_heap_term(&mut self, heap_val: HeapCellValue) { diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index 7c631654..e425d2b0 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -94,10 +94,10 @@ impl MachineState { } pub(super) fn print_term(&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 printer = HeapCellPrinter::new(iter, fmt, output); + let iter = HCPreOrderIterator::new(&self, a); + let printer = HCPrinter::new(iter, fmt, output); printer.print() } diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index ad07beb1..fa19f6e5 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -424,7 +424,7 @@ impl Machine { } pub fn heap_view(&self, var_dir: &HeapVarDict, mut output: Outputter) -> Outputter - where Outputter: HeapCellValueOutputter + where Outputter: HCValueOutputter { for (var, addr) in var_dir { output.begin_new_var(); diff --git a/src/tests.rs b/src/tests.rs index 1b177d90..5b94ddb4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -23,7 +23,7 @@ impl TestOutputter { } } -impl HeapCellValueOutputter for TestOutputter { +impl HCValueOutputter for TestOutputter { type Output = Vec>; fn new() -> Self {