private void ResolveIndex(PredicateDescr pd) { #if persistent if (pd is PersistentPredDescr) return; // does not have a clauseTerm #endif ClauseNode clause = pd.GetClauseList(null, null); while (clause != null) // iterate over all clauses of this predicate. ClauseNode.Term contains predicate clauseHead { Term clauseHead = clause.Term; // clause = clauseHead :- clauseTerm* TermNode clauseTerm = clause.NextNode; while (clauseTerm != null) // non-facts only. Iterate over all clauseTerm-terms t of this clause { if (clauseTerm.BuiltinId == BI.none) clauseTerm.PredDescr = this[clauseTerm.Term.KbKey]; // builtins (>=0) are handled differently (in Execute ()) clauseTerm = clauseTerm.NextNode; } clause = clause.NextClause; } return; }
private void FindUndefined(SortedList sd, PredicateDescr pd) { #if persistent if (pd is PersistentPredDescr) return; #endif ClauseNode clause = pd.GetClauseList(null, null); Term clauseHead; TermNode clauseTerm; while (clause != null) // iterate over all clauses of this predicate { clauseHead = clause.Term; clauseTerm = clause.NextNode; while (clauseTerm != null) // non-facts only. Iterate over all clauseTerm-terms t of this clause { if (clauseTerm.BuiltinId == BI.none && clauseTerm.PredDescr == null) sd[clauseTerm.Term.Index] = null; clauseTerm = clauseTerm.NextNode; } clause = clause.NextClause; } return; }
private bool ListClause(PredicateDescr pd, string functor, int arity, int seqno) { ClauseNode clause = null; string details; #if persistent if (pd is PersistentPredDescr) { details = "persistent, details: " + pd.DefiningFile; } else #endif { if ((clause = pd.GetClauseList(null, null)) == null) return false; details = "source: " + pd.DefiningFile; } #if arg1index if (pd.IsFirstArgIndexed) details += "; arg1-indexed (jump points marked with '.')"; #endif Console.WriteLine("\n{0}/{1}: ({2}) {3}", functor, arity, details, ((seqno == 1) ? "" : ("(" + seqno.ToString() + ")"))); while (clause != null) { TermNode next; #if arg1index // prefix a clause that is pointed to by first-argument indexing with '.' Console.Write (" {0}{1}", (pd.IsFirstArgMarked (clause))?".":" ", clause.Term); #else Console.Write(" {0}", clause.Term); #endif if ((next = clause.NextNode) != null) { BI builtinId = next.BuiltinId; Console.Write(" :-\n{0}", (builtinId == BI.none) ? next.ToString() : builtinId.ToString()); } Console.WriteLine("."); clause = clause.NextClause; } return true; }