From d18c67aa2a2e760273b21fcface127bd57382485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Fri, 8 Feb 2013 10:35:40 -0600 Subject: [PATCH 1/4] try to reset stack --- console/yap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/yap.c b/console/yap.c index d067acee9..fd5ed46a6 100755 --- a/console/yap.c +++ b/console/yap.c @@ -166,7 +166,7 @@ main (int argc, char **argv) YAP_RunGoalOnce(t_goal); } } - YAP_ClearExceptions(); + YAP_Reset(); /* End preprocessor code */ exec_top_level(BootMode, &init_args); From 046cb5f8d6b079dddeed535ec8244e780dc1321b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Fri, 8 Feb 2013 10:36:45 -0600 Subject: [PATCH 2/4] debugging --- C/absmi.c | 26 ---- C/c_interface.c | 23 +-- C/cdmgr.c | 1 + C/exec.c | 77 +++------- C/signals.c | 381 ++++++++++++++++++++++++++++++++++++++++++++++ C/stdpreds.c | 225 +-------------------------- C/sysbits.c | 203 ------------------------ H/Yapproto.h | 7 +- pl/attributes.yap | 8 +- pl/boot.yap | 105 +++++++------ pl/consult.yap | 8 +- pl/control.yap | 31 ---- pl/debug.yap | 114 ++++++++------ pl/errors.yap | 8 +- pl/hacks.yap | 1 + pl/modules.yap | 2 +- pl/signals.yap | 131 ++-------------- 17 files changed, 573 insertions(+), 778 deletions(-) create mode 100644 C/signals.c diff --git a/C/absmi.c b/C/absmi.c index f64ef6ae6..8a95d799c 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -512,26 +512,6 @@ Term Yap_XREGS[MaxTemps]; /* 29 */ #include "arith2.h" -/* - I can creep if I am not a prolog builtin that has been called - by a prolog builtin, - exception: meta-calls -*/ -static PredEntry * -creep_allowed(PredEntry *p, PredEntry *p0) -{ - if (!p0) - return NULL; - if (p0 == PredMetaCall) - return p0; - if (!p0->ModuleOfPred && - (!p || - !p->ModuleOfPred || - p->PredFlags & StandardPredFlag)) - return NULL; - return p; -} - #ifdef COROUTINING /* Imagine we are interrupting the execution, say, because we have a spy @@ -2868,11 +2848,6 @@ Yap_absmi(int inp) CreepFlag = CalculateStackGap(); goto fail; } - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { - PredEntry *ap = PREG->u.Osbpp.p; - SREG = (CELL *) ap; - goto creepc; - } SREG = (CELL *) PREG->u.Osbpp.p; if (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL) { SET_ASP(YREG, PREG->u.Osbpp.s); @@ -3331,7 +3306,6 @@ Yap_absmi(int inp) /* tell whether we can creep or not, this is hard because we will lose the info RSN */ - PP = creep_allowed((PredEntry*)SREG,PP); BEGD(d0); d0 = ((PredEntry *)(SREG))->ArityOfPE; if (d0 == 0) { diff --git a/C/c_interface.c b/C/c_interface.c index e5952e877..27b85ceac 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -3240,28 +3240,29 @@ X_API int YAP_Reset(void) { CACHE_REGS + int res = TRUE; #ifndef THREADS int worker_id = 0; #endif BACKUP_MACHINE_REGS(); + YAP_ClearExceptions(); /* first, backtrack to the root */ - if (B != NULL) { - while (B->cp_b != NULL) - B = B->cp_b; + while (B->cp_b) { + B = B->cp_b; P = FAILCODE; - if (Yap_exec_absmi(0) != 0) { - GLOBAL_Initialised = TRUE; - - Yap_InitYaamRegs( worker_id ); - RECOVER_MACHINE_REGS(); - return FALSE; - } + res = Yap_exec_absmi(0); } /* reinitialise the engine */ // Yap_InitYaamRegs( worker_id ); GLOBAL_Initialised = TRUE; - + ENV = LCL0; + ASP = B; + /* the first real choice-point will also have AP=FAIL */ + /* always have an empty slots for people to use */ + CurSlot = 0; + Yap_StartSlots( PASS_REGS1 ); + P = CP = YESCODE; RECOVER_MACHINE_REGS(); return(TRUE); } diff --git a/C/cdmgr.c b/C/cdmgr.c index 4e0ab65ba..9dd938664 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -5667,6 +5667,7 @@ p_cpc_info( USES_REGS1 ) PredEntry *pe; yamop *ipc = (yamop *)IntegerOfTerm(Deref(ARG1)); + printf("ipc = %p %p\n", ipc, PREVOP(ipc,Osbpp)); pe = PREVOP(ipc,Osbpp)->u.Osbpp.p0; return UnifyPredInfo(pe, 2 PASS_REGS) && Yap_unify(ARG5,MkIntegerTerm(ClauseId(ipc,pe))); diff --git a/C/exec.c b/C/exec.c index 9c2a16a7f..c8b0458ff 100644 --- a/C/exec.c +++ b/C/exec.c @@ -165,8 +165,8 @@ do_execute(Term t, Term mod USES_REGS) if (PRED_GOAL_EXPANSION_ALL) { LOCK(LOCAL_SignalLock); /* disable creeping when we do goal expansion */ - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL && !LOCAL_InterruptsDisabled) { - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; + if (LOCAL_ActiveSignals & (YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL) && !LOCAL_InterruptsDisabled) { + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); CreepFlag = CalculateStackGap(); } UNLOCK(LOCAL_SignalLock); @@ -337,8 +337,8 @@ do_execute_n(Term t, Term mod, unsigned int n USES_REGS) if (PRED_GOAL_EXPANSION_ALL) { LOCK(LOCAL_SignalLock); /* disable creeping when we do goal expansion */ - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL && !LOCAL_InterruptsDisabled) { - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; + if (LOCAL_ActiveSignals & (YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL) && !LOCAL_InterruptsDisabled) { + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); CreepFlag = CalculateStackGap(); } UNLOCK(LOCAL_SignalLock); @@ -391,12 +391,16 @@ EnterCreepMode(Term t, Term mod USES_REGS) { return do_execute(ARG1, mod PASS_REGS); } } - PP = PredMetaCall; PredCreep = RepPredProp(PredPropByFunc(FunctorCreep,1)); - if (mod) { - ARG1 = MkPairTerm(mod,t); + PP = PredCreep; + if (!IsVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) == FunctorModule) { + ARG1 = MkPairTerm(ArgOfTerm(1,t),ArgOfTerm(2,t)); } else { - ARG1 = MkPairTerm(TermProlog,t); + if (mod) { + ARG1 = MkPairTerm(mod,t); + } else { + ARG1 = MkPairTerm(TermProlog,t); + } } LOCK(LOCAL_SignalLock); CreepFlag = CalculateStackGap(); @@ -635,7 +639,8 @@ p_execute_clause( USES_REGS1 ) } else { code = Yap_ClauseFromTerm(clt)->ClCode; } - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { + if (LOCAL_ActiveSignals & (YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL)) { + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); Yap_signal(YAP_CREEP_SIGNAL); } return CallPredicate(RepPredProp(pe), cut_cp, code PASS_REGS); @@ -650,7 +655,7 @@ p_execute_in_mod( USES_REGS1 ) static Int p_do_goal_expansion( USES_REGS1 ) { - Int creeping = LOCAL_ActiveSignals & YAP_CREEP_SIGNAL; + Int creeping = LOCAL_ActiveSignals & (YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); Int out = FALSE; PredEntry *pe; Term cmod = Deref(ARG2); @@ -658,7 +663,7 @@ p_do_goal_expansion( USES_REGS1 ) ARG2 = ARG3; /* disable creeping */ LOCK(LOCAL_SignalLock); - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); if (!LOCAL_ActiveSignals) CreepFlag = CalculateStackGap(); UNLOCK(LOCAL_SignalLock); @@ -713,14 +718,14 @@ p_do_goal_expansion( USES_REGS1 ) static Int p_do_term_expansion( USES_REGS1 ) { - Int creeping = LOCAL_ActiveSignals & YAP_CREEP_SIGNAL; + Int creeping = LOCAL_ActiveSignals & (YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); Int out = FALSE; PredEntry *pe; Term cmod = CurrentModule; /* disable creeping */ LOCK(LOCAL_SignalLock); - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); if (!LOCAL_ActiveSignals) CreepFlag = CalculateStackGap(); UNLOCK(LOCAL_SignalLock); @@ -896,7 +901,8 @@ p_execute_nonstop( USES_REGS1 ) /* N = arity; */ /* call may not define new system predicates!! */ if (RepPredProp(pe)->PredFlags & SpiedPredFlag) { - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL && !LOCAL_InterruptsDisabled) { + if (LOCAL_ActiveSignals & (YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL) && !LOCAL_InterruptsDisabled) { + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); Yap_signal(YAP_CREEP_SIGNAL); } #if defined(YAPOR) || defined(THREADS) @@ -1771,12 +1777,9 @@ Yap_InitYaamRegs( int myworker_id ) #endif /* FROZEN_STACKS */ LOCK(REMOTE_SignalLock(myworker_id)); CreepFlag = CalculateStackGap(); - UNLOCK(REMOTE_SignalLock(myworker_id)); - Yap_PrepGoal(0, NULL, NULL PASS_REGS); /* the first real choice-point will also have AP=FAIL */ /* always have an empty slots for people to use */ CurSlot = 0; - Yap_StartSlots( PASS_REGS1 ); REMOTE_GlobalArena(myworker_id) = TermNil; h0var = MkVarTerm(); #if defined(YAPOR) || defined(THREADS) @@ -1802,11 +1805,14 @@ Yap_InitYaamRegs( int myworker_id ) #if defined MYDDAS_MYSQL || defined MYDDAS_ODBC Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL; #endif + Yap_PrepGoal(0, NULL, NULL PASS_REGS); + Yap_StartSlots( PASS_REGS1 ); #ifdef TABLING /* ensure that LOCAL_top_dep_fr is always valid */ if (REMOTE_top_dep_fr(myworker_id)) DepFr_cons_cp(REMOTE_top_dep_fr(myworker_id)) = NORM_CP(B); #endif + UNLOCK(REMOTE_SignalLock(myworker_id)); } static Int @@ -1817,41 +1823,6 @@ p_uncaught_throw( USES_REGS1 ) return out; } -static Int -p_creep_allowed( USES_REGS1 ) -{ - if (PP != NULL) { - LOCK(LOCAL_SignalLock); - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL && !LOCAL_InterruptsDisabled) { - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; - if (!LOCAL_ActiveSignals) - CreepFlag = CalculateStackGap(); - UNLOCK(LOCAL_SignalLock); - } else { - UNLOCK(LOCAL_SignalLock); - } - return TRUE; - } - return FALSE; -} - -static Int -p_debug_on( USES_REGS1 ) -{ - Term t = Deref(ARG1); - if (IsVarTerm(t)) { - if (LOCAL_DebugOn) - return Yap_unify(MkAtomTerm(AtomTrue),ARG1); - else - return Yap_unify(MkAtomTerm(AtomFalse),ARG1); - } - if (t == MkAtomTerm(AtomTrue)) - LOCAL_DebugOn = TRUE; - else - LOCAL_DebugOn = FALSE; - return TRUE; -} - Term Yap_GetException(void) { @@ -1939,7 +1910,6 @@ Yap_InitExecFs(void) Yap_InitCPred("call_with_args", 9, p_execute_8, 0); Yap_InitCPred("call_with_args", 10, p_execute_9, 0); Yap_InitCPred("call_with_args", 11, p_execute_10, 0); - Yap_InitCPred("$debug_on", 1, p_debug_on, 0); #ifdef DEPTH_LIMIT Yap_InitCPred("$execute_under_depth_limit", 2, p_execute_depth_limit, 0); #endif @@ -1959,7 +1929,6 @@ Yap_InitExecFs(void) Yap_InitCPred("$clean_ifcp", 1, p_clean_ifcp, SafePredFlag); Yap_InitCPred("qpack_clean_up_to_disjunction", 0, p_cut_up_to_next_disjunction, SafePredFlag); Yap_InitCPred("$jump_env_and_store_ball", 1, p_jump_env, 0); - Yap_InitCPred("$creep_allowed", 0, p_creep_allowed, 0); Yap_InitCPred("$generate_pred_info", 4, p_generate_pred_info, 0); Yap_InitCPred("$uncaught_throw", 0, p_uncaught_throw, 0); Yap_InitCPred("$reset_exception", 1, p_reset_exception, 0); diff --git a/C/signals.c b/C/signals.c new file mode 100644 index 000000000..0a6aea138 --- /dev/null +++ b/C/signals.c @@ -0,0 +1,381 @@ +/************************************************************************* +* * +* YAP Prolog * +* * +* Yap Prolog was developed at NCCUP - Universidade do Porto * +* * +* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- * +* * +************************************************************************** +* * +* File: signal.c * +* comments: Signal Handling & Debugger Support * +* * +* * +* * +*************************************************************************/ +#ifdef SCCS +static char SccsId[] = "%W% %G%"; +#endif + +#define HAS_CACHE_REGS 1 + +#include "Yap.h" +#include "Yatom.h" +#include "YapHeap.h" +#include "eval.h" +#include "yapio.h" +#ifdef TABLING +#include "tab.macros.h" +#endif /* TABLING */ +#include +#if HAVE_STRING_H +#include +#endif +#if HAVE_MALLOC_H +#include +#endif +#include + +inline static void +do_signal(yap_signals sig USES_REGS) +{ + LOCK(LOCAL_SignalLock); + if (!LOCAL_InterruptsDisabled) + CreepFlag = Unsigned(LCL0); + LOCAL_ActiveSignals |= sig; + UNLOCK(LOCAL_SignalLock); +} + +inline static void +undo_signal(yap_signals sig USES_REGS) +{ + LOCK(LOCAL_SignalLock); + if ((LOCAL_ActiveSignals & ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL)) == sig) { + CreepFlag = CalculateStackGap(); + } + LOCAL_ActiveSignals &= ~sig; + UNLOCK(LOCAL_SignalLock); +} + +static Int +p_creep( USES_REGS1 ) +{ + Atom at; + PredEntry *pred; + + at = AtomCreep; + pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0)); + CreepCode = pred; + do_signal(YAP_CREEP_SIGNAL PASS_REGS); + return TRUE; +} + +static Int +p_stop_creeping( USES_REGS1 ) +{ + Atom at; + PredEntry *pred; + + LOCK(LOCAL_SignalLock); + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); + if (!LOCAL_ActiveSignals) { + CreepFlag = CalculateStackGap(); + } + UNLOCK(LOCAL_SignalLock); + return TRUE; +} + +static Int +p_meta_creep( USES_REGS1 ) +{ + Atom at; + PredEntry *pred; + + at = AtomCreep; + pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0)); + CreepCode = pred; + LOCK(LOCAL_SignalLock); + LOCAL_ActiveSignals |= YAP_DELAY_CREEP_SIGNAL; + UNLOCK(LOCAL_SignalLock); + return TRUE; +} + +static Int +p_creep_allowed( USES_REGS1 ) +{ + if (PP != NULL) { + LOCK(LOCAL_SignalLock); + if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL && !LOCAL_InterruptsDisabled) { + LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; + if (!LOCAL_ActiveSignals) + CreepFlag = CalculateStackGap(); + UNLOCK(LOCAL_SignalLock); + } else { + UNLOCK(LOCAL_SignalLock); + } + return TRUE; + } + return FALSE; +} + +static Int +p_debug_on( USES_REGS1 ) +{ + Term t = Deref(ARG1); + if (IsVarTerm(t)) { + if (LOCAL_DebugOn) + return Yap_unify(MkAtomTerm(AtomTrue),ARG1); + else + return Yap_unify(MkAtomTerm(AtomFalse),ARG1); + } + if (t == MkAtomTerm(AtomTrue)) + LOCAL_DebugOn = TRUE; + else + LOCAL_DebugOn = FALSE; + return TRUE; +} + + +void +Yap_signal(yap_signals sig) +{ + CACHE_REGS + do_signal(sig PASS_REGS); +} + +void +Yap_undo_signal(yap_signals sig) +{ + CACHE_REGS + undo_signal(sig PASS_REGS); +} + +#ifdef DEBUG +static Int +p_debug( USES_REGS1 ) +{ /* $debug(+Flag) */ + int i = IntOfTerm(Deref(ARG1)); + + if (i >= 'a' && i <= 'z') + GLOBAL_Option[i - 96] = !GLOBAL_Option[i - 96]; + return (1); +} +#endif + +static Int +p_first_signal( USES_REGS1 ) +{ + LOCK(LOCAL_SignalLock); +#ifdef THREADS + pthread_mutex_lock(&(LOCAL_ThreadHandle.tlock)); +#endif + /* always do wakeups first, because you don't want to keep the + non-backtrackable variable bad */ + if (LOCAL_ActiveSignals & YAP_WAKEUP_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_WAKEUP_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigWakeUp)); + } + if (LOCAL_ActiveSignals & YAP_ITI_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_ITI_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigIti)); + } + if (LOCAL_ActiveSignals & YAP_INT_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_INT_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigInt)); + } + if (LOCAL_ActiveSignals & YAP_USR2_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_USR2_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigUsr2)); + } + if (LOCAL_ActiveSignals & YAP_USR1_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_USR1_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigUsr1)); + } + if (LOCAL_ActiveSignals & YAP_PIPE_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_PIPE_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigPipe)); + } + if (LOCAL_ActiveSignals & YAP_HUP_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_HUP_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigHup)); + } + if (LOCAL_ActiveSignals & YAP_ALARM_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_ALARM_SIGNAL; + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigAlarm)); + } + if (LOCAL_ActiveSignals & YAP_VTALARM_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_VTALARM_SIGNAL; + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigVTAlarm)); + } + if (LOCAL_ActiveSignals & YAP_DELAY_CREEP_SIGNAL) { + LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigDelayCreep)); + } + if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigCreep)); + } + if (LOCAL_ActiveSignals & YAP_TRACE_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_TRACE_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigTrace)); + } + if (LOCAL_ActiveSignals & YAP_DEBUG_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_DEBUG_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigDebug)); + } + if (LOCAL_ActiveSignals & YAP_BREAK_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_BREAK_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigBreak)); + } + if (LOCAL_ActiveSignals & YAP_STACK_DUMP_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_STACK_DUMP_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigStackDump)); + } + if (LOCAL_ActiveSignals & YAP_STATISTICS_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_STATISTICS_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomSigStatistics)); + } + if (LOCAL_ActiveSignals & YAP_FAIL_SIGNAL) { + LOCAL_ActiveSignals &= ~YAP_FAIL_SIGNAL; +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return Yap_unify(ARG1, MkAtomTerm(AtomFail)); + } +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + UNLOCK(LOCAL_SignalLock); + return FALSE; +} + +static Int +p_continue_signals( USES_REGS1 ) +{ + /* hack to force the signal anew */ + if (LOCAL_ActiveSignals & YAP_ITI_SIGNAL) { + Yap_signal(YAP_ITI_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_INT_SIGNAL) { + Yap_signal(YAP_INT_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_USR2_SIGNAL) { + Yap_signal(YAP_USR2_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_USR1_SIGNAL) { + Yap_signal(YAP_USR1_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_HUP_SIGNAL) { + Yap_signal(YAP_HUP_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_ALARM_SIGNAL) { + Yap_signal(YAP_ALARM_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_VTALARM_SIGNAL) { + Yap_signal(YAP_VTALARM_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { + Yap_signal(YAP_CREEP_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_DELAY_CREEP_SIGNAL) { + Yap_signal(YAP_DELAY_CREEP_SIGNAL|YAP_CREEP_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_TRACE_SIGNAL) { + Yap_signal(YAP_TRACE_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_DEBUG_SIGNAL) { + Yap_signal(YAP_DEBUG_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_BREAK_SIGNAL) { + Yap_signal(YAP_BREAK_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_STACK_DUMP_SIGNAL) { + Yap_signal(YAP_STACK_DUMP_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_STATISTICS_SIGNAL) { + Yap_signal(YAP_STATISTICS_SIGNAL); + } + if (LOCAL_ActiveSignals & YAP_FAIL_SIGNAL) { + Yap_signal(YAP_FAIL_SIGNAL); + } +#ifdef THREADS + pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); +#endif + return TRUE; +} + +void +Yap_InitSignalCPreds(void) +{ + /* Basic predicates for the debugger */ + Yap_InitCPred("$creep", 0, p_creep, SafePredFlag); + Yap_InitCPred("$meta_creep", 0, p_meta_creep, SafePredFlag); + Yap_InitCPred("$stop_creeping", 0, p_stop_creeping, SafePredFlag); + Yap_InitCPred ("$first_signal", 1, p_first_signal, SafePredFlag|SyncPredFlag); + Yap_InitCPred ("$continue_signals", 0, p_continue_signals, SafePredFlag|SyncPredFlag); + Yap_InitCPred("$debug_on", 1, p_debug_on, 0); + Yap_InitCPred("$creep_allowed", 0, p_creep_allowed, 0); +#ifdef DEBUG + Yap_InitCPred("$debug", 1, p_debug, SafePredFlag|SyncPredFlag); +#endif +} diff --git a/C/stdpreds.c b/C/stdpreds.c index 8345ab901..eaeb66e2d 100644 --- a/C/stdpreds.c +++ b/C/stdpreds.c @@ -474,207 +474,6 @@ p_values( USES_REGS1 ) return (TRUE); } -inline static void -do_signal(yap_signals sig USES_REGS) -{ - LOCK(LOCAL_SignalLock); - if (!LOCAL_InterruptsDisabled) - CreepFlag = Unsigned(LCL0); - LOCAL_ActiveSignals |= sig; - UNLOCK(LOCAL_SignalLock); -} - -inline static void -undo_signal(yap_signals sig USES_REGS) -{ - LOCK(LOCAL_SignalLock); - if (LOCAL_ActiveSignals == sig) { - CreepFlag = CalculateStackGap(); - } - LOCAL_ActiveSignals &= ~sig; - UNLOCK(LOCAL_SignalLock); -} - - -static Int -p_creep( USES_REGS1 ) -{ - Atom at; - PredEntry *pred; - - at = AtomCreep; - pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0)); - CreepCode = pred; - do_signal(YAP_CREEP_SIGNAL PASS_REGS); - return TRUE; -} - -static Int -p_signal_creep( USES_REGS1 ) -{ - Atom at; - PredEntry *pred; - - at = AtomCreep; - pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0)); - CreepCode = pred; - LOCK(LOCAL_SignalLock); - LOCAL_ActiveSignals |= YAP_CREEP_SIGNAL; - UNLOCK(LOCAL_SignalLock); - return TRUE; -} - -static Int -p_disable_creep( USES_REGS1 ) -{ - LOCK(LOCAL_SignalLock); - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; - if (!LOCAL_ActiveSignals) - CreepFlag = CalculateStackGap(); - UNLOCK(LOCAL_SignalLock); - return TRUE; - } - UNLOCK(LOCAL_SignalLock); - return FALSE; -} - -/* never fails */ -static Int -p_disable_docreep( USES_REGS1 ) -{ - LOCK(LOCAL_SignalLock); - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; - if (!LOCAL_ActiveSignals) - CreepFlag = CalculateStackGap(); - UNLOCK(LOCAL_SignalLock); - } else { - UNLOCK(LOCAL_SignalLock); - } - return TRUE; -} - -static Int -p_stop_creep( USES_REGS1 ) -{ - LOCK(LOCAL_SignalLock); - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; - if (!LOCAL_ActiveSignals) { - CreepFlag = CalculateStackGap(); - } - UNLOCK(LOCAL_SignalLock); - return TRUE; -} - -void -Yap_signal(yap_signals sig) -{ - CACHE_REGS - do_signal(sig PASS_REGS); -} - -void -Yap_undo_signal(yap_signals sig) -{ - CACHE_REGS - undo_signal(sig PASS_REGS); -} - -#ifdef undefined - -/* - * Returns where some particular piece of code is, it may take its time but - * then you only need it while creeping, so why bother ? - */ -static CODEADDR * -FindAtom(codeToFind, arity) - CODEADDR codeToFind; - unsigned int *arityp; -{ - Atom a; - int i; - - for (i = 0; i < AtomHashTableSize; ++i) { - READ_LOCK(HashChain[i].AeRWLock); - a = HashChain[i].Entry; - READ_UNLOCK(HashChain[i].AeRWLock); - while (a != NIL) { - register PredEntry *pp; - AtomEntry *ae = RepAtom(a); - READ_LOCK(ae->ARWLock); - pp = RepPredProp(RepAtom(a)->PropsOfAE); - while (!EndOfPAEntr(pp) && ((pp->KindOfPE & 0x8000) - || (pp->CodeOfPred != codeToFind))) - pp = RepPredProp(pp->NextOfPE); - if (pp != NIL) { - CODEADDR *out; - PELOCK(90,pp); - out = &(pp->CodeOfPred) - *arityp = pp->ArityOfPE; - UNLOCK(pp->PELock); - READ_UNLOCK(ae->ARWLock); - return (out); - } - a = RepAtom(a)->NextOfAE; - READ_UNLOCK(ae->ARWLock); - } - } - for (i = 0; i < WideAtomHashTableSize; ++i) { - READ_LOCK(HashChain[i].AeRWLock); - a = HashChain[i].Entry; - READ_UNLOCK(HashChain[i].AeRWLock); - while (a != NIL) { - register PredEntry *pp; - AtomEntry *ae = RepAtom(a); - READ_LOCK(ae->ARWLock); - pp = RepPredProp(RepAtom(a)->PropsOfAE); - while (!EndOfPAEntr(pp) && ((pp->KindOfPE & 0x8000) - || (pp->CodeOfPred != codeToFind))) - pp = RepPredProp(pp->NextOfPE); - if (pp != NIL) { - CODEADDR *out; - PELOCK(91,pp); - out = &(pp->CodeOfPred) - *arityp = pp->ArityOfPE; - UNLOCK(pp->PELock); - READ_UNLOCK(ae->ARWLock); - return (out); - } - a = RepAtom(a)->NextOfAE; - READ_UNLOCK(ae->ARWLock); - } - } - *arityp = 0; - return (0); -} - -/* - * This is called when you want to creep a C-predicate or a predicate written - * in assembly - */ -CELL -FindWhatCreep(toCreep) - CELL toCreep; -{ - unsigned int arity; - Atom at; - CODEADDR *place; - - if (toCreep > 64) { /* written in C */ - int i; - place = FindAtom((CODEADDR) toCreep, &arity); - *--ASP = Unsigned(P); - *--ASP = N = arity; - for (i = 1; i <= arity; ++i) - *--ASP = X[i]; - /* P = CellPtr(CCREEPCODE); */ - return (Unsigned(place)); - } -} - -#endif /* undefined */ - static Int p_opdec( USES_REGS1 ) { /* '$opdec'(p,type,atom) */ @@ -3466,18 +3265,6 @@ init_current_atom_op( USES_REGS1 ) return cont_current_atom_op( PASS_REGS1 ); } -#ifdef DEBUG -static Int -p_debug( USES_REGS1 ) -{ /* $debug(+Flag) */ - int i = IntOfTerm(Deref(ARG1)); - - if (i >= 'a' && i <= 'z') - GLOBAL_Option[i - 96] = !GLOBAL_Option[i - 96]; - return (1); -} -#endif - static Int p_flags( USES_REGS1 ) { /* $flags(+Functor,+Mod,?OldFlags,?NewFlags) */ @@ -4441,17 +4228,6 @@ Yap_InitCPreds(void) Yap_InitCPred("$unlock_system", 0, p_unlock_system, SafePredFlag); Yap_InitCPred("$enter_undefp", 0, p_enterundefp, SafePredFlag); Yap_InitCPred("$exit_undefp", 0, p_exitundefp, SafePredFlag); - /* basic predicates for the prolog machine tracer */ - /* they are defined in analyst.c */ - /* Basic predicates for the debugger */ - Yap_InitCPred("$creep", 0, p_creep, SafePredFlag); - Yap_InitCPred("$signal_creep", 0, p_signal_creep, SafePredFlag); - Yap_InitCPred("$disable_creep", 0, p_disable_creep, SafePredFlag); - Yap_InitCPred("$disable_docreep", 0, p_disable_docreep, SafePredFlag); - Yap_InitCPred("$do_not_creep", 0, p_stop_creep, SafePredFlag|SyncPredFlag); -#ifdef DEBUG - Yap_InitCPred("$debug", 1, p_debug, SafePredFlag|SyncPredFlag); -#endif /* Accessing and changing the flags for a predicate */ Yap_InitCPred("$flags", 4, p_flags, SyncPredFlag); /* hiding and unhiding some predicates */ @@ -4510,6 +4286,7 @@ Yap_InitCPreds(void) #endif Yap_udi_init(); + Yap_InitSignalCPreds(); Yap_InitUserCPreds(); Yap_InitUtilCPreds(); Yap_InitSortPreds(); diff --git a/C/sysbits.c b/C/sysbits.c index 4725607c6..9e26c9add 100755 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -2804,207 +2804,6 @@ Yap_ReInitWallTime (void) InitLastWtime(); } -static Int -p_first_signal( USES_REGS1 ) -{ - LOCK(LOCAL_SignalLock); -#ifdef THREADS - pthread_mutex_lock(&(LOCAL_ThreadHandle.tlock)); -#endif - /* always do wakeups first, because you don't want to keep the - non-backtrackable variable bad */ - if (LOCAL_ActiveSignals & YAP_WAKEUP_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_WAKEUP_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigWakeUp)); - } - if (LOCAL_ActiveSignals & YAP_ITI_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_ITI_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigIti)); - } - if (LOCAL_ActiveSignals & YAP_INT_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_INT_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigInt)); - } - if (LOCAL_ActiveSignals & YAP_USR2_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_USR2_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigUsr2)); - } - if (LOCAL_ActiveSignals & YAP_USR1_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_USR1_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigUsr1)); - } - if (LOCAL_ActiveSignals & YAP_PIPE_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_PIPE_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigPipe)); - } - if (LOCAL_ActiveSignals & YAP_HUP_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_HUP_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigHup)); - } - if (LOCAL_ActiveSignals & YAP_ALARM_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_ALARM_SIGNAL; - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigAlarm)); - } - if (LOCAL_ActiveSignals & YAP_VTALARM_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_VTALARM_SIGNAL; - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigVTAlarm)); - } - if (LOCAL_ActiveSignals & YAP_DELAY_CREEP_SIGNAL) { - LOCAL_ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL); -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigDelayCreep)); - } - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigCreep)); - } - if (LOCAL_ActiveSignals & YAP_TRACE_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_TRACE_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigTrace)); - } - if (LOCAL_ActiveSignals & YAP_DEBUG_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_DEBUG_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigDebug)); - } - if (LOCAL_ActiveSignals & YAP_BREAK_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_BREAK_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigBreak)); - } - if (LOCAL_ActiveSignals & YAP_STACK_DUMP_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_STACK_DUMP_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigStackDump)); - } - if (LOCAL_ActiveSignals & YAP_STATISTICS_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_STATISTICS_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomSigStatistics)); - } - if (LOCAL_ActiveSignals & YAP_FAIL_SIGNAL) { - LOCAL_ActiveSignals &= ~YAP_FAIL_SIGNAL; -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return Yap_unify(ARG1, MkAtomTerm(AtomFail)); - } -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - UNLOCK(LOCAL_SignalLock); - return FALSE; -} - -static Int -p_continue_signals( USES_REGS1 ) -{ - /* hack to force the signal anew */ - if (LOCAL_ActiveSignals & YAP_ITI_SIGNAL) { - Yap_signal(YAP_ITI_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_INT_SIGNAL) { - Yap_signal(YAP_INT_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_USR2_SIGNAL) { - Yap_signal(YAP_USR2_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_USR1_SIGNAL) { - Yap_signal(YAP_USR1_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_HUP_SIGNAL) { - Yap_signal(YAP_HUP_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_ALARM_SIGNAL) { - Yap_signal(YAP_ALARM_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_VTALARM_SIGNAL) { - Yap_signal(YAP_VTALARM_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) { - Yap_signal(YAP_CREEP_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_DELAY_CREEP_SIGNAL) { - Yap_signal(YAP_DELAY_CREEP_SIGNAL|YAP_CREEP_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_TRACE_SIGNAL) { - Yap_signal(YAP_TRACE_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_DEBUG_SIGNAL) { - Yap_signal(YAP_DEBUG_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_BREAK_SIGNAL) { - Yap_signal(YAP_BREAK_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_STACK_DUMP_SIGNAL) { - Yap_signal(YAP_STACK_DUMP_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_STATISTICS_SIGNAL) { - Yap_signal(YAP_STATISTICS_SIGNAL); - } - if (LOCAL_ActiveSignals & YAP_FAIL_SIGNAL) { - Yap_signal(YAP_FAIL_SIGNAL); - } -#ifdef THREADS - pthread_mutex_unlock(&(LOCAL_ThreadHandle.tlock)); -#endif - return TRUE; -} - static Int p_unix( USES_REGS1 ) { @@ -3295,9 +3094,7 @@ Yap_InitSysPreds(void) Yap_InitCPred ("$getenv", 2, p_getenv, SafePredFlag); Yap_InitCPred ("$putenv", 2, p_putenv, SafePredFlag|SyncPredFlag); Yap_InitCPred ("$set_fpu_exceptions", 0, p_set_fpu_exceptions, SafePredFlag|SyncPredFlag); - Yap_InitCPred ("$first_signal", 1, p_first_signal, SafePredFlag|SyncPredFlag); Yap_InitCPred ("$host_type", 1, p_host_type, SafePredFlag|SyncPredFlag); - Yap_InitCPred ("$continue_signals", 0, p_continue_signals, SafePredFlag|SyncPredFlag); Yap_InitCPred ("$env_separator", 1, p_env_separator, SafePredFlag); Yap_InitCPred ("$unix", 0, p_unix, SafePredFlag); Yap_InitCPred ("$win32", 0, p_win32, SafePredFlag); diff --git a/H/Yapproto.h b/H/Yapproto.h index a132d015a..3e273c7f7 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -338,6 +338,11 @@ void STD_PROTO(Yap_InitSavePreds,(void)); /* scanner.c */ +/* signals.c */ +void STD_PROTO(Yap_signal,(yap_signals)); +void STD_PROTO(Yap_undo_signal,(yap_signals)); +void STD_PROTO(Yap_InitSignalPreds,(void)); + /* sort.c */ void STD_PROTO(Yap_InitSortPreds,(void)); @@ -345,8 +350,6 @@ void STD_PROTO(Yap_InitSortPreds,(void)); void STD_PROTO(Yap_InitBackCPreds,(void)); void STD_PROTO(Yap_InitCPreds,(void)); void STD_PROTO(Yap_show_statistics,(void)); -void STD_PROTO(Yap_signal,(yap_signals)); -void STD_PROTO(Yap_undo_signal,(yap_signals)); int STD_PROTO(Yap_IsOpMaxPrio,(Atom)); /* sysbits.c */ diff --git a/pl/attributes.yap b/pl/attributes.yap index 89ad495b3..84078cac4 100644 --- a/pl/attributes.yap +++ b/pl/attributes.yap @@ -216,14 +216,14 @@ attvar_residuals(att(Module,Value,As), V) --> -> [] ; - { '$notrace'(Module:attribute_goal(V, Goal)) }, + { call(Module:attribute_goal(V, Goal)) }, dot_list(Goal) ) ; ( { current_predicate(Module:attribute_goals/3) } - -> { '$notrace'(Module:attribute_goals(V, Goals, [])) }, + -> { call(Module:attribute_goals(V, Goals, [])) }, list(Goals) ; { current_predicate(Module:attribute_goal/2) } - -> { '$notrace'(Module:attribute_goal(V, Goal)) }, + -> { call(Module:attribute_goal(V, Goal)) }, dot_list(Goal) ; [put_attr(V, Module, Value)] ), @@ -312,7 +312,7 @@ pick_att_vars([_|L],NL) :- project_module([], _, _). project_module([Mod|LMods], LIV, LAV) :- '$pred_exists'(project_attributes(LIV, LAV),Mod), - '$notrace'(Mod:project_attributes(LIV, LAV)), !, + call(Mod:project_attributes(LIV, LAV)), !, attributes:all_attvars(NLAV), project_module(LMods,LIV,NLAV). project_module([_|LMods], LIV, LAV) :- diff --git a/pl/boot.yap b/pl/boot.yap index 3c1ddd51a..410069815 100755 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -220,7 +220,6 @@ true :- true. '$run_atom_goal'(GA), ( '$pred_exists'(halt(_), user) -> halt(0) ; '$halt'(0) ). '$enter_top_level' :- - '$disable_docreep', '$run_toplevel_hooks', prompt1(' ?- '), '$read_toplevel'(Command,Varnames), @@ -378,9 +377,7 @@ true :- true. % but YAP and SICStus does. % '$process_directive'(G, _, M, VL, Pos) :- - '$exit_system_mode', - ( '$notrace'(M:G) -> true ; format(user_error,':- ~w:~w failed.~n',[M,G]) ), - '$enter_system_mode'. + ( '$execute'(M:G) -> true ; format(user_error,':- ~w:~w failed.~n',[M,G]) ). '$continue_with_command'(Where,V,'$stream_position'(C,_P,A1,A2,A3),'$source_location'(_F,L):G,Source) :- !, '$continue_with_command'(Where,V,'$stream_position'(C,L,A1,A2,A3),G,Source). @@ -489,10 +486,9 @@ true :- true. '$query'(G,V) :- ( yap_hacks:current_choice_point(CP), - '$exit_system_mode', - '$execute'(G), + '$current_module'(M), + '$execute_outside_system_mode'(G, M), yap_hacks:current_choice_point(NCP), - ( '$enter_system_mode' ; '$exit_system_mode', fail), '$delayed_goals'(G, V, NV, LGs, DCP), '$write_answer'(NV, LGs, Written), '$write_query_answer_true'(Written), @@ -507,7 +503,6 @@ true :- true. ), fail ; - '$enter_system_mode', '$out_neg_answer' ). @@ -516,13 +511,16 @@ true :- true. '$do_yes_no'(G,M), '$delayed_goals'(G, [], NV, LGs, _), '$write_answer'(NV, LGs, Written), - ( Written = [] -> - !,'$present_answer'(C, yes); - '$another', ! + ( + Written = [] + -> + !, + '$present_answer'(C, yes) + ; + '$another', ! ), fail. '$yes_no'(_,_) :- - '$enter_system_mode', '$out_neg_answer'. '$add_env_and_fail' :- fail. @@ -552,11 +550,11 @@ true :- true. ), fail. -'$do_yes_no'([X|L], M) :- !, '$csult'([X|L], M). +'$do_yes_no'([X|L], M) :- + !, + '$csult'([X|L], M). '$do_yes_no'(G, M) :- - '$exit_system_mode', - '$execute'(M:G), - ( '$enter_system_mode' ; '$exit_system_mode', fail). + '$execute_outside_system_mode'(G, M). '$write_query_answer_true'([]) :- !, format(user_error,'~ntrue',[]). @@ -1090,7 +1088,7 @@ bootstrap(F) :- % support SWI hook in a separate predicate, to avoid slow down standard consult. '$enter_command_with_hook'(Stream,Status) :- '$read_vars'(Stream,Command,_,Pos,Vars, '|: ', Comments), - ('$notrace'(prolog:comment_hook(Comments,Pos,Command)) -> true ; true ), + ('$exit_system_mode'(comment_hook(Comments,Pos,Command), prolog) -> true ; true ), '$command'(Command,Vars,Pos,Status). '$abort_loop'(Stream) :- @@ -1236,47 +1234,58 @@ catch_ball(C, C). '$nb_getval'('$break', 0, fail), recorded('$toplevel_hooks',H,_), H \= fail, !, - ( '$oncenotrace'(H) -> true ; true). + ( '$exit_system_mode'(H) -> true ; true). '$run_toplevel_hooks'. '$enter_system_mode' :- + '$stop_creeping', nb_setval('$system_mode',on). +'$in_system_mode' :- + '$nb_getval'('$system_mode',on,fail). + +'$execute_outside_system_mode'(G,M) :- + CP is '$last_choice_pt', + '$execute_outside_system_mode'(G,M,CP). + +'$execute_outside_system_mode'(V,M,_) :- + var(V), !, + call(M:G). +'$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), !, + '$do_spy'(G, M, CP, no). +'$execute_outside_system_mode'(G, M, CP) :- + ( + yap_hacks:current_choice_point(CP1), + '$exit_system_mode', + '$execute_nonstop'(G,M), + yap_hacks:current_choice_point(CP2), + (CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', fail ) ), + '$enter_system_mode' + ; + '$enter_system_mode', + fail + ). + + '$exit_system_mode' :- nb_setval('$system_mode',off), - ( '$nb_getval'('$trace',on,fail) -> '$creep' ; true). - -% -% just prevent creeping from going on... -% -'$notrace'(G) :- - '$disable_creep', !, - ( - % creep was going on... - yap_hacks:current_choice_point(CP0), - '$execute'(G), - yap_hacks:current_choice_point(CP1), - ( CP0 == CP1 -> - !, - '$creep' - ; - ( - '$creep' - ; - '$disable_docreep', - fail - ) - ) - ; - '$creep', - fail - ). -'$notrace'(G) :- - '$execute'(G). + ( '$nb_getval'('$trace',on,fail) -> '$meta_creep' ; true). '$run_at_thread_start' :- recorded('$thread_initialization',M:D,_), - '$notrace'(M:D), + '$exit_system_mode'(D, M), fail. '$run_at_thread_start'. diff --git a/pl/consult.yap b/pl/consult.yap index e0364f46a..dcf78a9ae 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -394,7 +394,7 @@ initialization(G,OPT) :- '$do_error'(type_error(OPT),initialization(G,OPT)) ). '$initialization'(G,now) :- - ( '$notrace'(G) -> true ; format(user_error,':- ~w:~w failed.~n',[M,G]) ). + ( '$exit_system_mode'(G,prolog) -> true ; format(user_error,':- ~w:~w failed.~n',[M,G]) ). '$initialization'(G,after_load) :- '$initialization'(G). % ignore for now. @@ -412,7 +412,7 @@ initialization(G,OPT) :- recorded('$system_initialisation',G,R), erase(R), G \= '$', - '$notrace'(G), + '$exit_system_mode'(G, prolog), fail. '$exec_initialisation_goals' :- '$show_consult_level'(Level), @@ -426,7 +426,7 @@ initialization(G,OPT) :- ( OldMode == on -> '$exit_system_mode' ; true ), % run initialization under user control (so allow debugging this stuff). ( - '$system_catch'('$oncenotrace'(M:G), M, Error, user:'$LoopError'(Error, top)), + '$system_catch'(once(M:G), M, Error, user:'$LoopError'(Error, top)), fail ; OldMode = on, @@ -895,7 +895,7 @@ absolute_file_name(File,Opts,TrueFileName) :- '$extend_path_directory'(Name, D, File, Opts, NewFile, Call) :- - '$notrace'(user:file_search_path(Name, Dir)), + user:file_search_path(Name, Dir), '$extend_pathd'(Dir, D, File, Opts, NewFile, Call). '$extend_pathd'(Dir, A, File, Opts, NewFile, Call) :- diff --git a/pl/control.yap b/pl/control.yap index 52c1a081d..de7665ba1 100644 --- a/pl/control.yap +++ b/pl/control.yap @@ -289,37 +289,6 @@ version(T) :- fail. '$set_toplevel_hook'(_). -'$oncenotrace'(G) :- - '$disable_creep', !, - ( - '$execute'(G) - -> - '$creep' - ; - '$creep', - fail - ). -'$oncenotrace'(G) :- - '$execute'(G), !. - - -'$once0'(G, M) :- - '$pred_exists'(G, M), - ( - '$disable_creep' - -> - ( - '$execute_nonstop'(G, M) - -> - '$creep' - ; - '$creep', - fail - ) - ; - '$execute_nonstop'(G,M) - ). - nb_getval(GlobalVariable, Val) :- '$nb_getval'(GlobalVariable, Val, Error), (var(Error) diff --git a/pl/debug.yap b/pl/debug.yap index ffe3d36fe..3dfb6ebf4 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -123,21 +123,21 @@ recorded('$spy','$spy'(G,M),_), !. spy Spec :- - '$notrace'(prolog:debug_action_hook(spy(Spec))), !. + prolog:debug_action_hook(spy(Spec)), !. spy L :- '$current_module'(M), '$suspy'(L, spy, M), fail. spy _ :- debug. nospy Spec :- - '$notrace'(prolog:debug_action_hook(nospy(Spec))), !. + prolog:debug_action_hook(nospy(Spec)), !. nospy L :- '$current_module'(M), '$suspy'(L, nospy, M), fail. nospy _. nospyall :- - '$notrace'(prolog:debug_action_hook(nospyall)), !. + prolog:debug_action_hook(nospyall), !. nospyall :- recorded('$spy','$spy'(T,M),_), functor(T,F,N), '$suspy'(F/N,nospy,M), fail. nospyall. @@ -173,7 +173,7 @@ trace :- nb_setval('$trace',on), '$start_debugging'(on), print_message(informational,debug(trace)), - '$creep'. + '$meta_creep'. notrace :- nodebug. @@ -283,17 +283,21 @@ debugging :- '$debug_on'(F), F = false, !, '$execute_nonstop'(G,Mod). '$spy'([Mod|G]) :- - nb_getval('$system_mode',on), !, + '$in_system_mode', !, '$execute_nonstop'(G,Mod). '$spy'([Mod|G]) :- CP is '$last_choice_pt', - '$do_spy'(G, Mod, CP, no). + '$do_spy'(G, Mod, CP, spy). % last argument to do_spy says that we are at the end of a context. It % is required to know whether we are controlled by the debugger. -'$do_spy'(V, M, CP, Flag) :- var(V), !, '$do_spy'(call(V), M, CP, Flag). -'$do_spy'(!, _, CP, _) :- !, '$$cut_by'(CP). -'$do_spy'('$cut_by'(M), _, _, _) :- !, '$$cut_by'(M). +'$do_spy'(V, M, CP, Flag) :- + var(V), !, + '$do_spy'(call(V), M, CP, Flag). +'$do_spy'(!, _, CP, _) :- + !, '$$cut_by'(CP). +'$do_spy'('$cut_by'(M), _, _, _) :- + !, '$$cut_by'(M). '$do_spy'(true, _, _, _) :- !. %'$do_spy'(fail, _, _, _) :- !, fail. '$do_spy'(M:G, _, CP, CalledFromDebugger) :- !, @@ -307,7 +311,7 @@ debugging :- '$do_spy'(B, M, CP, CalledFromDebugger) ). '$do_spy'((T->A|B), M, CP, CalledFromDebugger) :- !, - ( '$do_spy'(T, M, CP, yes) -> '$do_spy'(A, M, CP, yes) + ( '$do_spy'(T, M, CP, debugger) -> '$do_spy'(A, M, CP, yes) ; '$do_spy'(B, M, CP, CalledFromDebugger) ). @@ -315,13 +319,13 @@ debugging :- ( '$do_spy'(T, M, CP, yes) -> '$do_spy'(A, M, CP, yes) ). '$do_spy'((A;B), M, CP, CalledFromDebugger) :- !, ( - '$do_spy'(A, M, CP, yes) + '$do_spy'(A, M, CP, CalledFromDebugger) ; '$do_spy'(B, M, CP, CalledFromDebugger) ). '$do_spy'((A|B), M, CP, CalledFromDebugger) :- !, ( - '$do_spy'(A, M, CP, yes) + '$do_spy'(A, M, CP, CalledFromDebugger) ; '$do_spy'(B, M, CP, CalledFromDebugger) ). @@ -335,7 +339,7 @@ debugging :- nb_setval('$spy_gn',L1), /* and save it globaly */ b_getval('$spy_glist',History), /* get goal list */ b_setval('$spy_glist',[info(L,Module,G,_Retry,_Det,_HasFoundAnswers)|History]), /* and update it */ - '$loop_spy'(L, G, Module, CalledFromDebugger). /* set creep on */ + '$loop_spy'(L, G, Module, CalledFromDebugger). % we are skipping, so we can just call the goal, % while leaving the minimal structure in place. @@ -360,7 +364,7 @@ debugging :- throw(error('$fail_spy'(GoalNumber),[])). '$loop_spy_event'(error('$done_spy'(G0),_), GoalNumber, G, _, CalledFromDebugger) :- G0 >= GoalNumber, !, - '$continue_debugging'(CalledFromDebugger). + '$continue_debugging'(zip, CalledFromDebugger). '$loop_spy_event'(error('$done_spy'(GoalNumber),_), _, _, _, _) :- !, throw(error('$done_spy'(GoalNumber),[])). '$loop_spy_event'(Event, GoalNumber, G, Module, CalledFromDebugger) :- @@ -380,8 +384,8 @@ debugging :- % just fail here, don't really need to call debugger, the user knows what he % wants to do -'$loop_fail'(_GoalNumber, _G, _Module, _CalledFromDebugger) :- - '$continue_debugging'(CalledFromDebugger), +'$loop_fail'(_GoalNumber, _G, _Module, CalledFromDebugger) :- + '$continue_debugging'(fail, CalledFromDebugger), fail. % if we are in @@ -400,16 +404,16 @@ debugging :- /* call port */ '$enter_goal'(GoalNumber, G, Module), '$spycall'(G, Module, CalledFromDebugger, Retry), - '$disable_docreep', ( '$debugger_deterministic_goal'(G) -> Det=true ; Det=false ), - /* go execute the predicate */ + /* go execute the continuation */ ( - Retry = false -> + /* exit port */ + Retry = false, /* found an answer, so it can redo */ nb_setarg(6, Info, true), '$show_trace'(exit,G,Module,GoalNumber,Det), /* output message at exit */ @@ -422,26 +426,25 @@ debugging :- ; true ), - '$continue_debugging'(CalledFromDebugger) - ; + '$continue_debugging'(exit, CalledFromDebugger) + ; /* backtracking from exit */ /* we get here when we want to redo a goal */ /* redo port */ - '$disable_docreep', ( - arg(6, Info, true) + arg(6, Info, true) -> '$show_trace'(redo,G,Module,GoalNumber,_), /* inform user_error */ nb_setarg(6, Info, false) ; true ), - '$continue_debugging'(CalledFromDebugger), + '$continue_debugging'(fail, CalledFromDebugger), fail /* to backtrack to spycalls */ ) ; '$show_trace'(fail,G,Module,GoalNumber,_), /* inform at fail port */ - '$continue_debugging'(CalledFromDebugger), + '$continue_debugging'(fail, CalledFromDebugger), /* fail port */ fail ). @@ -483,16 +486,23 @@ debugging :- !, '$execute_nonstop'(G,M). '$spycall'(G, M, _, _) :- - '$system_predicate'(G,M), - \+ '$is_metapredicate'(G,M), !, - '$execute'(M:G). -'$spycall'(G, M, _, _) :- - '$system_module'(M), !, - '$execute'(M:G). + ( + '$system_predicate'(G,M) + ; + '$system_module'(M) + ), + !, + ( + '$is_metapredicate'(G,M) + -> + '$meta_creep'(G,M) + ; + '$execute'(M:G) + ). '$spycall'(G, M, _, _) :- '$tabled_predicate'(G,M), !, - '$continue_debugging'(no, '$execute_nonstop'(G,M)). + '$continue_debugging_goal'(no, '$execute_nonstop'(G,M)). '$spycall'(G, M, CalledFromDebugger, InRedo) :- '$flags'(G,M,F,F), F /\ 0x08402000 =\= 0, !, % dynamic procedure, logical semantics, or source @@ -500,7 +510,6 @@ debugging :- CP is '$last_choice_pt', '$clause'(G, M, Cl, _), % I may backtrack to here from far away - '$disable_docreep', ( '$do_spy'(Cl, M, CP, CalledFromDebugger) ; InRedo = true ). '$spycall'(G, M, CalledFromDebugger, InRedo) :- '$undefined'(G, M), !, @@ -511,13 +520,26 @@ debugging :- CP is '$last_choice_pt', '$static_clause'(G,M,_,R), % I may backtrack to here from far away - '$disable_docreep', ( - '$continue_debugging'(no, '$execute_clause'(G, M, R, CP)) + '$continue_debugging_goal'(no, '$execute_clause'(G, M, R, CP)) ; InRedo = true ). +'$meta_creep'(G,M) :- + ( + yap_hacks:current_choice_point(CP1), + '$exit_system_mode', + '$meta_creep', + '$execute_nonstop'(G,M), + yap_hacks:current_choice_point(CP2), + (CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', '$meta_creep', fail ) ), + '$enter_system_mode' + ; + '$enter_system_mode', + fail + ). + '$tabled_predicate'(G,M) :- '$flags'(G,M,F,F), F /\ 0x00000040 =\= 0. @@ -584,8 +606,6 @@ debugging :- '$action'(13,P,CallNumber,G,Module,Zip) :- !, % newline creep get0(user_input,C), '$action'(C,P,CallNumber,G,Module,Zip). -%'$action'(10,_,_,_,_,on) :- % newline creep -% nb_setval('$debug_jump',false). '$action'(10,_,_,_,_,on) :- !, % newline creep nb_setval('$debug_jump',false). '$action'(0'!,_,_,_,_,_) :- !, % ! 'g execute @@ -708,20 +728,26 @@ debugging :- '$ilgl'(C), fail. -'$continue_debugging'(yes). +% first argument is exit, zip or fail +% second is creep, meta_creep, spy, or debugger +'$continue_debugging'(exit, debugger) :- !. +'$continue_debugging'(zip, debugger) :- !. +'$continue_debugging'(fail, debugger) :- !. % do not need to debug! -'$continue_debugging'(no) :- +'$continue_debugging'(exit, meta_creep) :- !, + '$meta_creep'. +'$continue_debugging'(_, no) :- '$creep'. % if we are in the interpreter, don't need to care about forcing a trace, do we? -'$continue_debugging'(yes,G) :- !, +'$continue_debugging_goal'(_, yes,G) :- !, '$execute_dgoal'(G). % do not need to debug! -'$continue_debugging'(_,G) :- +'$continue_debugging_goal'(_, _,G) :- 'nb_getval'('$debug_run',Zip), (Zip == nodebug ; number(Zip) ; Zip == spy ), !, '$execute_dgoal'(G). -'$continue_debugging'(_,G) :- +'$continue_debugging_goal'(_, _,G) :- '$execute_creep_dgoal'(G). '$execute_dgoal'('$execute_nonstop'(G,M)) :- @@ -730,10 +756,10 @@ debugging :- '$execute_clause'(G, M, R, CP). '$execute_creep_dgoal'('$execute_nonstop'(G,M)) :- - '$signal_creep', + '$creep', '$execute_nonstop'(G,M). '$execute_creep_dgoal'('$execute_clause'(G, M, R, CP)) :- - '$signal_creep', + '$creep', '$execute_clause'(G, M, R, CP). '$show_ancestors'(HowMany) :- diff --git a/pl/errors.yap b/pl/errors.yap index 478fd425e..2a5e7c11e 100644 --- a/pl/errors.yap +++ b/pl/errors.yap @@ -242,13 +242,13 @@ print_message(error, error(Msg,[Info|local_sp(P,CP,Envs,CPs)])) :- !, erase(R). print_message(Severity, Msg) :- nonvar(Severity), nonvar(Msg), - '$notrace'(user:portray_message(Severity, Msg)), !. + user:portray_message(Severity, Msg), !. % This predicate has more hooks than a pirate ship! print_message(Severity, Term) :- % first step at hook processing '$message_to_lines'(Term, Lines), ( nonvar(Term), - '$once0'(message_hook(Term, Severity, Lines), user) + user:message_hook(Term, Severity, Lines) -> true ; @@ -263,9 +263,9 @@ print_message(_, Term) :- format(user_error,'~q~n',[Term]). '$message_to_lines'(Term, Lines) :- - '$once0'(generate_message_hook(Term, [], Lines), user), !. + user:generate_message_hook(Term, [], Lines), !. '$message_to_lines'(Term, Lines) :- - '$once0'(message(Term, Lines, []), prolog), !. + prolog:message(Term, Lines, []), !. '$message_to_lines'(Term, Lines) :- '$messages':generate_message(Term, Lines, []), !. diff --git a/pl/hacks.yap b/pl/hacks.yap index c185ce79c..4ae8aef43 100644 --- a/pl/hacks.yap +++ b/pl/hacks.yap @@ -126,6 +126,7 @@ show_cp(CP, Continuation) --> show_env(Env,Cont,NCont) --> { yap_hacks:continuation(Env, Addr, NCont, _), + format('0x~16r 0x~16r~n',[Env,NCont]), yap_hacks:cp_to_predicate(Cont, Mod, Name, Arity, ClId) }, [ '0x~16r~t ~16+ ~d~16+ ~q:' - diff --git a/pl/modules.yap b/pl/modules.yap index 2f8ec6066..9cd2531dc 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -535,7 +535,7 @@ expand_goal(G, G). % expand argument '$meta_expansion_loop'(0,_,_,_,_,_,_,_) :- !. '$meta_expansion_loop'(I,D,G,NG,HVars,CurMod,M,HM) :- - arg(I,D,X), (X==':' ; integer(X)), + arg(I,D,X), (X==':' -> true ; integer(X)), arg(I,G,A), '$do_expand'(A,HVars), !, arg(I,NG,M:A), diff --git a/pl/signals.yap b/pl/signals.yap index 5a7e08912..ae553a988 100644 --- a/pl/signals.yap +++ b/pl/signals.yap @@ -33,39 +33,10 @@ '$wake_up_goal'(G, LG). % never creep on entering system mode!!! % don't creep on meta-call. -'$do_signal'(sig_creep, [M|G]) :- - '$creep_allowed', !, - ( - ( G = '$notrace'(G0) ; G = '$oncenotrace'(G0) ; G = '$once0'(G0) ; G = '$execute0'(G0,M) ; '$system_module'(M), G = G0 ) - -> - ( - '$execute_nonstop'(G0,M), - '$signal_creep' - ; - '$signal_creep', - fail - ) - ; - '$start_creep'([M|G]) - ). -% -'$do_signal'(sig_creep, [M|G]) :- - ( G = '$notrace'(G0) ; G = '$oncenotrace'(G0) ; G = '$once0'(G0) ; G = '$execute0'(G0,M) ; '$system_module'(M), G = G0 ), - !, - ( - '$execute_nonstop'(G0,M), - '$signal_creep' - ; - '$signal_creep', - fail - ). -% -'$do_signal'(sig_creep, [M|G]) :- - '$signal_creep', - '$execute_nonstop'(G,M). -'$do_signal'(sig_delay_creep, [M|G]) :- - '$execute'(M:G), - '$creep'. +'$do_signal'(sig_creep, MG) :- + '$start_creep'(MG, creep). +'$do_signal'(sig_delay_creep, MG) :- + '$start_creep'(MG, meta_creep). '$do_signal'(sig_iti, [M|G]) :- '$thread_gfetch'(Goal), % if more signals alive, set creep flag @@ -117,96 +88,12 @@ '$current_module'(M0), '$execute0'((Goal,M:G),M0). -% '$execute0' should be ignored. -'$start_creep'([_|'$execute0'(G,M)]) :- - !, - '$start_creep'([M|G]). -% '$call'() is a complicated thing -'$start_creep'([M0|'$call'(G, CP, G0, M)]) :- - !, - '$creep', - '$execute_nonstop'('$call'(G, CP, G0, M),M0). -% donotrace: means do not trace! So, -% ignore and then put creep back for the continuation. -'$start_creep'([M0|'$notrace'(G)]) :- - !, - ( - CP0 is '$last_choice_pt', - '$execute_nonstop'(G,M0), - CP1 is '$last_choice_pt', - % exit port: creep - '$creep', - ( - % if deterministic just creep all you want. - CP0 = CP1 -> - ! - ; - % extra disjunction protects reentry into usergoal - ( - % cannot cut here - true - ; - % be sure to disable creep on redo port - '$disable_creep', - fail - ) - ) - ; - % put it back again on fail - '$creep', - fail - ). -'$start_creep'([M0|'$oncenotrace'(G)]) :- - !, - ('$execute_nonstop'(G,M0), - CP1 is '$last_choice_pt', - % exit port: creep - '$creep', - ! - ; - % put it back again on fail - '$creep', - fail - ). -'$start_creep'([M0|'$once0'(G)]) :- - !, - ('$execute_nonstop'(G,M0), - CP1 is '$last_choice_pt', - % exit port: creep - '$creep', - ! - ; - % put it back again on fail - '$creep', - fail - ). -% do not debug if we are not in debug mode. -'$start_creep'([Mod|G]) :- - '$debug_on'(DBON), DBON = false, !, - '$execute_nonstop'(G,Mod). -'$start_creep'([Mod|G]) :- - nb_getval('$system_mode',on), !, - '$execute_nonstop'(G,Mod). -% notice that the last signal to be processed must always be creep -'$start_creep'([_|'$cut_by'(CP)]) :- !, - '$$cut_by'(CP), - '$creep'. -'$start_creep'([_|true]) :- !, - '$creep'. -'$start_creep'([Mod|G]) :- - '$hidden_predicate'(G,Mod), !, - '$execute_nonstop'(G,Mod), - '$creep'. -% do not debug if we are zipping through. -'$start_creep'([Mod|G]) :- - nb_getval('$debug_run',Run), - Run \= off, - '$zip'(-1, G, Mod), !, - '$signal_creep', - '$execute_goal'(G, Mod). -'$start_creep'([Mod|G]) :- +'$start_creep'([Mod|G], _) :- + '$in_system_mode', !, + '$execute0'(G, Mod). +'$start_creep'([Mod|G], WhereFrom) :- CP is '$last_choice_pt', - '$do_spy'(G, Mod, CP, no). + '$do_spy'(G, Mod, CP, WhereFrom). '$execute_goal'(G, Mod) :- ( From 67208c81576f1c223c4cc275676b9d8a79472b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Sat, 9 Feb 2013 08:51:33 -0600 Subject: [PATCH 3/4] signals --- Makefile.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index c28285ac4..afd438a20 100755 --- a/Makefile.in +++ b/Makefile.in @@ -257,7 +257,7 @@ C_SOURCES= \ $(srcdir)/C/qlyr.c \ $(srcdir)/C/qlyw.c \ $(srcdir)/C/range.c \ - $(srcdir)/C/save.c $(srcdir)/C/scanner.c \ + $(srcdir)/C/save.c $(srcdir)/C/scanner.c $(srcdir)/C/signals.c \ $(srcdir)/C/sort.c $(srcdir)/C/stdpreds.c $(srcdir)/C/sysbits.c \ $(srcdir)/C/threads.c \ $(srcdir)/C/tracer.c $(srcdir)/C/unify.c $(srcdir)/C/userpreds.c \ @@ -366,7 +366,7 @@ ENGINE_OBJECTS = \ myddas_util.o myddas_statistics.o myddas_top_level.o \ myddas_wkb2prolog.o modules.o other.o \ parser.o qlyr.o qlyw.o range.o \ - save.o scanner.o sort.o stdpreds.o \ + save.o scanner.o signals.o sort.o stdpreds.o \ sysbits.o threads.o tracer.o \ udi.o\ unify.o userpreds.o utilpreds.o \ @@ -466,6 +466,9 @@ qlyw.o: $(srcdir)/C/qlyw.c config.h save.o: $(srcdir)/C/save.c config.h $(CC) -c $(CFLAGS) $(srcdir)/C/save.c -o $@ +signals.o: $(srcdir)/C/signals.c config.h + $(CC) -c $(CFLAGS) $(srcdir)/C/signals.c -o $@ + sysbits.o: $(srcdir)/C/sysbits.c config.h $(CC) -c $(CFLAGS) $(srcdir)/C/sysbits.c -o $@ From ec7158eb997d98f38a250afb201136c0d765f5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 13 Feb 2013 09:06:06 -0600 Subject: [PATCH 4/4] debugger progress --- BEAM/eam_am.c | 2 ++ BEAM/eamamasm.h | 21 ++++++++++---------- C/compiler.c | 2 ++ C/computils.c | 3 +++ C/exec.c | 1 + C/exo.c | 4 ++-- C/inlines.c | 22 +++++++++++++++++++++ H/amidefs.h | 1 + pl/boot.yap | 45 ++++++++++++++++++++++++++---------------- pl/control.yap | 6 +++--- pl/debug.yap | 52 ++++++++++++++++++++++++++++++++++--------------- pl/hacks.yap | 2 +- pl/signals.yap | 3 +++ 13 files changed, 115 insertions(+), 49 deletions(-) diff --git a/BEAM/eam_am.c b/BEAM/eam_am.c index e02dc2e40..f9c5fe187 100644 --- a/BEAM/eam_am.c +++ b/BEAM/eam_am.c @@ -1428,6 +1428,7 @@ static void *OpAddress[]= { &&p_db_ref, &&p_primitive, &&p_cut_by, + &&p_save_by, &&p_succ, &&p_predc, &&p_plus, @@ -3536,6 +3537,7 @@ break_debug(contador); p_db_ref: p_primitive: p_cut_by: + p_save_by: p_succ: p_predc: p_plus: diff --git a/BEAM/eamamasm.h b/BEAM/eamamasm.h index c7d731cee..bbfa97a40 100644 --- a/BEAM/eamamasm.h +++ b/BEAM/eamamasm.h @@ -115,15 +115,16 @@ #define _p_db_ref (_std_base+8) #define _p_primitive (_std_base+9) #define _p_cut_by (_std_base+10) -#define _p_succ (_std_base+11) -#define _p_predc (_std_base+12) -#define _p_plus (_std_base+13) -#define _p_minus (_std_base+14) -#define _p_times (_std_base+15) -#define _p_div (_std_base+16) -#define _p_dif (_std_base+17) -#define _p_eq (_std_base+18) -#define _p_arg (_std_base+19) -#define _p_functor (_std_base+20) +#define _p_save_by (_std_base+11) +#define _p_succ (_std_base+12) +#define _p_predc (_std_base+13) +#define _p_plus (_std_base+14) +#define _p_minus (_std_base+15) +#define _p_times (_std_base+16) +#define _p_div (_std_base+17) +#define _p_dif (_std_base+18) +#define _p_eq (_std_base+19) +#define _p_arg (_std_base+20) +#define _p_functor (_std_base+21) diff --git a/C/compiler.c b/C/compiler.c index 9d6907a70..579d0a167 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -923,6 +923,8 @@ c_test(Int Op, Term t1, compiler_struct *cglobs) { } if (Op == _cut_by) c_var(t, commit_b_flag, 1, 0, cglobs); + else if (Op == _save_by) + c_var(t, save_b_flag, 1, 0, cglobs); else c_var(t, f_flag,(unsigned int)Op, 0, cglobs); } diff --git a/C/computils.c b/C/computils.c index 4d90d9890..c3f117195 100644 --- a/C/computils.c +++ b/C/computils.c @@ -331,6 +331,9 @@ bip_name(Int op, char *s) case _cut_by: strcpy(s,"cut_by"); break; + case _save_by: + strcpy(s,"save_by"); + break; case _db_ref: strcpy(s,"db_ref"); break; diff --git a/C/exec.c b/C/exec.c index c8b0458ff..d595327c9 100644 --- a/C/exec.c +++ b/C/exec.c @@ -1916,6 +1916,7 @@ Yap_InitExecFs(void) Yap_InitCPred("$execute0", 2, p_execute0, 0); Yap_InitCPred("$execute_nonstop", 2, p_execute_nonstop, 0); Yap_InitCPred("$execute_clause", 4, p_execute_clause, 0); + Yap_InitCPred("$current_choice_point", 1, p_save_cp, 0); CurrentModule = HACKS_MODULE; Yap_InitCPred("current_choice_point", 1, p_save_cp, 0); Yap_InitCPred("current_choicepoint", 1, p_save_cp, 0); diff --git a/C/exo.c b/C/exo.c index c9721f568..3541a55dd 100644 --- a/C/exo.c +++ b/C/exo.c @@ -258,13 +258,13 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count, UInt bnds[] if (!(base = (CELL *)Yap_AllocCodeSpace(sizeof(CELL)*(ncls+i->hsize)))) { CACHE_REGS save_machine_regs(); - LOCAL_Error_Size = 3*ncls*sizeof(CELL); + LOCAL_Error_Size = sizeof(CELL)*(ncls+i->hsize); LOCAL_ErrorMessage = "not enough space to generate indices"; Yap_FreeCodeSpace((void *)i); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); return NULL; } - bzero(base, 3*sizeof(CELL)*ncls); + bzero(base, sizeof(CELL)*(ncls+i->hsize)); } i->size = sizeof(CELL)*(ncls+i->hsize)+sz+sizeof(struct index_t); i->key = (CELL **)base; diff --git a/C/inlines.c b/C/inlines.c index 59a563a46..356de33a4 100644 --- a/C/inlines.c +++ b/C/inlines.c @@ -760,6 +760,13 @@ p_functor( USES_REGS1 ) /* functor(?,?,?) */ ENDD(d0); } +static Term +cp_as_integer(choiceptr cp USES_REGS) +{ + return(MkIntegerTerm(LCL0-(CELL *)cp)); +} + + static Int p_cut_by( USES_REGS1 ) { @@ -897,6 +904,20 @@ cont_genarg( USES_REGS1 ) Yap_unify(ARG3,pt[0]); } +static Int +p_save_cp( USES_REGS1 ) +{ + Term t = Deref(ARG1); + Term td; +#if SHADOW_HB + register CELL *HBREG = HB; +#endif + if (!IsVarTerm(t)) return(FALSE); + td = cp_as_integer(B PASS_REGS); + Bind((CELL *)t,td); + return(TRUE); +} + void Yap_InitInlines(void) @@ -904,6 +925,7 @@ Yap_InitInlines(void) CACHE_REGS Term cm = CurrentModule; Yap_InitAsmPred("$$cut_by", 1, _cut_by, p_cut_by, SafePredFlag); + Yap_InitAsmPred("$$save_by", 1, _save_by, p_save_cp, SafePredFlag); Yap_InitAsmPred("atom", 1, _atom, p_atom, SafePredFlag); Yap_InitAsmPred("atomic", 1, _atomic, p_atomic, SafePredFlag); Yap_InitAsmPred("integer", 1, _integer, p_integer, SafePredFlag); diff --git a/H/amidefs.h b/H/amidefs.h index cf424bc22..fbb2c224b 100644 --- a/H/amidefs.h +++ b/H/amidefs.h @@ -163,6 +163,7 @@ typedef enum { _number, _var, _cut_by, + _save_by, _db_ref, _primitive, _dif, diff --git a/pl/boot.yap b/pl/boot.yap index 410069815..ac477fb81 100755 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -485,10 +485,10 @@ true :- true. '$yes_no'(G,(?-)). '$query'(G,V) :- ( - yap_hacks:current_choice_point(CP), + '$current_choice_point'(CP), '$current_module'(M), '$execute_outside_system_mode'(G, M), - yap_hacks:current_choice_point(NCP), + '$current_choice_point'(NCP), '$delayed_goals'(G, V, NV, LGs, DCP), '$write_answer'(NV, LGs, Written), '$write_query_answer_true'(Written), @@ -531,9 +531,9 @@ true :- true. '$delayed_goals'(G, V, NV, LGs, NCP) :- ( CP is '$last_choice_pt', - yap_hacks:current_choice_point(NCP1), + '$current_choice_point'(NCP1), '$attributes':delayed_goals(G, V, NV, LGs), - yap_hacks:current_choice_point(NCP2), + '$current_choice_point'(NCP2), '$clean_ifcp'(CP), NCP is NCP2-NCP1 ; @@ -759,7 +759,7 @@ incore(G) :- '$execute'(G). % standard meta-call, called if $execute could not do everything. % '$meta_call'(G, M) :- - yap_hacks:current_choice_point(CP), + '$current_choice_point'(CP), '$call'(G, CP, G, M). @@ -814,7 +814,7 @@ not(G) :- \+ '$execute'(G). % '$meta_call'(G,_ISO,M) :- '$iso_check_goal'(G,G), - yap_hacks:current_choice_point(CP), + '$current_choice_point'(CP), '$call'(G, CP, G, M). '$meta_call'(G, CP, G0, M) :- @@ -851,7 +851,7 @@ not(G) :- \+ '$execute'(G). ). '$call'((X*->Y; Z),CP,G0,M) :- !, ( - yap_hacks:current_choicepoint(DCP), + '$current_choicepoint'(DCP), '$call'(X,CP,G0,M), yap_hacks:cut_at(DCP), '$call'(Y,CP,G0,M) @@ -874,7 +874,7 @@ not(G) :- \+ '$execute'(G). ). '$call'((X*->Y| Z),CP,G0,M) :- !, ( - yap_hacks:current_choicepoint(DCP), + '$current_choicepoint'(DCP), '$call'(X,CP,G0,M), yap_hacks:cut_at(DCP), '$call'(Y,CP,G0,M) @@ -888,7 +888,7 @@ not(G) :- \+ '$execute'(G). '$call'(B,CP,G0,M) ). '$call'(\+ X, _CP, _G0, M) :- !, - yap_hacks:current_choicepoint(CP), + '$current_choicepoint'(CP), \+ '$call'(X,CP,G0,M). '$call'(not(X), _CP, _G0, M) :- !, \+ '$call'(X,CP,G0,M). @@ -1165,9 +1165,9 @@ expand_term(Term,Expanded) :- % where was the previous catch catch(G, C, A) :- '$catch'(C,A,_), - yap_hacks:current_choice_point(CP0), + '$$save_by'(CP0), '$execute'(G), - yap_hacks:current_choice_point(CP1), + '$$save_by'(CP1), (CP0 == CP1 -> !; true ). % makes sure we have an environment. @@ -1182,9 +1182,9 @@ catch(G, C, A) :- '$system_catch'(G, M, C, A) :- % check current trail '$catch'(C,A,_), - yap_hacks:current_choice_point(CP0), + '$$save_by'(CP0), '$execute_nonstop'(G, M), - yap_hacks:current_choice_point(CP1), + '$$save_by'(CP1), (CP0 == CP1 -> !; true ). % @@ -1264,13 +1264,24 @@ catch_ball(C, C). ). '$execute_outside_system_mode'(G, M, CP) :- nb_getval('$trace', on), !, - '$do_spy'(G, M, CP, no). -'$execute_outside_system_mode'(G, M, CP) :- ( - yap_hacks:current_choice_point(CP1), + '$$save_by'(CP1), + '$do_spy'(G, M, CP, meta_creep), + % we may exit system mode... + '$$save_by'(CP2), + (CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', fail ) ), + '$enter_system_mode' + ; + '$enter_system_mode', + fail + ). +'$execute_outside_system_mode'(G, M, CP) :- + format('start~n', []), + ( + '$$save_by'(CP1), '$exit_system_mode', '$execute_nonstop'(G,M), - yap_hacks:current_choice_point(CP2), + '$$save_by'(CP2), (CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', fail ) ), '$enter_system_mode' ; diff --git a/pl/control.yap b/pl/control.yap index de7665ba1..e3e678578 100644 --- a/pl/control.yap +++ b/pl/control.yap @@ -112,16 +112,16 @@ setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup) :- throw(Exception). '$safe_call_cleanup'(Goal, Cleanup, Catcher, Exception) :- - yap_hacks:current_choice_point(MyCP1), + '$current_choice_point'(MyCP1), '$coroutining':freeze_goal(Catcher, '$clean_call'(Active, Cleanup)), ( yap_hacks:trail_suspension_marker(Catcher), yap_hacks:enable_interrupts, - yap_hacks:current_choice_point(CP0), + '$current_choice_point'(CP0), '$execute'(Goal), % ensure environment for delayed variables in Goal '$true', - yap_hacks:current_choice_point(CPF), + '$current_choice_point'(CPF), ( CP0 =:= CPF -> diff --git a/pl/debug.yap b/pl/debug.yap index 3dfb6ebf4..f7b707631 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -287,10 +287,13 @@ debugging :- '$execute_nonstop'(G,Mod). '$spy'([Mod|G]) :- CP is '$last_choice_pt', + '$enter_system_mode', '$do_spy'(G, Mod, CP, spy). % last argument to do_spy says that we are at the end of a context. It % is required to know whether we are controlled by the debugger. +%'$do_spy'(V, M, CP, Flag) :- +% writeln('$do_spy'(V, M, CP, Flag)), fail. '$do_spy'(V, M, CP, Flag) :- var(V), !, '$do_spy'(call(V), M, CP, Flag). @@ -303,20 +306,20 @@ debugging :- '$do_spy'(M:G, _, CP, CalledFromDebugger) :- !, '$do_spy'(G, M, CP, CalledFromDebugger). '$do_spy'((A,B), M, CP, CalledFromDebugger) :- !, - '$do_spy'(A, M, CP, yes), + '$do_spy'(A, M, CP, debugger), '$do_spy'(B, M, CP, CalledFromDebugger). '$do_spy'((T->A;B), M, CP, CalledFromDebugger) :- !, - ( '$do_spy'(T, M, CP, yes) -> '$do_spy'(A, M, CP, yes) + ( '$do_spy'(T, M, CP, debugger) -> '$do_spy'(A, M, CP, CalledFromDebugger) ; '$do_spy'(B, M, CP, CalledFromDebugger) ). '$do_spy'((T->A|B), M, CP, CalledFromDebugger) :- !, - ( '$do_spy'(T, M, CP, debugger) -> '$do_spy'(A, M, CP, yes) + ( '$do_spy'(T, M, CP, debugger) -> '$do_spy'(A, M, CP, CalledFromDebugger) ; '$do_spy'(B, M, CP, CalledFromDebugger) ). -'$do_spy'((T->A), M, CP, _) :- !, - ( '$do_spy'(T, M, CP, yes) -> '$do_spy'(A, M, CP, yes) ). +'$do_spy'((T->A), M, CP, CalledFromDebugger) :- !, + ( '$do_spy'(T, M, CP, debugger) -> '$do_spy'(A, M, CP, CalledFromDebugger) ). '$do_spy'((A;B), M, CP, CalledFromDebugger) :- !, ( '$do_spy'(A, M, CP, CalledFromDebugger) @@ -344,7 +347,7 @@ debugging :- % we are skipping, so we can just call the goal, % while leaving the minimal structure in place. '$loop_spy'(GoalNumber, G, Module, CalledFromDebugger) :- - yap_hacks:current_choice_point(CP), + '$current_choice_point'(CP), '$system_catch'('$loop_spy2'(GoalNumber, G, Module, CalledFromDebugger, CP), Module, error(Event,Context), '$loop_spy_event'(error(Event,Context), GoalNumber, G, Module, CalledFromDebugger)). @@ -404,6 +407,8 @@ debugging :- /* call port */ '$enter_goal'(GoalNumber, G, Module), '$spycall'(G, Module, CalledFromDebugger, Retry), + % make sure we are in system mode when running the debugger. + '$enter_system_mode', ( '$debugger_deterministic_goal'(G) -> Det=true @@ -428,6 +433,8 @@ debugging :- ), '$continue_debugging'(exit, CalledFromDebugger) ; + % make sure we are in system mode when running the debugger. + '$enter_system_mode', /* backtracking from exit */ /* we get here when we want to redo a goal */ /* redo port */ @@ -443,6 +450,7 @@ debugging :- fail /* to backtrack to spycalls */ ) ; + '$enter_system_mode', '$show_trace'(fail,G,Module,GoalNumber,_), /* inform at fail port */ '$continue_debugging'(fail, CalledFromDebugger), /* fail port */ @@ -510,7 +518,7 @@ debugging :- CP is '$last_choice_pt', '$clause'(G, M, Cl, _), % I may backtrack to here from far away - ( '$do_spy'(Cl, M, CP, CalledFromDebugger) ; InRedo = true ). + ( '$do_spy'(Cl, M, CP, debugger) ; InRedo = true ). '$spycall'(G, M, CalledFromDebugger, InRedo) :- '$undefined'(G, M), !, '$find_goal_definition'(M, G, NM, Goal), @@ -528,11 +536,11 @@ debugging :- '$meta_creep'(G,M) :- ( - yap_hacks:current_choice_point(CP1), + '$$save_by'(CP1), '$exit_system_mode', '$meta_creep', '$execute_nonstop'(G,M), - yap_hacks:current_choice_point(CP2), + '$$save_by'(CP2), (CP1 == CP2 -> ! ; ( true ; '$exit_system_mode', '$meta_creep', fail ) ), '$enter_system_mode' ; @@ -544,6 +552,8 @@ debugging :- '$flags'(G,M,F,F), F /\ 0x00000040 =\= 0. +%'$trace'(P,G,Module,L,Deterministic) :- +% '$nb_getval'('$system_mode',On,fail), writeln(On), fail. '$trace'(P,G,Module,L,Deterministic) :- % at this point we are done with leap or skip nb_setval('$debug_run',off), @@ -730,24 +740,34 @@ debugging :- % first argument is exit, zip or fail % second is creep, meta_creep, spy, or debugger -'$continue_debugging'(exit, debugger) :- !. -'$continue_debugging'(zip, debugger) :- !. -'$continue_debugging'(fail, debugger) :- !. +%'$continue_debugging'(Exit, Debugger) :- +% writeln('$continue_debugging'(Exit, Debugger)), fail. +% that's what follows +'$continue_debugging'(_, debugger) :- !. % do not need to debug! +% go back to original sequence. +'$continue_debugging'(zip, _) :- !, '$exit_system_mode'. +'$continue_debugging'(fail, _) :- !. '$continue_debugging'(exit, meta_creep) :- !, + '$exit_system_mode', '$meta_creep'. -'$continue_debugging'(_, no) :- +'$continue_debugging'(_, creep) :- !, + '$exit_system_mode', '$creep'. +'$continue_debugging'(_, spy) :- !, + '$exit_system_mode', + '$creep'. +'$continue_debugging'(_, _) :- '$exit_system_mode'. % if we are in the interpreter, don't need to care about forcing a trace, do we? -'$continue_debugging_goal'(_, yes,G) :- !, +'$continue_debugging_goal'(yes,G) :- !, '$execute_dgoal'(G). % do not need to debug! -'$continue_debugging_goal'(_, _,G) :- +'$continue_debugging_goal'(_,G) :- 'nb_getval'('$debug_run',Zip), (Zip == nodebug ; number(Zip) ; Zip == spy ), !, '$execute_dgoal'(G). -'$continue_debugging_goal'(_, _,G) :- +'$continue_debugging_goal'(_,G) :- '$execute_creep_dgoal'(G). '$execute_dgoal'('$execute_nonstop'(G,M)) :- diff --git a/pl/hacks.yap b/pl/hacks.yap index 4ae8aef43..015d28379 100644 --- a/pl/hacks.yap +++ b/pl/hacks.yap @@ -47,7 +47,7 @@ code_location(Info,Where,Location) :- integer(Where) , !, '$pred_for_code'(Where,Name,Arity,Mod,Clause), construct_code(Clause,Name,Arity,Mod,Info,Location). -code_location(Info,_,Info). +code_location(Ixnfo,_,Info). construct_code(-1,Name,Arity,Mod,Where,Location) :- !, number_codes(Arity,ArityCode), diff --git a/pl/signals.yap b/pl/signals.yap index ae553a988..bd629c42c 100644 --- a/pl/signals.yap +++ b/pl/signals.yap @@ -88,6 +88,9 @@ '$current_module'(M0), '$execute0'((Goal,M:G),M0). +% we may be creeping outside and coming back to system mode. +'$start_creep'([_|'$enter_system_mode'], _) :- !, + '$enter_system_mode'. '$start_creep'([Mod|G], _) :- '$in_system_mode', !, '$execute0'(G, Mod).