Merge branch 'master' of ssh://yap.git.sourceforge.net/gitroot/yap/yap-6.3

Conflicts:
	C/exec.c
This commit is contained in:
Vítor Santos Costa 2013-02-17 07:03:38 -06:00
commit 8cadc14ed4
26 changed files with 672 additions and 813 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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) {

View File

@ -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);
}

View File

@ -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)));

View File

@ -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);
}

View File

@ -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;

View File

@ -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
@ -1961,7 +1931,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);

View File

@ -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;

View File

@ -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);

381
C/signals.c Normal file
View File

@ -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 <stdio.h>
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <wchar.h>
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
}

View File

@ -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();

View File

@ -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);

View File

@ -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 */

View File

@ -163,6 +163,7 @@ typedef enum {
_number,
_var,
_cut_by,
_save_by,
_db_ref,
_primitive,
_dif,

View File

@ -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 $@

View File

@ -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);

View File

@ -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) :-

View File

@ -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).
@ -488,11 +485,10 @@ true :- true.
'$yes_no'(G,(?-)).
'$query'(G,V) :-
(
yap_hacks:current_choice_point(CP),
'$exit_system_mode',
'$execute'(G),
yap_hacks:current_choice_point(NCP),
( '$enter_system_mode' ; '$exit_system_mode', fail),
'$current_choice_point'(CP),
'$current_module'(M),
'$execute_outside_system_mode'(G, M),
'$current_choice_point'(NCP),
'$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'
).
@ -523,7 +518,6 @@ true :- true.
),
fail.
'$yes_no'(_,_) :-
'$enter_system_mode',
'$out_neg_answer'.
'$add_env_and_fail' :- fail.
@ -534,9 +528,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
;
@ -553,11 +547,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,'true',[]).
@ -762,7 +756,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).
@ -817,7 +811,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) :-
@ -854,7 +848,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)
@ -877,7 +871,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)
@ -891,7 +885,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).
@ -1091,7 +1085,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) :-
@ -1168,9 +1162,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.
@ -1185,9 +1179,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 ).
%
@ -1237,47 +1231,69 @@ 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), !,
(
'$$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),
'$$save_by'(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'.

View File

@ -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) :-

View File

@ -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
->
@ -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)

View File

@ -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,45 +283,52 @@ 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).
'$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) :- 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) :-
% writeln('$do_spy'(V, M, CP, Flag)), fail.
'$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) :- !,
'$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, 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), 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, 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,12 +342,12 @@ 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.
'$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)).
@ -360,7 +367,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 +387,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 +407,18 @@ debugging :-
/* call port */
'$enter_goal'(GoalNumber, G, Module),
'$spycall'(G, Module, CalledFromDebugger, Retry),
'$disable_docreep',
% make sure we are in system mode when running the debugger.
'$enter_system_mode',
(
'$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 +431,28 @@ debugging :-
;
true
),
'$continue_debugging'(CalledFromDebugger)
;
'$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 */
'$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 */
)
;
'$enter_system_mode',
'$show_trace'(fail,G,Module,GoalNumber,_), /* inform at fail port */
'$continue_debugging'(CalledFromDebugger),
'$continue_debugging'(fail, CalledFromDebugger),
/* fail port */
fail
).
@ -483,16 +494,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,8 +518,7 @@ 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 ).
( '$do_spy'(Cl, M, CP, debugger) ; InRedo = true ).
'$spycall'(G, M, CalledFromDebugger, InRedo) :-
'$undefined'(G, M), !,
'$find_goal_definition'(M, G, NM, Goal),
@ -511,17 +528,32 @@ 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) :-
(
'$$save_by'(CP1),
'$exit_system_mode',
'$meta_creep',
'$execute_nonstop'(G,M),
'$$save_by'(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.
%'$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),
@ -584,8 +616,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 +738,36 @@ 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) :-
% writeln('$continue_debugging'(Exit, Debugger)), fail.
% that's what follows
'$continue_debugging'(_, debugger) :- !.
% do not need to debug!
'$continue_debugging'(no) :-
% 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'(_, 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'(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 +776,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) :-

View File

@ -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, []), !.

View File

@ -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),
@ -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:' -

View File

@ -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),

View File

@ -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,15 @@
'$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]) :-
% 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).
'$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) :-
(