From 0f313755ccc2a0ebd6db5e4de9389e4fee46abe7 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 2 Nov 2018 17:16:18 +0000 Subject: [PATCH] top --- C/exec.c | 9 ++++++++- H/YapHandles.h | 4 ++-- pl/consult.yap | 8 ++++---- pl/control.yap | 2 +- pl/debug.yap | 2 +- pl/grammar.yap | 3 +++ pl/init.yap | 6 +++--- pl/top.yap | 8 ++++---- pl/yio.yap | 2 +- 9 files changed, 27 insertions(+), 17 deletions(-) diff --git a/C/exec.c b/C/exec.c index 92b341905..deab9ddcd 100755 --- a/C/exec.c +++ b/C/exec.c @@ -1009,6 +1009,7 @@ static bool complete_ge(bool out, Term omod, yhandle_t sl, bool creeping) { } static Int _user_expand_goal(USES_REGS1) { + BACKUP_MACHINE_REGS(); yhandle_t sl = Yap_StartSlots(); Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL); PredEntry *pe; @@ -1055,12 +1056,15 @@ static Int _user_expand_goal(USES_REGS1) { Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && Yap_execute_pred(pe, NULL PASS_REGS, false)) { + RECOVER_MACHINE_REGS(); return complete_ge(true, omod, sl, creeping); } + RECOVER_MACHINE_REGS(); return complete_ge(false, omod, sl, creeping); } static Int do_term_expansion(USES_REGS1) { + BACKUP_MACHINE_REGS(); yhandle_t sl = Yap_StartSlots(); Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL); PredEntry *pe; @@ -1075,6 +1079,7 @@ static Int do_term_expansion(USES_REGS1) { Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE))) && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && Yap_execute_pred(pe, NULL, false PASS_REGS)) { + RECOVER_MACHINE_REGS(); return complete_ge(true, omod, sl, creeping); } /* CurMod:term_expansion(A,B) */ @@ -1083,6 +1088,7 @@ static Int do_term_expansion(USES_REGS1) { (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, cmod))) && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && Yap_execute_pred(pe, NULL, false PASS_REGS)) { + RECOVER_MACHINE_REGS(); return complete_ge(true, omod, sl, creeping); } /* system:term_expansion(A,B) */ @@ -1094,8 +1100,10 @@ static Int do_term_expansion(USES_REGS1) { Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE))) && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && Yap_execute_pred(pe, NULL, false PASS_REGS)) { + RECOVER_MACHINE_REGS(); return complete_ge(true, omod, sl, creeping); } + RECOVER_MACHINE_REGS(); return complete_ge(false, omod, sl, creeping); } @@ -1659,7 +1667,6 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) { yamop *saved_p, *saved_cp; yamop *CodeAdr; bool out; - saved_p = P; saved_cp = CP; LOCAL_PrologMode |= TopGoalMode; diff --git a/H/YapHandles.h b/H/YapHandles.h index cd5d2bc09..f7a6be6d3 100755 --- a/H/YapHandles.h +++ b/H/YapHandles.h @@ -218,9 +218,9 @@ INLINE_ONLY yhandle_t Yap_InitHandle__(Term t USES_REGS) { ensure_slots(1 PASS_REGS); if (t==0) { t = MkVarTerm(); - } else if (IsVarTerm(t) ) { + } else if (IsVarTerm(t) && VarOfTerm(t) > HR ) { Term tg = MkVarTerm(); - Bind_Global( VarOfTerm(t), tg); + Bind_Local(VarOfTerm(t), tg); } LOCAL_HandleBase[old_slots] = t; LOCAL_CurHandle++; diff --git a/pl/consult.yap b/pl/consult.yap index f7c69abd9..b5a8f6364 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -834,7 +834,7 @@ nb_setval('$if_le1vel',0). erase(R), G \= '$', strip_module(user:G, M0, G0), - ( catch(M0:G0, Error, loop_error(Error, top)) + ( catch(M0:G0, Error, error_handler(Error, top)) -> true ; @@ -851,7 +851,7 @@ nb_setval('$if_le1vel',0). '$process_init_goal'([G|_]) :- '$yap_strip_module'( G, M0, G0), ( - catch(M0:G0, Error, loop_error(Error, top)) + catch(M0:G0, Error, error_handler(Error, top)) -> true ; @@ -915,7 +915,7 @@ nb_setval('$if_le1vel',0). '$init_win_graphics', fail. '$do_startup_reconsult'(X) :- - catch(load_files(user:X, [silent(true)]), Error, loop_error(Error, consult)), + catch(load_files(user:X, [silent(true)]), Error, error_handler(Error, consult)), !, ( current_prolog_flag(halt_after_consult, false) -> true ; halt). '$do_startup_reconsult'(_). @@ -1463,7 +1463,7 @@ initialization(G,OPT) :- ( OPT == now -> - ( catch(G,E,loop_error(E)) -> true ; format(user_error,':- ~w failed.~n',[G]) ) + ( catch(G,E,error_handler(E)) -> true ; format(user_error,':- ~w failed.~n',[G]) ) ; OPT == after_load -> diff --git a/pl/control.yap b/pl/control.yap index 8ab9a08f5..14e5c78dd 100644 --- a/pl/control.yap +++ b/pl/control.yap @@ -599,7 +599,7 @@ halt(X) :- '$run_atom_goal'(GA) :- '$current_module'(Module), atom_to_term(GA, G, _), - catch(once(Module:G), Error,loop_error(Error)). + catch(once(Module:G), Error,error_handler(Error)). '$add_dot_to_atom_goal'([],[0'.]) :- !. %' '$add_dot_to_atom_goal'([0'.],[0'.]) :- !. diff --git a/pl/debug.yap b/pl/debug.yap index a2cbec7c8..d371e1696 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -497,7 +497,7 @@ be lost. ). '$debugger':execute_nonstop(G,M) :- - '$execute_nonstop'(G,M) + '$execute_nonstop'(G,M). /** * @pred '$sys':enter_trace(+L, 0:G, +Module, +Info) diff --git a/pl/grammar.yap b/pl/grammar.yap index 7e233dbc5..3e7c08718 100644 --- a/pl/grammar.yap +++ b/pl/grammar.yap @@ -94,6 +94,9 @@ Grammar related built-in predicates: Also, phrase/2-3 check their first argument. */ +prolog:'$translate_rule'(Rule, T) :- + translate_rule(Rule, T ). + translate_rule(Rule, (NH :- B) ) :- source_module( SM ), '$yap_strip_module'( SM:Rule, M0, (LP-->RP) ), diff --git a/pl/init.yap b/pl/init.yap index 7e51b519b..43aa8bfd6 100644 --- a/pl/init.yap +++ b/pl/init.yap @@ -114,7 +114,7 @@ fail. '$startup_goals' :- recorded('$startup_goal',G,_), - catch(once(user:G),Error,loop_error(Error)), + catch(once(user:G),Error,error_handler(Error)), fail. '$startup_goals' :- get_value('$init_goal',GA), @@ -125,7 +125,7 @@ '$startup_goals' :- recorded('$restore_flag', goal(Module:GA), R), erase(R), - catch(once(Module:GA),Error,loop_error(Error)), + catch(once(Module:GA),Error,error_handler(Error)), fail. '$startup_goals' :- get_value('$myddas_goal',GA), GA \= [], @@ -204,7 +204,7 @@ recorded('$restore_goal',G,R), erase(R), prompt(_,'| '), - catch(once(user:G),Error,loop_error(Error)), + catch(once(user:G),Error,error_handler(Error)), fail. '$init_path_extensions' :- diff --git a/pl/top.yap b/pl/top.yap index 51053f44e..81a6fc1be 100644 --- a/pl/top.yap +++ b/pl/top.yap @@ -76,7 +76,7 @@ live :- % stop at spy-points if debugging is on. nb_setval('$debug_run',off), nb_setval('$debug_jump',off), - catch('$sys':command(Command,Varnames,Pos,top),E,loop_error(E)), + catch('$sys':command(Command,Varnames,Pos,top),E,error_handler(E)), current_prolog_flag(break_level, BreakLevel), ( BreakLevel \= 0 @@ -785,7 +785,7 @@ write_query_answer( Bindings ) :- format(user_error, ':- ~w failed.~n', [Goal]). '$boot_dcg'( H, B, Where ) :- - '$_grammar':translate_rule((H --> B), (NH :- NB) ), + '$translate_rule'((H --> B), (NH :- NB) ), '$$compile'((NH :- NB), Where, ( H --> B), _R), !. '$boot_dcg'( H, B, _ ) :- @@ -810,7 +810,7 @@ write_query_answer( Bindings ) :- ; read_clause(Stream, Command, Options) ), - catch('$sys':command(Command,Vars,Pos, Status), Error, loop_error(Error,top)). + catch('$sys':command(Command,Vars,Pos, Status), Error, error_handler(Error,top)). /** @pred user:expand_term( _T_,- _X_) is dynamic,multifile. @@ -909,7 +909,7 @@ expand_term(Term,Expanded) :- % Grammar Rules expansion % '$expand_term_grammar'((A-->B), C) :- - '$_grammar':translate_rule((A-->B),C), !. + '$translate_rule'((A-->B),C), !. '$expand_term_grammar'(A, A). % diff --git a/pl/yio.yap b/pl/yio.yap index 67964859a..4bbc7a708 100644 --- a/pl/yio.yap +++ b/pl/yio.yap @@ -181,7 +181,7 @@ display(Stream, T) :- /* interface to user portray */ '$portray'(T) :- \+ '$undefined'(portray(_),user), - catch(user:portray(T),Error,loop_error(Error)), !, + catch(user:portray(T),Error,error_handler(Error)), !, set_value('$portray',true), fail. '$portray'(_) :- set_value('$portray',false), fail.