small improvements to debugger, prolog mode and meta-call (*->)

This commit is contained in:
Vítor Santos Costa 2013-12-10 22:58:02 +00:00
parent 795f01d125
commit e768a7e7be
7 changed files with 41 additions and 60 deletions

View File

@ -7527,7 +7527,7 @@ Yap_absmi(int inp)
/* make sure that we can still have access to our old PREG after calling user defined goals and backtracking or failing */ /* make sure that we can still have access to our old PREG after calling user defined goals and backtracking or failing */
yamop *savedP; yamop *savedP;
LOCAL_PrologMode = UserCCallMode; LOCAL_PrologMode |= UserCCallMode;
{ {
PredEntry *p = PREG->u.Osbpp.p; PredEntry *p = PREG->u.Osbpp.p;
@ -7539,7 +7539,7 @@ Yap_absmi(int inp)
SREG = (CELL *) YAP_Execute(p, p->cs.f_code); SREG = (CELL *) YAP_Execute(p, p->cs.f_code);
} }
setregs(); setregs();
LOCAL_PrologMode = UserMode; LOCAL_PrologMode &= ~UserCCallMode;
restore_machine_regs(); restore_machine_regs();
PREG = savedP; PREG = savedP;
} }
@ -7708,7 +7708,7 @@ Yap_absmi(int inp)
#endif #endif
SET_BB(B_YREG); SET_BB(B_YREG);
ENDCACHE_Y(); ENDCACHE_Y();
LOCAL_PrologMode = UserCCallMode; LOCAL_PrologMode |= UserCCallMode;
ASP = YREG; ASP = YREG;
saveregs(); saveregs();
save_machine_regs(); save_machine_regs();
@ -7716,7 +7716,7 @@ Yap_absmi(int inp)
EX = NULL; EX = NULL;
restore_machine_regs(); restore_machine_regs();
setregs(); setregs();
LOCAL_PrologMode = UserMode; LOCAL_PrologMode &= ~UserCCallMode;
if (!SREG) { if (!SREG) {
FAIL(); FAIL();
} }
@ -7748,7 +7748,7 @@ Yap_absmi(int inp)
restore_args(PREG->u.OtapFs.s); restore_args(PREG->u.OtapFs.s);
ENDCACHE_Y(); ENDCACHE_Y();
LOCAL_PrologMode = UserCCallMode; LOCAL_PrologMode |= UserCCallMode;
SET_ASP(YREG, E_CB*sizeof(CELL)); SET_ASP(YREG, E_CB*sizeof(CELL));
saveregs(); saveregs();
save_machine_regs(); save_machine_regs();
@ -7756,7 +7756,7 @@ Yap_absmi(int inp)
EX = NULL; EX = NULL;
restore_machine_regs(); restore_machine_regs();
setregs(); setregs();
LOCAL_PrologMode = UserMode; LOCAL_PrologMode &= ~UserCCallMode;
if (!SREG) { if (!SREG) {
#ifdef CUT_C #ifdef CUT_C
/* Removes the cut functions from the stack /* Removes the cut functions from the stack

View File

@ -2384,9 +2384,9 @@ run_emulator(YAP_dogoalinfo *dgi USES_REGS)
{ {
int out; int out;
LOCAL_PrologMode = UserMode; LOCAL_PrologMode &= ~(UserCCallMode|CCallMode);
out = Yap_absmi(0); out = Yap_absmi(0);
LOCAL_PrologMode = UserCCallMode; LOCAL_PrologMode |= UserCCallMode;
return out; return out;
} }

View File

@ -172,7 +172,9 @@ do_execute(Term t, Term mod USES_REGS)
} }
UNLOCK(LOCAL_SignalLock); UNLOCK(LOCAL_SignalLock);
return CallMetaCall(ARG1, mod PASS_REGS); return CallMetaCall(ARG1, mod PASS_REGS);
} else if (LOCAL_ActiveSignals && !LOCAL_InterruptsDisabled) { } else if (LOCAL_ActiveSignals && !LOCAL_InterruptsDisabled &&
!(LOCAL_PrologMode & (AbortMode|InterruptMode|SystemMode))) {
printf("here %lx\n", LOCAL_PrologMode);
return EnterCreepMode(t, mod PASS_REGS); return EnterCreepMode(t, mod PASS_REGS);
} }
restart_exec: restart_exec:

View File

@ -1840,11 +1840,20 @@ p_set_yap_flags( USES_REGS1 )
static Int static Int
p_system_mode( USES_REGS1 ) p_system_mode( USES_REGS1 )
{ {
Int i = IntegerOfTerm(Deref(ARG1)); Term t1 = Deref(ARG1);
if (i == 0)
LOCAL_PrologMode &= ~SystemMode; if (IsVarTerm(t1)) {
else if (LOCAL_PrologMode & SystemMode)
LOCAL_PrologMode |= SystemMode; return Yap_unify( t1, MkAtomTerm(AtomTrue));
else
return Yap_unify( t1, MkAtomTerm(AtomFalse));
} else {
Atom at = AtomOfTerm(t1);
if (at == AtomFalse)
LOCAL_PrologMode &= ~SystemMode;
else
LOCAL_PrologMode |= SystemMode;
}
return TRUE; return TRUE;
} }
@ -2002,7 +2011,7 @@ Yap_InitCPreds(void)
Yap_InitCPred("$walltime", 2, p_walltime, SafePredFlag|SyncPredFlag); Yap_InitCPred("$walltime", 2, p_walltime, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$access_yap_flags", 2, p_access_yap_flags, SafePredFlag); Yap_InitCPred("$access_yap_flags", 2, p_access_yap_flags, SafePredFlag);
Yap_InitCPred("$set_yap_flags", 2, p_set_yap_flags, SafePredFlag|SyncPredFlag); Yap_InitCPred("$set_yap_flags", 2, p_set_yap_flags, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$p_system_mode", 1, p_system_mode, SafePredFlag|SyncPredFlag); Yap_InitCPred("$system_mode", 1, p_system_mode, SafePredFlag|SyncPredFlag);
Yap_InitCPred("abort", 0, p_abort, SyncPredFlag); Yap_InitCPred("abort", 0, p_abort, SyncPredFlag);
Yap_InitCPred("$break", 1, p_break, SafePredFlag); Yap_InitCPred("$break", 1, p_break, SafePredFlag);
#ifdef BEAM #ifdef BEAM

View File

@ -95,7 +95,7 @@ true :- true.
'$init_consult', '$init_consult',
% '$swi_set_prolog_flag'(break_level, 0), % '$swi_set_prolog_flag'(break_level, 0),
% '$set_read_error_handler'(error), let the user do that % '$set_read_error_handler'(error), let the user do that
nb_setval('$system_mode',off), '$system_mode'(true),
nb_setval('$chr_toplevel_show_store',false). nb_setval('$chr_toplevel_show_store',false).
'$init_consult' :- '$init_consult' :-
@ -1200,58 +1200,26 @@ catch_ball(C, C).
'$enter_system_mode' :- '$enter_system_mode' :-
'$stop_creeping', '$stop_creeping',
nb_setval('$system_mode',on). '$system_mode'(true).
'$in_system_mode' :- '$in_system_mode' :-
'$nb_getval'('$system_mode',on,fail). '$system_mode'(State),
State = true.
'$execute_outside_system_mode'(G,M) :- '$execute_outside_system_mode'(G,M) :-
CP is '$last_choice_pt', ( '$$save_by'(CP1),
'$execute_outside_system_mode'(G,M,CP). '$exit_system_mode',
'$call'(G, CP, M:G, M),
'$execute_outside_system_mode'(V,M,_) :-
var(V), !,
call(M:V).
'$execute_outside_system_mode'(M:G, _M, CP) :- !,
'$execute_outside_system_mode'(G, M, CP).
'$execute_outside_system_mode'((G1,G2), M, CP) :- !,
'$execute_outside_system_mode'(G1, M, CP),
'$execute_outside_system_mode'(G2, M, CP).
'$execute_outside_system_mode'((G1;G2), M, CP) :- !,
(
'$execute_outside_system_mode'(G1, M, CP)
;
'$execute_outside_system_mode'(G2, M, CP)
).
'$execute_outside_system_mode'(G, M, CP) :-
'$nb_getval'('$trace', on, fail), !,
(
'$$save_by'(CP1),
'$do_spy'(G, M, CP, meta_creep),
% we may exit system mode...
'$$save_by'(CP2), '$$save_by'(CP2),
(CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', fail ) ), (CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', fail ) ),
'$enter_system_mode' '$enter_system_mode'
;
'$enter_system_mode',
fail
).
'$execute_outside_system_mode'(G, M, CP) :-
(
'$$save_by'(CP1),
'$exit_system_mode',
'$call'(G, CP, M:G, M),
'$$save_by'(CP2),
(CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', fail ) ),
'$enter_system_mode'
; ;
'$enter_system_mode', '$enter_system_mode',
fail fail
). ).
'$exit_system_mode' :- '$exit_system_mode' :-
nb_setval('$system_mode',off), '$system_mode'(false),
( '$nb_getval'('$trace',on,fail) -> '$meta_creep' ; true). ( '$nb_getval'('$trace',on,fail) -> '$meta_creep' ; true).
'$run_at_thread_start' :- '$run_at_thread_start' :-

View File

@ -401,8 +401,8 @@ use_module(M,F,Is) :-
'$extend_exports'(ContextModule, Imports) '$extend_exports'(ContextModule, Imports)
), ),
( LC == 0 -> prompt(_,' |: ') ; true), ( LC == 0 -> prompt(_,' |: ') ; true),
( OldMode == off -> '$exit_system_mode' ; true ),
'$exec_initialisation_goals', '$exec_initialisation_goals',
( OldMode == true -> '$enter_system_mode' ; true ),
% format( 'O=~w~n', [Mod=UserFile] ), % format( 'O=~w~n', [Mod=UserFile] ),
!. !.
@ -436,8 +436,8 @@ use_module(M,F,Is) :-
'$get_if'(0). '$get_if'(0).
'$into_system_mode'(OldMode) :- '$into_system_mode'(OldMode) :-
( '$nb_getval'('$system_mode', OldMode, fail) -> true ; OldMode = off), '$system_mode'(OldMode),
( OldMode == off -> '$enter_system_mode' ; true ). '$system_mode'(true).
'$bind_module'(_, load_files). '$bind_module'(_, load_files).
'$bind_module'(Mod, use_module(Mod)). '$bind_module'(Mod, use_module(Mod)).

View File

@ -193,7 +193,9 @@ trace :-
'$do_trace' :- '$do_trace' :-
'$init_debugger', '$init_debugger',
'$nb_getval'('$trace', on, fail), !. '$nb_getval'('$trace', on, fail), !,
'$start_debugging'(on),
'$creep'.
'$do_trace' :- '$do_trace' :-
nb_setval('$trace',on), nb_setval('$trace',on),
'$start_debugging'(on), '$start_debugging'(on),