Implemented the Debug trait for all data structures

This commit is contained in:
notoria
2020-04-26 02:18:45 +02:00
parent ae9232a2cb
commit c98e869564
33 changed files with 198 additions and 67 deletions

View File

@@ -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"

View File

@@ -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>>,
}
@@ -68,6 +69,7 @@ impl<'a> ArithInstructionIterator<'a> {
}
}
#[derive(Debug)]
pub enum ArithTermRef<'a> {
Constant(&'a Constant),
Op(ClauseName, usize), // name, arity.
@@ -109,6 +111,7 @@ impl<'a> Iterator for ArithInstructionIterator<'a> {
}
}
#[derive(Debug)]
pub struct ArithmeticEvaluator<'a> {
bindings: &'a AllocVarDict,
interm: Vec<ArithmeticTerm>,

View File

@@ -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,
@@ -31,7 +31,7 @@ impl CompareNumberQT {
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompareTermQT {
LessThan,
LessThanOrEqual,
@@ -50,7 +50,7 @@ impl CompareTermQT {
}
}
#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ArithmeticTerm {
Reg(RegType),
Interm(usize),
@@ -67,7 +67,7 @@ impl ArithmeticTerm {
}
}
#[derive(Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum InlinedClauseType {
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
IsAtom(RegType),
@@ -145,7 +145,7 @@ impl InlinedClauseType {
}
}
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum SystemClauseType {
AbolishClause,
AbolishModuleClause,
@@ -557,7 +557,7 @@ impl SystemClauseType {
}
}
#[derive(Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BuiltInClauseType {
AcyclicTerm,
Arg,
@@ -575,7 +575,7 @@ pub enum BuiltInClauseType {
Sort,
}
#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ClauseType {
BuiltIn(BuiltInClauseType),
CallN,

View File

@@ -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,

View File

@@ -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,

View File

@@ -30,7 +30,7 @@ valid_time([H1,H2,M1,M2], T) :-
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

View File

@@ -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, _)
@@ -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),
@@ -36,6 +38,7 @@ impl VarData {
}
}
#[derive(Debug)]
pub struct TempVarData {
pub last_term_arity: usize,
pub use_set: OccurrenceSet,
@@ -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>>
@@ -248,6 +252,7 @@ impl<'a> VariableFixtures<'a> {
}
}
#[derive(Debug)]
pub struct UnsafeVarMarker {
pub unsafe_vars: IndexMap<RegType, usize>,
pub safe_vars: IndexSet<RegType>,

View File

@@ -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
@@ -42,7 +42,7 @@ impl TopLevel {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum Level {
Deep,
Root,
@@ -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),
@@ -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 {
@@ -114,7 +114,7 @@ impl Predicate {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum ListingSource {
File(ClauseName, PathBuf), // filename, path
User,
@@ -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.
@@ -371,7 +371,7 @@ impl PredicateClause {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum ModuleSource {
Library(ClauseName),
File(ClauseName),
@@ -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,
@@ -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 {
@@ -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,
@@ -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>),

View File

@@ -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>,
@@ -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.
@@ -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>,
@@ -269,6 +272,7 @@ impl<'a> Iterator for HCAcyclicIterator<'a>
}
}
#[derive(Debug)]
pub struct HCZippedAcyclicIterator<'a> {
i1: HCPreOrderIterator<'a>,
i2: HCPreOrderIterator<'a>,

View File

@@ -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),
@@ -162,7 +162,7 @@ fn char_to_string(is_quoted: bool, c: char) -> String {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
enum TokenOrRedirect {
Atom(ClauseName),
BarAsOp,
@@ -197,6 +197,7 @@ pub trait HCValueOutputter {
fn range_from(&self, range: RangeFrom<usize>) -> &str;
}
#[derive(Debug)]
pub struct PrinterOutputter {
contents: String,
}
@@ -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,

View File

@@ -45,6 +45,7 @@ impl ArithmeticTerm {
}
}
#[derive(Debug)]
pub enum ChoiceInstruction {
DefaultRetryMeElse(usize),
DefaultTrustMe,
@@ -75,6 +76,7 @@ impl ChoiceInstruction {
}
}
#[derive(Debug)]
pub enum CutInstruction {
Cut(RegType),
GetLevel(RegType),
@@ -104,6 +106,7 @@ impl CutInstruction {
}
}
#[derive(Debug)]
pub enum IndexedChoiceInstruction {
Retry(usize),
Trust(usize),
@@ -140,6 +143,7 @@ impl IndexedChoiceInstruction {
}
}
#[derive(Debug)]
pub enum Line {
Arithmetic(ArithmeticInstruction),
Choice(ChoiceInstruction),
@@ -175,7 +179,7 @@ impl Line {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum ArithmeticInstruction {
Add(ArithmeticTerm, ArithmeticTerm, usize),
Sub(ArithmeticTerm, ArithmeticTerm, usize),
@@ -374,6 +378,7 @@ impl ArithmeticInstruction {
}
}
#[derive(Debug)]
pub enum ControlInstruction {
Allocate(usize), // num_frames.
// name, arity, perm_vars after threshold, last call, use default call policy.
@@ -419,6 +424,7 @@ impl ControlInstruction {
}
}
#[derive(Debug)]
pub enum IndexingInstruction {
SwitchOnTerm(usize, usize, usize, usize),
SwitchOnConstant(usize, IndexMap<Constant, usize>),
@@ -459,7 +465,7 @@ impl IndexingInstruction {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum FactInstruction {
GetConstant(Level, Constant, RegType),
GetList(Level, RegType),
@@ -571,7 +577,7 @@ impl FactInstruction {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum QueryInstruction {
GetVariable(RegType, usize),
PutConstant(Level, Constant, RegType),

View File

@@ -6,11 +6,12 @@ use crate::prolog::machine::machine_indices::*;
use std::cell::Cell;
use std::collections::VecDeque;
use std::fmt;
use std::iter::*;
use std::rc::Rc;
use std::vec::Vec;
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum TermRef<'a> {
AnonVar(Level),
Cons(Level, &'a Cell<RegType>, &'a Term, &'a Term),
@@ -33,6 +34,7 @@ impl<'a> TermRef<'a> {
}
}
#[derive(Debug)]
pub enum TermIterState<'a> {
AnonVar(Level),
Constant(Level, &'a Cell<RegType>, &'a Constant),
@@ -124,6 +126,7 @@ impl<'a> TermIterState<'a> {
}
}
#[derive(Debug)]
pub struct QueryIterator<'a> {
state_stack: Vec<TermIterState<'a>>,
}
@@ -294,6 +297,7 @@ impl<'a> Iterator for QueryIterator<'a> {
}
}
#[derive(Debug)]
pub struct FactIterator<'a> {
state_queue: VecDeque<TermIterState<'a>>,
iterable_root: bool,
@@ -402,6 +406,7 @@ pub fn breadth_first_iter(term: &Term, iterable_root: bool) -> FactIterator {
FactIterator::new(term, iterable_root)
}
#[derive(Debug)]
pub enum ChunkedTerm<'a> {
HeadClause(ClauseName, &'a Vec<Box<Term>>),
BodyTerm(&'a QueryTerm),
@@ -439,6 +444,18 @@ pub struct ChunkedIterator<'a> {
cut_var_in_head: bool,
}
impl<'a> fmt::Debug for ChunkedIterator<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("ChunkedIterator")
.field("chunk_num", &self.chunk_num)
// Hacky solution.
.field("iter", &"Box<dyn Iterator<Item = ChunkedTerm<'a>> + 'a>")
.field("deep_cut_encountered", &self.deep_cut_encountered)
.field("cut_var_in_head", &self.cut_var_in_head)
.finish()
}
}
type ChunkedIteratorItem<'a> = (usize, usize, Vec<ChunkedTerm<'a>>);
type RuleBodyIteratorItem<'a> = (usize, usize, Vec<&'a QueryTerm>);

View File

@@ -9,7 +9,7 @@ between(Lower, Upper, X) :-
must_be(integer, Lower),
must_be(integer, Upper),
can_be(integer, X),
between_(Lower, Upper, X).
between_(Lower, Upper, X).
between_(Lower, Upper, Lower) :-
Lower =< Upper.

View File

@@ -291,7 +291,7 @@ wkl_add_to_existing_answer_cluster(Worklist, Answer) :-
wkl_add_to_new_answer_cluster(
wkl_worklist(Dll,_Ria,_FlagExecutingWork,_AlreadyInMetaworklist,_TableIdentifier),
Answer,AnswerClusterPointer
) :-
) :-
dll_append_left(Dll,wkl_answer_cluster(AnswerFlag),AnswerClusterPointer),
put_atts(AnswerFlag, wkl_answer_cluster([Answer])).

View File

@@ -8,6 +8,7 @@ pub static PROJECT_ATTRS: &str = include_str!("project_attributes.pl");
pub(super) type Bindings = Vec<(usize, Addr)>;
#[derive(Debug)]
pub(super) struct AttrVarInitializer {
pub(super) attribute_goals: Vec<Addr>,
pub(super) attr_var_queue: Vec<usize>,

View File

@@ -12,6 +12,7 @@ use indexmap::IndexSet;
use std::collections::VecDeque;
use std::mem;
#[derive(Debug)]
pub struct CodeRepo {
pub(super) cached_query: Code,
pub(super) goal_expanders: Code,

View File

@@ -409,6 +409,7 @@ fn compile_into_module_impl(
Ok(compiler.drop_expansions(&mut wam.code_repo))
}
#[derive(Debug)]
pub struct GatherResult {
dynamic_clause_map: DynamicClauseMap,
pub(crate) worker_results: Vec<PredicateCompileQueue>,
@@ -423,6 +424,7 @@ pub struct GatherResult {
in_situ_module_dir: ModuleStubDir,
}
#[derive(Debug)]
pub struct ClauseCodeGenerator {
len_offset: usize,
code: Code,
@@ -529,6 +531,7 @@ fn insert_or_refresh_term_dir_quantum(
}
}
#[derive(Debug)]
pub struct ListingCompiler {
module: Option<Module>,
user_term_dir: TermDir,

View File

@@ -7,7 +7,7 @@ use std::ops::IndexMut;
type Trail = Vec<(Ref, HeapCellValue)>;
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum AttrVarPolicy {
DeepCopy,
StripAttributes
@@ -28,6 +28,7 @@ fn copy_term<T: CopierTarget>(target: T, addr: Addr, attr_var_policy: AttrVarPol
copy_term_state.copy_term_impl(addr);
}
#[derive(Debug)]
struct CopyTermState<T: CopierTarget> {
trail: Trail,
scan: usize,

View File

@@ -11,6 +11,7 @@ use std::mem;
use std::ops::{Index, IndexMut};
use std::ptr;
#[derive(Debug)]
pub(crate) struct StandardHeapTraits {}
impl RawBlockTraits for StandardHeapTraits {
@@ -25,6 +26,7 @@ impl RawBlockTraits for StandardHeapTraits {
}
}
#[derive(Debug)]
pub(crate) struct HeapTemplate<T: RawBlockTraits> {
buf: RawBlock<T>,
_marker: PhantomData<HeapCellValue>,
@@ -39,6 +41,7 @@ impl<T: RawBlockTraits> Drop for HeapTemplate<T> {
}
}
#[derive(Debug)]
pub(crate)
struct HeapIntoIter<T: RawBlockTraits> {
offset: usize,
@@ -72,6 +75,7 @@ impl<T: RawBlockTraits> Iterator for HeapIntoIter<T> {
}
}
#[derive(Debug)]
pub(crate)
struct HeapIter<'a, T: RawBlockTraits> {
offset: usize,
@@ -110,6 +114,7 @@ fn print_heap_terms<'a, I: Iterator<Item = &'a HeapCellValue>>(heap: I, h: usize
}
}
#[derive(Debug)]
pub(crate)
struct HeapIterMut<'a, T: RawBlockTraits> {
offset: usize,

View File

@@ -10,12 +10,13 @@ use std::rc::Rc;
pub(crate) type MachineStub = Vec<HeapCellValue>;
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
enum ErrorProvenance {
Constructed, // if constructed, offset the addresses.
Received, // otherwise, preserve the addresses.
}
#[derive(Debug)]
pub(super) struct MachineError {
stub: MachineStub,
location: Option<(usize, usize)>, // line_num, col_num
@@ -447,7 +448,7 @@ impl MachineError {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum Permission {
Access,
Create,
@@ -469,7 +470,7 @@ impl Permission {
}
// from 7.12.2 b) of 13211-1:1995
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum ValidType {
Atom,
Atomic,
@@ -514,7 +515,7 @@ impl ValidType {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum DomainErrorType {
NotLessThanZero,
Order,
@@ -534,7 +535,7 @@ impl DomainErrorType {
}
// from 7.12.2 f) of 13211-1:1995
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum RepFlag {
Character,
CharacterCode,
@@ -558,7 +559,7 @@ impl RepFlag {
}
// from 7.12.2 g) of 13211-1:1995
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum EvalError {
FloatOverflow,
Undefined,
@@ -578,7 +579,7 @@ impl EvalError {
}
// used by '$skip_max_list'.
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub(super) enum CycleSearchResult {
EmptyList,
NotList,
@@ -722,6 +723,7 @@ impl MachineState {
}
}
#[derive(Debug)]
pub enum ExistenceError {
Module(ClauseName),
Procedure(ClauseName, usize),
@@ -729,6 +731,7 @@ pub enum ExistenceError {
Stream(Addr),
}
#[derive(Debug)]
pub enum SessionError {
CannotOverwriteBuiltIn(ClauseName),
CannotOverwriteImport(ClauseName),
@@ -741,6 +744,7 @@ pub enum SessionError {
ParserError(ParserError),
}
#[derive(Debug)]
pub enum EvalSession {
EntrySuccess,
Error(SessionError),

View File

@@ -21,16 +21,17 @@ use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::{BTreeMap, VecDeque};
use std::convert::TryFrom;
use std::fmt;
use std::mem;
use std::ops::{Add, AddAssign, Sub, SubAssign};
use std::rc::Rc;
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct OrderedOpDirKey(pub ClauseName, pub Fixity);
pub type OssifiedOpDir = BTreeMap<OrderedOpDirKey, (usize, Specifier)>;
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DBRef {
NamedPred(ClauseName, usize, Option<SharedOpDesc>),
Op(
@@ -43,7 +44,7 @@ pub enum DBRef {
}
// 7.2
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum TermOrderCategory {
Variable,
FloatingPoint,
@@ -52,7 +53,7 @@ pub enum TermOrderCategory {
Compound,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Addr {
AttrVar(usize),
Char(char),
@@ -71,7 +72,7 @@ pub enum Addr {
Usize(usize),
}
#[derive(Clone, Copy, Hash, Eq, PartialEq, PartialOrd)]
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, PartialOrd)]
pub enum Ref {
AttrVar(usize),
HeapCell(usize),
@@ -361,7 +362,7 @@ impl SubAssign<usize> for Addr {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum TrailRef {
Ref(Ref),
AttrVarHeapLink(usize),
@@ -374,6 +375,7 @@ impl From<Ref> for TrailRef {
}
}
#[derive(Debug)]
pub enum HeapCellValue {
Addr(Addr),
Atom(ClauseName, Option<SharedOpDesc>),
@@ -446,7 +448,7 @@ impl From<Addr> for HeapCellValue {
}
}
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
pub enum IndexPtr {
DynamicUndefined, // a predicate, declared as dynamic, whose location in code is as yet undefined.
Undefined,
@@ -456,7 +458,7 @@ pub enum IndexPtr {
UserTermExpansion
}
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct CodeIndex(pub Rc<RefCell<(IndexPtr, ClauseName)>>);
impl CodeIndex {
@@ -511,7 +513,7 @@ impl From<(usize, ClauseName)> for CodeIndex {
}
}
#[derive(Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DynamicAssertPlace {
Back,
Front,
@@ -535,7 +537,7 @@ impl DynamicAssertPlace {
}
}
#[derive(Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DynamicTransactionType {
Abolish,
Assert(DynamicAssertPlace),
@@ -545,7 +547,7 @@ pub enum DynamicTransactionType {
Retract, // dynamic index of the clause to remove.
}
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
pub enum REPLCodePtr {
CompileBatch,
UseModule,
@@ -554,7 +556,7 @@ pub enum REPLCodePtr {
UseQualifiedModuleFromFile
}
#[derive(Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub enum CodePtr {
BuiltInClause(BuiltInClauseType, LocalCodePtr), // local is the successor call.
CallN(usize, LocalCodePtr, bool), // arity, local, last call.
@@ -773,7 +775,7 @@ impl AddAssign<usize> for CodePtr {
pub type HeapVarDict = IndexMap<Rc<Var>, Addr>;
pub type AllocVarDict = IndexMap<Rc<Var>, VarData>;
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct DynamicPredicateInfo {
pub(super) clauses_subsection_p: usize, // a LocalCodePtr::DirEntry value.
}
@@ -793,6 +795,7 @@ pub type DynamicCodeDir = IndexMap<(ClauseName, ClauseName, usize), DynamicPredi
pub type GlobalVarDir = IndexMap<ClauseName, (Ball, Option<usize>)>;
#[derive(Debug)]
pub(crate) struct ModuleStub {
pub(crate) atom_tbl: TabledData<Atom>,
pub(crate) in_situ_code_dir: InSituCodeDir,
@@ -810,6 +813,7 @@ impl ModuleStub {
pub(crate) type ModuleStubDir = IndexMap<ClauseName, ModuleStub>;
pub(crate) type StreamAliasDir = IndexMap<ClauseName, Stream>;
#[derive(Debug)]
pub struct IndexStore {
pub(super) atom_tbl: TabledData<Atom>,
pub(super) code_dir: CodeDir,
@@ -960,6 +964,7 @@ impl IndexStore {
pub type CodeDir = BTreeMap<PredicateKey, CodeIndex>;
pub type TermDir = IndexMap<PredicateKey, (Predicate, VecDeque<TopLevel>)>;
#[derive(Debug)]
pub struct TermDirQuantumEntry {
pub old_terms: (Predicate, VecDeque<TopLevel>),
pub new_terms: (Predicate, VecDeque<TopLevel>),
@@ -988,6 +993,7 @@ impl TermDirQuantumEntry {
}
}
#[derive(Debug)]
pub struct TermDirQuantum(IndexMap<PredicateKey, TermDirQuantumEntry>);
impl TermDirQuantum {
@@ -1031,7 +1037,7 @@ impl TermDirQuantum {
}
}
#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
pub enum CompileTimeHook {
GoalExpansion,
TermExpansion,
@@ -1085,6 +1091,16 @@ pub enum RefOrOwned<'a, T: 'a> {
Owned(T),
}
impl<'a, T: 'a + fmt::Debug> fmt::Debug for RefOrOwned<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&RefOrOwned::Borrowed(ref borrowed) =>
write!(f, "Borrowed({:?})", borrowed),
&RefOrOwned::Owned(ref owned) => write!(f, "Owned({:?})", owned),
}
}
}
impl<'a, T> RefOrOwned<'a, T> {
pub fn as_ref(&'a self) -> &'a T {
match self {

View File

@@ -21,10 +21,12 @@ use indexmap::{IndexMap, IndexSet};
use std::cmp::Ordering;
use std::convert::TryFrom;
use std::fmt;
use std::io::Write;
use std::mem;
use std::ops::{Index, IndexMut};
#[derive(Debug)]
pub(crate) struct HeapPStrIter<'a> {
focus: Addr,
machine_st: &'a MachineState,
@@ -74,7 +76,7 @@ impl<'a> HeapPStrIter<'a> {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub(crate) enum PStrIteratee {
Char(char),
PStrSegment(usize, usize),
@@ -100,7 +102,7 @@ impl<'a> Iterator for HeapPStrIter<'a> {
} else {
Addr::EmptyList
};
return Some(PStrIteratee::PStrSegment(h, n));
} else {
unreachable!()
@@ -306,6 +308,7 @@ fn compare_pstr_to_string<'a>(
Some(s_offset)
}
#[derive(Debug)]
pub struct Ball {
pub(super) boundary: usize,
pub(super) stub: Heap,
@@ -357,6 +360,7 @@ impl Ball {
}
}
#[derive(Debug)]
pub(super) struct CopyTerm<'a> {
state: &'a mut MachineState,
}
@@ -404,6 +408,7 @@ impl<'a> CopierTarget for CopyTerm<'a> {
}
}
#[derive(Debug)]
pub(super) struct CopyBallTerm<'a> {
stack: &'a mut Stack,
heap: &'a mut Heap,
@@ -529,13 +534,13 @@ impl IndexMut<RegType> for MachineState {
pub type Registers = Vec<Addr>;
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub(super) enum MachineMode {
Read,
Write,
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub(super) enum HeapPtr {
HeapCell(usize),
PStrChar(usize, usize),
@@ -576,6 +581,7 @@ impl Default for HeapPtr {
}
}
#[derive(Debug)]
pub struct MachineState {
pub(super) s: HeapPtr,
pub(super) p: CodePtr,
@@ -934,7 +940,7 @@ fn try_in_situ(
pub(crate) type CallResult = Result<(), Vec<HeapCellValue>>;
pub(crate) trait CallPolicy: Any {
pub(crate) trait CallPolicy: Any + fmt::Debug {
fn retry_me_else(&mut self, machine_st: &mut MachineState, offset: usize) -> CallResult {
let b = machine_st.b;
let n = machine_st.stack.index_or_frame(b).prelude.univ_prelude.num_cells;
@@ -1517,10 +1523,12 @@ impl CallPolicy for CWILCallPolicy {
downcast!(dyn CallPolicy);
#[derive(Debug)]
pub(crate) struct DefaultCallPolicy {}
impl CallPolicy for DefaultCallPolicy {}
#[derive(Debug)]
pub(crate) struct CWILCallPolicy {
pub(crate) prev_policy: Box<dyn CallPolicy>,
count: Integer,
@@ -1601,7 +1609,7 @@ impl CWILCallPolicy {
}
}
pub(crate) trait CutPolicy: Any {
pub(crate) trait CutPolicy: Any + fmt::Debug {
// returns true iff we fail or cut redirected the MachineState's p itself
fn cut(&mut self, machine_st: &mut MachineState, r: RegType) -> bool;
}
@@ -1627,6 +1635,7 @@ fn cut_body(machine_st: &mut MachineState, addr: &Addr) -> bool {
false
}
#[derive(Debug)]
pub(crate) struct DefaultCutPolicy {}
pub(super) fn deref_cut(machine_st: &mut MachineState, r: RegType) {
@@ -1641,6 +1650,7 @@ impl CutPolicy for DefaultCutPolicy {
}
}
#[derive(Debug)]
pub(crate) struct SCCCutPolicy {
// locations of cleaners, cut points, the previous block
cont_pts: Vec<(Addr, usize, usize)>,

View File

@@ -53,6 +53,7 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::sync::atomic::AtomicBool;
#[derive(Debug)]
pub struct MachinePolicies {
call_policy: Box<dyn CallPolicy>,
cut_policy: Box<dyn CutPolicy>,
@@ -79,6 +80,7 @@ impl Default for MachinePolicies {
}
}
#[derive(Debug)]
pub struct Machine {
pub(super) machine_st: MachineState,
pub(super) inner_heap: Heap,

View File

@@ -7,6 +7,7 @@ use std::ops::RangeFrom;
use std::slice;
use std::str;
#[derive(Debug)]
pub struct PartialString {
buf: *const u8,
len: usize,
@@ -46,6 +47,7 @@ fn scan_for_terminator<Iter: Iterator<Item = char>>(iter: Iter) -> usize {
terminator_idx
}
#[derive(Debug)]
pub struct PStrIter {
buf: *const u8,
len: usize,

View File

@@ -14,6 +14,7 @@ pub(crate) trait RawBlockTraits {
}
}
#[derive(Debug)]
pub(crate) struct RawBlock<T: RawBlockTraits> {
pub(crate) size: usize,
pub(crate) base: *const u8,

View File

@@ -7,6 +7,7 @@ use std::mem;
use std::ops::{Index, IndexMut};
use std::ptr;
#[derive(Debug)]
struct StackTraits {}
impl RawBlockTraits for StackTraits {
@@ -35,6 +36,7 @@ const fn prelude_size<Prelude>() -> usize {
(size & !(align - 1)) + align
}
#[derive(Debug)]
pub struct Stack {
buf: RawBlock<StackTraits>,
_marker: PhantomData<Addr>,
@@ -47,11 +49,12 @@ impl Drop for Stack {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub struct FramePrelude {
pub num_cells: usize,
}
#[derive(Debug)]
pub struct AndFramePrelude {
pub univ_prelude: FramePrelude,
pub e: usize,
@@ -59,6 +62,7 @@ pub struct AndFramePrelude {
pub interrupt_cp: LocalCodePtr,
}
#[derive(Debug)]
pub struct AndFrame {
pub prelude: AndFramePrelude,
}
@@ -99,6 +103,7 @@ impl IndexMut<usize> for AndFrame {
}
}
#[derive(Debug)]
pub struct OrFramePrelude {
pub univ_prelude: FramePrelude,
pub e: usize,
@@ -113,6 +118,7 @@ pub struct OrFramePrelude {
pub attr_var_init_bindings_b: usize,
}
#[derive(Debug)]
pub struct OrFrame {
pub prelude: OrFramePrelude,
}

View File

@@ -11,13 +11,13 @@ use std::hash::{Hash, Hasher};
use std::net::TcpStream;
use std::rc::Rc;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StreamType {
Binary,
Text,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EOFAction {
EOFCode,
Error,
@@ -37,7 +37,26 @@ pub enum StreamInstance {
TcpStream(TcpStream),
}
#[derive(Clone)]
impl fmt::Debug for StreamInstance {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self {
&StreamInstance::Bytes(ref bytes) =>
write!(fmt, "Bytes({:?})", bytes),
&StreamInstance::DynReadSource(_) =>
write!(fmt, "DynReadSource(_)"), // Hacky solution.
&StreamInstance::File(ref file) => write!(fmt, "File({:?})", file),
&StreamInstance::Null => write!(fmt, "Null"),
&StreamInstance::ReadlineStream(ref readline_stream) =>
write!(fmt, "ReadlineStream({:?})", readline_stream),
&StreamInstance::Stdin => write!(fmt, "Stdin"),
&StreamInstance::Stdout => write!(fmt, "Stdout"),
&StreamInstance::TcpStream(ref tcp_stream) =>
write!(fmt, "TcpStream({:?})", tcp_stream),
}
}
}
#[derive(Debug, Clone)]
struct WrappedStreamInstance(Rc<RefCell<StreamInstance>>);
impl WrappedStreamInstance {
@@ -95,7 +114,7 @@ impl fmt::Display for StreamError {
impl Error for StreamError {}
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StreamOptions {
pub stream_type: StreamType,
pub reposition: bool,
@@ -115,7 +134,7 @@ impl Default for StreamOptions {
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Stream {
pub options: StreamOptions,
stream_inst: WrappedStreamInstance,

View File

@@ -61,6 +61,7 @@ pub fn get_single_char() -> char {
c
}
#[derive(Debug)]
struct BrentAlgState {
hare: Addr,
tortoise: Addr,

View File

@@ -47,6 +47,7 @@ fn extract_from_list(
}
}
#[derive(Debug)]
pub struct TermStream<'a> {
stack: Vec<Term>,
pub(crate) wam: &'a mut Machine,
@@ -57,6 +58,7 @@ pub struct TermStream<'a> {
top_level_terms: Vec<(Term, usize, usize)>, // term, line_num, col_num.
}
#[derive(Debug)]
pub struct ExpansionAdditionResult {
term_expansion_additions: (Predicate, VecDeque<TopLevel>),
goal_expansion_additions: (Predicate, VecDeque<TopLevel>),

View File

@@ -14,6 +14,7 @@ use std::borrow::BorrowMut;
use std::cell::Cell;
use std::collections::VecDeque;
use std::convert::TryFrom;
use std::fmt;
use std::mem;
use std::ops::DerefMut;
use std::rc::Rc;
@@ -23,6 +24,15 @@ enum IndexSource<'a, T> {
Local(&'a mut T)
}
impl<'a, T: fmt::Debug> fmt::Debug for IndexSource<'a, T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self {
IndexSource::TermStream => write!(fmt, "TermStream"),
IndexSource::Local(ref local) => write!(fmt, "Local({:?})", local),
}
}
}
fn op_dir<'a, 'b: 'a>(from: &'b IndexSource<'a, IndexStore>) -> RefOrOwned<'a, OpDir> {
match from {
IndexSource::TermStream => RefOrOwned::Owned(OpDir::new()),
@@ -30,6 +40,7 @@ fn op_dir<'a, 'b: 'a>(from: &'b IndexSource<'a, IndexStore>) -> RefOrOwned<'a, O
}
}
#[derive(Debug)]
struct CompositeIndices<'a, 'b, 'c> {
term_stream: &'b mut TermStream<'a>,
index_src: IndexSource<'c, IndexStore>,
@@ -690,6 +701,7 @@ fn setup_declaration<'a, 'b, 'c>(
}
}
#[derive(Debug)]
struct RelationWorker {
flags: MachineFlags,
dynamic_clauses: Vec<(Term, Term)>, // Head, Body.
@@ -1141,6 +1153,7 @@ pub type DynamicClause = Vec<(Term, Term)>;
pub type DynamicClauseMap = IndexMap<(ClauseName, usize), DynamicClause>;
#[derive(Debug)]
pub struct TopLevelBatchWorker<'a> {
pub(crate) term_stream: TermStream<'a>,
rel_worker: RelationWorker,

View File

@@ -35,6 +35,7 @@ pub mod readline {
}
}
#[derive(Debug)]
pub struct ReadlineStream {
rl: Editor<()>,
pending_input: Cursor<String>,
@@ -114,12 +115,14 @@ fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) -> TermWriteRe
term_writer.write_term_to_heap(term)
}
#[derive(Debug)]
struct TermWriter<'a> {
machine_st: &'a mut MachineState,
queue: SubtermDeque,
var_dict: HeapVarDict,
}
#[derive(Debug)]
pub struct TermWriteResult {
pub(crate) heap_loc: usize,
pub(crate) var_dict: HeapVarDict,

View File

@@ -33,6 +33,6 @@ test_queries_on_predicates :-
assertz((p(X, Y) :- q(Z), p(X, X))),
once(p(X,b)),
retract((p(X, Y) :- q(Z), p(X, X))),
retract(q(z)).
retract(q(z)).
:- initialization(test_queries_on_predicates).

View File

@@ -24,5 +24,5 @@ test_queries_on_setup_call_cleanup :-
findall(Pat, catch(setup_call_cleanup(true,throw(goal),throw(cl)), Pat, true), [goal]),
findall(Pat, catch(( setup_call_cleanup(true,(G=1;G=2),throw(cl)), throw(cont)), Pat, true), [cont]),
findall([X,Y], (setup_call_cleanup(true, (X=1;X=2), writeq(a)), setup_call_cleanup(true,(Y=1;Y=2),writeq(b)), !), [[1,1]]).
:- initialization(test_queries_on_setup_call_cleanup).