Merge branch 'master' of yap.dcc.fc.up.pt:yap-6

This commit is contained in:
Vitor Santos Costa 2010-04-16 10:33:11 +01:00
commit be91864c1e
13 changed files with 312 additions and 255 deletions

View File

@ -3509,7 +3509,7 @@ static Term
all_calls(void)
{
Term ts[4];
Functor f = Yap_MkFunctor(AtomLocal,4);
Functor f = Yap_MkFunctor(AtomLocalSp,4);
ts[0] = MkIntegerTerm((Int)P);
ts[1] = MkIntegerTerm((Int)CP);

View File

@ -273,6 +273,9 @@ static char SccsId[] = "%W% %G%";
#include "YapHeap.h"
#include "eval.h"
#include "yapio.h"
#ifdef TABLING
#include "tab.macros.h"
#endif /* TABLING */
#include <stdio.h>
#if HAVE_STRING_H
#include <string.h>
@ -3656,28 +3659,19 @@ p_access_yap_flags(void)
}
#ifdef TABLING
if (flag == TABLING_MODE_FLAG) {
int n = 0;
if (IsMode_CompletedOn(yap_flags[flag])) {
if (IsMode_LoadAnswers(yap_flags[flag]))
tout = MkAtomTerm(AtomLoadAnswers);
else
tout = MkAtomTerm(AtomExecAnswers);
n++;
}
if (IsMode_SchedulingOn(yap_flags[flag])) {
Term taux = tout;
if (IsMode_Local(yap_flags[flag]))
tout = MkAtomTerm(AtomLocalA);
else
tout = MkAtomTerm(AtomBatched);
if (n) {
taux = MkPairTerm(taux, MkAtomTerm(AtomNil));
tout = MkPairTerm(tout, taux);
}
n++;
}
if (n == 0)
tout = MkAtomTerm(AtomDefault);
tout = TermNil;
if (IsMode_LocalTrie(yap_flags[flag]))
tout = MkPairTerm(MkAtomTerm(AtomLocalTrie), tout);
else if (IsMode_GlobalTrie(yap_flags[flag]))
tout = MkPairTerm(MkAtomTerm(AtomGlobalTrie), tout);
if (IsMode_ExecAnswers(yap_flags[flag]))
tout = MkPairTerm(MkAtomTerm(AtomExecAnswers), tout);
else if (IsMode_LoadAnswers(yap_flags[flag]))
tout = MkPairTerm(MkAtomTerm(AtomLoadAnswers), tout);
if (IsMode_Batched(yap_flags[flag]))
tout = MkPairTerm(MkAtomTerm(AtomBatched), tout);
else if (IsMode_Local(yap_flags[flag]))
tout = MkPairTerm(MkAtomTerm(AtomLocal), tout);
} else
#endif /* TABLING */
tout = MkIntegerTerm(yap_flags[flag]);
@ -3804,14 +3798,7 @@ p_set_yap_flags(void)
if (value == 0) { /* default */
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) {
if (IsDefaultMode_Local(TabEnt_mode(tab_ent)))
SetMode_Local(TabEnt_mode(tab_ent));
else
SetMode_Batched(TabEnt_mode(tab_ent));
if (IsDefaultMode_LoadAnswers(TabEnt_mode(tab_ent)))
SetMode_LoadAnswers(TabEnt_mode(tab_ent));
else
SetMode_ExecAnswers(TabEnt_mode(tab_ent));
TabEnt_mode(tab_ent) = TabEnt_flags(tab_ent);
tab_ent = TabEnt_next(tab_ent);
}
yap_flags[TABLING_MODE_FLAG] = 0;
@ -3822,7 +3809,6 @@ p_set_yap_flags(void)
tab_ent = TabEnt_next(tab_ent);
}
SetMode_Batched(yap_flags[TABLING_MODE_FLAG]);
SetMode_SchedulingOn(yap_flags[TABLING_MODE_FLAG]);
} else if (value == 2) { /* local */
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) {
@ -3830,7 +3816,6 @@ p_set_yap_flags(void)
tab_ent = TabEnt_next(tab_ent);
}
SetMode_Local(yap_flags[TABLING_MODE_FLAG]);
SetMode_SchedulingOn(yap_flags[TABLING_MODE_FLAG]);
} else if (value == 3) { /* exec_answers */
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) {
@ -3838,7 +3823,6 @@ p_set_yap_flags(void)
tab_ent = TabEnt_next(tab_ent);
}
SetMode_ExecAnswers(yap_flags[TABLING_MODE_FLAG]);
SetMode_CompletedOn(yap_flags[TABLING_MODE_FLAG]);
} else if (value == 4) { /* load_answers */
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) {
@ -3846,7 +3830,20 @@ p_set_yap_flags(void)
tab_ent = TabEnt_next(tab_ent);
}
SetMode_LoadAnswers(yap_flags[TABLING_MODE_FLAG]);
SetMode_CompletedOn(yap_flags[TABLING_MODE_FLAG]);
} else if (value == 5) { /* local_trie */
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) {
SetMode_LocalTrie(TabEnt_mode(tab_ent));
tab_ent = TabEnt_next(tab_ent);
}
SetMode_LocalTrie(yap_flags[TABLING_MODE_FLAG]);
} else if (value == 6) { /* global_trie */
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) {
SetMode_GlobalTrie(TabEnt_mode(tab_ent));
tab_ent = TabEnt_next(tab_ent);
}
SetMode_GlobalTrie(yap_flags[TABLING_MODE_FLAG]);
}
break;
#endif /* TABLING */

View File

@ -114,7 +114,8 @@
AtomGeneratePredInfo = Yap_FullLookupAtom("$generate_pred_info");
AtomGetwork = Yap_FullLookupAtom("$getwork");
AtomGetworkSeq = Yap_FullLookupAtom("$getwork_seq");
AtomGlobal = Yap_LookupAtom("global_sp");
AtomGlobalSp = Yap_LookupAtom("global_sp");
AtomGlobalTrie = Yap_LookupAtom("global_trie");
AtomGoalExpansion = Yap_LookupAtom("goal_expansion");
AtomHERE = Yap_LookupAtom("\n <====HERE====> \n");
AtomHandleThrow = Yap_FullLookupAtom("$handle_throw");
@ -142,8 +143,9 @@
AtomList = Yap_LookupAtom("list");
AtomLive = Yap_FullLookupAtom("$live");
AtomLoadAnswers = Yap_LookupAtom("load_answers");
AtomLocal = Yap_LookupAtom("local_sp");
AtomLocalA = Yap_LookupAtom("local");
AtomLocal = Yap_LookupAtom("local");
AtomLocalSp = Yap_LookupAtom("local_sp");
AtomLocalTrie = Yap_LookupAtom("local_trie");
AtomMaxArity = Yap_LookupAtom("max_arity");
AtomMaxFiles = Yap_LookupAtom("max_files");
AtomMegaClause = Yap_FullLookupAtom("$mega_clause");

View File

@ -114,7 +114,8 @@
AtomGeneratePredInfo = AtomAdjust(AtomGeneratePredInfo);
AtomGetwork = AtomAdjust(AtomGetwork);
AtomGetworkSeq = AtomAdjust(AtomGetworkSeq);
AtomGlobal = AtomAdjust(AtomGlobal);
AtomGlobalSp = AtomAdjust(AtomGlobalSp);
AtomGlobalTrie = AtomAdjust(AtomGlobalTrie);
AtomGoalExpansion = AtomAdjust(AtomGoalExpansion);
AtomHERE = AtomAdjust(AtomHERE);
AtomHandleThrow = AtomAdjust(AtomHandleThrow);
@ -143,7 +144,8 @@
AtomLive = AtomAdjust(AtomLive);
AtomLoadAnswers = AtomAdjust(AtomLoadAnswers);
AtomLocal = AtomAdjust(AtomLocal);
AtomLocalA = AtomAdjust(AtomLocalA);
AtomLocalSp = AtomAdjust(AtomLocalSp);
AtomLocalTrie = AtomAdjust(AtomLocalTrie);
AtomMaxArity = AtomAdjust(AtomMaxArity);
AtomMaxFiles = AtomAdjust(AtomMaxFiles);
AtomMegaClause = AtomAdjust(AtomMegaClause);

View File

@ -230,8 +230,10 @@
#define AtomGetwork Yap_heap_regs->AtomGetwork_
Atom AtomGetworkSeq_;
#define AtomGetworkSeq Yap_heap_regs->AtomGetworkSeq_
Atom AtomGlobal_;
#define AtomGlobal Yap_heap_regs->AtomGlobal_
Atom AtomGlobalSp_;
#define AtomGlobalSp Yap_heap_regs->AtomGlobalSp_
Atom AtomGlobalTrie_;
#define AtomGlobalTrie Yap_heap_regs->AtomGlobalTrie_
Atom AtomGoalExpansion_;
#define AtomGoalExpansion Yap_heap_regs->AtomGoalExpansion_
Atom AtomHERE_;
@ -288,8 +290,10 @@
#define AtomLoadAnswers Yap_heap_regs->AtomLoadAnswers_
Atom AtomLocal_;
#define AtomLocal Yap_heap_regs->AtomLocal_
Atom AtomLocalA_;
#define AtomLocalA Yap_heap_regs->AtomLocalA_
Atom AtomLocalSp_;
#define AtomLocalSp Yap_heap_regs->AtomLocalSp_
Atom AtomLocalTrie_;
#define AtomLocalTrie Yap_heap_regs->AtomLocalTrie_
Atom AtomMaxArity_;
#define AtomMaxArity Yap_heap_regs->AtomMaxArity_
Atom AtomMaxFiles_;

View File

@ -65,6 +65,7 @@ static Int p_show_table(void);
static Int p_show_all_tables(void);
#ifdef GLOBAL_TRIE
static Int p_show_global_trie(void);
static Int p_global_trie_statistics(void);
#endif /* GLOBAL_TRIE */
static Int p_table_statistics(void);
static Int p_tabling_statistics(void);
@ -154,6 +155,7 @@ void Yap_init_optyap_preds(void) {
Yap_InitCPred("show_all_tables", 0, p_show_all_tables, SafePredFlag|SyncPredFlag);
#ifdef GLOBAL_TRIE
Yap_InitCPred("show_global_trie", 0, p_show_global_trie, SafePredFlag|SyncPredFlag);
Yap_InitCPred("global_trie_statistics", 0, p_global_trie_statistics, SafePredFlag|SyncPredFlag);
#endif /* GLOBAL_TRIE */
Yap_InitCPred("$c_table_statistics", 2, p_table_statistics, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("tabling_statistics", 0, p_tabling_statistics, SafePredFlag|SyncPredFlag);
@ -616,10 +618,6 @@ Int p_table(void) {
return (FALSE); /* predicate already compiled */
pe->PredFlags |= TabledPredFlag;
new_table_entry(tab_ent, pe, at, arity);
if (IsMode_Local(yap_flags[TABLING_MODE_FLAG]))
SetMode_Local(TabEnt_mode(tab_ent));
if (IsMode_LoadAnswers(yap_flags[TABLING_MODE_FLAG]))
SetMode_LoadAnswers(TabEnt_mode(tab_ent));
pe->TableOfPred = tab_ent;
return (TRUE);
}
@ -627,7 +625,7 @@ Int p_table(void) {
static
Int p_tabling_mode(void) {
Term mod, t, val;
Term mod, t, tvalue;
tab_ent_ptr tab_ent;
mod = Deref(ARG1);
@ -638,62 +636,70 @@ Int p_tabling_mode(void) {
tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred;
else
return (FALSE);
val = Deref(ARG3);
if (IsVarTerm(val)) {
Term mode;
t = MkAtomTerm(AtomNil);
if (IsDefaultMode_LoadAnswers(TabEnt_mode(tab_ent)))
mode = MkAtomTerm(Yap_LookupAtom("load_answers"));
else
mode = MkAtomTerm(Yap_LookupAtom("exec_answers"));
t = MkPairTerm(mode, t);
if (IsDefaultMode_Local(TabEnt_mode(tab_ent)))
mode = MkAtomTerm(Yap_LookupAtom("local"));
else
mode = MkAtomTerm(Yap_LookupAtom("batched"));
t = MkPairTerm(mode, t);
mode = MkAtomTerm(Yap_LookupAtom("default"));
t = MkPairTerm(mode, t);
t = MkPairTerm(t, MkAtomTerm(AtomNil));
if (IsMode_LoadAnswers(TabEnt_mode(tab_ent)))
mode = MkAtomTerm(Yap_LookupAtom("load_answers"));
else
mode = MkAtomTerm(Yap_LookupAtom("exec_answers"));
t = MkPairTerm(mode, t);
if (IsMode_Local(TabEnt_mode(tab_ent)))
mode = MkAtomTerm(Yap_LookupAtom("local"));
else
mode = MkAtomTerm(Yap_LookupAtom("batched"));
t = MkPairTerm(mode, t);
Bind((CELL *)val, t);
tvalue = Deref(ARG3);
if (IsVarTerm(tvalue)) {
t = TermNil;
if (IsMode_LocalTrie(TabEnt_flags(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomLocalTrie), t);
else if (IsMode_GlobalTrie(TabEnt_flags(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomGlobalTrie), t);
if (IsMode_ExecAnswers(TabEnt_flags(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomExecAnswers), t);
else if (IsMode_LoadAnswers(TabEnt_flags(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomLoadAnswers), t);
if (IsMode_Batched(TabEnt_flags(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomBatched), t);
else if (IsMode_Local(TabEnt_flags(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomLocal), t);
t = MkPairTerm(MkAtomTerm(AtomDefault), t);
t = MkPairTerm(t, TermNil);
if (IsMode_LocalTrie(TabEnt_mode(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomLocalTrie), t);
else if (IsMode_GlobalTrie(TabEnt_mode(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomGlobalTrie), t);
if (IsMode_ExecAnswers(TabEnt_mode(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomExecAnswers), t);
else if (IsMode_LoadAnswers(TabEnt_mode(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomLoadAnswers), t);
if (IsMode_Batched(TabEnt_mode(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomBatched), t);
else if (IsMode_Local(TabEnt_mode(tab_ent)))
t = MkPairTerm(MkAtomTerm(AtomLocal), t);
Bind((CELL *) tvalue, t);
return(TRUE);
}
if (IsAtomTerm(val)) {
char *str_val = RepAtom(AtomOfTerm(val))->StrOfAE;
if (strcmp(str_val,"batched") == 0) {
SetDefaultMode_Batched(TabEnt_mode(tab_ent));
if (IsMode_SchedulingOff(yap_flags[TABLING_MODE_FLAG]))
} else if (IsIntTerm(tvalue)) {
Int value = IntOfTerm(tvalue);
if (value == 1) { /* batched */
SetMode_Batched(TabEnt_flags(tab_ent));
if (! IsMode_Local(yap_flags[TABLING_MODE_FLAG]))
SetMode_Batched(TabEnt_mode(tab_ent));
return(TRUE);
}
if (strcmp(str_val,"local") == 0) {
SetDefaultMode_Local(TabEnt_mode(tab_ent));
if (IsMode_SchedulingOff(yap_flags[TABLING_MODE_FLAG]))
} else if (value == 2) { /* local */
SetMode_Local(TabEnt_flags(tab_ent));
if (! IsMode_Batched(yap_flags[TABLING_MODE_FLAG]))
SetMode_Local(TabEnt_mode(tab_ent));
return(TRUE);
}
if (strcmp(str_val,"exec_answers") == 0) {
SetDefaultMode_ExecAnswers(TabEnt_mode(tab_ent));
if (IsMode_CompletedOff(yap_flags[TABLING_MODE_FLAG]))
} else if (value == 3) { /* exec_answers */
SetMode_ExecAnswers(TabEnt_flags(tab_ent));
if (! IsMode_LoadAnswers(yap_flags[TABLING_MODE_FLAG]))
SetMode_ExecAnswers(TabEnt_mode(tab_ent));
return(TRUE);
}
if (strcmp(str_val,"load_answers") == 0) {
SetDefaultMode_LoadAnswers(TabEnt_mode(tab_ent));
if (IsMode_CompletedOff(yap_flags[TABLING_MODE_FLAG]))
} else if (value == 4) { /* load_answers */
SetMode_LoadAnswers(TabEnt_flags(tab_ent));
if (! IsMode_ExecAnswers(yap_flags[TABLING_MODE_FLAG]))
SetMode_LoadAnswers(TabEnt_mode(tab_ent));
return(TRUE);
}
} else if (value == 5) { /* local_trie */
SetMode_LocalTrie(TabEnt_flags(tab_ent));
if (! IsMode_GlobalTrie(yap_flags[TABLING_MODE_FLAG]))
SetMode_LocalTrie(TabEnt_mode(tab_ent));
return(TRUE);
} else if (value == 6) { /* global_trie */
SetMode_GlobalTrie(TabEnt_flags(tab_ent));
if (! IsMode_LocalTrie(yap_flags[TABLING_MODE_FLAG]))
SetMode_GlobalTrie(TabEnt_mode(tab_ent));
return(TRUE);
}
}
return (FALSE);
}
@ -763,7 +769,7 @@ Int p_show_tabled_predicates(void) {
tab_ent = GLOBAL_root_tab_ent;
fprintf(Yap_stdout, "Tabled predicates\n");
if (tab_ent == NULL)
fprintf(Yap_stdout, " none\n");
fprintf(Yap_stdout, " NONE\n");
else
while(tab_ent) {
fprintf(Yap_stdout, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
@ -807,7 +813,13 @@ Int p_show_all_tables(void) {
#ifdef GLOBAL_TRIE
static
Int p_show_global_trie(void) {
show_global_trie();
show_global_trie(SHOW_MODE_STRUCTURE);
return (TRUE);
}
static
Int p_global_trie_statistics(void) {
show_global_trie(SHOW_MODE_STATISTICS);
return (TRUE);
}
#endif /* GLOBAL_TRIE */

View File

@ -82,7 +82,7 @@ void free_answer_trie_branch(ans_node_ptr, int);
void update_answer_trie(sg_fr_ptr);
void show_table(tab_ent_ptr, int);
#ifdef GLOBAL_TRIE
void show_global_trie(void);
void show_global_trie(int);
#endif /* GLOBAL_TRIE */
void private_completion(sg_fr_ptr);
#endif /* TABLING */

View File

@ -56,6 +56,35 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int);
/*********************************
** Tabling mode flags **
*********************************/
#define Flag_Batched 0x001
#define Flag_Local 0x002
#define Flags_SchedulingMode (Flag_Batched | Flag_Local)
#define Flag_ExecAnswers 0x010
#define Flag_LoadAnswers 0x020
#define Flags_AnswersMode (Flag_ExecAnswers | Flag_LoadAnswers)
#define Flag_LocalTrie 0x100
#define Flag_GlobalTrie 0x200
#define Flags_TrieMode (Flag_LocalTrie | Flag_GlobalTrie)
#define SetMode_Batched(X) (X) = ((X) & ~Flags_SchedulingMode) | Flag_Batched
#define SetMode_Local(X) (X) = ((X) & ~Flags_SchedulingMode) | Flag_Local
#define SetMode_ExecAnswers(X) (X) = ((X) & ~Flags_AnswersMode) | Flag_ExecAnswers
#define SetMode_LoadAnswers(X) (X) = ((X) & ~Flags_AnswersMode) | Flag_LoadAnswers
#define SetMode_LocalTrie(X) (X) = ((X) & ~Flags_TrieMode) | Flag_LocalTrie
#define SetMode_GlobalTrie(X) (X) = ((X) & ~Flags_TrieMode) | Flag_GlobalTrie
#define IsMode_Batched(X) ((X) & Flag_Batched)
#define IsMode_Local(X) ((X) & Flag_Local)
#define IsMode_ExecAnswers(X) ((X) & Flag_ExecAnswers)
#define IsMode_LoadAnswers(X) ((X) & Flag_LoadAnswers)
#define IsMode_LocalTrie(X) ((X) & Flag_LocalTrie)
#define IsMode_GlobalTrie(X) ((X) & Flag_GlobalTrie)
/*********************
** Macros **
*********************/
@ -227,19 +256,29 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int);
#define TrNode_init_lock_field(NODE)
#endif /* TABLE_LOCK_AT_NODE_LEVEL */
#define new_table_entry(TAB_ENT, PRED_ENTRY, ATOM, ARITY) \
{ register sg_node_ptr sg_node; \
new_subgoal_trie_node(sg_node, 0, NULL, NULL, NULL); \
ALLOC_TABLE_ENTRY(TAB_ENT); \
TabEnt_init_lock_field(TAB_ENT); \
TabEnt_pe(TAB_ENT) = PRED_ENTRY; \
TabEnt_atom(TAB_ENT) = ATOM; \
TabEnt_arity(TAB_ENT) = ARITY; \
TabEnt_mode(TAB_ENT) = 0; \
TabEnt_subgoal_trie(TAB_ENT) = sg_node; \
TabEnt_hash_chain(TAB_ENT) = NULL; \
TabEnt_next(TAB_ENT) = GLOBAL_root_tab_ent; \
GLOBAL_root_tab_ent = TAB_ENT; \
#define new_table_entry(TAB_ENT, PRED_ENTRY, ATOM, ARITY) \
{ register sg_node_ptr sg_node; \
new_subgoal_trie_node(sg_node, 0, NULL, NULL, NULL); \
ALLOC_TABLE_ENTRY(TAB_ENT); \
TabEnt_init_lock_field(TAB_ENT); \
TabEnt_pe(TAB_ENT) = PRED_ENTRY; \
TabEnt_atom(TAB_ENT) = ATOM; \
TabEnt_arity(TAB_ENT) = ARITY; \
TabEnt_flags(TAB_ENT) = 0; \
SetMode_Batched(TabEnt_flags(TAB_ENT)); \
SetMode_ExecAnswers(TabEnt_flags(TAB_ENT)); \
SetMode_LocalTrie(TabEnt_flags(TAB_ENT)); \
TabEnt_mode(TAB_ENT) = TabEnt_flags(TAB_ENT); \
if (IsMode_Local(yap_flags[TABLING_MODE_FLAG])) \
SetMode_Local(TabEnt_mode(TAB_ENT)); \
if (IsMode_LoadAnswers(yap_flags[TABLING_MODE_FLAG])) \
SetMode_LoadAnswers(TabEnt_mode(TAB_ENT)); \
if (IsMode_GlobalTrie(yap_flags[TABLING_MODE_FLAG])) \
SetMode_GlobalTrie(TabEnt_mode(TAB_ENT)); \
TabEnt_subgoal_trie(TAB_ENT) = sg_node; \
TabEnt_hash_chain(TAB_ENT) = NULL; \
TabEnt_next(TAB_ENT) = GLOBAL_root_tab_ent; \
GLOBAL_root_tab_ent = TAB_ENT; \
}
#define new_subgoal_frame(SG_FR, CODE) \

View File

@ -11,58 +11,23 @@
** **
************************************************************************/
/*********************************
** Tabling mode flags **
*********************************/
/************************************************************************
** Table Space Data Structures **
************************************************************************/
#define Mode_SchedulingOn 0x00000001L /* yap_flags[TABLING_MODE_FLAG] */
#define Mode_CompletedOn 0x00000002L /* yap_flags[TABLING_MODE_FLAG] */
#define Mode_Local 0x10000000L /* yap_flags[TABLING_MODE_FLAG] + struct table_entry */
#define Mode_LoadAnswers 0x20000000L /* yap_flags[TABLING_MODE_FLAG] + struct table_entry */
#define DefaultMode_Local 0x00000001L /* struct table_entry */
#define DefaultMode_LoadAnswers 0x00000002L /* struct table_entry */
#define SetMode_SchedulingOn(X) (X) |= Mode_SchedulingOn
#define SetMode_CompletedOn(X) (X) |= Mode_CompletedOn
#define IsMode_SchedulingOn(X) ((X) & Mode_SchedulingOn)
#define IsMode_SchedulingOff(X) (!IsMode_SchedulingOn(X))
#define IsMode_CompletedOn(X) ((X) & Mode_CompletedOn)
#define IsMode_CompletedOff(X) (!IsMode_CompletedOn(X))
#define SetMode_Local(X) (X) |= Mode_Local
#define SetMode_Batched(X) (X) &= ~Mode_Local
#define SetMode_LoadAnswers(X) (X) |= Mode_LoadAnswers
#define SetMode_ExecAnswers(X) (X) &= ~Mode_LoadAnswers
#define IsMode_Local(X) ((X) & Mode_Local)
#define IsMode_Batched(X) (!IsMode_Local(X))
#define IsMode_LoadAnswers(X) ((X) & Mode_LoadAnswers)
#define IsMode_ExecAnswers(X) (!IsMode_LoadAnswers(X))
#define SetDefaultMode_Local(X) (X) |= DefaultMode_Local
#define SetDefaultMode_Batched(X) (X) &= ~DefaultMode_Local
#define SetDefaultMode_LoadAnswers(X) (X) |= DefaultMode_LoadAnswers
#define SetDefaultMode_ExecAnswers(X) (X) &= ~DefaultMode_LoadAnswers
#define IsDefaultMode_Local(X) ((X) & DefaultMode_Local)
#define IsDefaultMode_Batched(X) (!IsDefaultMode_Local(X))
#define IsDefaultMode_LoadAnswers(X) ((X) & DefaultMode_LoadAnswers)
#define IsDefaultMode_ExecAnswers(X) (!IsDefaultMode_LoadAnswers(X))
/*********************************
** Struct table_entry **
*********************************/
/**************************
** table_entry **
**************************/
typedef struct table_entry {
#if defined(YAPOR) || defined(THREADS)
lockvar lock;
#endif /* YAPOR */
#endif /* YAPOR || THREADS */
struct pred_entry *pred_entry;
Atom pred_atom;
int pred_arity;
int mode_flags;
short pred_flags;
short execution_mode; /* combines yap_flags with pred_flags */
struct subgoal_trie_node *subgoal_trie;
struct subgoal_trie_hash *hash_chain;
struct table_entry *next;
@ -72,16 +37,17 @@ typedef struct table_entry {
#define TabEnt_pe(X) ((X)->pred_entry)
#define TabEnt_atom(X) ((X)->pred_atom)
#define TabEnt_arity(X) ((X)->pred_arity)
#define TabEnt_mode(X) ((X)->mode_flags)
#define TabEnt_flags(X) ((X)->pred_flags)
#define TabEnt_mode(X) ((X)->execution_mode)
#define TabEnt_subgoal_trie(X) ((X)->subgoal_trie)
#define TabEnt_hash_chain(X) ((X)->hash_chain)
#define TabEnt_next(X) ((X)->next)
/*******************************************************************************
** Structs global_trie_node, subgoal_trie_node and answer_trie_node **
*******************************************************************************/
/***********************************************************************
** global_trie_node, subgoal_trie_node and answer_trie_node **
***********************************************************************/
#ifdef GLOBAL_TRIE
typedef struct global_trie_node {
@ -127,9 +93,9 @@ typedef struct answer_trie_node {
/*******************************************************************************
** Structs global_trie_hash, subgoal_trie_hash and answer_trie_hash **
*******************************************************************************/
/***********************************************************************
** global_trie_hash, subgoal_trie_hash and answer_trie_hash **
***********************************************************************/
#ifdef GLOBAL_TRIE
typedef struct global_trie_hash {
@ -172,9 +138,54 @@ typedef struct answer_trie_hash {
/***********************************
** Struct subgoal_frame **
***********************************/
/************************************************************************
** Execution Data Structures **
************************************************************************/
/****************************
** choice points **
****************************/
struct generator_choicept {
struct choicept cp;
struct dependency_frame *cp_dep_fr; /* always NULL if batched scheduling */
struct subgoal_frame *cp_sg_fr;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};
#ifdef DETERMINISTIC_TABLING
struct deterministic_generator_choicept {
struct deterministic_choicept cp;
struct subgoal_frame *cp_sg_fr;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};
#endif /* DETERMINISTIC_TABLING */
struct consumer_choicept {
struct choicept cp;
struct dependency_frame *cp_dep_fr;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};
struct loader_choicept {
struct choicept cp;
struct answer_trie_node *cp_last_answer;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};
/****************************
** subgoal_frame **
****************************/
typedef struct subgoal_frame {
#if defined(YAPOR) || defined(THREADS)
@ -185,7 +196,7 @@ typedef struct subgoal_frame {
struct or_frame *top_or_frame_on_generator_branch;
#endif /* YAPOR */
yamop *code_of_subgoal;
enum {
enum { /* do not change order !!! */
incomplete = 0, /* INCOMPLETE_TABLING */
ready = 1,
evaluating = 2,
@ -193,7 +204,7 @@ typedef struct subgoal_frame {
complete_in_use = 4, /* LIMIT_TABLING */
compiled = 5,
compiled_in_use = 6 /* LIMIT_TABLING */
} state_flag; /* do not change order !!! */
} state_flag;
choiceptr generator_choice_point;
struct answer_trie_hash *hash_chain;
struct answer_trie_node *answer_trie;
@ -252,14 +263,14 @@ typedef struct subgoal_frame {
/**************************************
** Struct dependency_frame **
**************************************/
/*******************************
** dependency_frame **
*******************************/
typedef struct dependency_frame {
#if defined(YAPOR) || defined(THREADS)
lockvar lock;
#endif
#endif /* YAPOR || THREADS */
#ifdef YAPOR
int leader_dependency_is_on_stack;
struct or_frame *top_or_frame;
@ -307,9 +318,9 @@ typedef struct dependency_frame {
/**************************************
** Struct suspension_frame **
**************************************/
/*******************************
** suspension_frame **
*******************************/
#ifdef YAPOR
typedef struct suspension_frame {
@ -338,44 +349,3 @@ typedef struct suspension_frame {
#define SuspFr_trail_start(X) ((X)->trail_block.block_start)
#define SuspFr_trail_size(X) ((X)->trail_block.block_size)
#define SuspFr_next(X) ((X)->next)
/************************************
** Structs choice points **
************************************/
struct generator_choicept {
struct choicept cp;
struct dependency_frame *cp_dep_fr; /* always NULL if batched scheduling */
struct subgoal_frame *cp_sg_fr;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};
#ifdef DETERMINISTIC_TABLING
struct deterministic_generator_choicept {
struct deterministic_choicept cp;
struct subgoal_frame *cp_sg_fr;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};
#endif /* DETERMINISTIC_TABLING */
struct consumer_choicept {
struct choicept cp;
struct dependency_frame *cp_dep_fr;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};
struct loader_choicept {
struct choicept cp;
struct answer_trie_node *cp_last_answer;
#ifdef LOW_LEVEL_TRACER
struct pred_entry *cp_pred_entry;
#endif /* LOW_LEVEL_TRACER */
};

View File

@ -89,6 +89,7 @@ static struct trie_statistics{
#ifdef GLOBAL_TRIE
long global_trie_terms;
long global_trie_nodes;
long global_trie_references;
#endif /* GLOBAL_TRIE */
} trie_stats;
@ -103,6 +104,7 @@ static struct trie_statistics{
#define TrStat_ans_nodes trie_stats.answer_trie_nodes
#define TrStat_gt_terms trie_stats.global_trie_terms
#define TrStat_gt_nodes trie_stats.global_trie_nodes
#define TrStat_gt_refs trie_stats.global_trie_references
#define SHOW_TABLE_STR_ARRAY_SIZE 100000
#define SHOW_TABLE_ARITY_ARRAY_SIZE 10000
#define SHOW_TABLE_STRUCTURE(MESG, ARGS...) \
@ -496,7 +498,7 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str, int str_in
else {
TrStat_gt_terms++;
str[str_index] = 0;
SHOW_TABLE_STRUCTURE(" TERM (x%ld): %s\n", (unsigned long int) TrNode_child(current_node), str);
SHOW_TABLE_STRUCTURE(" TERMx%ld: %s\n", (unsigned long int) TrNode_child(current_node), str);
}
/* restore the initial state and continue with sibling nodes */
@ -816,6 +818,7 @@ static inline void traverse_trie_node(Term t, char *str, int *str_index_ptr, int
} else if (IsVarTerm(t)) {
#ifdef GLOBAL_TRIE
if (t > VarIndexOfTableTerm(MAX_TABLE_VARS)) {
TrStat_gt_refs++;
traverse_global_trie_for_term((gt_node_ptr) t, str, &str_index, arity, &mode, type);
} else
#endif /* GLOBAL_TRIE */
@ -1335,8 +1338,11 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
TrStat_answers_pruned = 0;
#endif /* TABLING_INNER_CUTS */
TrStat_ans_nodes = 0;
#ifdef GLOBAL_TRIE
TrStat_gt_refs = 0;
#endif /* GLOBAL_TRIE */
fprintf(Yap_stdout, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
} else { /* show_mode == SHOW_MODE_STRUCTURE */
} else { /* SHOW_MODE_STRUCTURE */
fprintf(Yap_stdout, "Table structure for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
}
sg_node = TrNode_child(TabEnt_subgoal_trie(tab_ent));
@ -1383,20 +1389,25 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
fprintf(Yap_stdout, " Answers 'TRUE': %ld\n", TrStat_answers_true);
fprintf(Yap_stdout, " Answers 'NO': %ld\n", TrStat_answers_no);
fprintf(Yap_stdout, " Answer trie nodes: %ld\n", TrStat_ans_nodes);
fprintf(Yap_stdout, " Total memory in use: %ld bytes\n",
sizeof(struct table_entry) + TrStat_sg_nodes * sizeof(struct subgoal_trie_node) +
TrStat_ans_nodes * sizeof(struct answer_trie_node) + TrStat_subgoals * sizeof(struct subgoal_frame));
#ifdef GLOBAL_TRIE
fprintf(Yap_stdout, " Global trie references: %ld\n", TrStat_gt_refs);
#endif /* GLOBAL_TRIE */
}
return;
}
#ifdef GLOBAL_TRIE
void show_global_trie(void) {
TrStat_show = SHOW_MODE_STRUCTURE;
TrStat_gt_terms = 0;
TrStat_gt_nodes = 1;
fprintf(Yap_stdout, "Global trie structure\n");
void show_global_trie(int show_mode) {
TrStat_show = show_mode;
if (show_mode == SHOW_MODE_STATISTICS) {
TrStat_gt_terms = 0;
TrStat_gt_nodes = 1;
TrStat_gt_refs = 0;
fprintf(Yap_stdout, "Global trie statistics\n");
} else { /* SHOW_MODE_STRUCTURE */
fprintf(Yap_stdout, "Global trie structure\n");
}
if (TrNode_child(GLOBAL_root_gt)) {
char *str = (char *) malloc(sizeof(char) * SHOW_TABLE_STR_ARRAY_SIZE);
int *arity = (int *) malloc(sizeof(int) * SHOW_TABLE_ARITY_ARRAY_SIZE);
@ -1406,10 +1417,11 @@ void show_global_trie(void) {
free(arity);
} else
SHOW_TABLE_STRUCTURE(" EMPTY\n");
fprintf(Yap_stdout, "Global trie statistics\n");
fprintf(Yap_stdout, " Terms: %ld\n", TrStat_gt_terms);
fprintf(Yap_stdout, " Global trie nodes: %ld\n", TrStat_gt_nodes);
fprintf(Yap_stdout, " Total memory in use: %ld bytes\n", TrStat_gt_nodes * sizeof(struct global_trie_node));
if (show_mode == SHOW_MODE_STATISTICS) {
fprintf(Yap_stdout, " Terms: %ld\n", TrStat_gt_terms);
fprintf(Yap_stdout, " Global trie nodes: %ld\n", TrStat_gt_nodes);
fprintf(Yap_stdout, " Global trie auto references: %ld\n", TrStat_gt_refs);
}
return;
}
#endif /* GLOBAL_TRIE */

View File

@ -123,7 +123,8 @@ A GcVeryVerbose F "$gc_very_verbose"
A GeneratePredInfo F "$generate_pred_info"
A Getwork F "$getwork"
A GetworkSeq F "$getwork_seq"
A Global N "global_sp"
A GlobalSp N "global_sp"
A GlobalTrie N "global_trie"
A GoalExpansion N "goal_expansion"
A HERE N "\n <====HERE====> \n"
A HandleThrow F "$handle_throw"
@ -151,8 +152,9 @@ A Leash F "$leash"
A List N "list"
A Live F "$live"
A LoadAnswers N "load_answers"
A Local N "local_sp"
A LocalA N "local"
A Local N "local"
A LocalSp N "local_sp"
A LocalTrie N "local_trie"
A MaxArity N "max_arity"
A MaxFiles N "max_files"
A MegaClause F "$mega_clause"

View File

@ -190,25 +190,25 @@ yap_flag(home,X) :-
yap_flag(tabling_mode,Options) :-
var(Options), !,
'$access_yap_flags'(20,Options).
yap_flag(tabling_mode,[]) :- !.
yap_flag(tabling_mode,[]) :- !,
yap_flag(tabling_mode,default).
yap_flag(tabling_mode,[HOption|TOption]) :- !,
yap_flag(tabling_mode,HOption),
yap_flag(tabling_mode,TOption).
yap_flag(tabling_mode,(Option1,Option2)) :- !,
yap_flag(tabling_mode,Option1),
yap_flag(tabling_mode,Option2).
yap_flag(tabling_mode,TOption),
yap_flag(tabling_mode,HOption).
yap_flag(tabling_mode,Option) :-
'$transl_to_tabling_mode'(Flag,Option),
'$transl_to_yap_flag_tabling_mode'(Flag,Option), !,
'$set_yap_flags'(20,Flag).
yap_flag(tabling_mode,Options) :-
'$do_error'(domain_error(flag_value,tabling_mode+Options),yap_flag(tabling_mode,Options)).
% should match with code in stdpreds.c
'$transl_to_tabling_mode'(0,default).
'$transl_to_tabling_mode'(1,batched).
'$transl_to_tabling_mode'(2,local).
'$transl_to_tabling_mode'(3,exec_answers).
'$transl_to_tabling_mode'(4,load_answers).
'$transl_to_yap_flag_tabling_mode'(0,default).
'$transl_to_yap_flag_tabling_mode'(1,batched).
'$transl_to_yap_flag_tabling_mode'(2,local).
'$transl_to_yap_flag_tabling_mode'(3,exec_answers).
'$transl_to_yap_flag_tabling_mode'(4,load_answers).
'$transl_to_yap_flag_tabling_mode'(5,local_trie).
'$transl_to_yap_flag_tabling_mode'(6,global_trie).
yap_flag(informational_messages,X) :- var(X), !,
get_value('$verbose',X).

View File

@ -120,9 +120,12 @@ tabling_mode(Pred,Options) :-
integer(PredArity),
functor(PredFunctor,PredName,PredArity),
'$flags'(PredFunctor,Mod,Flags,Flags), !,
(Flags /\ 0x000040 =\= 0, !, '$set_tabling_mode'(Mod,PredFunctor,Options)
(
Flags /\ 0x000040 =\= 0, !, '$set_tabling_mode'(Mod,PredFunctor,Options)
;
'$do_error'(domain_error(table,Mod:PredName/PredArity),tabling_mode(Mod:PredName/PredArity,Options))).
write(icardioi),nl,
'$do_error'(domain_error(table,Mod:PredName/PredArity),tabling_mode(Mod:PredName/PredArity,Options))
).
'$do_tabling_mode'(Mod,Pred,Options) :-
'$do_error'(type_error(callable,Mod:Pred),tabling_mode(Mod:Pred,Options)).
@ -137,12 +140,20 @@ tabling_mode(Pred,Options) :-
'$set_tabling_mode'(Mod,PredFunctor,Option1),
'$set_tabling_mode'(Mod,PredFunctor,Option2).
'$set_tabling_mode'(Mod,PredFunctor,Option) :-
(Option = batched ; Option = local ; Option = exec_answers ; Option = load_answers), !,
'$c_tabling_mode'(Mod,PredFunctor,Option).
'$transl_to_pred_flag_tabling_mode'(Flag,Option), !,
'$c_tabling_mode'(Mod,PredFunctor,Flag).
'$set_tabling_mode'(Mod,PredFunctor,Options) :-
functor(PredFunctor,PredName,PredArity),
'$do_error'(domain_error(flag_value,tabling_mode+Options),tabling_mode(Mod:PredName/PredArity,Options)).
% should match with code in OPTYap/opt.preds.c
'$transl_to_pred_flag_tabling_mode'(1,batched).
'$transl_to_pred_flag_tabling_mode'(2,local).
'$transl_to_pred_flag_tabling_mode'(3,exec_answers).
'$transl_to_pred_flag_tabling_mode'(4,load_answers).
'$transl_to_pred_flag_tabling_mode'(5,local_trie).
'$transl_to_pred_flag_tabling_mode'(6,global_trie).
/**************************
@ -170,9 +181,11 @@ abolish_table(Pred) :-
integer(PredArity),
functor(PredFunctor,PredName,PredArity),
'$flags'(PredFunctor,Mod,Flags,Flags), !,
(Flags /\ 0x000040 =\= 0, !, '$c_abolish_table'(Mod,PredFunctor)
(
Flags /\ 0x000040 =\= 0, !, '$c_abolish_table'(Mod,PredFunctor)
;
'$do_error'(domain_error(table,Mod:PredName/PredArity),abolish_table(Mod:PredName/PredArity))).
'$do_error'(domain_error(table,Mod:PredName/PredArity),abolish_table(Mod:PredName/PredArity))
).
'$do_abolish_table'(Mod,Pred) :-
'$do_error'(type_error(callable,Mod:Pred),abolish_table(Mod:Pred)).
@ -203,9 +216,11 @@ show_table(Pred) :-
integer(PredArity),
functor(PredFunctor,PredName,PredArity),
'$flags'(PredFunctor,Mod,Flags,Flags), !,
(Flags /\ 0x000040 =\= 0, !, '$c_show_table'(Mod,PredFunctor)
(
Flags /\ 0x000040 =\= 0, !, '$c_show_table'(Mod,PredFunctor)
;
'$do_error'(domain_error(table,Mod:PredName/PredArity),show_table(Mod:PredName/PredArity))).
'$do_error'(domain_error(table,Mod:PredName/PredArity),show_table(Mod:PredName/PredArity))
).
'$do_show_table'(Mod,Pred) :-
'$do_error'(type_error(callable,Mod:Pred),show_table(Mod:Pred)).
@ -236,8 +251,10 @@ table_statistics(Pred) :-
integer(PredArity),
functor(PredFunctor,PredName,PredArity),
'$flags'(PredFunctor,Mod,Flags,Flags), !,
(Flags /\ 0x000040 =\= 0, !, '$c_table_statistics'(Mod,PredFunctor)
(
Flags /\ 0x000040 =\= 0, !, '$c_table_statistics'(Mod,PredFunctor)
;
'$do_error'(domain_error(table,Mod:PredName/PredArity),table_statistics(Mod:PredName/PredArity))).
'$do_error'(domain_error(table,Mod:PredName/PredArity),table_statistics(Mod:PredName/PredArity))
).
'$do_table_statistics'(Mod,Pred) :-
'$do_error'(type_error(callable,Mod:Pred),table_statistics(Mod:Pred)).