diff --git a/OPTYap/opt.preds.c b/OPTYap/opt.preds.c index 6ecdc0622..85d133e68 100644 --- a/OPTYap/opt.preds.c +++ b/OPTYap/opt.preds.c @@ -37,7 +37,9 @@ #ifdef TABLING static Int p_freeze_choice_point(void); static Int p_wake_choice_point(void); -static Int p_abolish_all_frozen_choice_points(void); +static Int p_reset_frozen_choice_points(void); +static Int p_abolish_frozen_choice_points_until(void); +static Int p_abolish_frozen_choice_points_all(void); static Int p_table(void); static Int p_tabling_mode(void); static Int p_abolish_table(void); @@ -122,7 +124,8 @@ void Yap_init_optyap_preds(void) { #ifdef TABLING Yap_InitCPred("freeze_choice_point", 1, p_freeze_choice_point, SafePredFlag|SyncPredFlag); Yap_InitCPred("wake_choice_point", 1, p_wake_choice_point, SafePredFlag|SyncPredFlag); - Yap_InitCPred("abolish_all_frozen_choice_points", 0, p_abolish_all_frozen_choice_points, SafePredFlag|SyncPredFlag); + Yap_InitCPred("abolish_frozen_choice_points", 1, p_abolish_frozen_choice_points_until, SafePredFlag|SyncPredFlag); + Yap_InitCPred("abolish_frozen_choice_points", 0, p_abolish_frozen_choice_points_all, SafePredFlag|SyncPredFlag); Yap_InitCPred("$c_table", 2, p_table, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_tabling_mode", 3, p_tabling_mode, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_abolish_table", 2, p_abolish_table, SafePredFlag|SyncPredFlag|HiddenPredFlag); @@ -170,32 +173,32 @@ void finish_yapor(void) { #ifdef TABLING static Int p_freeze_choice_point(void) { - Term term_arg, term_cp; - - term_arg = Deref(ARG1); - if (IsVarTerm(term_arg)) { - choiceptr cp = freeze_current_cp(); - term_cp = MkIntegerTerm((Int) cp); - return Yap_unify(ARG1, term_cp); + if (IsVarTerm(Deref(ARG1))) { + Int offset = freeze_current_cp(); + return Yap_unify(ARG1, MkIntegerTerm(offset)); } return (FALSE); } static Int p_wake_choice_point(void) { - Term term_arg; - - term_arg = Deref(ARG1); - if (IsIntegerTerm(term_arg)) { - choiceptr cp = (choiceptr) IntegerOfTerm(term_arg); - resume_frozen_cp(cp); - } + Term term_offset = Deref(ARG1); + if (IsIntegerTerm(term_offset)) + wake_frozen_cp(IntegerOfTerm(term_offset)); return (FALSE); } -static Int p_abolish_all_frozen_choice_points(void) { - abolish_all_frozen_cps(); +static Int p_abolish_frozen_choice_points_until(void) { + Term term_offset = Deref(ARG1); + if (IsIntegerTerm(term_offset)) + abolish_frozen_cps_until(IntegerOfTerm(term_offset)); + return (TRUE); +} + + +static Int p_abolish_frozen_choice_points_all(void) { + abolish_frozen_cps_all(); return (TRUE); } diff --git a/OPTYap/tab.macros.h b/OPTYap/tab.macros.h old mode 100755 new mode 100644 index 740ff28f9..4038d26ba --- a/OPTYap/tab.macros.h +++ b/OPTYap/tab.macros.h @@ -21,9 +21,10 @@ #endif /* HAVE_STRING_H */ #include "opt.mavar.h" -static inline choiceptr freeze_current_cp(void); -static inline void resume_frozen_cp(choiceptr); -static inline void abolish_all_frozen_cps(void); +static inline Int freeze_current_cp(void); +static inline void wake_frozen_cp(Int); +static inline void abolish_frozen_cps_until(Int); +static inline void abolish_frozen_cps_all(void); static inline void adjust_freeze_registers(void); static inline void mark_as_completed(sg_fr_ptr); static inline void unbind_variables(tr_fr_ptr, tr_fr_ptr); @@ -421,7 +422,7 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int); ** Inline funcions ** ******************************/ -static inline choiceptr freeze_current_cp(void) { +static inline Int freeze_current_cp(void) { choiceptr freeze_cp = B; B_FZ = freeze_cp; @@ -429,11 +430,13 @@ static inline choiceptr freeze_current_cp(void) { TR_FZ = freeze_cp->cp_tr; B = B->cp_b; HB = B->cp_h; - return freeze_cp; + return (Yap_LocalBase - (ADDR)freeze_cp); } -static inline void resume_frozen_cp(choiceptr frozen_cp) { +static inline void wake_frozen_cp(Int frozen_offset) { + choiceptr frozen_cp = (choiceptr)(Yap_LocalBase - frozen_offset); + restore_bindings(TR, frozen_cp->cp_tr); B = frozen_cp; TR = TR_FZ; @@ -442,7 +445,17 @@ static inline void resume_frozen_cp(choiceptr frozen_cp) { } -static inline void abolish_all_frozen_cps(void) { +static inline void abolish_frozen_cps_until(Int frozen_offset) { + choiceptr frozen_cp = (choiceptr)(Yap_LocalBase - frozen_offset); + + B_FZ = frozen_cp; + H_FZ = frozen_cp->cp_h; + TR_FZ = frozen_cp->cp_tr; + return; +} + + +static inline void abolish_frozen_cps_all(void) { B_FZ = (choiceptr) Yap_LocalBase; H_FZ = (CELL *) Yap_GlobalBase; TR_FZ = (tr_fr_ptr) Yap_TrailBase;