prepare for batch processing.

This commit is contained in:
Mark Thom
2018-01-28 23:25:39 -07:00
parent f72ad860c6
commit e148152eef
4 changed files with 18 additions and 5 deletions

View File

@@ -35,6 +35,8 @@ impl GenContext {
} }
} }
pub type Predicate = Vec<PredicateClause>;
pub enum PredicateClause { pub enum PredicateClause {
Fact(Term), Fact(Term),
Rule(Rule) Rule(Rule)
@@ -80,7 +82,7 @@ pub enum Declaration {
pub enum TopLevel { pub enum TopLevel {
Declaration(Declaration), Declaration(Declaration),
Fact(Term), Fact(Term),
Predicate(Vec<PredicateClause>), Predicate(Predicate),
Query(Vec<QueryTerm>), Query(Vec<QueryTerm>),
Rule(Rule) Rule(Rule)
} }
@@ -264,8 +266,8 @@ pub enum ParserError
InadmissibleFact, InadmissibleFact,
InadmissibleQueryTerm, InadmissibleQueryTerm,
IncompleteReduction, IncompleteReduction,
InconsistentDeclaration, InconsistentEntry, // was InconsistentDeclaration.
InconsistentPredicate, // InconsistentPredicate, //TODO: admit this is not needed.
InvalidRuleHead, InvalidRuleHead,
ParseBigInt, ParseBigInt,
ParseFloat(ParseFloatError), ParseFloat(ParseFloatError),

View File

@@ -7,12 +7,21 @@ use std::rc::Rc;
pub type TabledData<T> = Rc<RefCell<HashSet<Rc<T>>>>; pub type TabledData<T> = Rc<RefCell<HashSet<Rc<T>>>>;
#[derive(Clone, PartialEq, Eq)] #[derive(Clone)]
pub struct TabledRc<T: Hash + Eq> { pub struct TabledRc<T: Hash + Eq> {
atom: Rc<T>, atom: Rc<T>,
table: TabledData<T> table: TabledData<T>
} }
impl<T: Hash + Eq> PartialEq for TabledRc<T> {
fn eq(&self, other: &TabledRc<T>) -> bool
{
self.atom == other.atom
}
}
impl<T: Hash + Eq> Eq for TabledRc<T> {}
impl<T: Hash + Eq> Hash for TabledRc<T> { impl<T: Hash + Eq> Hash for TabledRc<T> {
fn hash<H: Hasher>(&self, state: &mut H) fn hash<H: Hasher>(&self, state: &mut H)
{ {

View File

@@ -1262,6 +1262,8 @@ fn test_queries_on_builtins()
assert_prolog_success!(&mut wam, "?- f(1,2,3) =.. [f,1,2,3]."); assert_prolog_success!(&mut wam, "?- f(1,2,3) =.. [f,1,2,3].");
assert_prolog_failure!(&mut wam, "?- f(1,2,3) =.. [f,1]."); assert_prolog_failure!(&mut wam, "?- f(1,2,3) =.. [f,1].");
assert_prolog_failure!(&mut wam, "?- f(1,2,3) =.. [g,1,2,3]."); assert_prolog_failure!(&mut wam, "?- f(1,2,3) =.. [g,1,2,3].");
assert_prolog_success!(&mut wam, "?- f(1,2,3) =.. [f,X,Y,Z].",
[["X = 1", "Y = 2", "Z = 3"]]);
assert_prolog_success_with_limit!(&mut wam, "?- length(Xs, N).", assert_prolog_success_with_limit!(&mut wam, "?- length(Xs, N).",
[["N = 0", "Xs = []"], [["N = 0", "Xs = []"],