Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the Debug trait for all data structures #399

Merged
merged 1 commit into from Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ libc = "0.2.62"
nix = "0.15.0"
num-rug-adapter = { optional = true, version = "0.1.3" }
ordered-float = "0.5.0"
prolog_parser = { version = "0.8.53", default-features = false }
prolog_parser = { version = "0.8.54", default-features = false }
ref_thread_local = "0.0.0"
rug = { version = "1.4.0", optional = true }
rustyline = "6.0.0"
Expand Down
3 changes: 3 additions & 0 deletions src/prolog/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::ops::{Add, Div, Mul, Neg, Sub};
use std::rc::Rc;
use std::vec::Vec;

#[derive(Debug)]
pub struct ArithInstructionIterator<'a> {
state_stack: Vec<TermIterState<'a>>,
}
Expand Down Expand Up @@ -68,6 +69,7 @@ impl<'a> ArithInstructionIterator<'a> {
}
}

#[derive(Debug)]
pub enum ArithTermRef<'a> {
Constant(&'a Constant),
Op(ClauseName, usize), // name, arity.
Expand Down Expand Up @@ -109,6 +111,7 @@ impl<'a> Iterator for ArithInstructionIterator<'a> {
}
}

#[derive(Debug)]
pub struct ArithmeticEvaluator<'a> {
bindings: &'a AllocVarDict,
interm: Vec<ArithmeticTerm>,
Expand Down
14 changes: 7 additions & 7 deletions src/prolog/clause_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ref_thread_local::RefThreadLocal;

use std::collections::BTreeMap;

#[derive(Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum CompareNumberQT {
GreaterThan,
LessThan,
Expand All @@ -31,7 +31,7 @@ impl CompareNumberQT {
}
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompareTermQT {
LessThan,
LessThanOrEqual,
Expand All @@ -50,7 +50,7 @@ impl CompareTermQT {
}
}

#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ArithmeticTerm {
Reg(RegType),
Interm(usize),
Expand All @@ -67,7 +67,7 @@ impl ArithmeticTerm {
}
}

#[derive(Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum InlinedClauseType {
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
IsAtom(RegType),
Expand Down Expand Up @@ -145,7 +145,7 @@ impl InlinedClauseType {
}
}

#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum SystemClauseType {
AbolishClause,
AbolishModuleClause,
Expand Down Expand Up @@ -557,7 +557,7 @@ impl SystemClauseType {
}
}

#[derive(Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BuiltInClauseType {
AcyclicTerm,
Arg,
Expand All @@ -575,7 +575,7 @@ pub enum BuiltInClauseType {
Sort,
}

#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ClauseType {
BuiltIn(BuiltInClauseType),
CallN,
Expand Down
2 changes: 2 additions & 0 deletions src/prolog/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ use std::cell::Cell;
use std::rc::Rc;
use std::vec::Vec;

#[derive(Debug)]
pub struct CodeGenerator<TermMarker> {
marker: TermMarker,
pub var_count: IndexMap<Rc<Var>, usize>,
non_counted_bt: bool,
}

#[derive(Debug)]
pub struct ConjunctInfo<'a> {
pub perm_vs: VariableFixtures<'a>,
pub num_of_chunks: usize,
Expand Down
1 change: 1 addition & 0 deletions src/prolog/debray_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::cell::Cell;
use std::collections::BTreeSet;
use std::rc::Rc;

#[derive(Debug)]
pub struct DebrayAllocator {
bindings: IndexMap<Rc<Var>, VarData>,
arg_c: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/prolog/examples/least_time.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
memberd_t(H2, [0,1,2,3,4,5,6,7,8,9], TH2),
memberd_t(M1, [0,1,2,3,4,5], TM1),
memberd_t(M2, [0,1,2,3,4,5,6,7,8,9], TM2),
( maplist(=(true), [TH1, TH2, TM1, TM2]) ->
( maplist(=(true), [TH1, TH2, TM1, TM2]) ->
( H1 =:= 2 ->
( H2 =< 3 ->
T = true
Expand Down
5 changes: 5 additions & 0 deletions src/prolog/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::rc::Rc;
use std::vec::Vec;

// labeled with chunk numbers.
#[derive(Debug)]
pub enum VarStatus {
Perm(usize),
Temp(usize, TempVarData), // Perm(chunk_num) | Temp(chunk_num, _)
Expand All @@ -22,6 +23,7 @@ pub type OccurrenceSet = BTreeSet<(GenContext, usize)>;

// Perm: 0 initially, a stack register once processed.
// Temp: labeled with chunk_num and temp offset (unassigned if 0).
#[derive(Debug)]
pub enum VarData {
Perm(usize),
Temp(usize, usize, TempVarData),
Expand All @@ -36,6 +38,7 @@ impl VarData {
}
}

#[derive(Debug)]
pub struct TempVarData {
pub last_term_arity: usize,
pub use_set: OccurrenceSet,
Expand Down Expand Up @@ -79,6 +82,7 @@ impl TempVarData {

type VariableFixture<'a> = (VarStatus, Vec<&'a Cell<VarReg>>);

#[derive(Debug)]
pub struct VariableFixtures<'a>{
perm_vars: IndexMap<Rc<Var>, VariableFixture<'a>>,
last_chunk_temp_vars: IndexSet<Rc<Var>>
Expand Down Expand Up @@ -248,6 +252,7 @@ impl<'a> VariableFixtures<'a> {
}
}

#[derive(Debug)]
pub struct UnsafeVarMarker {
pub unsafe_vars: IndexMap<RegType, usize>,
pub safe_vars: IndexSet<RegType>,
Expand Down
29 changes: 15 additions & 14 deletions src/prolog/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub type PredicateKey = (ClauseName, usize); // name, arity.
// of vars (we get their adjoining cells this way).
pub type JumpStub = Vec<Term>;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum TopLevel {
Declaration(Declaration),
Fact(Term, usize, usize), // Term, line_num, col_num
Expand All @@ -42,7 +42,7 @@ impl TopLevel {
}
}

#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum Level {
Deep,
Root,
Expand All @@ -58,7 +58,7 @@ impl Level {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum QueryTerm {
// register, clause type, subterms, use default call policy.
Clause(Cell<RegType>, ClauseType, Vec<Box<Term>>, bool),
Expand Down Expand Up @@ -86,13 +86,13 @@ impl QueryTerm {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Rule {
pub head: (ClauseName, Vec<Box<Term>>, QueryTerm),
pub clauses: Vec<QueryTerm>,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Predicate(pub Vec<PredicateClause>);

impl Predicate {
Expand All @@ -114,7 +114,7 @@ impl Predicate {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum ListingSource {
File(ClauseName, PathBuf), // filename, path
User,
Expand Down Expand Up @@ -326,7 +326,7 @@ impl ClauseConsistency for Predicate {

pub type CompiledResult = (Predicate, VecDeque<TopLevel>);

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum PredicateClause {
Fact(Term, usize, usize), // Term, line number, column number.
Rule(Rule, usize, usize), // Term, line number, column number.
Expand Down Expand Up @@ -371,7 +371,7 @@ impl PredicateClause {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum ModuleSource {
Library(ClauseName),
File(ClauseName),
Expand All @@ -392,13 +392,13 @@ impl ModuleSource {

pub type ScopedPredicateKey = (ClauseName, PredicateKey); // module name, predicate indicator.

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum MultiFileIndicator {
LocalScoped(ClauseName, usize), // name, arity
ModuleScoped(ScopedPredicateKey),
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum Declaration {
Dynamic(ClauseName, usize), // name, arity
EndOfFile,
Expand Down Expand Up @@ -433,7 +433,7 @@ impl Declaration {
}
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct OpDecl(pub usize, pub Specifier, pub ClauseName);

impl OpDecl {
Expand Down Expand Up @@ -558,18 +558,19 @@ pub fn fetch_op_spec(

pub type ModuleDir = IndexMap<ClauseName, Module>;

#[derive(Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub enum ModuleExport {
OpDecl(OpDecl),
PredicateKey(PredicateKey),
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct ModuleDecl {
pub name: ClauseName,
pub exports: Vec<ModuleExport>,
}

#[derive(Debug)]
pub struct Module {
pub atom_tbl: TabledData<Atom>,
pub module_decl: ModuleDecl,
Expand All @@ -587,7 +588,7 @@ pub struct Module {
pub listing_src: ListingSource,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum Number {
Float(OrderedFloat<f64>),
Integer(Rc<Integer>),
Expand Down
4 changes: 4 additions & 0 deletions src/prolog/heap_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::cmp::Ordering;
use std::ops::Deref;
use std::vec::Vec;

#[derive(Debug)]
pub struct HCPreOrderIterator<'a> {
pub machine_st: &'a MachineState,
pub state_stack: Vec<Addr>,
Expand Down Expand Up @@ -127,6 +128,7 @@ pub trait MutStackHCIterator<'b> where Self: Iterator
fn stack(&'b mut self) -> Self::MutStack;
}

#[derive(Debug)]
pub struct HCPostOrderIterator<'a> {
base_iter: HCPreOrderIterator<'a>,
parent_stack: Vec<(usize, Addr)>, // number of children, parent node.
Expand Down Expand Up @@ -229,6 +231,7 @@ impl<'b, 'a: 'b> MutStackHCIterator<'b> for HCPreOrderIterator<'a> {
}
}

#[derive(Debug)]
pub struct HCAcyclicIterator<'a> {
iter: HCPreOrderIterator<'a>,
seen: IndexSet<Addr>,
Expand Down Expand Up @@ -269,6 +272,7 @@ impl<'a> Iterator for HCAcyclicIterator<'a>
}
}

#[derive(Debug)]
pub struct HCZippedAcyclicIterator<'a> {
i1: HCPreOrderIterator<'a>,
i2: HCPreOrderIterator<'a>,
Expand Down
6 changes: 4 additions & 2 deletions src/prolog/heap_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::ops::{Range, RangeFrom};
use std::rc::Rc;

/* contains the location, name, precision and Specifier of the parent op. */
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum DirectedOp {
Left(ClauseName, SharedOpDesc),
Right(ClauseName, SharedOpDesc),
Expand Down Expand Up @@ -162,7 +162,7 @@ fn char_to_string(is_quoted: bool, c: char) -> String {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
enum TokenOrRedirect {
Atom(ClauseName),
BarAsOp,
Expand Down Expand Up @@ -197,6 +197,7 @@ pub trait HCValueOutputter {
fn range_from(&self, range: RangeFrom<usize>) -> &str;
}

#[derive(Debug)]
pub struct PrinterOutputter {
contents: String,
}
Expand Down Expand Up @@ -335,6 +336,7 @@ impl MachineState {

type ReverseHeapVarDict = IndexMap<Addr, Rc<Var>>;

#[derive(Debug)]
pub struct HCPrinter<'a, Outputter> {
outputter: Outputter,
machine_st: &'a MachineState,
Expand Down
Loading