Merge with upstream code
This commit is contained in:
commit
dd8a92aaf3
@ -2255,14 +2255,12 @@ YAP_AtomToPred(Atom at)
|
|||||||
X_API PredEntry *
|
X_API PredEntry *
|
||||||
YAP_FunctorToPredInModule(Functor func, Term mod)
|
YAP_FunctorToPredInModule(Functor func, Term mod)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
|
||||||
return RepPredProp(PredPropByFunc(func, mod));
|
return RepPredProp(PredPropByFunc(func, mod));
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API PredEntry *
|
X_API PredEntry *
|
||||||
YAP_AtomToPredInModule(Atom at, Term mod)
|
YAP_AtomToPredInModule(Atom at, Term mod)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
|
||||||
return RepPredProp(PredPropByAtom(at, mod));
|
return RepPredProp(PredPropByAtom(at, mod));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2434,7 +2432,6 @@ YAP_RunGoal(Term t)
|
|||||||
LOCAL_AllowRestart = FALSE;
|
LOCAL_AllowRestart = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -2562,6 +2559,8 @@ YAP_RestartGoal(void)
|
|||||||
if (LOCAL_AllowRestart) {
|
if (LOCAL_AllowRestart) {
|
||||||
P = (yamop *)FAILCODE;
|
P = (yamop *)FAILCODE;
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
|
// exec_absmi destroys slots on top of stack....
|
||||||
|
Yap_CloseSlots( PASS_REGS1 );
|
||||||
out = Yap_exec_absmi(TRUE);
|
out = Yap_exec_absmi(TRUE);
|
||||||
LOCAL_PrologMode = UserCCallMode;
|
LOCAL_PrologMode = UserCCallMode;
|
||||||
if (out == FALSE) {
|
if (out == FALSE) {
|
||||||
@ -3072,7 +3071,7 @@ YAP_Init(YAP_init_args *yap_init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ BACKUP_MACHINE_REGS();
|
{ BACKUP_MACHINE_REGS();
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( 0);
|
||||||
|
|
||||||
#if HAVE_MPE
|
#if HAVE_MPE
|
||||||
Yap_InitMPE ();
|
Yap_InitMPE ();
|
||||||
@ -3112,7 +3111,7 @@ YAP_Init(YAP_init_args *yap_init)
|
|||||||
In the SBA we cannot just happily inherit registers
|
In the SBA we cannot just happily inherit registers
|
||||||
from the other workers
|
from the other workers
|
||||||
*/
|
*/
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( 0);
|
||||||
#endif /* YAPOR_COPY || YAPOR_SBA */
|
#endif /* YAPOR_COPY || YAPOR_SBA */
|
||||||
#ifndef YAPOR_THREADS
|
#ifndef YAPOR_THREADS
|
||||||
Yap_InitPreAllocCodeSpace();
|
Yap_InitPreAllocCodeSpace();
|
||||||
@ -3191,7 +3190,7 @@ YAP_Init(YAP_init_args *yap_init)
|
|||||||
/* first, initialise the saved state */
|
/* first, initialise the saved state */
|
||||||
Term t_goal = MkAtomTerm(AtomInitProlog);
|
Term t_goal = MkAtomTerm(AtomInitProlog);
|
||||||
YAP_RunGoalOnce(t_goal);
|
YAP_RunGoalOnce(t_goal);
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( 0 );
|
||||||
/* reset stacks */
|
/* reset stacks */
|
||||||
return YAP_BOOT_FROM_SAVED_CODE;
|
return YAP_BOOT_FROM_SAVED_CODE;
|
||||||
} else {
|
} else {
|
||||||
@ -3225,7 +3224,7 @@ YAP_Init(YAP_init_args *yap_init)
|
|||||||
goal = Yap_MkApplTerm(fgoal, 1, as);
|
goal = Yap_MkApplTerm(fgoal, 1, as);
|
||||||
YAP_RunGoalOnce(goal);
|
YAP_RunGoalOnce(goal);
|
||||||
/* reset stacks */
|
/* reset stacks */
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( 0 );
|
||||||
}
|
}
|
||||||
Yap_PutValue(Yap_FullLookupAtom("$live"), MkAtomTerm (Yap_FullLookupAtom("$true")));
|
Yap_PutValue(Yap_FullLookupAtom("$live"), MkAtomTerm (Yap_FullLookupAtom("$true")));
|
||||||
}
|
}
|
||||||
@ -3296,6 +3295,9 @@ X_API int
|
|||||||
YAP_Reset(void)
|
YAP_Reset(void)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
#ifndef THREADS
|
||||||
|
int worker_id = 0;
|
||||||
|
#endif
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
|
|
||||||
/* first, backtrack to the root */
|
/* first, backtrack to the root */
|
||||||
@ -3306,13 +3308,13 @@ YAP_Reset(void)
|
|||||||
if (Yap_exec_absmi(0) != 0) {
|
if (Yap_exec_absmi(0) != 0) {
|
||||||
GLOBAL_Initialised = TRUE;
|
GLOBAL_Initialised = TRUE;
|
||||||
|
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( worker_id );
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* reinitialise the engine */
|
/* reinitialise the engine */
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( worker_id );
|
||||||
GLOBAL_Initialised = TRUE;
|
GLOBAL_Initialised = TRUE;
|
||||||
|
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
|
48
C/cdmgr.c
48
C/cdmgr.c
@ -2151,6 +2151,7 @@ goal_expansion_support(PredEntry *p, Term tf)
|
|||||||
if (p0) {
|
if (p0) {
|
||||||
mark_preds_with_this_func(FunctorOfTerm(tg), p0);
|
mark_preds_with_this_func(FunctorOfTerm(tg), p0);
|
||||||
} else {
|
} else {
|
||||||
|
CACHE_REGS
|
||||||
Term mod = CurrentModule;
|
Term mod = CurrentModule;
|
||||||
PredEntry *npe;
|
PredEntry *npe;
|
||||||
if (CurrentModule == PROLOG_MODULE)
|
if (CurrentModule == PROLOG_MODULE)
|
||||||
@ -4420,7 +4421,7 @@ Yap_HidePred(PredEntry *pe)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int /* $system_predicate(P) */
|
static Int /* $system_predicate(P) */
|
||||||
p_hide_predicate( USES_REGS1 )
|
p_stash_predicate( USES_REGS1 )
|
||||||
{
|
{
|
||||||
PredEntry *pe;
|
PredEntry *pe;
|
||||||
|
|
||||||
@ -4463,6 +4464,50 @@ p_hide_predicate( USES_REGS1 )
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int /* $system_predicate(P) */
|
||||||
|
p_hide_predicate( USES_REGS1 )
|
||||||
|
{
|
||||||
|
PredEntry *pe;
|
||||||
|
|
||||||
|
Term t1 = Deref(ARG1);
|
||||||
|
Term mod = Deref(ARG2);
|
||||||
|
|
||||||
|
restart_system_pred:
|
||||||
|
if (IsVarTerm(t1))
|
||||||
|
return (FALSE);
|
||||||
|
if (IsAtomTerm(t1)) {
|
||||||
|
Atom a = AtomOfTerm(t1);
|
||||||
|
|
||||||
|
pe = RepPredProp(Yap_GetPredPropByAtom(a, mod));
|
||||||
|
} else if (IsApplTerm(t1)) {
|
||||||
|
Functor funt = FunctorOfTerm(t1);
|
||||||
|
if (IsExtensionFunctor(funt)) {
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
if (funt == FunctorModule) {
|
||||||
|
Term nmod = ArgOfTerm(1, t1);
|
||||||
|
if (IsVarTerm(nmod)) {
|
||||||
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"hide_predicate/1");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
if (!IsAtomTerm(nmod)) {
|
||||||
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"hide_predicate/1");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
t1 = ArgOfTerm(2, t1);
|
||||||
|
goto restart_system_pred;
|
||||||
|
}
|
||||||
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
||||||
|
} else if (IsPairTerm(t1)) {
|
||||||
|
return TRUE;
|
||||||
|
} else
|
||||||
|
return FALSE;
|
||||||
|
if (EndOfPAEntr(pe))
|
||||||
|
return FALSE;
|
||||||
|
pe->PredFlags |= HiddenPredFlag;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Int /* $hidden_predicate(P) */
|
static Int /* $hidden_predicate(P) */
|
||||||
p_hidden_predicate( USES_REGS1 )
|
p_hidden_predicate( USES_REGS1 )
|
||||||
@ -6016,6 +6061,7 @@ Yap_InitCdMgr(void)
|
|||||||
Yap_InitCPred("$system_predicate", 2, p_system_pred, SafePredFlag);
|
Yap_InitCPred("$system_predicate", 2, p_system_pred, SafePredFlag);
|
||||||
Yap_InitCPred("$all_system_predicate", 3, p_all_system_pred, SafePredFlag);
|
Yap_InitCPred("$all_system_predicate", 3, p_all_system_pred, SafePredFlag);
|
||||||
Yap_InitCPred("$hide_predicate", 2, p_hide_predicate, SafePredFlag);
|
Yap_InitCPred("$hide_predicate", 2, p_hide_predicate, SafePredFlag);
|
||||||
|
Yap_InitCPred("$stash_predicate", 2, p_stash_predicate, SafePredFlag);
|
||||||
Yap_InitCPred("$hidden_predicate", 2, p_hidden_predicate, SafePredFlag);
|
Yap_InitCPred("$hidden_predicate", 2, p_hidden_predicate, SafePredFlag);
|
||||||
Yap_InitCPred("$pred_for_code", 5, p_pred_for_code, SyncPredFlag);
|
Yap_InitCPred("$pred_for_code", 5, p_pred_for_code, SyncPredFlag);
|
||||||
Yap_InitCPred("$current_stack", 1, p_current_stack, SyncPredFlag);
|
Yap_InitCPred("$current_stack", 1, p_current_stack, SyncPredFlag);
|
||||||
|
163
C/exec.c
163
C/exec.c
@ -646,6 +646,117 @@ p_execute_in_mod( USES_REGS1 )
|
|||||||
return(do_execute(Deref(ARG1), Deref(ARG2) PASS_REGS));
|
return(do_execute(Deref(ARG1), Deref(ARG2) PASS_REGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int
|
||||||
|
p_do_goal_expansion( USES_REGS1 )
|
||||||
|
{
|
||||||
|
Int creeping = LOCAL_ActiveSignals & YAP_CREEP_SIGNAL;
|
||||||
|
Int out = FALSE;
|
||||||
|
PredEntry *pe;
|
||||||
|
Term cmod = Deref(ARG2);
|
||||||
|
|
||||||
|
ARG2 = ARG3;
|
||||||
|
/* disable creeping */
|
||||||
|
LOCK(LOCAL_SignalLock);
|
||||||
|
LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
||||||
|
if (!LOCAL_ActiveSignals)
|
||||||
|
CreepFlag = CalculateStackGap();
|
||||||
|
UNLOCK(LOCAL_SignalLock);
|
||||||
|
|
||||||
|
/* CurMod:goal_expansion(A,B) */
|
||||||
|
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, cmod) ) ) &&
|
||||||
|
pe->OpcodeOfPred != FAIL_OPCODE &&
|
||||||
|
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
|
CallPredicate(pe, B, pe->CodeOfPred PASS_REGS) ) {
|
||||||
|
out = TRUE;
|
||||||
|
ARG3 = ARG2;
|
||||||
|
goto complete;
|
||||||
|
}
|
||||||
|
/* system:goal_expansion(A,B) */
|
||||||
|
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE ) ) ) &&
|
||||||
|
pe->OpcodeOfPred != FAIL_OPCODE &&
|
||||||
|
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
|
CallPredicate(pe, B, pe->CodeOfPred PASS_REGS) ) {
|
||||||
|
out = TRUE;
|
||||||
|
ARG3 = ARG2;
|
||||||
|
goto complete;
|
||||||
|
}
|
||||||
|
ARG3 = ARG2;
|
||||||
|
ARG2 = cmod;
|
||||||
|
/* user:goal_expansion(A,CurMod,B) */
|
||||||
|
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE ) ) ) &&
|
||||||
|
pe->OpcodeOfPred != FAIL_OPCODE &&
|
||||||
|
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
|
CallPredicate(pe, B, pe->CodeOfPred PASS_REGS) ) {
|
||||||
|
out = TRUE;
|
||||||
|
goto complete;
|
||||||
|
}
|
||||||
|
ARG2 = ARG3;
|
||||||
|
/* user:goal_expansion(A,B) */
|
||||||
|
if ( cmod != USER_MODULE && /* we have tried this before */
|
||||||
|
(pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE ) ) ) &&
|
||||||
|
pe->OpcodeOfPred != FAIL_OPCODE &&
|
||||||
|
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
|
CallPredicate(pe, B, pe->CodeOfPred PASS_REGS) ) {
|
||||||
|
ARG3 = ARG2;
|
||||||
|
out = TRUE;
|
||||||
|
}
|
||||||
|
complete:
|
||||||
|
LOCK(LOCAL_SignalLock);
|
||||||
|
if (creeping) {
|
||||||
|
LOCAL_ActiveSignals |= YAP_CREEP_SIGNAL;
|
||||||
|
}
|
||||||
|
UNLOCK(LOCAL_SignalLock);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Int
|
||||||
|
p_do_term_expansion( USES_REGS1 )
|
||||||
|
{
|
||||||
|
Int creeping = LOCAL_ActiveSignals & YAP_CREEP_SIGNAL;
|
||||||
|
Int out = FALSE;
|
||||||
|
PredEntry *pe;
|
||||||
|
Term cmod = CurrentModule;
|
||||||
|
|
||||||
|
/* disable creeping */
|
||||||
|
LOCK(LOCAL_SignalLock);
|
||||||
|
LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
||||||
|
if (!LOCAL_ActiveSignals)
|
||||||
|
CreepFlag = CalculateStackGap();
|
||||||
|
UNLOCK(LOCAL_SignalLock);
|
||||||
|
|
||||||
|
/* CurMod:term_expansion(A,B) */
|
||||||
|
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, cmod) ) ) &&
|
||||||
|
pe->OpcodeOfPred != FAIL_OPCODE &&
|
||||||
|
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
|
CallPredicate(pe, B, pe->CodeOfPred PASS_REGS) ) {
|
||||||
|
out = TRUE;
|
||||||
|
goto complete;
|
||||||
|
}
|
||||||
|
/* system:term_expansion(A,B) */
|
||||||
|
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE ) ) ) &&
|
||||||
|
pe->OpcodeOfPred != FAIL_OPCODE &&
|
||||||
|
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
|
CallPredicate(pe, B, pe->CodeOfPred PASS_REGS) ) {
|
||||||
|
out = TRUE;
|
||||||
|
goto complete;
|
||||||
|
}
|
||||||
|
/* user:term_expansion(A,B) */
|
||||||
|
if ( cmod != USER_MODULE && /* we have tried this before */
|
||||||
|
(pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE ) ) ) &&
|
||||||
|
pe->OpcodeOfPred != FAIL_OPCODE &&
|
||||||
|
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
|
CallPredicate(pe, B, pe->CodeOfPred PASS_REGS) ) {
|
||||||
|
out = TRUE;
|
||||||
|
}
|
||||||
|
complete:
|
||||||
|
LOCK(LOCAL_SignalLock);
|
||||||
|
if (creeping) {
|
||||||
|
LOCAL_ActiveSignals |= YAP_CREEP_SIGNAL;
|
||||||
|
}
|
||||||
|
UNLOCK(LOCAL_SignalLock);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
p_execute0( USES_REGS1 )
|
p_execute0( USES_REGS1 )
|
||||||
{ /* '$execute0'(Goal,Mod) */
|
{ /* '$execute0'(Goal,Mod) */
|
||||||
@ -1604,18 +1715,22 @@ p_generate_pred_info( USES_REGS1 ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitYaamRegs(void)
|
Yap_InitYaamRegs( int myworker_id )
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
|
||||||
Term h0var;
|
Term h0var;
|
||||||
#if PUSH_REGS
|
#if PUSH_REGS
|
||||||
/* Guarantee that after a longjmp we go back to the original abstract
|
/* Guarantee that after a longjmp we go back to the original abstract
|
||||||
machine registers */
|
machine registers */
|
||||||
#ifdef THREADS
|
#ifdef THREADS
|
||||||
int myworker_id = worker_id;
|
CACHE_REGS
|
||||||
|
int wid = worker_id;
|
||||||
|
if (wid != myworker_id) {
|
||||||
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(myworker_id).default_yaam_regs);
|
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(myworker_id).default_yaam_regs);
|
||||||
|
REFRESH_CACHE_REGS
|
||||||
REMOTE_ThreadHandle(myworker_id).current_yaam_regs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs;
|
REMOTE_ThreadHandle(myworker_id).current_yaam_regs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs;
|
||||||
worker_id = myworker_id; /* ricroc: for what I understand, this shouldn't be necessary */
|
worker_id = myworker_id;
|
||||||
|
}
|
||||||
|
/* may be run by worker_id on behalf on myworker_id */
|
||||||
#else
|
#else
|
||||||
Yap_regp = &Yap_standard_regs;
|
Yap_regp = &Yap_standard_regs;
|
||||||
#endif
|
#endif
|
||||||
@ -1623,12 +1738,10 @@ Yap_InitYaamRegs(void)
|
|||||||
Yap_ResetExceptionTerm ();
|
Yap_ResetExceptionTerm ();
|
||||||
Yap_PutValue (AtomBreak, MkIntTerm (0));
|
Yap_PutValue (AtomBreak, MkIntTerm (0));
|
||||||
TR = (tr_fr_ptr)LOCAL_TrailBase;
|
TR = (tr_fr_ptr)LOCAL_TrailBase;
|
||||||
if (Yap_AttsSize > (LOCAL_LocalBase-LOCAL_GlobalBase)/8)
|
H = H0 = ((CELL *) REMOTE_GlobalBase(wid));
|
||||||
Yap_AttsSize = (LOCAL_LocalBase-LOCAL_GlobalBase)/8;
|
|
||||||
H = H0 = ((CELL *) LOCAL_GlobalBase)+ Yap_AttsSize/sizeof(CELL);
|
|
||||||
RESET_VARIABLE(H0-1);
|
RESET_VARIABLE(H0-1);
|
||||||
LCL0 = ASP = (CELL *) LOCAL_LocalBase;
|
LCL0 = ASP = (CELL *) REMOTE_LocalBase(wid);
|
||||||
CurrentTrailTop = (tr_fr_ptr)(LOCAL_TrailTop-MinTrailGap);
|
CurrentTrailTop = (tr_fr_ptr)(REMOTE_TrailTop(wid)-MinTrailGap);
|
||||||
/* notice that an initial choice-point and environment
|
/* notice that an initial choice-point and environment
|
||||||
*must* be created since for the garbage collector to work */
|
*must* be created since for the garbage collector to work */
|
||||||
B = NULL;
|
B = NULL;
|
||||||
@ -1643,27 +1756,27 @@ Yap_InitYaamRegs(void)
|
|||||||
#ifdef YAPOR_SBA
|
#ifdef YAPOR_SBA
|
||||||
BSEG =
|
BSEG =
|
||||||
#endif /* YAPOR_SBA */
|
#endif /* YAPOR_SBA */
|
||||||
BBREG = B_FZ = (choiceptr) LOCAL_LocalBase;
|
BBREG = B_FZ = (choiceptr) REMOTE_LocalBase(wid);
|
||||||
TR = TR_FZ = (tr_fr_ptr) LOCAL_TrailBase;
|
TR = TR_FZ = (tr_fr_ptr) REMOTE_TrailBase(wid);
|
||||||
#endif /* FROZEN_STACKS */
|
#endif /* FROZEN_STACKS */
|
||||||
LOCK(LOCAL_SignalLock);
|
LOCK(REMOTE_SignalLock(wid));
|
||||||
CreepFlag = CalculateStackGap();
|
CreepFlag = CalculateStackGap();
|
||||||
UNLOCK(LOCAL_SignalLock);
|
UNLOCK(REMOTE_SignalLock(wid));
|
||||||
EX = NULL;
|
EX = NULL;
|
||||||
init_stack(0, NULL, TRUE, NULL PASS_REGS);
|
init_stack(0, NULL, TRUE, NULL PASS_REGS);
|
||||||
/* the first real choice-point will also have AP=FAIL */
|
/* the first real choice-point will also have AP=FAIL */
|
||||||
/* always have an empty slots for people to use */
|
/* always have an empty slots for people to use */
|
||||||
CurSlot = 0;
|
CurSlot = 0;
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( PASS_REGS1 );
|
||||||
LOCAL_GlobalArena = TermNil;
|
REMOTE_GlobalArena(wid) = TermNil;
|
||||||
h0var = MkVarTerm();
|
h0var = MkVarTerm();
|
||||||
#if COROUTINING
|
#if COROUTINING
|
||||||
LOCAL_WokenGoals = Yap_NewTimedVar(TermNil);
|
REMOTE_WokenGoals(wid) = Yap_NewTimedVar(TermNil);
|
||||||
LOCAL_AttsMutableList = Yap_NewTimedVar(h0var);
|
REMOTE_AttsMutableList(wid) = Yap_NewTimedVar(h0var);
|
||||||
#endif
|
#endif
|
||||||
LOCAL_GcGeneration = Yap_NewTimedVar(h0var);
|
REMOTE_GcGeneration(wid) = Yap_NewTimedVar(h0var);
|
||||||
LOCAL_GcCurrentPhase = 0L;
|
REMOTE_GcCurrentPhase(wid) = 0L;
|
||||||
LOCAL_GcPhase = Yap_NewTimedVar(MkIntTerm(LOCAL_GcCurrentPhase));
|
REMOTE_GcPhase(wid) = Yap_NewTimedVar(MkIntTerm(REMOTE_GcCurrentPhase(wid)));
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
PREG_ADDR = NULL;
|
PREG_ADDR = NULL;
|
||||||
@ -1678,8 +1791,14 @@ Yap_InitYaamRegs(void)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef TABLING
|
#ifdef TABLING
|
||||||
/* ensure that LOCAL_top_dep_fr is always valid */
|
/* ensure that LOCAL_top_dep_fr is always valid */
|
||||||
if (LOCAL_top_dep_fr)
|
if (REMOTE_top_dep_fr(wid))
|
||||||
DepFr_cons_cp(LOCAL_top_dep_fr) = NORM_CP(B);
|
DepFr_cons_cp(REMOTE_top_dep_fr(wid)) = NORM_CP(B);
|
||||||
|
#endif
|
||||||
|
#ifdef THREADS
|
||||||
|
worker_id = wid;
|
||||||
|
if (myworker_id != worker_id) {
|
||||||
|
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(worker_id).default_yaam_regs);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1838,6 +1957,8 @@ Yap_InitExecFs(void)
|
|||||||
Yap_InitCPred("$generate_pred_info", 4, p_generate_pred_info, 0);
|
Yap_InitCPred("$generate_pred_info", 4, p_generate_pred_info, 0);
|
||||||
Yap_InitCPred("$uncaught_throw", 0, p_uncaught_throw, 0);
|
Yap_InitCPred("$uncaught_throw", 0, p_uncaught_throw, 0);
|
||||||
Yap_InitCPred("$reset_exception", 1, p_reset_exception, 0);
|
Yap_InitCPred("$reset_exception", 1, p_reset_exception, 0);
|
||||||
|
Yap_InitCPred("$do_goal_expansion", 3, p_do_goal_expansion, 0);
|
||||||
|
Yap_InitCPred("$do_term_expansion", 2, p_do_term_expansion, 0);
|
||||||
Yap_InitCPred("$get_exception", 1, p_get_exception, 0);
|
Yap_InitCPred("$get_exception", 1, p_get_exception, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2367,7 +2367,7 @@ cls_head_info(ClauseDef *min, ClauseDef *max, UInt argno, int in_idb)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (cl <= max) {
|
while (cl <= max) {
|
||||||
add_head_info(cl, argno);
|
add_info(cl, argno);
|
||||||
/* if (IsVarTerm(cl->Tag)) cl->Tag = (CELL)NULL; */
|
/* if (IsVarTerm(cl->Tag)) cl->Tag = (CELL)NULL; */
|
||||||
cl++;
|
cl++;
|
||||||
}
|
}
|
||||||
|
3
C/init.c
3
C/init.c
@ -1157,6 +1157,7 @@ InitFirstWorkerThreadHandle(void)
|
|||||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock, NULL);
|
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock, NULL);
|
||||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock_status, NULL);
|
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock_status, NULL);
|
||||||
LOCAL_ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
|
LOCAL_ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
|
||||||
|
LOCAL_ThreadHandle.ref_count = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1314,7 +1315,7 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
|
|||||||
#endif /* YAPOR || TABLING */
|
#endif /* YAPOR || TABLING */
|
||||||
|
|
||||||
Yap_AttsSize = Atts;
|
Yap_AttsSize = Atts;
|
||||||
Yap_InitTime();
|
Yap_InitTime( 0 );
|
||||||
/* InitAbsmi must be done before InitCodes */
|
/* InitAbsmi must be done before InitCodes */
|
||||||
/* This must be done before initialising predicates */
|
/* This must be done before initialising predicates */
|
||||||
for (i = 0; i <= NUMBER_OF_YAP_FLAGS; i++) {
|
for (i = 0; i <= NUMBER_OF_YAP_FLAGS; i++) {
|
||||||
|
10
C/load_dl.c
10
C/load_dl.c
@ -191,21 +191,27 @@ Yap_ShutdownLoadForeign(void)
|
|||||||
|
|
||||||
f_code = ForeignCodeLoaded;
|
f_code = ForeignCodeLoaded;
|
||||||
while (f_code != NULL) {
|
while (f_code != NULL) {
|
||||||
StringList objs, libs;
|
StringList objs, libs, old;
|
||||||
|
ForeignObj *of_code = f_code;
|
||||||
|
|
||||||
objs = f_code->objs;
|
objs = f_code->objs;
|
||||||
while (objs != NULL) {
|
while (objs != NULL) {
|
||||||
|
old = objs;
|
||||||
if (dlclose(objs->handle) != 0)
|
if (dlclose(objs->handle) != 0)
|
||||||
return; /* ERROR */
|
return; /* ERROR */
|
||||||
objs = objs->next;
|
objs = objs->next;
|
||||||
|
Yap_FreeCodeSpace(old);
|
||||||
}
|
}
|
||||||
libs = f_code->libs;
|
libs = f_code->libs;
|
||||||
while (libs != NULL) {
|
while (libs != NULL) {
|
||||||
|
old = libs;
|
||||||
if (dlclose(libs->handle) != 0)
|
if (dlclose(libs->handle) != 0)
|
||||||
return; /* ERROR */
|
return; /* ERROR */
|
||||||
objs = libs->next;
|
libs = libs->next;
|
||||||
|
Yap_FreeCodeSpace(old);
|
||||||
}
|
}
|
||||||
f_code = f_code->next;
|
f_code = f_code->next;
|
||||||
|
Yap_FreeCodeSpace((ADDR)of_code);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
make sure that we don't try to close foreign code several times, eg,
|
make sure that we don't try to close foreign code several times, eg,
|
||||||
|
2
C/qlyr.c
2
C/qlyr.c
@ -1008,7 +1008,7 @@ ReInitProlog(void)
|
|||||||
#if defined(YAPOR) || defined(TABLING)
|
#if defined(YAPOR) || defined(TABLING)
|
||||||
Yap_init_root_frames();
|
Yap_init_root_frames();
|
||||||
#endif /* YAPOR || TABLING */
|
#endif /* YAPOR || TABLING */
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( 0 );
|
||||||
YAP_RunGoalOnce(t);
|
YAP_RunGoalOnce(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
C/save.c
2
C/save.c
@ -1781,7 +1781,7 @@ Restore(char *s, char *lib_dir USES_REGS)
|
|||||||
break;
|
break;
|
||||||
case DO_ONLY_CODE:
|
case DO_ONLY_CODE:
|
||||||
UnmarkTrEntries( PASS_REGS1 );
|
UnmarkTrEntries( PASS_REGS1 );
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( 0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
89
C/sysbits.c
89
C/sysbits.c
@ -90,7 +90,7 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
STATIC_PROTO (void InitTime, (void));
|
STATIC_PROTO (void InitTime, (int));
|
||||||
STATIC_PROTO (void InitWTime, (void));
|
STATIC_PROTO (void InitWTime, (void));
|
||||||
STATIC_PROTO (Int p_sh, ( USES_REGS1 ));
|
STATIC_PROTO (Int p_sh, ( USES_REGS1 ));
|
||||||
STATIC_PROTO (Int p_shell, ( USES_REGS1 ));
|
STATIC_PROTO (Int p_shell, ( USES_REGS1 ));
|
||||||
@ -335,32 +335,60 @@ bla bla
|
|||||||
#define StartOfTimes (*(LOCAL_ThreadHandle.start_of_timesp))
|
#define StartOfTimes (*(LOCAL_ThreadHandle.start_of_timesp))
|
||||||
#define last_time (*(LOCAL_ThreadHandle.last_timep))
|
#define last_time (*(LOCAL_ThreadHandle.last_timep))
|
||||||
|
|
||||||
|
#define StartOfTimes_sys (*(LOCAL_ThreadHandle.start_of_times_sysp))
|
||||||
|
#define last_time_sys (*(LOCAL_ThreadHandle.last_time_sysp))
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* since the point YAP was started */
|
/* since the point YAP was started */
|
||||||
static struct timeval StartOfTimes;
|
static struct timeval StartOfTimes;
|
||||||
|
|
||||||
/* since last call to runtime */
|
/* since last call to runtime */
|
||||||
static struct timeval last_time;
|
static struct timeval last_time;
|
||||||
#endif
|
|
||||||
|
/* same for system time */
|
||||||
static struct timeval last_time_sys;
|
static struct timeval last_time_sys;
|
||||||
static struct timeval StartOfTimes_sys;
|
static struct timeval StartOfTimes_sys;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* store user time in this variable */
|
/* store user time in this variable */
|
||||||
static void
|
static void
|
||||||
InitTime (void)
|
InitTime (int wid)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
|
||||||
struct rusage rusage;
|
struct rusage rusage;
|
||||||
|
|
||||||
#if THREADS
|
#if THREADS
|
||||||
LOCAL_ThreadHandle.start_of_timesp = (struct timeval *)malloc(sizeof(struct timeval));
|
REMOTE_ThreadHandle(wid).start_of_timesp = (struct timeval *)malloc(sizeof(struct timeval));
|
||||||
LOCAL_ThreadHandle.last_timep = (struct timeval *)malloc(sizeof(struct timeval));
|
REMOTE_ThreadHandle(wid).last_timep = (struct timeval *)malloc(sizeof(struct timeval));
|
||||||
#endif
|
REMOTE_ThreadHandle(wid).start_of_times_sysp = (struct timeval *)malloc(sizeof(struct timeval));
|
||||||
|
REMOTE_ThreadHandle(wid).last_time_sysp = (struct timeval *)malloc(sizeof(struct timeval));
|
||||||
getrusage(RUSAGE_SELF, &rusage);
|
getrusage(RUSAGE_SELF, &rusage);
|
||||||
last_time.tv_sec = StartOfTimes.tv_sec = rusage.ru_utime.tv_sec;
|
(*REMOTE_ThreadHandle(wid).last_timep).tv_sec =
|
||||||
last_time.tv_usec = StartOfTimes.tv_usec = rusage.ru_utime.tv_usec;
|
(*REMOTE_ThreadHandle(wid).start_of_timesp).tv_sec =
|
||||||
last_time_sys.tv_sec = StartOfTimes_sys.tv_sec = rusage.ru_stime.tv_sec;
|
rusage.ru_utime.tv_sec;
|
||||||
last_time_sys.tv_usec = StartOfTimes_sys.tv_usec = rusage.ru_stime.tv_usec;
|
(*REMOTE_ThreadHandle(wid).last_timep).tv_usec =
|
||||||
|
(*REMOTE_ThreadHandle(wid).start_of_timesp).tv_usec =
|
||||||
|
rusage.ru_utime.tv_usec;
|
||||||
|
(*REMOTE_ThreadHandle(wid).last_time_sysp).tv_sec =
|
||||||
|
(*REMOTE_ThreadHandle(wid).start_of_times_sysp).tv_sec =
|
||||||
|
rusage.ru_stime.tv_sec;
|
||||||
|
(*REMOTE_ThreadHandle(wid).last_time_sysp).tv_usec =
|
||||||
|
(*REMOTE_ThreadHandle(wid).start_of_times_sysp).tv_usec =
|
||||||
|
rusage.ru_stime.tv_usec;
|
||||||
|
#else
|
||||||
|
getrusage(RUSAGE_SELF, &rusage);
|
||||||
|
last_time.tv_sec =
|
||||||
|
StartOfTimes.tv_sec =
|
||||||
|
rusage.ru_utime.tv_sec;
|
||||||
|
last_time.tv_usec =
|
||||||
|
StartOfTimes.tv_usec =
|
||||||
|
rusage.ru_utime.tv_usec;
|
||||||
|
last_time_sys.tv_sec =
|
||||||
|
StartOfTimes_sys.tv_sec =
|
||||||
|
rusage.ru_stime.tv_sec;
|
||||||
|
last_time_sys.tv_usec =
|
||||||
|
StartOfTimes_sys.tv_usec =
|
||||||
|
rusage.ru_stime.tv_usec;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -391,6 +419,7 @@ void Yap_cputime_interval(Int *now,Int *interval)
|
|||||||
|
|
||||||
void Yap_systime_interval(Int *now,Int *interval)
|
void Yap_systime_interval(Int *now,Int *interval)
|
||||||
{
|
{
|
||||||
|
CACHE_REGS
|
||||||
struct rusage rusage;
|
struct rusage rusage;
|
||||||
|
|
||||||
getrusage(RUSAGE_SELF, &rusage);
|
getrusage(RUSAGE_SELF, &rusage);
|
||||||
@ -437,7 +466,7 @@ static clock_t TimesStartOfTimes, Times_last_time;
|
|||||||
|
|
||||||
/* store user time in this variable */
|
/* store user time in this variable */
|
||||||
static void
|
static void
|
||||||
InitTime (void)
|
InitTime (int)
|
||||||
{
|
{
|
||||||
HANDLE hProcess = GetCurrentProcess();
|
HANDLE hProcess = GetCurrentProcess();
|
||||||
FILETIME CreationTime, ExitTime, KernelTime, UserTime;
|
FILETIME CreationTime, ExitTime, KernelTime, UserTime;
|
||||||
@ -447,14 +476,22 @@ InitTime (void)
|
|||||||
t = clock ();
|
t = clock ();
|
||||||
Times_last_time = TimesStartOfTimes = t;
|
Times_last_time = TimesStartOfTimes = t;
|
||||||
} else {
|
} else {
|
||||||
last_time.dwLowDateTime = UserTime.dwLowDateTime;
|
(*REMOTE_ThreadHandle(wid).last_timep).dwLowDateTime =
|
||||||
last_time.dwHighDateTime = UserTime.dwHighDateTime;
|
UserTime.dwLowDateTime;
|
||||||
StartOfTimes.dwLowDateTime = UserTime.dwLowDateTime;
|
(*REMOTE_ThreadHandle(wid).last_timep).dwHighDateTime =
|
||||||
StartOfTimes.dwHighDateTime = UserTime.dwHighDateTime;
|
UserTime.dwHighDateTime;
|
||||||
last_time_sys.dwLowDateTime = KernelTime.dwLowDateTime;
|
(*REMOTE_ThreadHandle(wid).start_of_timesp).dwLowDateTime =
|
||||||
last_time_sys.dwHighDateTime = KernelTime.dwHighDateTime;
|
UserTime.dwLowDateTime;
|
||||||
StartOfTimes_sys.dwLowDateTime = KernelTime.dwLowDateTime;
|
(*REMOTE_ThreadHandle(wid).start_of_timesp).dwHighDateTime =
|
||||||
StartOfTimes_sys.dwHighDateTime = KernelTime.dwHighDateTime;
|
UserTime.dwHighDateTime;
|
||||||
|
(*REMOTE_ThreadHandle(wid).last_time_sysp).dwLowDateTime =
|
||||||
|
KernelTime.dwLowDateTime;
|
||||||
|
(*REMOTE_ThreadHandle(wid).last_time_sysp).dwHighDateTime =
|
||||||
|
KernelTime.dwHighDateTime;
|
||||||
|
(*REMOTE_ThreadHandle(wid).start_of_times_sysp).dwLowDateTime =
|
||||||
|
KernelTime.dwLowDateTime;
|
||||||
|
(*REMOTE_ThreadHandle(wid).start_of_times_sysp).dwHighDateTime =
|
||||||
|
KernelTime.dwHighDateTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,7 +641,7 @@ InitTime (void)
|
|||||||
{
|
{
|
||||||
struct tms t;
|
struct tms t;
|
||||||
times (&t);
|
times (&t);
|
||||||
last_time = StartOfTimes = t.tms_utime;
|
(*REMOTE_ThreadHandle(wid).last_timep) = StartOfTimes = t.tms_utime;
|
||||||
last_time_sys = StartOfTimes_sys = t.tms_stime;
|
last_time_sys = StartOfTimes_sys = t.tms_stime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,13 +685,13 @@ static struct timeval last_time;
|
|||||||
|
|
||||||
/* store user time in this variable */
|
/* store user time in this variable */
|
||||||
static void
|
static void
|
||||||
InitTime (void)
|
InitTime (int wid)
|
||||||
{
|
{
|
||||||
struct timeval tp;
|
struct timeval tp;
|
||||||
|
|
||||||
gettimeofday(&tp,NULL);
|
gettimeofday(&tp,NULL);
|
||||||
last_time.tv_sec = StartOfTimes.tv_sec = tp.tv_sec;
|
(*REMOTE_ThreadHandle(wid).last_timep).tv_sec = (*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_sec = tp.tv_sec;
|
||||||
last_time.tv_usec = StartOfTimes.tv_usec = tp.tv_usec;
|
(*REMOTE_ThreadHandle(wid).last_timep).tv_usec = (*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_usec = tp.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2730,9 +2767,9 @@ Yap_InitSysbits (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitTime(void)
|
Yap_InitTime( int wid )
|
||||||
{
|
{
|
||||||
InitTime();
|
InitTime( wid );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
13
C/threads.c
13
C/threads.c
@ -237,8 +237,8 @@ setup_engine(int myworker_id, int init_thread)
|
|||||||
LOCAL = REMOTE(worker_id);
|
LOCAL = REMOTE(worker_id);
|
||||||
Yap_InitExStacks(REMOTE_ThreadHandle(myworker_id).tsize, REMOTE_ThreadHandle(myworker_id).ssize);
|
Yap_InitExStacks(REMOTE_ThreadHandle(myworker_id).tsize, REMOTE_ThreadHandle(myworker_id).ssize);
|
||||||
CurrentModule = REMOTE_ThreadHandle(myworker_id).cmod;
|
CurrentModule = REMOTE_ThreadHandle(myworker_id).cmod;
|
||||||
Yap_InitTime();
|
Yap_InitTime( myworker_id );
|
||||||
Yap_InitYaamRegs();
|
Yap_InitYaamRegs( myworker_id );
|
||||||
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
|
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
|
||||||
/* I exist */
|
/* I exist */
|
||||||
GLOBAL_NOfThreadsCreated++;
|
GLOBAL_NOfThreadsCreated++;
|
||||||
@ -246,7 +246,7 @@ setup_engine(int myworker_id, int init_thread)
|
|||||||
DEBUG_TLOCK_ACCESS(2, myworker_id);
|
DEBUG_TLOCK_ACCESS(2, myworker_id);
|
||||||
pthread_mutex_unlock(&(REMOTE_ThreadHandle(myworker_id).tlock));
|
pthread_mutex_unlock(&(REMOTE_ThreadHandle(myworker_id).tlock));
|
||||||
#ifdef TABLING
|
#ifdef TABLING
|
||||||
new_dependency_frame(LOCAL_top_dep_fr, FALSE, NULL, NULL, B, NULL, FALSE, NULL); /* same as in Yap_init_root_frames() */
|
new_dependency_frame(REMOTE_top_dep_fr(myworker_id), FALSE, NULL, NULL, B, NULL, FALSE, NULL); /* same as in Yap_init_root_frames() */
|
||||||
#endif /* TABLING */
|
#endif /* TABLING */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -456,8 +456,9 @@ Yap_thread_create_engine(thread_attr *ops)
|
|||||||
Term t = TermNil;
|
Term t = TermNil;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ok, this creates a problem, because we are initializing an engine from some "empty" thread.
|
ok, this creates a problem, because we are initializing an engine from
|
||||||
We need first to foool the thread into believing it is the main thread
|
some "empty" thread.
|
||||||
|
We need first to fool the thread into believing it is the main thread
|
||||||
*/
|
*/
|
||||||
if (new_id == -1) {
|
if (new_id == -1) {
|
||||||
/* YAP ERROR */
|
/* YAP ERROR */
|
||||||
@ -492,7 +493,6 @@ Yap_thread_create_engine(thread_attr *ops)
|
|||||||
Int
|
Int
|
||||||
Yap_thread_attach_engine(int wid)
|
Yap_thread_attach_engine(int wid)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
|
||||||
/*
|
/*
|
||||||
already locked
|
already locked
|
||||||
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
|
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
|
||||||
@ -507,6 +507,7 @@ Yap_thread_attach_engine(int wid)
|
|||||||
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
|
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
|
||||||
REMOTE_ThreadHandle(wid).ref_count++;
|
REMOTE_ThreadHandle(wid).ref_count++;
|
||||||
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(wid).default_yaam_regs);
|
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(wid).default_yaam_regs);
|
||||||
|
CACHE_REGS
|
||||||
worker_id = wid; /* ricroc: for what I understand, this shouldn't be necessary */
|
worker_id = wid; /* ricroc: for what I understand, this shouldn't be necessary */
|
||||||
DEBUG_TLOCK_ACCESS(9, wid);
|
DEBUG_TLOCK_ACCESS(9, wid);
|
||||||
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
|
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
|
||||||
|
@ -282,7 +282,7 @@ writebig(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, stru
|
|||||||
blob_info = big_tag - USER_BLOB_START;
|
blob_info = big_tag - USER_BLOB_START;
|
||||||
if (GLOBAL_OpaqueHandlers &&
|
if (GLOBAL_OpaqueHandlers &&
|
||||||
(f= GLOBAL_OpaqueHandlers[blob_info].write_handler)) {
|
(f= GLOBAL_OpaqueHandlers[blob_info].write_handler)) {
|
||||||
(f)(wglb->stream, big_tag, (void *)((MP_INT *)(pt+1)), 0);
|
(f)(wglb->stream, big_tag, ExternalBlobFromTerm(t), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wrputs("0",wglb->stream);
|
wrputs("0",wglb->stream);
|
||||||
|
3
H/Regs.h
3
H/Regs.h
@ -83,6 +83,7 @@ INLINE_ONLY inline EXTERN void restore_B(void);
|
|||||||
INLINE_ONLY inline EXTERN void save_B(void);
|
INLINE_ONLY inline EXTERN void save_B(void);
|
||||||
|
|
||||||
#define CACHE_REGS
|
#define CACHE_REGS
|
||||||
|
#define REFRESH_CACHE_REGS
|
||||||
#define INIT_REGS
|
#define INIT_REGS
|
||||||
#define PASS_REGS1
|
#define PASS_REGS1
|
||||||
#define PASS_REGS
|
#define PASS_REGS
|
||||||
@ -182,12 +183,14 @@ extern Term Yap_XREGS[MaxTemps]; /* 29 */
|
|||||||
extern pthread_key_t Yap_yaamregs_key;
|
extern pthread_key_t Yap_yaamregs_key;
|
||||||
|
|
||||||
#undef CACHE_REGS
|
#undef CACHE_REGS
|
||||||
|
#undef REFRESH_CACHE_REGS
|
||||||
#undef INIT_REGS
|
#undef INIT_REGS
|
||||||
#undef PASS_REGS
|
#undef PASS_REGS
|
||||||
#undef PASS_REGS1
|
#undef PASS_REGS1
|
||||||
#undef USES_REGS
|
#undef USES_REGS
|
||||||
#undef USES_REGS1
|
#undef USES_REGS1
|
||||||
#define CACHE_REGS REGSTORE *regcache = ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key));
|
#define CACHE_REGS REGSTORE *regcache = ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key));
|
||||||
|
#define REFRESH_CACHE_REGS regcache = ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key));
|
||||||
#define INIT_REGS , ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key))
|
#define INIT_REGS , ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key))
|
||||||
#define PASS_REGS1 regcache
|
#define PASS_REGS1 regcache
|
||||||
#define PASS_REGS , regcache
|
#define PASS_REGS , regcache
|
||||||
|
35
H/Yap.h
35
H/Yap.h
@ -749,6 +749,8 @@ typedef struct thandle {
|
|||||||
#if HAVE_GETRUSAGE||defined(_WIN32)
|
#if HAVE_GETRUSAGE||defined(_WIN32)
|
||||||
struct timeval *start_of_timesp;
|
struct timeval *start_of_timesp;
|
||||||
struct timeval *last_timep;
|
struct timeval *last_timep;
|
||||||
|
struct timeval *start_of_times_sysp;
|
||||||
|
struct timeval *last_time_sysp;
|
||||||
#endif
|
#endif
|
||||||
} yap_thandle;
|
} yap_thandle;
|
||||||
#endif /* THREADS */
|
#endif /* THREADS */
|
||||||
@ -850,22 +852,6 @@ Yap_StartSlots( USES_REGS1 ) {
|
|||||||
CurSlot = LCL0-ASP;
|
CurSlot = LCL0-ASP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
Yap_CloseSlots( USES_REGS1 ) {
|
|
||||||
Int old_slots;
|
|
||||||
if (CurSlot < LCL0-ASP)
|
|
||||||
return;
|
|
||||||
old_slots = IntOfTerm(ASP[0]);
|
|
||||||
ASP += (old_slots+1);
|
|
||||||
CurSlot = IntOfTerm(*ASP);
|
|
||||||
ASP++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Int
|
|
||||||
Yap_CurrentSlot( USES_REGS1 ) {
|
|
||||||
return IntOfTerm(ASP[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pop slots when pruning */
|
/* pop slots when pruning */
|
||||||
static inline void
|
static inline void
|
||||||
Yap_PopSlots( USES_REGS1 ) {
|
Yap_PopSlots( USES_REGS1 ) {
|
||||||
@ -878,6 +864,23 @@ Yap_PopSlots( USES_REGS1 ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
Yap_CloseSlots( USES_REGS1 ) {
|
||||||
|
Int old_slots;
|
||||||
|
Yap_PopSlots( PASS_REGS1 );
|
||||||
|
if (LCL0-CurSlot == ASP) {
|
||||||
|
old_slots = IntOfTerm(ASP[0]);
|
||||||
|
ASP += (old_slots+1);
|
||||||
|
CurSlot = IntOfTerm(*ASP);
|
||||||
|
ASP++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline Int
|
||||||
|
Yap_CurrentSlot( USES_REGS1 ) {
|
||||||
|
return IntOfTerm(ASP[0]);
|
||||||
|
}
|
||||||
|
|
||||||
static inline Term
|
static inline Term
|
||||||
Yap_GetFromSlot(Int slot USES_REGS)
|
Yap_GetFromSlot(Int slot USES_REGS)
|
||||||
{
|
{
|
||||||
|
@ -319,9 +319,9 @@
|
|||||||
OPCODE(p_func2f_yx ,yxx),
|
OPCODE(p_func2f_yx ,yxx),
|
||||||
OPCODE(p_func2f_yy ,yyx),
|
OPCODE(p_func2f_yy ,yyx),
|
||||||
OPCODE(p_functor ,e),
|
OPCODE(p_functor ,e),
|
||||||
|
OPCODE(p_execute_tail ,Osbmp),
|
||||||
OPCODE(p_execute2 ,Osbpp),
|
OPCODE(p_execute2 ,Osbpp),
|
||||||
OPCODE(p_execute ,Osbmp),
|
OPCODE(p_execute ,Osbmp),
|
||||||
OPCODE(p_execute_tail ,Osbpp),
|
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
OPCODE(getwork_first_time ,e),
|
OPCODE(getwork_first_time ,e),
|
||||||
OPCODE(getwork ,Otapl),
|
OPCODE(getwork ,Otapl),
|
||||||
|
@ -248,7 +248,7 @@ void STD_PROTO(Yap_KillStacks,(int));
|
|||||||
#else
|
#else
|
||||||
void STD_PROTO(Yap_KillStacks,(int));
|
void STD_PROTO(Yap_KillStacks,(int));
|
||||||
#endif
|
#endif
|
||||||
void STD_PROTO(Yap_InitYaamRegs,(void));
|
void STD_PROTO(Yap_InitYaamRegs,(int));
|
||||||
void STD_PROTO(Yap_ReInitWallTime, (void));
|
void STD_PROTO(Yap_ReInitWallTime, (void));
|
||||||
int STD_PROTO(Yap_OpDec,(int,char *,Atom,Term));
|
int STD_PROTO(Yap_OpDec,(int,char *,Atom,Term));
|
||||||
void STD_PROTO(Yap_CloseScratchPad,(void));
|
void STD_PROTO(Yap_CloseScratchPad,(void));
|
||||||
@ -360,7 +360,7 @@ void STD_PROTO(Yap_systime_interval,(Int *,Int *));
|
|||||||
void STD_PROTO(Yap_walltime_interval,(Int *,Int *));
|
void STD_PROTO(Yap_walltime_interval,(Int *,Int *));
|
||||||
void STD_PROTO(Yap_InitSysbits,(void));
|
void STD_PROTO(Yap_InitSysbits,(void));
|
||||||
void STD_PROTO(Yap_InitSysPreds,(void));
|
void STD_PROTO(Yap_InitSysPreds,(void));
|
||||||
void STD_PROTO(Yap_InitTime,(void));
|
void STD_PROTO(Yap_InitTime,(int));
|
||||||
int STD_PROTO(Yap_TrueFileName, (char *, char *, int));
|
int STD_PROTO(Yap_TrueFileName, (char *, char *, int));
|
||||||
double STD_PROTO(Yap_random, (void));
|
double STD_PROTO(Yap_random, (void));
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -292,7 +292,7 @@
|
|||||||
case _write_void:
|
case _write_void:
|
||||||
cl = NEXTOP(cl,e);
|
cl = NEXTOP(cl,e);
|
||||||
break;
|
break;
|
||||||
case _write_struct:
|
case _write_l_struc:
|
||||||
cl = NEXTOP(cl,fa);
|
cl = NEXTOP(cl,fa);
|
||||||
break;
|
break;
|
||||||
case _write_longint:
|
case _write_longint:
|
||||||
@ -358,6 +358,12 @@
|
|||||||
case _unify_l_float_write:
|
case _unify_l_float_write:
|
||||||
cl = NEXTOP(cl,od);
|
cl = NEXTOP(cl,od);
|
||||||
break;
|
break;
|
||||||
|
case _unify_l_struc:
|
||||||
|
cl = NEXTOP(cl,ofa);
|
||||||
|
break;
|
||||||
|
case _unify_l_struc_write:
|
||||||
|
cl = NEXTOP(cl,ofa);
|
||||||
|
break;
|
||||||
case _unify_struct:
|
case _unify_struct:
|
||||||
cl = NEXTOP(cl,ofa);
|
cl = NEXTOP(cl,ofa);
|
||||||
break;
|
break;
|
||||||
|
@ -327,6 +327,12 @@
|
|||||||
case _unify_l_float_write:
|
case _unify_l_float_write:
|
||||||
cl = NEXTOP(cl,od);
|
cl = NEXTOP(cl,od);
|
||||||
break;
|
break;
|
||||||
|
case _unify_l_struc:
|
||||||
|
cl = NEXTOP(cl,ofa);
|
||||||
|
break;
|
||||||
|
case _unify_l_struc_write:
|
||||||
|
cl = NEXTOP(cl,ofa);
|
||||||
|
break;
|
||||||
case _unify_struct:
|
case _unify_struct:
|
||||||
cl = NEXTOP(cl,ofa);
|
cl = NEXTOP(cl,ofa);
|
||||||
break;
|
break;
|
||||||
|
@ -289,6 +289,7 @@
|
|||||||
AtomSystemLibraryDir = Yap_LookupAtom("system_library_directory");
|
AtomSystemLibraryDir = Yap_LookupAtom("system_library_directory");
|
||||||
AtomTerm = Yap_LookupAtom("term");
|
AtomTerm = Yap_LookupAtom("term");
|
||||||
AtomTerms = Yap_LookupAtom("terms");
|
AtomTerms = Yap_LookupAtom("terms");
|
||||||
|
AtomTermExpansion = Yap_LookupAtom("term_expansion");
|
||||||
AtomTextStream = Yap_LookupAtom("text_stream");
|
AtomTextStream = Yap_LookupAtom("text_stream");
|
||||||
AtomThreads = Yap_LookupAtom("threads");
|
AtomThreads = Yap_LookupAtom("threads");
|
||||||
AtomThrow = Yap_LookupAtom("throw");
|
AtomThrow = Yap_LookupAtom("throw");
|
||||||
@ -424,6 +425,7 @@
|
|||||||
FunctorStreamPos = Yap_MkFunctor(AtomStreamPos,4);
|
FunctorStreamPos = Yap_MkFunctor(AtomStreamPos,4);
|
||||||
FunctorSyntaxError = Yap_MkFunctor(AtomSyntaxError,7);
|
FunctorSyntaxError = Yap_MkFunctor(AtomSyntaxError,7);
|
||||||
FunctorShortSyntaxError = Yap_MkFunctor(AtomSyntaxError,1);
|
FunctorShortSyntaxError = Yap_MkFunctor(AtomSyntaxError,1);
|
||||||
|
FunctorTermExpansion = Yap_MkFunctor(AtomTermExpansion,2);
|
||||||
FunctorThreadRun = Yap_MkFunctor(AtomTopThreadGoal,2);
|
FunctorThreadRun = Yap_MkFunctor(AtomTopThreadGoal,2);
|
||||||
FunctorThrow = Yap_MkFunctor(AtomThrow,1);
|
FunctorThrow = Yap_MkFunctor(AtomThrow,1);
|
||||||
FunctorTimeoutError = Yap_MkFunctor(AtomTimeoutError,2);
|
FunctorTimeoutError = Yap_MkFunctor(AtomTimeoutError,2);
|
||||||
|
@ -289,6 +289,7 @@
|
|||||||
AtomSystemLibraryDir = AtomAdjust(AtomSystemLibraryDir);
|
AtomSystemLibraryDir = AtomAdjust(AtomSystemLibraryDir);
|
||||||
AtomTerm = AtomAdjust(AtomTerm);
|
AtomTerm = AtomAdjust(AtomTerm);
|
||||||
AtomTerms = AtomAdjust(AtomTerms);
|
AtomTerms = AtomAdjust(AtomTerms);
|
||||||
|
AtomTermExpansion = AtomAdjust(AtomTermExpansion);
|
||||||
AtomTextStream = AtomAdjust(AtomTextStream);
|
AtomTextStream = AtomAdjust(AtomTextStream);
|
||||||
AtomThreads = AtomAdjust(AtomThreads);
|
AtomThreads = AtomAdjust(AtomThreads);
|
||||||
AtomThrow = AtomAdjust(AtomThrow);
|
AtomThrow = AtomAdjust(AtomThrow);
|
||||||
@ -424,6 +425,7 @@
|
|||||||
FunctorStreamPos = FuncAdjust(FunctorStreamPos);
|
FunctorStreamPos = FuncAdjust(FunctorStreamPos);
|
||||||
FunctorSyntaxError = FuncAdjust(FunctorSyntaxError);
|
FunctorSyntaxError = FuncAdjust(FunctorSyntaxError);
|
||||||
FunctorShortSyntaxError = FuncAdjust(FunctorShortSyntaxError);
|
FunctorShortSyntaxError = FuncAdjust(FunctorShortSyntaxError);
|
||||||
|
FunctorTermExpansion = FuncAdjust(FunctorTermExpansion);
|
||||||
FunctorThreadRun = FuncAdjust(FunctorThreadRun);
|
FunctorThreadRun = FuncAdjust(FunctorThreadRun);
|
||||||
FunctorThrow = FuncAdjust(FunctorThrow);
|
FunctorThrow = FuncAdjust(FunctorThrow);
|
||||||
FunctorTimeoutError = FuncAdjust(FunctorTimeoutError);
|
FunctorTimeoutError = FuncAdjust(FunctorTimeoutError);
|
||||||
|
@ -53,6 +53,7 @@ restore_opcodes(yamop *pc, yamop *max USES_REGS)
|
|||||||
break;
|
break;
|
||||||
/* instructions type Osbmp */
|
/* instructions type Osbmp */
|
||||||
case _p_execute:
|
case _p_execute:
|
||||||
|
case _p_execute_tail:
|
||||||
OrArgAdjust(pc->u.Osbmp.or_arg);
|
OrArgAdjust(pc->u.Osbmp.or_arg);
|
||||||
pc->u.Osbmp.s = ConstantAdjust(pc->u.Osbmp.s);
|
pc->u.Osbmp.s = ConstantAdjust(pc->u.Osbmp.s);
|
||||||
pc->u.Osbmp.bmap = CellPtoHeapAdjust(pc->u.Osbmp.bmap);
|
pc->u.Osbmp.bmap = CellPtoHeapAdjust(pc->u.Osbmp.bmap);
|
||||||
@ -75,7 +76,6 @@ restore_opcodes(yamop *pc, yamop *max USES_REGS)
|
|||||||
case _call_usercpred:
|
case _call_usercpred:
|
||||||
case _fcall:
|
case _fcall:
|
||||||
case _p_execute2:
|
case _p_execute2:
|
||||||
case _p_execute_tail:
|
|
||||||
OrArgAdjust(pc->u.Osbpp.or_arg);
|
OrArgAdjust(pc->u.Osbpp.or_arg);
|
||||||
pc->u.Osbpp.s = ConstantAdjust(pc->u.Osbpp.s);
|
pc->u.Osbpp.s = ConstantAdjust(pc->u.Osbpp.s);
|
||||||
pc->u.Osbpp.bmap = CellPtoHeapAdjust(pc->u.Osbpp.bmap);
|
pc->u.Osbpp.bmap = CellPtoHeapAdjust(pc->u.Osbpp.bmap);
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
break;
|
break;
|
||||||
/* instructions type Osbmp */
|
/* instructions type Osbmp */
|
||||||
case _p_execute:
|
case _p_execute:
|
||||||
|
case _p_execute_tail:
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
CHECK(save_OrArg(stream, pc->u.Osbmp.or_arg));
|
CHECK(save_OrArg(stream, pc->u.Osbmp.or_arg));
|
||||||
#endif
|
#endif
|
||||||
@ -75,7 +76,6 @@
|
|||||||
case _call_usercpred:
|
case _call_usercpred:
|
||||||
case _fcall:
|
case _fcall:
|
||||||
case _p_execute2:
|
case _p_execute2:
|
||||||
case _p_execute_tail:
|
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
CHECK(save_OrArg(stream, pc->u.Osbpp.or_arg));
|
CHECK(save_OrArg(stream, pc->u.Osbpp.or_arg));
|
||||||
#endif
|
#endif
|
||||||
|
@ -576,6 +576,8 @@
|
|||||||
#define AtomTerm Yap_heap_regs->AtomTerm_
|
#define AtomTerm Yap_heap_regs->AtomTerm_
|
||||||
Atom AtomTerms_;
|
Atom AtomTerms_;
|
||||||
#define AtomTerms Yap_heap_regs->AtomTerms_
|
#define AtomTerms Yap_heap_regs->AtomTerms_
|
||||||
|
Atom AtomTermExpansion_;
|
||||||
|
#define AtomTermExpansion Yap_heap_regs->AtomTermExpansion_
|
||||||
Atom AtomTextStream_;
|
Atom AtomTextStream_;
|
||||||
#define AtomTextStream Yap_heap_regs->AtomTextStream_
|
#define AtomTextStream Yap_heap_regs->AtomTextStream_
|
||||||
Atom AtomThreads_;
|
Atom AtomThreads_;
|
||||||
@ -846,6 +848,8 @@
|
|||||||
#define FunctorSyntaxError Yap_heap_regs->FunctorSyntaxError_
|
#define FunctorSyntaxError Yap_heap_regs->FunctorSyntaxError_
|
||||||
Functor FunctorShortSyntaxError_;
|
Functor FunctorShortSyntaxError_;
|
||||||
#define FunctorShortSyntaxError Yap_heap_regs->FunctorShortSyntaxError_
|
#define FunctorShortSyntaxError Yap_heap_regs->FunctorShortSyntaxError_
|
||||||
|
Functor FunctorTermExpansion_;
|
||||||
|
#define FunctorTermExpansion Yap_heap_regs->FunctorTermExpansion_
|
||||||
Functor FunctorThreadRun_;
|
Functor FunctorThreadRun_;
|
||||||
#define FunctorThreadRun Yap_heap_regs->FunctorThreadRun_
|
#define FunctorThreadRun Yap_heap_regs->FunctorThreadRun_
|
||||||
Functor FunctorThrow_;
|
Functor FunctorThrow_;
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
break;
|
break;
|
||||||
/* instructions type Osbmp */
|
/* instructions type Osbmp */
|
||||||
case _p_execute:
|
case _p_execute:
|
||||||
|
case _p_execute_tail:
|
||||||
pc = NEXTOP(pc,Osbmp);
|
pc = NEXTOP(pc,Osbmp);
|
||||||
break;
|
break;
|
||||||
/* instructions type Osbpa */
|
/* instructions type Osbpa */
|
||||||
@ -47,8 +48,6 @@
|
|||||||
return walk_found_c_pred(pp, startp, endp);
|
return walk_found_c_pred(pp, startp, endp);
|
||||||
case _p_execute2:
|
case _p_execute2:
|
||||||
return found_meta_call(startp, endp);
|
return found_meta_call(startp, endp);
|
||||||
case _p_execute_tail:
|
|
||||||
return found_meta_call(startp, endp);
|
|
||||||
case _call:
|
case _call:
|
||||||
case _fcall:
|
case _fcall:
|
||||||
clause_code = TRUE;
|
clause_code = TRUE;
|
||||||
|
6
configure
vendored
6
configure
vendored
@ -4665,7 +4665,7 @@ fi
|
|||||||
if test "${enable_clpbn_bp+set}" = set; then :
|
if test "${enable_clpbn_bp+set}" = set; then :
|
||||||
enableval=$enable_clpbn_bp; yap_cv_clpbn_bp="$enableval"
|
enableval=$enable_clpbn_bp; yap_cv_clpbn_bp="$enableval"
|
||||||
else
|
else
|
||||||
yap_cv_clpbn_bp=no
|
yap_cv_clpbn_bp=yes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -5059,6 +5059,7 @@ else
|
|||||||
INSTALL_MATLAB=""
|
INSTALL_MATLAB=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "$yap_cv_clpbn_bp"="yes"; then
|
||||||
ac_ext=cpp
|
ac_ext=cpp
|
||||||
ac_cpp='$CXXCPP $CPPFLAGS'
|
ac_cpp='$CXXCPP $CPPFLAGS'
|
||||||
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||||
@ -5083,10 +5084,10 @@ _ACEOF
|
|||||||
if ac_fn_cxx_try_compile "$LINENO"; then :
|
if ac_fn_cxx_try_compile "$LINENO"; then :
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||||
$as_echo "yes" >&6; }
|
$as_echo "yes" >&6; }
|
||||||
yap_cv_clpbn_bp=yes
|
|
||||||
else
|
else
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||||
$as_echo "no" >&6; }
|
$as_echo "no" >&6; }
|
||||||
|
yap_cv_clpbn_bp=no
|
||||||
|
|
||||||
fi
|
fi
|
||||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||||
@ -5097,6 +5098,7 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
|||||||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
if test "$yap_cv_clpbn_bp" = no
|
if test "$yap_cv_clpbn_bp" = no
|
||||||
then
|
then
|
||||||
|
@ -218,7 +218,7 @@ AC_ARG_ENABLE(cplint,
|
|||||||
|
|
||||||
AC_ARG_ENABLE(clpbn-bp,
|
AC_ARG_ENABLE(clpbn-bp,
|
||||||
[ --enable-clpbn-bp enable belief propagation solver in CLPBN. ],
|
[ --enable-clpbn-bp enable belief propagation solver in CLPBN. ],
|
||||||
yap_cv_clpbn_bp="$enableval", yap_cv_clpbn_bp=no)
|
yap_cv_clpbn_bp="$enableval", yap_cv_clpbn_bp=yes)
|
||||||
|
|
||||||
AC_ARG_WITH(gmp,
|
AC_ARG_WITH(gmp,
|
||||||
[ --with-gmp[=DIR] use GNU Multiple Precision in DIR],
|
[ --with-gmp[=DIR] use GNU Multiple Precision in DIR],
|
||||||
@ -516,17 +516,19 @@ else
|
|||||||
INSTALL_MATLAB=""
|
INSTALL_MATLAB=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "$yap_cv_clpbn_bp"="yes"; then
|
||||||
AC_LANG_PUSH([C++])
|
AC_LANG_PUSH([C++])
|
||||||
my_save_cxxflags="$CXXFLAGS"
|
my_save_cxxflags="$CXXFLAGS"
|
||||||
CXXFLAGS=-std=c++0x
|
CXXFLAGS=-std=c++0x
|
||||||
AC_MSG_CHECKING([whether CXX supports -std-c++0x])
|
AC_MSG_CHECKING([whether CXX supports -std-c++0x])
|
||||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
|
||||||
[AC_MSG_RESULT([yes])]
|
[AC_MSG_RESULT([yes])],
|
||||||
[yap_cv_clpbn_bp=yes],
|
|
||||||
[AC_MSG_RESULT([no])]
|
[AC_MSG_RESULT([no])]
|
||||||
|
[yap_cv_clpbn_bp=no]
|
||||||
)
|
)
|
||||||
CXXFLAGS="$my_save_cxxflags"
|
CXXFLAGS="$my_save_cxxflags"
|
||||||
AC_LANG_POP()
|
AC_LANG_POP()
|
||||||
|
fi
|
||||||
|
|
||||||
if test "$yap_cv_clpbn_bp" = no
|
if test "$yap_cv_clpbn_bp" = no
|
||||||
then
|
then
|
||||||
|
16
docs/yap.tex
16
docs/yap.tex
@ -1818,6 +1818,14 @@ Make hidden atom @var{Atom} visible.
|
|||||||
Make predicate @var{Pred} invisible to @code{current_predicate/2},
|
Make predicate @var{Pred} invisible to @code{current_predicate/2},
|
||||||
@code{listing}, and friends.
|
@code{listing}, and friends.
|
||||||
|
|
||||||
|
@item stash_predicate(+@var{Pred})
|
||||||
|
@findex stash_predicate/1
|
||||||
|
@snindex stash_predicate/1
|
||||||
|
@cnindex stash_predicate/1
|
||||||
|
Make predicate @var{Pred} invisible to new code, and to @code{current_predicate/2},
|
||||||
|
@code{listing}, and friends. New predicates with the same name and
|
||||||
|
functor can be declared.
|
||||||
|
|
||||||
@item expand_exprs(-@var{O},+@var{N})
|
@item expand_exprs(-@var{O},+@var{N})
|
||||||
@findex expand_exprs/2
|
@findex expand_exprs/2
|
||||||
@snindex expand_exprs/2
|
@snindex expand_exprs/2
|
||||||
@ -4616,10 +4624,10 @@ If @code{first} (default), the predicates leaves no choice-point.
|
|||||||
Otherwise a choice-point will be left and backtracking may yield
|
Otherwise a choice-point will be left and backtracking may yield
|
||||||
more solutions.
|
more solutions.
|
||||||
|
|
||||||
@c @item expand(@code{true}/@code{false})
|
@item expand(@code{true}/@code{false})
|
||||||
@c If @code{true} (default is @code{false}) and @var{Spec} is atomic,
|
If @code{true} (default is @code{false}) and @var{Spec} is atomic,
|
||||||
@c call @code{expand_file_name/2} followed by @code{member/2} on @var{Spec} before
|
call @code{expand_file_name/2} followed by @code{member/2} on @var{Spec} before
|
||||||
@c proceeding. This is a SWI-Prolog extension.
|
proceeding. This is originally a SWI-Prolog extension.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@c The Prolog flag @code{verbose_file_search} can be set to @code{true}
|
@c The Prolog flag @code{verbose_file_search} can be set to @code{true}
|
||||||
|
@ -2545,6 +2545,7 @@ X_API PL_engine_t
|
|||||||
PL_create_engine(const PL_thread_attr_t *attr)
|
PL_create_engine(const PL_thread_attr_t *attr)
|
||||||
{
|
{
|
||||||
#if THREADS
|
#if THREADS
|
||||||
|
int eng;
|
||||||
if (attr) {
|
if (attr) {
|
||||||
YAP_thread_attr yapt;
|
YAP_thread_attr yapt;
|
||||||
|
|
||||||
@ -2552,13 +2553,15 @@ PL_create_engine(const PL_thread_attr_t *attr)
|
|||||||
yapt.tsize = attr->global_size;
|
yapt.tsize = attr->global_size;
|
||||||
yapt.alias = (YAP_Term)attr->alias;
|
yapt.alias = (YAP_Term)attr->alias;
|
||||||
yapt.cancel = attr->cancel;
|
yapt.cancel = attr->cancel;
|
||||||
return Yap_local+YAP_ThreadCreateEngine(&yapt);
|
|
||||||
|
eng = YAP_ThreadCreateEngine(&yapt);
|
||||||
} else {
|
} else {
|
||||||
return Yap_local+YAP_ThreadCreateEngine(NULL);
|
eng = YAP_ThreadCreateEngine(NULL);
|
||||||
}
|
}
|
||||||
#else
|
if (eng >= 0)
|
||||||
return NULL;
|
return Yap_local[eng];
|
||||||
#endif
|
#endif
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2578,7 +2581,6 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
#if THREADS
|
#if THREADS
|
||||||
int cwid = PL_thread_self(), nwid;
|
int cwid = PL_thread_self(), nwid;
|
||||||
|
|
||||||
if (cwid >= 0) {
|
if (cwid >= 0) {
|
||||||
if (old) *old = (PL_engine_t)(Yap_local[cwid]);
|
if (old) *old = (PL_engine_t)(Yap_local[cwid]);
|
||||||
}
|
}
|
||||||
@ -2599,7 +2601,7 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
|
|||||||
}
|
}
|
||||||
return PL_ENGINE_SET;
|
return PL_ENGINE_SET;
|
||||||
} else {
|
} else {
|
||||||
nwid = ((struct worker_local *)engine)->ThreadHandle_.current_yaam_regs->worker_id_;
|
nwid = ((struct worker_local *)engine)->ThreadHandle_.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&(REMOTE_ThreadHandle(nwid).tlock));
|
pthread_mutex_lock(&(REMOTE_ThreadHandle(nwid).tlock));
|
||||||
@ -2610,13 +2612,6 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
|
|||||||
}
|
}
|
||||||
return PL_ENGINE_SET;
|
return PL_ENGINE_SET;
|
||||||
}
|
}
|
||||||
if (cwid >= 0) {
|
|
||||||
if (!YAP_ThreadDetachEngine(cwid)) {
|
|
||||||
*old = NULL;
|
|
||||||
pthread_mutex_unlock(&(REMOTE_ThreadHandle(nwid).tlock));
|
|
||||||
return PL_ENGINE_INVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!YAP_ThreadAttachEngine(nwid)) {
|
if (!YAP_ThreadAttachEngine(nwid)) {
|
||||||
return PL_ENGINE_INVAL;
|
return PL_ENGINE_INVAL;
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,8 @@ process_err_stream_for_exec(Stream, Stream, _, L, L) :-
|
|||||||
stream_property(Stream, input).
|
stream_property(Stream, input).
|
||||||
|
|
||||||
close_temp_streams([]).
|
close_temp_streams([]).
|
||||||
close_temp_streams([S|Ss]) :- close(S),
|
close_temp_streams([S|Ss]) :-
|
||||||
|
close(S),
|
||||||
close_temp_streams(Ss).
|
close_temp_streams(Ss).
|
||||||
|
|
||||||
popen(Command, Mode, Stream) :-
|
popen(Command, Mode, Stream) :-
|
||||||
|
@ -294,6 +294,7 @@ A SystemError N "system_error"
|
|||||||
A SystemLibraryDir N "system_library_directory"
|
A SystemLibraryDir N "system_library_directory"
|
||||||
A Term N "term"
|
A Term N "term"
|
||||||
A Terms N "terms"
|
A Terms N "terms"
|
||||||
|
A TermExpansion N "term_expansion"
|
||||||
A TextStream N "text_stream"
|
A TextStream N "text_stream"
|
||||||
A Threads N "threads"
|
A Threads N "threads"
|
||||||
A Throw N "throw"
|
A Throw N "throw"
|
||||||
@ -429,6 +430,7 @@ F StreamEOS EndOfStream 1
|
|||||||
F StreamPos StreamPos 4
|
F StreamPos StreamPos 4
|
||||||
F SyntaxError SyntaxError 7
|
F SyntaxError SyntaxError 7
|
||||||
F ShortSyntaxError SyntaxError 1
|
F ShortSyntaxError SyntaxError 1
|
||||||
|
F TermExpansion TermExpansion 2
|
||||||
F ThreadRun TopThreadGoal 2
|
F ThreadRun TopThreadGoal 2
|
||||||
F Throw Throw 1
|
F Throw Throw 1
|
||||||
F TimeoutError TimeoutError 2
|
F TimeoutError TimeoutError 2
|
||||||
|
@ -1034,9 +1034,10 @@ opinfo("unify_l_n_atoms_write",[]).
|
|||||||
opinfo("write_n_atoms",[body]).
|
opinfo("write_n_atoms",[body]).
|
||||||
opinfo("unify_struct",[]).
|
opinfo("unify_struct",[]).
|
||||||
opinfo("unify_struct_write",[]).
|
opinfo("unify_struct_write",[]).
|
||||||
opinfo("unify_l_struct",[]).
|
opinfo("unify_l_struc",[]).
|
||||||
opinfo("unify_l_struct_write",[]).
|
opinfo("unify_l_struc_write",[]).
|
||||||
opinfo("write_struct",[body]).
|
opinfo("write_struc",[body]).
|
||||||
|
opinfo("write_l_struc",[body]).
|
||||||
opinfo("unify_float",[]).
|
opinfo("unify_float",[]).
|
||||||
opinfo("unify_float_write",[]).
|
opinfo("unify_float_write",[]).
|
||||||
opinfo("unify_l_float",[]).
|
opinfo("unify_l_float",[]).
|
||||||
|
@ -4796,8 +4796,7 @@ struct PL_local_data *Yap_InitThreadIO(int wid)
|
|||||||
}
|
}
|
||||||
#if THREADS
|
#if THREADS
|
||||||
if (wid) {
|
if (wid) {
|
||||||
/* copy from other worker */
|
memcpy(p, Yap_local[0]->PL_local_data_p_, sizeof(struct PL_local_data));
|
||||||
memcpy(p, Yap_local[worker_id]->PL_local_data_p_, sizeof(struct PL_local_data));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return p;
|
return p;
|
||||||
|
@ -256,6 +256,8 @@ project_attributes(GVars, AVars) :-
|
|||||||
AVars = [_|_],
|
AVars = [_|_],
|
||||||
solver(Solver),
|
solver(Solver),
|
||||||
( GVars = [_|_] ; Solver = graphs), !,
|
( GVars = [_|_] ; Solver = graphs), !,
|
||||||
|
% we don't pass query variables in this way
|
||||||
|
b_setval(clpbn_query_variables, none),
|
||||||
clpbn_vars(AVars, DiffVars, AllVars),
|
clpbn_vars(AVars, DiffVars, AllVars),
|
||||||
get_clpbn_vars(GVars,CLPBNGVars0),
|
get_clpbn_vars(GVars,CLPBNGVars0),
|
||||||
simplify_query_vars(CLPBNGVars0, CLPBNGVars),
|
simplify_query_vars(CLPBNGVars0, CLPBNGVars),
|
||||||
|
@ -53,6 +53,8 @@
|
|||||||
:- use_module(library(lists),
|
:- use_module(library(lists),
|
||||||
[reverse/2]).
|
[reverse/2]).
|
||||||
|
|
||||||
|
:- use_module(library(maplist)).
|
||||||
|
|
||||||
:- use_module(library('clpbn/aggregates'),
|
:- use_module(library('clpbn/aggregates'),
|
||||||
[check_for_agg_vars/2]).
|
[check_for_agg_vars/2]).
|
||||||
|
|
||||||
@ -87,33 +89,29 @@
|
|||||||
jt([[]],_,_) :- !.
|
jt([[]],_,_) :- !.
|
||||||
jt(LLVs,Vs0,AllDiffs) :-
|
jt(LLVs,Vs0,AllDiffs) :-
|
||||||
init_jt_solver(LLVs, Vs0, AllDiffs, State),
|
init_jt_solver(LLVs, Vs0, AllDiffs, State),
|
||||||
run_jt_solver(LLVs, LLPs, State),
|
maplist(run_jt_solver, LLVs, LLPs, State),
|
||||||
clpbn_bind_vals(LLVs,LLPs,AllDiffs).
|
clpbn_bind_vals(LLVs,LLPs,AllDiffs).
|
||||||
|
|
||||||
|
|
||||||
init_jt_solver(LLVs, Vs0, _, State) :-
|
init_jt_solver(LLVs, Vs0, _, State) :-
|
||||||
check_for_agg_vars(Vs0, Vs1),
|
check_for_agg_vars(Vs0, Vs1),
|
||||||
init_influences(Vs1, G, RG),
|
init_influences(Vs1, G, RG),
|
||||||
init_jt_solver_for_questions(LLVs, G, RG, State).
|
maplist(init_jt_solver_for_question(G, RG), LLVs, State).
|
||||||
|
|
||||||
init_jt_solver_for_questions([], _, _, []).
|
init_jt_solver_for_question(G, RG, LLVs, state(JTree, Evidence)) :-
|
||||||
init_jt_solver_for_questions([LLVs|MoreLLVs], G, RG, [state(JTree, Evidence)|State]) :-
|
|
||||||
influences(LLVs, G, RG, NVs0),
|
influences(LLVs, G, RG, NVs0),
|
||||||
sort(NVs0, NVs),
|
sort(NVs0, NVs),
|
||||||
get_graph(NVs, BayesNet, CPTs, Evidence),
|
get_graph(NVs, BayesNet, CPTs, Evidence),
|
||||||
build_jt(BayesNet, CPTs, JTree),
|
build_jt(BayesNet, CPTs, JTree).
|
||||||
init_jt_solver_for_questions(MoreLLVs, G, RG, State).
|
|
||||||
|
|
||||||
run_jt_solver([], [], []).
|
run_jt_solver(LVs, LPs, state(JTree, Evidence)) :-
|
||||||
run_jt_solver([LVs|MoreLVs], [LPs|MorePs], [state(JTree, Evidence)|MoreState]) :-
|
|
||||||
% JTree is a dgraph
|
% JTree is a dgraph
|
||||||
% now our tree has cpts
|
% now our tree has cpts
|
||||||
fill_with_cpts(JTree, NewTree),
|
fill_with_cpts(JTree, NewTree),
|
||||||
% write_tree(NewTree,0),
|
% write_tree(0, NewTree),
|
||||||
propagate_evidence(Evidence, NewTree, EvTree),
|
propagate_evidence(Evidence, NewTree, EvTree),
|
||||||
message_passing(EvTree, MTree),
|
message_passing(EvTree, MTree),
|
||||||
get_margin(MTree, LVs, LPs),
|
get_margin(MTree, LVs, LPs).
|
||||||
run_jt_solver(MoreLVs, MorePs, MoreState).
|
|
||||||
|
|
||||||
get_graph(LVs, BayesNet, CPTs, Evidence) :-
|
get_graph(LVs, BayesNet, CPTs, Evidence) :-
|
||||||
run_vars(LVs, Edges, Vertices, CPTs, Evidence),
|
run_vars(LVs, Edges, Vertices, CPTs, Evidence),
|
||||||
@ -510,16 +508,16 @@ find_clique_from_kids([_|Kids], LVs, Clique, Dist) :-
|
|||||||
find_clique_from_kids(Kids, LVs, Clique, Dist).
|
find_clique_from_kids(Kids, LVs, Clique, Dist).
|
||||||
|
|
||||||
|
|
||||||
write_tree(tree(Clique-(Dist,_),Leaves), I0) :- !,
|
write_tree(I0, tree(Clique-(Dist,_),Leaves)) :- !,
|
||||||
matrix:matrix_to_list(Dist,L),
|
matrix:matrix_to_list(Dist,L),
|
||||||
format('~*c ~w:~w~n',[I0,0' ,Clique,L]),
|
format('~*c ~w:~w~n',[I0,0' ,Clique,L]),
|
||||||
I is I0+2,
|
I is I0+2,
|
||||||
write_subtree(Leaves, I).
|
maplist(write_tree(I), Leaves).
|
||||||
write_tree(tree(Clique-Dist,Leaves), I0) :-
|
write_tree(I0, tree(Clique-Dist,Leaves), I0) :-
|
||||||
matrix:matrix_to_list(Dist,L),
|
matrix:matrix_to_list(Dist,L),
|
||||||
format('~*c ~w:~w~n',[I0,0' ,Clique, L]),
|
format('~*c ~w:~w~n',[I0,0' ,Clique, L]),
|
||||||
I is I0+2,
|
I is I0+2,
|
||||||
write_subtree(Leaves, I).
|
maplist(write_tree(I), Leaves).
|
||||||
|
|
||||||
write_subtree([], _).
|
write_subtree([], _).
|
||||||
write_subtree([Tree|Leaves], I) :-
|
write_subtree([Tree|Leaves], I) :-
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
:- use_module(library(clpbn/learning/em)).
|
:- use_module(library(clpbn/learning/em)).
|
||||||
|
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,gibbs).
|
%:- set_pfl_flag(em_solver,gibbs).
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,jt).
|
%:- set_pfl_flag(em_solver,jt).
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,hve).
|
%:- set_pfl_flag(em_solver,hve).
|
||||||
:- clpbn:set_clpbn_flag(em_solver,bdd).
|
%:- set_pfl_flag(em_solver,bp).
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,bp).
|
%:- set_pfl_flag(em_solver,ve).
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,ve).
|
:- set_pfl_flag(em_solver,bdd).
|
||||||
|
|
||||||
data(t,t,t,t).
|
data(t,t,t,t).
|
||||||
data(_,t,_,t).
|
data(_,t,_,t).
|
||||||
@ -25,8 +25,6 @@ data(t,t,_,f).
|
|||||||
data(t,f,f,t).
|
data(t,f,f,t).
|
||||||
data(t,f,t,t).
|
data(t,f,t,t).
|
||||||
|
|
||||||
:- dynamic id/1.
|
|
||||||
|
|
||||||
timed_main :-
|
timed_main :-
|
||||||
statistics(runtime, _),
|
statistics(runtime, _),
|
||||||
main(Lik),
|
main(Lik),
|
||||||
|
@ -52,7 +52,7 @@ set_bdd_from_list(T0, VS, Manager, Cudd) :-
|
|||||||
numbervars(VS,0,_),
|
numbervars(VS,0,_),
|
||||||
generate_releases(T0, Manager, T),
|
generate_releases(T0, Manager, T),
|
||||||
% T0 = T,
|
% T0 = T,
|
||||||
% writeln_list(T),
|
% writeln_list(T0),
|
||||||
list_to_cudd(T,Manager,_Cudd0,Cudd).
|
list_to_cudd(T,Manager,_Cudd0,Cudd).
|
||||||
|
|
||||||
generate_releases(T0, Manager, T) :-
|
generate_releases(T0, Manager, T) :-
|
||||||
@ -82,31 +82,31 @@ writeln_list(B.Bindings) :-
|
|||||||
|
|
||||||
%list_to_cudd(H._List,_Manager,_Cudd0,_CuddF) :- writeln(l:H), fail.
|
%list_to_cudd(H._List,_Manager,_Cudd0,_CuddF) :- writeln(l:H), fail.
|
||||||
list_to_cudd([],_Manager,Cudd,Cudd) :- writeln('X').
|
list_to_cudd([],_Manager,Cudd,Cudd) :- writeln('X').
|
||||||
list_to_cudd(release_node(M,cudd(V)).T, Manager, Cudd0, CuddF) :- !,
|
list_to_cudd([release_node(M,cudd(V))|T], Manager, Cudd0, CuddF) :- !,
|
||||||
write('-'), flush_output,
|
write('-'), flush_output,
|
||||||
cudd_release_node(M,V),
|
cudd_release_node(M,V),
|
||||||
list_to_cudd(T, Manager, Cudd0, CuddF).
|
list_to_cudd(T, Manager, Cudd0, CuddF).
|
||||||
list_to_cudd((V=0*_Par).T, Manager, _Cudd0, CuddF) :- !,
|
list_to_cudd([(V=0*_Par)|T], Manager, _Cudd0, CuddF) :- !,
|
||||||
write('0'), flush_output,
|
write('0'), flush_output,
|
||||||
term_to_cudd(0, Manager, Cudd),
|
term_to_cudd(0, Manager, Cudd),
|
||||||
V = cudd(Cudd),
|
V = cudd(Cudd),
|
||||||
list_to_cudd(T, Manager, Cudd, CuddF).
|
list_to_cudd(T, Manager, Cudd, CuddF).
|
||||||
list_to_cudd((V=0).T, Manager, _Cudd0, CuddF) :- !,
|
list_to_cudd([(V=0)|T], Manager, _Cudd0, CuddF) :- !,
|
||||||
write('0'), flush_output,
|
write('0'), flush_output,
|
||||||
term_to_cudd(0, Manager, Cudd),
|
term_to_cudd(0, Manager, Cudd),
|
||||||
V = cudd(Cudd),
|
V = cudd(Cudd),
|
||||||
list_to_cudd(T, Manager, Cudd, CuddF).
|
list_to_cudd(T, Manager, Cudd, CuddF).
|
||||||
list_to_cudd((V=_Tree*0).T, Manager, _Cudd0, CuddF) :- !,
|
list_to_cudd([(V=_Tree*0)|T], Manager, _Cudd0, CuddF) :- !,
|
||||||
write('0'), flush_output,
|
write('0'), flush_output,
|
||||||
term_to_cudd(0, Manager, Cudd),
|
term_to_cudd(0, Manager, Cudd),
|
||||||
V = cudd(Cudd),
|
V = cudd(Cudd),
|
||||||
list_to_cudd(T, Manager, Cudd, CuddF).
|
list_to_cudd(T, Manager, Cudd, CuddF).
|
||||||
list_to_cudd((V=Tree*1).T, Manager, _Cudd0, CuddF) :- !,
|
list_to_cudd([(V=Tree*1)|T], Manager, _Cudd0, CuddF) :- !,
|
||||||
write('.'), flush_output,
|
write('.'), flush_output,
|
||||||
term_to_cudd(Tree, Manager, Cudd),
|
term_to_cudd(Tree, Manager, Cudd),
|
||||||
V = cudd(Cudd),
|
V = cudd(Cudd),
|
||||||
list_to_cudd(T, Manager, Cudd, CuddF).
|
list_to_cudd(T, Manager, Cudd, CuddF).
|
||||||
list_to_cudd((V=Tree).T, Manager, _Cudd0, CuddF) :-
|
list_to_cudd([(V=Tree)|T], Manager, _Cudd0, CuddF) :-
|
||||||
write('.'), flush_output,
|
write('.'), flush_output,
|
||||||
( ground(Tree) -> true ; throw(error(instantiation_error(Tree))) ),
|
( ground(Tree) -> true ; throw(error(instantiation_error(Tree))) ),
|
||||||
term_to_cudd(Tree, Manager, Cudd),
|
term_to_cudd(Tree, Manager, Cudd),
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 6dd05cb45b22cc38e3467d0264706f61381c8945
|
Subproject commit be76ebc1f9544a5ee96f9f94bebf58252b3a938c
|
@ -1 +1 @@
|
|||||||
Subproject commit 75108ca1f119a6fbae3907ce7666e07dc2dcf286
|
Subproject commit b813923455e5efb2b55770699b84411c6dd37952
|
@ -1 +1 @@
|
|||||||
Subproject commit 2a596b7cce313c2702f275a189c1ea6a67a20f84
|
Subproject commit fa667ecacf4128c10dc51215ff54f25672a782c8
|
106
packages/python/examples/mysql.pl
Normal file
106
packages/python/examples/mysql.pl
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
|
||||||
|
:- use_module(library(python)).
|
||||||
|
|
||||||
|
:- use_module(library(lists)).
|
||||||
|
|
||||||
|
:- python_import('MySQLdb').
|
||||||
|
|
||||||
|
:- initialization(main).
|
||||||
|
|
||||||
|
main :-
|
||||||
|
python_import(pyx),
|
||||||
|
ex(X),
|
||||||
|
flush_output,
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
|
ex(open) :-
|
||||||
|
connect,
|
||||||
|
% execute SQL query using execute() method.
|
||||||
|
:= $cursor:execute('SELECT VERSION()'),
|
||||||
|
% Fetch a single row using fetchone() method.
|
||||||
|
Data := cursor:fetchone(_),
|
||||||
|
Data = t(Version),
|
||||||
|
format( "Database version : ~a~n ", [ Version ]),
|
||||||
|
close.
|
||||||
|
|
||||||
|
ex(create) :-
|
||||||
|
connect,
|
||||||
|
% Drop table if it already exist using execute() method.
|
||||||
|
:= $cursor:execute('DROP TABLE IF EXISTS EMPLOYEE'),
|
||||||
|
% Create table as per requirement
|
||||||
|
sql := 'CREATE TABLE EMPLOYEE (
|
||||||
|
FIRST_NAME CHAR(20) NOT NULL,
|
||||||
|
LAST_NAME CHAR(20),
|
||||||
|
AGE INT,
|
||||||
|
SEX CHAR(1),
|
||||||
|
INCOME FLOAT ) DEFAULT charset=utf8',
|
||||||
|
:= $cursor:execute($sql),
|
||||||
|
close.
|
||||||
|
|
||||||
|
ex(insert) :-
|
||||||
|
connect,
|
||||||
|
% Prepare SQL query to INSERT a record into the database.
|
||||||
|
catch(add, _, rollback),
|
||||||
|
close.
|
||||||
|
|
||||||
|
add :-
|
||||||
|
customer(First, Last, Age, Sex, Income),
|
||||||
|
format(atom(Sql), 'INSERT INTO EMPLOYEE(FIRST_NAME,
|
||||||
|
LAST_NAME, AGE, SEX, INCOME)
|
||||||
|
VALUES (\'~a\', \'~a\', ~d, \'~a\', ~g)',
|
||||||
|
[ First, Last, Age, Sex, Income ]),
|
||||||
|
% Execute the SQL command
|
||||||
|
:= $cursor:execute(Sql),
|
||||||
|
fail.
|
||||||
|
add :-
|
||||||
|
% Commit your changes in the database
|
||||||
|
:= $db:commit(_).
|
||||||
|
|
||||||
|
rollback :-
|
||||||
|
:= db:rollback(_).
|
||||||
|
|
||||||
|
connect :-
|
||||||
|
db := connect('localhost','testuser','test123','TESTDB' ),
|
||||||
|
:= $db:set_character_set('utf8'),
|
||||||
|
% prepare a cursor object using cursor() method
|
||||||
|
cursor := db:cursor(_),
|
||||||
|
:= $cursor:execute('SET NAMES utf8;'),
|
||||||
|
:= $cursor:execute('SET CHARACTER SET utf8;'),
|
||||||
|
:= $cursor:execute('SET character_set_connection=utf8;').
|
||||||
|
|
||||||
|
close :-
|
||||||
|
% disconnect from server
|
||||||
|
:= db:close(_).
|
||||||
|
|
||||||
|
% Open database connection
|
||||||
|
ex(read) :-
|
||||||
|
connect,
|
||||||
|
% Prepare SQL query to SELECT a record from the database.
|
||||||
|
sql := 'SELECT * FROM EMPLOYEE \
|
||||||
|
WHERE INCOME > 1000',
|
||||||
|
catch(try, _, except),
|
||||||
|
close.
|
||||||
|
|
||||||
|
try:-
|
||||||
|
% Execute the SQL command
|
||||||
|
:= $cursor:execute($sql),
|
||||||
|
% Fetch all the rows in a list of lists.
|
||||||
|
Results := $cursor:fetchall(_),
|
||||||
|
Results =.. [_|LResults],
|
||||||
|
member(t(Fname, Lname, Age, Sex, Income), LResults),
|
||||||
|
% Now print fetched result
|
||||||
|
format("fname=~a, lname=~a, age=~d, sex=~a, income=~g~n",
|
||||||
|
[Fname, Lname, Age, Sex, Income ]),
|
||||||
|
fail.
|
||||||
|
try.
|
||||||
|
|
||||||
|
except:-
|
||||||
|
format('Error: unable to fecth data', []).
|
||||||
|
|
||||||
|
% disconnect from server
|
||||||
|
|
||||||
|
customer('João', 'Matos', 40, 'M', 2000).
|
||||||
|
customer('Maria', 'Söderling', 20, 'F', 3000).
|
||||||
|
customer('毛', '泽东', 44, 'M', 500).
|
||||||
|
customer('রবীন্দ্রনাথ', 'ঠাকুর', 30, 'M', 8000).
|
49
packages/python/examples/pyx.pl
Normal file
49
packages/python/examples/pyx.pl
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
:- use_module(library(python)).
|
||||||
|
|
||||||
|
:- initialization(main).
|
||||||
|
|
||||||
|
setup_dir :-
|
||||||
|
prolog_load_context(directory, Dir),
|
||||||
|
atom_concat(Dir,'pyx/',Base),
|
||||||
|
assert(base(Base)).
|
||||||
|
|
||||||
|
:- setup_dir.
|
||||||
|
|
||||||
|
main :-
|
||||||
|
python_import(pyx),
|
||||||
|
ex(X),
|
||||||
|
flush_output,
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
|
ex(hello) :-
|
||||||
|
c := canvas:canvas(_),
|
||||||
|
:= $c:text(0, 0, 'Hello, world!'),
|
||||||
|
:= $c:stroke(path:line(0, 0, 2, 0)),
|
||||||
|
:= $c:writePDFfile('hello').
|
||||||
|
|
||||||
|
ex(pathitem) :-
|
||||||
|
c := canvas:canvas(_),
|
||||||
|
rect1 := path:path(path:moveto(0, 0), path:lineto(1, 0),
|
||||||
|
path:moveto(1, 0), path:lineto(1, 1),
|
||||||
|
path:moveto(1, 1), path:lineto(0, 1),
|
||||||
|
path:moveto(0, 1), path:lineto(0, 0)),
|
||||||
|
rect2 := path:path(path:moveto(2, 0), path:lineto(3, 0),
|
||||||
|
path:lineto(3, 1), path:lineto(2, 1),
|
||||||
|
path:lineto(2, 0)),
|
||||||
|
rect3 := path:path(path:moveto(4, 0), path:lineto(5, 0),
|
||||||
|
path:lineto(5, 1), path:lineto(4, 1),
|
||||||
|
path:closepath(_)),
|
||||||
|
:= $c:stroke($rect1, [style:linewidth:'THICK']),
|
||||||
|
:= $c:stroke($rect2, [style:linewidth:'THICK']),
|
||||||
|
:= $c:stroke($rect3, [style:linewidth:'THICK']),
|
||||||
|
:= $c:writePDFfile('pathitem').
|
||||||
|
|
||||||
|
ex(changebar) :-
|
||||||
|
g := graph:graphxy(width=8, x=graph:axis:bar(_)),
|
||||||
|
base(Source), atomic_concat(Source, 'minimal.dat', Data),
|
||||||
|
:= $g:plot(graph:data:file(Data, xname=0, y=2), [graph:style:changebar(_)]),
|
||||||
|
:= $g:writePDFfile(changebar).
|
||||||
|
|
||||||
|
|
12
packages/python/examples/pyx/minimal.dat
Normal file
12
packages/python/examples/pyx/minimal.dat
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
January -5 1
|
||||||
|
Feburary -4 3
|
||||||
|
March 0 8
|
||||||
|
April 3 13
|
||||||
|
May 7 18
|
||||||
|
June 10 21
|
||||||
|
July 12 23
|
||||||
|
August 12 23
|
||||||
|
September 8 19
|
||||||
|
October 4 13
|
||||||
|
November 0 6
|
||||||
|
December -4 2
|
154
packages/python/examples/tut.pl
Normal file
154
packages/python/examples/tut.pl
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
|
||||||
|
:- use_module(library(python)).
|
||||||
|
|
||||||
|
:- initialization(main).
|
||||||
|
|
||||||
|
main :-
|
||||||
|
ex(X),
|
||||||
|
flush_output,
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
|
%
|
||||||
|
% strings are atoms in the interface
|
||||||
|
% with usual properties
|
||||||
|
%
|
||||||
|
% variables must be used with $
|
||||||
|
%
|
||||||
|
% UNICODE is supposed to work (does in Linux).
|
||||||
|
%
|
||||||
|
ex(currency) :-
|
||||||
|
(
|
||||||
|
currency := '€',
|
||||||
|
O := ord($currency),
|
||||||
|
X := $currency,
|
||||||
|
L := len($currency),
|
||||||
|
format('currency=~a ~d/~d~n',[X, O, L])
|
||||||
|
->
|
||||||
|
true
|
||||||
|
;
|
||||||
|
failed(currency)
|
||||||
|
).
|
||||||
|
|
||||||
|
ex(home) :-
|
||||||
|
(
|
||||||
|
filename := os:environ:get('HOME')
|
||||||
|
->
|
||||||
|
X := $filename,
|
||||||
|
format('HOME=~a~n',[X])
|
||||||
|
;
|
||||||
|
true
|
||||||
|
).
|
||||||
|
|
||||||
|
ex(site) :-
|
||||||
|
X := site:getusersitepackages(_),
|
||||||
|
format('site packages=~a~n',[X]).
|
||||||
|
|
||||||
|
ex(arith) :-
|
||||||
|
A := 2+2,
|
||||||
|
B := (50-5*6)/4,
|
||||||
|
C := 7/3,
|
||||||
|
width := 20,
|
||||||
|
height := 5*9,
|
||||||
|
D := $width* $height,
|
||||||
|
format('arith=~d ~d ~d ~d~n',[A,B,C,D]).
|
||||||
|
|
||||||
|
ex(undefined) :-
|
||||||
|
format('undefined variable~n', []),
|
||||||
|
X := $n,
|
||||||
|
format('undefined=~d',[X]).
|
||||||
|
|
||||||
|
ex(fp) :-
|
||||||
|
X := 3 * 3.75 / 1.5,
|
||||||
|
Y := 7.0 / 2,
|
||||||
|
format('fp=~f ~f~n',[X,Y]).
|
||||||
|
|
||||||
|
ex(complex) :-
|
||||||
|
A := complex(0,1) * complex(0,1),
|
||||||
|
B := complex(3,1)*3,
|
||||||
|
a := complex(1.5,0.5),
|
||||||
|
R := $a:real,
|
||||||
|
I := $a:imag,
|
||||||
|
format('complex=~w ~w ~w+~wj~n',[A,B,R,I]).
|
||||||
|
|
||||||
|
ex(floatint) :-
|
||||||
|
A := float(22000),
|
||||||
|
B := int(3.1),
|
||||||
|
C := long(15000000.5),
|
||||||
|
format('cast=~w ~w ~w~n',[A,B,C]).
|
||||||
|
|
||||||
|
ex(strings) :-
|
||||||
|
S1 := 'spam eggs',
|
||||||
|
S2 := 'doesn\'t',
|
||||||
|
S3 := '"Yes," he said.',
|
||||||
|
S4 := '"Isn\'t," she said.',
|
||||||
|
format('s=~a ~a ~a ~a~n',[S1,S2,S3,S4]),
|
||||||
|
hello := 'This is a rather long string containing\n\
|
||||||
|
several lines of text just as you would do in C.\n\
|
||||||
|
Note that whitespace at the beginning of the line is\
|
||||||
|
significant.',
|
||||||
|
python_command('print hello'),
|
||||||
|
X := $hello,
|
||||||
|
format('s=~a~n',[X]).
|
||||||
|
|
||||||
|
ex(strings2) :-
|
||||||
|
word := 'Help' + 'A',
|
||||||
|
X := '<' + $word*5 + '>',
|
||||||
|
Y := (str:strip) + ing,
|
||||||
|
A1 := $word^[4],
|
||||||
|
A2 := $word^[0:2],
|
||||||
|
A3 := $word^[2:4],
|
||||||
|
format('concat=~a ~a ~a ~a ~a~n',[X,Y,A1,A2,A3]).
|
||||||
|
|
||||||
|
ex(slices) :-
|
||||||
|
s := 'supercalifragilisticexpialidocious',
|
||||||
|
L := len($s),
|
||||||
|
S1 := $s^[1:6],
|
||||||
|
S2 := $s^[-6: -1],
|
||||||
|
S3 := $s^[_:6],
|
||||||
|
S4 := $s^[-6:_],
|
||||||
|
format('slices=~d ~a ~a ~a ~a~n',[L,S1,S2,S3,S4]).
|
||||||
|
|
||||||
|
|
||||||
|
ex(lists) :-
|
||||||
|
a := [66.25, 333, 333, 1, 1234.5],
|
||||||
|
A1 := $a:count(333), A2 := $a:count(66.25), A3 := $a:count(x),
|
||||||
|
format('counts=~d ~d ~d~n',[A1,A2,A3]),
|
||||||
|
:= $a:insert(2, -1),
|
||||||
|
:= $a:append(333),
|
||||||
|
A := $a,
|
||||||
|
format('a=~w~n', [A]),
|
||||||
|
I := $a:index(333),
|
||||||
|
:= $a:remove(333),
|
||||||
|
B := $a,
|
||||||
|
format('a=~w~n', [B]),
|
||||||
|
:= $a:reverse(_),
|
||||||
|
C := $a,
|
||||||
|
format('a=~w~n', [C]),
|
||||||
|
:= $a:sort(_),
|
||||||
|
D := $a,
|
||||||
|
format('a=~w~n', [D]).
|
||||||
|
|
||||||
|
ex(iter) :-
|
||||||
|
it := iter(abc),
|
||||||
|
format('iter= ', []),
|
||||||
|
iterate(iter).
|
||||||
|
|
||||||
|
iterate(iter) :-
|
||||||
|
repeat,
|
||||||
|
( X1 := $it:next,
|
||||||
|
format('i ~a~n', [X1])
|
||||||
|
->
|
||||||
|
fail
|
||||||
|
;
|
||||||
|
!
|
||||||
|
).
|
||||||
|
|
||||||
|
ex(range) :-
|
||||||
|
r1 := range(1000),
|
||||||
|
r2 := range(1000,2000),
|
||||||
|
r3 := range(2000,10000,1),
|
||||||
|
S := sum($r1+ $r2+ $r3),
|
||||||
|
format('range=~d~n', [S]).
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -59,8 +59,7 @@ Data types are
|
|||||||
:- use_module(library(lists)).
|
:- use_module(library(lists)).
|
||||||
:- use_module(library(apply_macros)).
|
:- use_module(library(apply_macros)).
|
||||||
:- use_module(library(charsio)).
|
:- use_module(library(charsio)).
|
||||||
|
:- dynamic python_mref_cache/2, python_obj_cache/2.
|
||||||
:- dynamic python_mref_cache/2.
|
|
||||||
|
|
||||||
:= F :- python(F,_).
|
:= F :- python(F,_).
|
||||||
|
|
||||||
@ -91,67 +90,110 @@ module_extend(M0, M:E, MF, EF, MRef0, MRef) :-
|
|||||||
module_extend(MM, E, MF, EF, MRef1, MRef).
|
module_extend(MM, E, MF, EF, MRef1, MRef).
|
||||||
module_extend(M, E, M, E, MRef, MRef).
|
module_extend(M, E, M, E, MRef, MRef).
|
||||||
|
|
||||||
% given an object, detect its len method
|
object_prefix('__obj__'(_)).
|
||||||
python_eval_term(Expression, O) :-
|
object_prefix('$'(_)).
|
||||||
fetch_module(Expression, Module, Exp, MRef), !,
|
object_prefix('__obj__'(_):_).
|
||||||
(
|
object_prefix('$'(_):_).
|
||||||
atom(Exp)
|
|
||||||
->
|
% from an exp take an object, and its corresponding Prolog representation
|
||||||
python_access(MRef, Exp, O)
|
descend_exp(V, _Obj, _F, _S) :-
|
||||||
|
var(V), !,
|
||||||
|
throw(error(instantiation_error,_)).
|
||||||
|
descend_exp(Exp, Obj, F, S) :-
|
||||||
|
object_prefix(Exp),
|
||||||
|
!,
|
||||||
|
python_field(Exp, Obj, F, S).
|
||||||
|
descend_exp(Exp, Obj, F, S) :-
|
||||||
|
python_mref_cache(_, MObj),
|
||||||
|
python_field(MObj:Exp, Obj, F, S), !.
|
||||||
|
descend_exp(Mod:Exp, Obj, F, S) :-
|
||||||
|
atom(Mod),
|
||||||
|
python_import(Mod, MObj),
|
||||||
|
python_field(MObj:Exp, Obj, F, S), !.
|
||||||
|
|
||||||
|
python_class(Obj) :-
|
||||||
|
python_obj_cache(inspect:isclass(_), F),
|
||||||
|
python_apply(F, isclass(Obj), {}, true).
|
||||||
|
|
||||||
|
process_obj(Obj, _, S, Obj, NS, Dict) :-
|
||||||
|
python_callable(Obj), !,
|
||||||
|
python_check_args(S, NS, Dict).
|
||||||
|
process_obj(Obj, _, S, Obj, NS, Dict) :-
|
||||||
|
python_class(Obj),
|
||||||
|
descend_object(Obj:'__init__', FObj, _, _),
|
||||||
|
python_check_args(S, NS, Dict).
|
||||||
|
|
||||||
|
python_eval_term(Obj, Obj) :-
|
||||||
|
var(Obj), !.
|
||||||
|
python_eval_term('__obj__'(Obj), '__obj__'(Obj)) :- !.
|
||||||
|
python_eval_term($Name, Obj) :- !,
|
||||||
|
python_is($Name, Obj).
|
||||||
|
python_eval_term([H|T], [NH|NT]) :- !,
|
||||||
|
python_eval_term(H, NH),
|
||||||
|
python_eval_term(T, NT).
|
||||||
|
python_eval_term(N, N) :- atomic(N), !.
|
||||||
|
python_eval_term(Exp, O) :-
|
||||||
|
descend_exp(Exp, Obj, Old, S), !,
|
||||||
|
(functor(S, _, 0) ->
|
||||||
|
O = Obj
|
||||||
;
|
;
|
||||||
functor(Exp, F, _),
|
python_check_args(S, NS, Dict),
|
||||||
python_f(MRef, F, FRef),
|
python_apply(Obj, NS, Dict, O)
|
||||||
python_check_args(FRef, Exp, NExp),
|
|
||||||
python_apply(FRef, NExp, O)
|
|
||||||
).
|
).
|
||||||
python_eval_term(Obj:Field, O) :-
|
python_eval_term(S, O) :-
|
||||||
python_access(Obj, Field, O).
|
python_check_args(S, NS, {}),
|
||||||
|
python_is(NS, O).
|
||||||
|
|
||||||
|
python_check_args(Exp, t, {}) :-
|
||||||
python_check_args(FRef, Exp, NExp) :-
|
Exp =.. [_,V], var(V), !.
|
||||||
|
python_check_args(Exp, NExp, Dict) :-
|
||||||
functor(Exp, _, Arity),
|
functor(Exp, _, Arity),
|
||||||
arg(Arity, Exp, _=_), !,
|
arg(Arity, Exp, A), nonvar(A), A = (_=_), !,
|
||||||
fetch_args(FRef, Dict),
|
Exp =.. [_F|LArgs],
|
||||||
Exp =.. [F|LArgs],
|
match_args(LArgs, NLArgs, Dict),
|
||||||
match_args(LArgs, Dict, NLArgs, _),
|
NExp =.. [t|NLArgs].
|
||||||
NExp =.. [F|NLArgs].
|
python_check_args(Exp, NExp, {}) :-
|
||||||
python_check_args(FRef, Exp, NExp).
|
Exp =.. [F|L],
|
||||||
|
maplist(python_eval_term, L, LF),
|
||||||
|
NExp =.. [F|LF].
|
||||||
|
|
||||||
fetch_args(FRef, Args) :-
|
% in case it is __init__ from __new__
|
||||||
python_import('inspect', M),
|
splice_class(Ref, Ref, ArgNames, ArgNames) :- !.
|
||||||
python_f(M, getargspec, F),
|
splice_class(_FRef, _Ref, [_|ArgNames], ArgNames).
|
||||||
python_apply(F, getargspec(FRef), ExtraArgs),
|
|
||||||
ExtraArgs=t(Args, _, _, _).
|
match_args([], [], {}).
|
||||||
|
match_args([V=A|LArgs], [], Dict) :- !,
|
||||||
|
match_named_args([V=A|LArgs], Map),
|
||||||
|
map_to_dict(Map, Dict).
|
||||||
|
match_args([A|LArgs], [VA|NLArgs], Dict) :-
|
||||||
|
python_eval_term(A, VA),
|
||||||
|
match_args(LArgs, NLArgs, Dict).
|
||||||
|
|
||||||
|
match_named_args([], []).
|
||||||
|
match_named_args([K=A|LArgs], [K=VA|Map]) :-
|
||||||
|
python_eval_term(A, VA),
|
||||||
|
match_named_args(LArgs, Map).
|
||||||
|
|
||||||
|
|
||||||
match_args([], _, [], ok).
|
map_to_dict([X=V], {X:V}) :- !.
|
||||||
match_args([A=V|LArgs], Dict, [I=V|NLArgs], OK) :-
|
map_to_dict([X=V|Map], {X:V,NDict}) :-
|
||||||
match_args(LArgs, Dict, NLArgs, ok), !,
|
map_to_dict(Map, {NDict}).
|
||||||
( nth0(I, Dict, A) -> true ; throw(type_error(argument(A=V))) ).
|
|
||||||
match_args([A|LArgs], Dict, [A|NLArgs], not_ok) :-
|
match_from_anames([K|_ArgNames], K, VA, [_|Defaults], [VA|Defaults]) :- !.
|
||||||
match_args(LArgs, Dict, NLArgs, _).
|
match_from_anames([_|ArgNames], K, VA, [V|Defaults], [V|NDefaults]) :-
|
||||||
|
match_from_anames(ArgNames, K, VA, Defaults, NDefaults).
|
||||||
|
|
||||||
|
fetch_args(FRef, Args, Kwd, Defaults) :-
|
||||||
|
FRef = '__obj__'(_), !,
|
||||||
|
python_mref_cache('inspect', M),
|
||||||
|
python_obj_cache(inspect:getargspec(_), F),
|
||||||
|
python_apply(F, getargspec(FRef), {}, ExtraArgs),
|
||||||
|
ExtraArgs=t(Args, _, Kwd, Defaults).
|
||||||
|
fetch_args(_, []).
|
||||||
|
|
||||||
|
|
||||||
python(Obj, Out) :-
|
python(Obj, Out) :-
|
||||||
python_eval_term(Obj, Out), !.
|
python_eval_term(Obj, Out).
|
||||||
python(Obj, OArg) :-
|
|
||||||
python_do_is(Obj, Obj1),
|
|
||||||
python_is(Obj1, OArg).
|
|
||||||
|
|
||||||
python_do_is(A+B, NA+NB) :- !,
|
|
||||||
python_do_is(A, NA),
|
|
||||||
python_do_is(B, NB).
|
|
||||||
python_do_is(A-B, NA-NB) :- !,
|
|
||||||
python_do_is(A, NA),
|
|
||||||
python_do_is(B, NB).
|
|
||||||
python_do_is(A*B, NA*NB) :- !,
|
|
||||||
python_do_is(A, NA),
|
|
||||||
python_do_is(B, NB).
|
|
||||||
python_do_is(A/B, NA/NB) :- !,
|
|
||||||
python_do_is(A, NA),
|
|
||||||
python_do_is(B, NB).
|
|
||||||
python_do_is(A, NA) :-
|
|
||||||
python_eval_term(A, NA), !.
|
|
||||||
python_do_is(A, A).
|
|
||||||
|
|
||||||
python_command(Cmd) :-
|
python_command(Cmd) :-
|
||||||
python_run_command(Cmd).
|
python_run_command(Cmd).
|
||||||
@ -159,8 +201,16 @@ python_command(Cmd) :-
|
|||||||
start_python :-
|
start_python :-
|
||||||
use_foreign_library(foreign(python)),
|
use_foreign_library(foreign(python)),
|
||||||
init_python,
|
init_python,
|
||||||
|
python_main_module(MRef),
|
||||||
|
assert(python_mref_cache('__main__', MRef)),
|
||||||
python_command('import sys'),
|
python_command('import sys'),
|
||||||
python_command('import inspect').
|
python_import('inspect'),
|
||||||
|
python_mref_cache(inspect, InspRef),
|
||||||
|
python_field(InspRef:isclass(_), IsClass, _, _),
|
||||||
|
assert(python_obj_cache(inspect:isclass(_), IsClass)),
|
||||||
|
python_field(InspRef:getargspec(_), GetArgSpec, _, _),
|
||||||
|
assert(python_obj_cache(inspect:getargspec(_), GetArgSpec)),
|
||||||
|
at_halt(end_python).
|
||||||
|
|
||||||
add_cwd_to_python :-
|
add_cwd_to_python :-
|
||||||
unix(getcwd(Dir)),
|
unix(getcwd(Dir)),
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 6575e08bd063e0d0476a1bdbfe216684b4d5e6e4
|
Subproject commit 29a8436d86886cf932a790a013cfcf10240c68c8
|
@ -270,7 +270,7 @@ call_residue(Goal,Module,Residue) :-
|
|||||||
|
|
||||||
delayed_goals(G, Vs, NVs, Gs) :-
|
delayed_goals(G, Vs, NVs, Gs) :-
|
||||||
project_delayed_goals(G),
|
project_delayed_goals(G),
|
||||||
copy_term(G.Vs, _.NVs, Gs).
|
copy_term([G|Vs], [_|NVs], Gs).
|
||||||
|
|
||||||
project_delayed_goals(G) :-
|
project_delayed_goals(G) :-
|
||||||
% SICStus compatible step,
|
% SICStus compatible step,
|
||||||
|
118
pl/boot.yap
118
pl/boot.yap
@ -92,7 +92,6 @@ true :- true.
|
|||||||
'$init_or_threads',
|
'$init_or_threads',
|
||||||
'$run_at_thread_start'.
|
'$run_at_thread_start'.
|
||||||
|
|
||||||
|
|
||||||
'$init_globals' :-
|
'$init_globals' :-
|
||||||
'$init_consult',
|
'$init_consult',
|
||||||
nb_setval('$chr_toplevel_show_store',false),
|
nb_setval('$chr_toplevel_show_store',false),
|
||||||
@ -218,7 +217,7 @@ true :- true.
|
|||||||
get_value('$top_level_goal',GA), GA \= [], !,
|
get_value('$top_level_goal',GA), GA \= [], !,
|
||||||
set_value('$top_level_goal',[]),
|
set_value('$top_level_goal',[]),
|
||||||
'$run_atom_goal'(GA),
|
'$run_atom_goal'(GA),
|
||||||
set_value('$live','$false').
|
halt(0).
|
||||||
'$enter_top_level' :-
|
'$enter_top_level' :-
|
||||||
'$disable_docreep',
|
'$disable_docreep',
|
||||||
'$run_toplevel_hooks',
|
'$run_toplevel_hooks',
|
||||||
@ -229,8 +228,7 @@ true :- true.
|
|||||||
nb_setval('$debug_run',off),
|
nb_setval('$debug_run',off),
|
||||||
nb_setval('$debug_jump',off),
|
nb_setval('$debug_jump',off),
|
||||||
'$command'(Command,Varnames,_Pos,top),
|
'$command'(Command,Varnames,_Pos,top),
|
||||||
'$sync_mmapped_arrays',
|
halt(0).
|
||||||
set_value('$live','$false').
|
|
||||||
|
|
||||||
|
|
||||||
'$erase_sets' :-
|
'$erase_sets' :-
|
||||||
@ -436,7 +434,7 @@ true :- true.
|
|||||||
->
|
->
|
||||||
'$assertz_dynamic'(L,G,G0,Mod)
|
'$assertz_dynamic'(L,G,G0,Mod)
|
||||||
;
|
;
|
||||||
catch(nb_getval('$assert_all',on),_,fail)
|
'$nb_getval'('$assert_all',on,fail)
|
||||||
->
|
->
|
||||||
functor(H,N,A),
|
functor(H,N,A),
|
||||||
'$dynamic'(N/A,Mod),
|
'$dynamic'(N/A,Mod),
|
||||||
@ -573,7 +571,7 @@ true :- true.
|
|||||||
flush_output,
|
flush_output,
|
||||||
fail.
|
fail.
|
||||||
'$present_answer'((?-), Answ) :-
|
'$present_answer'((?-), Answ) :-
|
||||||
nb_getval('$break',BL),
|
'$nb_getval'('$break',BL,fail),
|
||||||
( BL \= 0 -> format(user_error, '[~p] ',[BL]) ;
|
( BL \= 0 -> format(user_error, '[~p] ',[BL]) ;
|
||||||
true ),
|
true ),
|
||||||
( recorded('$print_options','$toplevel'(Opts),_) ->
|
( recorded('$print_options','$toplevel'(Opts),_) ->
|
||||||
@ -732,9 +730,8 @@ true :- true.
|
|||||||
'$name_vars_in_goals1'(GVL, 0, _).
|
'$name_vars_in_goals1'(GVL, 0, _).
|
||||||
|
|
||||||
'$name_well_known_vars'([]).
|
'$name_well_known_vars'([]).
|
||||||
'$name_well_known_vars'([[SName|V]|NVL0]) :-
|
'$name_well_known_vars'([Name=V|NVL0]) :-
|
||||||
var(V), !,
|
var(V), !,
|
||||||
atom_codes(Name, SName),
|
|
||||||
V = '$VAR'(Name),
|
V = '$VAR'(Name),
|
||||||
'$name_well_known_vars'(NVL0).
|
'$name_well_known_vars'(NVL0).
|
||||||
'$name_well_known_vars'([_|NVL0]) :-
|
'$name_well_known_vars'([_|NVL0]) :-
|
||||||
@ -903,7 +900,7 @@ not(G) :- \+ '$execute'(G).
|
|||||||
'$call'(G, CP, G0, CurMod) :-
|
'$call'(G, CP, G0, CurMod) :-
|
||||||
( '$is_expand_goal_or_meta_predicate'(G,CurMod) ->
|
( '$is_expand_goal_or_meta_predicate'(G,CurMod) ->
|
||||||
(
|
(
|
||||||
'$notrace'(('$pred_exists'(goal_expansion(G,NG), CurMod), CurMod:goal_expansion(G,NG) ; system:goal_expansion(G,NG) ; user:goal_expansion(G, CurMod, NG) ; user:goal_expansion(G,NG) )) ->
|
'$do_goal_expansion'(G, CurMod, NG) ->
|
||||||
'$call'(NG, CP, G0,CurMod)
|
'$call'(NG, CP, G0,CurMod)
|
||||||
;
|
;
|
||||||
% repeat other code.
|
% repeat other code.
|
||||||
@ -997,39 +994,6 @@ not(G) :- \+ '$execute'(G).
|
|||||||
throw(Ball).
|
throw(Ball).
|
||||||
|
|
||||||
|
|
||||||
/* This is the break predicate,
|
|
||||||
it saves the importante data about current streams and
|
|
||||||
debugger state */
|
|
||||||
|
|
||||||
break :-
|
|
||||||
nb_getval('$system_mode',SystemMode),
|
|
||||||
nb_getval('$trace',Trace),
|
|
||||||
nb_setval('$trace',off),
|
|
||||||
nb_getval('$debug_jump',Jump),
|
|
||||||
nb_getval('$debug_run',Run),
|
|
||||||
'$debug_on'(Debug),
|
|
||||||
'$debug_on'(false),
|
|
||||||
nb_getval('$break',BL), NBL is BL+1,
|
|
||||||
nb_getval('$spy_gn',SPY_GN),
|
|
||||||
b_getval('$spy_glist',GList),
|
|
||||||
b_setval('$spy_glist',[]),
|
|
||||||
nb_setval('$break',NBL),
|
|
||||||
current_output(OutStream), current_input(InpStream),
|
|
||||||
format(user_error, '% Break (level ~w)~n', [NBL]),
|
|
||||||
'$do_live',
|
|
||||||
!,
|
|
||||||
set_value('$live','$true'),
|
|
||||||
b_setval('$spy_glist',GList),
|
|
||||||
nb_setval('$spy_gn',SPY_GN),
|
|
||||||
set_input(InpStream),
|
|
||||||
set_output(OutStream),
|
|
||||||
'$debug_on'(Debug),
|
|
||||||
nb_setval('$debug_jump',Jump),
|
|
||||||
nb_setval('$debug_run',Run),
|
|
||||||
nb_setval('$trace',Trace),
|
|
||||||
nb_setval('$break',BL),
|
|
||||||
nb_setval('$system_mode',SystemMode).
|
|
||||||
|
|
||||||
'$silent_bootstrap'(F) :-
|
'$silent_bootstrap'(F) :-
|
||||||
'$init_globals',
|
'$init_globals',
|
||||||
nb_setval('$if_level',0),
|
nb_setval('$if_level',0),
|
||||||
@ -1153,18 +1117,12 @@ bootstrap(F) :-
|
|||||||
|
|
||||||
|
|
||||||
expand_term(Term,Expanded) :-
|
expand_term(Term,Expanded) :-
|
||||||
'$current_module'(Mod),
|
( '$do_term_expansion'(Term,Expanded)
|
||||||
( \+ '$undefined'(term_expansion(_,_), Mod),
|
->
|
||||||
'$notrace'(Mod:term_expansion(Term,Expanded))
|
true
|
||||||
; \+ '$undefined'(term_expansion(_,_), system),
|
|
||||||
'$notrace'(system:term_expansion(Term,Expanded))
|
|
||||||
; Mod \= user, \+ '$undefined'(term_expansion(_,_), user),
|
|
||||||
'$notrace'(user:term_expansion(Term,Expanded))
|
|
||||||
;
|
;
|
||||||
'$expand_term_grammar'(Term,Expanded)
|
'$expand_term_grammar'(Term,Expanded)
|
||||||
),
|
).
|
||||||
!.
|
|
||||||
|
|
||||||
|
|
||||||
%
|
%
|
||||||
% Grammar Rules expansion
|
% Grammar Rules expansion
|
||||||
@ -1173,15 +1131,6 @@ expand_term(Term,Expanded) :-
|
|||||||
'$translate_rule'((A-->B),C), !.
|
'$translate_rule'((A-->B),C), !.
|
||||||
'$expand_term_grammar'(A, A).
|
'$expand_term_grammar'(A, A).
|
||||||
|
|
||||||
%
|
|
||||||
% Arithmetic expansion
|
|
||||||
%
|
|
||||||
'$expand_term_arith'(G1, G2) :-
|
|
||||||
get_value('$c_arith',true),
|
|
||||||
'$c_arith'(G1, G2), !.
|
|
||||||
'$expand_term_arith'(G,G).
|
|
||||||
|
|
||||||
|
|
||||||
%
|
%
|
||||||
% Arithmetic expansion
|
% Arithmetic expansion
|
||||||
%
|
%
|
||||||
@ -1261,8 +1210,9 @@ catch_ball(Ball, V) :-
|
|||||||
catch_ball(C, C).
|
catch_ball(C, C).
|
||||||
|
|
||||||
'$run_toplevel_hooks' :-
|
'$run_toplevel_hooks' :-
|
||||||
nb_getval('$break',0),
|
'$nb_getval'('$break', 0, fail),
|
||||||
recorded('$toplevel_hooks',H,_), !,
|
recorded('$toplevel_hooks',H,_),
|
||||||
|
H \= fail, !,
|
||||||
( '$oncenotrace'(H) -> true ; true).
|
( '$oncenotrace'(H) -> true ; true).
|
||||||
'$run_toplevel_hooks'.
|
'$run_toplevel_hooks'.
|
||||||
|
|
||||||
@ -1271,7 +1221,7 @@ catch_ball(C, C).
|
|||||||
|
|
||||||
'$exit_system_mode' :-
|
'$exit_system_mode' :-
|
||||||
nb_setval('$system_mode',off),
|
nb_setval('$system_mode',off),
|
||||||
( catch(nb_getval('$trace',on),_,fail) -> '$creep' ; true).
|
( '$nb_getval'('$trace',on,fail) -> '$creep' ; true).
|
||||||
|
|
||||||
%
|
%
|
||||||
% just prevent creeping from going on...
|
% just prevent creeping from going on...
|
||||||
@ -1301,20 +1251,6 @@ catch_ball(C, C).
|
|||||||
'$notrace'(G) :-
|
'$notrace'(G) :-
|
||||||
'$execute'(G).
|
'$execute'(G).
|
||||||
|
|
||||||
'$oncenotrace'(G) :-
|
|
||||||
'$disable_creep', !,
|
|
||||||
(
|
|
||||||
'$execute'(G)
|
|
||||||
->
|
|
||||||
'$creep'
|
|
||||||
;
|
|
||||||
'$creep',
|
|
||||||
fail
|
|
||||||
).
|
|
||||||
'$oncenotrace'(G) :-
|
|
||||||
'$execute'(G), !.
|
|
||||||
|
|
||||||
|
|
||||||
'$run_at_thread_start' :-
|
'$run_at_thread_start' :-
|
||||||
recorded('$thread_initialization',M:D,_),
|
recorded('$thread_initialization',M:D,_),
|
||||||
'$notrace'(M:D),
|
'$notrace'(M:D),
|
||||||
@ -1322,31 +1258,5 @@ catch_ball(C, C).
|
|||||||
'$run_at_thread_start'.
|
'$run_at_thread_start'.
|
||||||
|
|
||||||
|
|
||||||
nb_getval(GlobalVariable, Val) :-
|
|
||||||
'$nb_getval'(GlobalVariable, Val, Error),
|
|
||||||
(var(Error)
|
|
||||||
->
|
|
||||||
true
|
|
||||||
;
|
|
||||||
'$getval_exception'(GlobalVariable, Val, nb_getval(GlobalVariable, Val)) ->
|
|
||||||
nb_getval(GlobalVariable, Val)
|
|
||||||
;
|
|
||||||
'$do_error'(existence_error(variable, GlobalVariable),nb_getval(GlobalVariable, Val))
|
|
||||||
).
|
|
||||||
|
|
||||||
|
|
||||||
b_getval(GlobalVariable, Val) :-
|
|
||||||
'$nb_getval'(GlobalVariable, Val, Error),
|
|
||||||
(var(Error)
|
|
||||||
->
|
|
||||||
true
|
|
||||||
;
|
|
||||||
'$getval_exception'(GlobalVariable, Val, b_getval(GlobalVariable, Val)) ->
|
|
||||||
true
|
|
||||||
;
|
|
||||||
'$do_error'(existence_error(variable, GlobalVariable),b_getval(GlobalVariable, Val))
|
|
||||||
).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -290,26 +290,26 @@ use_module(M,F,Is) :-
|
|||||||
!.
|
!.
|
||||||
|
|
||||||
'$reset_if'(OldIfLevel) :-
|
'$reset_if'(OldIfLevel) :-
|
||||||
catch(nb_getval('$if_level',OldIfLevel),_,fail), !,
|
'$nb_getval'('$if_level', OldIfLevel, fail), !,
|
||||||
nb_setval('$if_level',0).
|
nb_setval('$if_level',0).
|
||||||
'$reset_if'(0) :-
|
'$reset_if'(0) :-
|
||||||
nb_setval('$if_level',0).
|
nb_setval('$if_level',0).
|
||||||
|
|
||||||
'$get_if'(Level0) :-
|
'$get_if'(Level0) :-
|
||||||
catch(nb_getval('$if_level',Level),_,fail), !,
|
'$nb_getval'('$if_level', Level, fail), !,
|
||||||
Level0 = Level.
|
Level0 = Level.
|
||||||
'$get_if'(0).
|
'$get_if'(0).
|
||||||
|
|
||||||
'$into_system_mode'(OldMode) :-
|
'$into_system_mode'(OldMode) :-
|
||||||
( catch(nb_getval('$system_mode', OldMode),_,fail) -> true ; OldMode = off),
|
( '$nb_getval'('$system_mode', OldMode, fail) -> true ; OldMode = off),
|
||||||
( OldMode == off -> '$enter_system_mode' ; true ).
|
( OldMode == off -> '$enter_system_mode' ; true ).
|
||||||
|
|
||||||
'$ensure_consulting_file'(OldF, Stream) :-
|
'$ensure_consulting_file'(OldF, Stream) :-
|
||||||
( catch(nb_getval('$consulting_file',OldF), _, fail) -> true ; OldF = []),
|
( '$nb_getval'('$consulting_file',OldF, fail) -> true ; OldF = []),
|
||||||
'$set_consulting_file'(Stream).
|
'$set_consulting_file'(Stream).
|
||||||
|
|
||||||
'$ensure_consulting'(Old, New) :-
|
'$ensure_consulting'(Old, New) :-
|
||||||
( catch(nb_getval('$consulting',Old), _, fail) -> true ; Old = false ),
|
( '$nb_getval'('$consulting',Old, fail) -> true ; Old = false ),
|
||||||
nb_setval('$consulting', New).
|
nb_setval('$consulting', New).
|
||||||
|
|
||||||
'$bind_module'(_, load_files).
|
'$bind_module'(_, load_files).
|
||||||
@ -409,12 +409,12 @@ initialization(G,OPT) :-
|
|||||||
'$exec_initialisation_goals' :-
|
'$exec_initialisation_goals' :-
|
||||||
'$show_consult_level'(Level),
|
'$show_consult_level'(Level),
|
||||||
'$current_module'(M),
|
'$current_module'(M),
|
||||||
findall(
|
recorded('$initialisation',do(Level,_),_),
|
||||||
G,
|
findall(G,
|
||||||
(recorded('$initialisation',do(Level,G),R), erase(R), G\='$'),
|
'$fetch_init_goal'(Level, G),
|
||||||
LGs),
|
LGs),
|
||||||
lists:member(G,LGs),
|
lists:member(G,LGs),
|
||||||
nb_getval('$system_mode', OldMode),
|
'$nb_getval'('$system_mode', OldMode, fail),
|
||||||
( OldMode == on -> '$exit_system_mode' ; true ),
|
( OldMode == on -> '$exit_system_mode' ; true ),
|
||||||
% run initialization under user control (so allow debugging this stuff).
|
% run initialization under user control (so allow debugging this stuff).
|
||||||
(
|
(
|
||||||
@ -428,6 +428,12 @@ initialization(G,OPT) :-
|
|||||||
'$exec_initialisation_goals' :-
|
'$exec_initialisation_goals' :-
|
||||||
nb_setval('$initialization_goals',off).
|
nb_setval('$initialization_goals',off).
|
||||||
|
|
||||||
|
|
||||||
|
'$fetch_init_goal'(Level, G) :-
|
||||||
|
recorded('$initialisation',do(Level,G),R),
|
||||||
|
erase(R),
|
||||||
|
G\='$'.
|
||||||
|
|
||||||
'$include'(V, _) :- var(V), !,
|
'$include'(V, _) :- var(V), !,
|
||||||
'$do_error'(instantiation_error,include(V)).
|
'$do_error'(instantiation_error,include(V)).
|
||||||
'$include'([], _) :- !.
|
'$include'([], _) :- !.
|
||||||
@ -437,7 +443,7 @@ initialization(G,OPT) :-
|
|||||||
'$include'(X, Status) :-
|
'$include'(X, Status) :-
|
||||||
get_value('$lf_verbose',Verbosity),
|
get_value('$lf_verbose',Verbosity),
|
||||||
'$full_filename'(X,Y,include(X)),
|
'$full_filename'(X,Y,include(X)),
|
||||||
( catch( nb_getval('$included_file',OY), _, fail ) -> true ; OY = [] ),
|
( '$nb_getval'('$included_file', OY, fail ) -> true ; OY = [] ),
|
||||||
nb_setval('$included_file', Y),
|
nb_setval('$included_file', Y),
|
||||||
'$current_module'(Mod),
|
'$current_module'(Mod),
|
||||||
H0 is heapused, '$cputime'(T0,_),
|
H0 is heapused, '$cputime'(T0,_),
|
||||||
@ -489,13 +495,13 @@ source_file(Mod:Pred, FileName) :-
|
|||||||
'$owner_file'(T, Mod, FileName).
|
'$owner_file'(T, Mod, FileName).
|
||||||
|
|
||||||
prolog_load_context(_, _) :-
|
prolog_load_context(_, _) :-
|
||||||
nb_getval('$consulting_file',[]), !, fail.
|
'$nb_getval'('$consulting_file', [], fail), !, fail.
|
||||||
prolog_load_context(directory, DirName) :-
|
prolog_load_context(directory, DirName) :-
|
||||||
getcwd(DirName).
|
getcwd(DirName).
|
||||||
prolog_load_context(file, FileName) :-
|
prolog_load_context(file, FileName) :-
|
||||||
( catch( nb_getval('$included_file',IncFileName), _, fail ) -> true ; IncFileName = [] ),
|
( '$nb_getval'('$included_file', IncFileName, fail ) -> true ; IncFileName = [] ),
|
||||||
( IncFileName = [] ->
|
( IncFileName = [] ->
|
||||||
nb_getval('$consulting_file',FileName),
|
'$nb_getval'('$consulting_file', FileName, fail),
|
||||||
FileName \= []
|
FileName \= []
|
||||||
;
|
;
|
||||||
FileName = IncFileName
|
FileName = IncFileName
|
||||||
@ -649,8 +655,10 @@ absolute_file_name(File0,File) :-
|
|||||||
'$full_filename'(F0,F,G) :-
|
'$full_filename'(F0,F,G) :-
|
||||||
'$absolute_file_name'(F0,[access(read),file_type(source),file_errors(fail),solutions(first),expand(true)],F,G).
|
'$absolute_file_name'(F0,[access(read),file_type(source),file_errors(fail),solutions(first),expand(true)],F,G).
|
||||||
|
|
||||||
|
% fix wrong argument order, TrueFileName should be last.
|
||||||
absolute_file_name(File,TrueFileName,Opts) :-
|
absolute_file_name(File,TrueFileName,Opts) :-
|
||||||
( var(TrueFileName) ; atom(TrueFileName) ), !,
|
( var(TrueFileName) -> true ; atom(TrueFileName), TrueFileName \= [] ),
|
||||||
|
!,
|
||||||
absolute_file_name(File,Opts,TrueFileName).
|
absolute_file_name(File,Opts,TrueFileName).
|
||||||
absolute_file_name(File,Opts,TrueFileName) :-
|
absolute_file_name(File,Opts,TrueFileName) :-
|
||||||
'$absolute_file_name'(File,Opts,TrueFileName,absolute_file_name(File,Opts,TrueFileName)).
|
'$absolute_file_name'(File,Opts,TrueFileName,absolute_file_name(File,Opts,TrueFileName)).
|
||||||
@ -1006,7 +1014,7 @@ absolute_file_name(File,Opts,TrueFileName) :-
|
|||||||
'$set_yap_flags'(11,0).
|
'$set_yap_flags'(11,0).
|
||||||
|
|
||||||
'$fetch_comp_status'(assert_all) :-
|
'$fetch_comp_status'(assert_all) :-
|
||||||
catch(nb_getval('$assert_all',on), _, fail), !.
|
'$nb_getval'('$assert_all',on, fail), !.
|
||||||
'$fetch_comp_status'(source) :-
|
'$fetch_comp_status'(source) :-
|
||||||
'$access_yap_flags'(11,1).
|
'$access_yap_flags'(11,1).
|
||||||
'$fetch_comp_status'(compact).
|
'$fetch_comp_status'(compact).
|
||||||
@ -1049,7 +1057,7 @@ make_library_index(_Directory).
|
|||||||
).
|
).
|
||||||
|
|
||||||
'$current_loop_stream'(Stream) :-
|
'$current_loop_stream'(Stream) :-
|
||||||
catch(nb_getval('$loop_stream',Stream), _, fail).
|
'$nb_getval'('$loop_stream',Stream, fail).
|
||||||
|
|
||||||
exists_source(File) :-
|
exists_source(File) :-
|
||||||
'$full_filename'(File, AbsFile, exists_source(File)).
|
'$full_filename'(File, AbsFile, exists_source(File)).
|
||||||
|
106
pl/control.yap
106
pl/control.yap
@ -145,7 +145,7 @@ setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup) :-
|
|||||||
'$clean_call'(_, _).
|
'$clean_call'(_, _).
|
||||||
|
|
||||||
'$cc_check_throw' :-
|
'$cc_check_throw' :-
|
||||||
nb_getval('$catch',Ball),
|
'$nb_getval'('$catch', Ball, fail),
|
||||||
throw(Ball).
|
throw(Ball).
|
||||||
|
|
||||||
%%% The unknown predicate,
|
%%% The unknown predicate,
|
||||||
@ -289,11 +289,115 @@ version(T) :-
|
|||||||
fail.
|
fail.
|
||||||
'$set_toplevel_hook'(_).
|
'$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)
|
||||||
|
->
|
||||||
|
true
|
||||||
|
;
|
||||||
|
'$getval_exception'(GlobalVariable, Val, nb_getval(GlobalVariable, Val)) ->
|
||||||
|
nb_getval(GlobalVariable, Val)
|
||||||
|
;
|
||||||
|
'$do_error'(existence_error(variable, GlobalVariable),nb_getval(GlobalVariable, Val))
|
||||||
|
).
|
||||||
|
|
||||||
|
|
||||||
|
b_getval(GlobalVariable, Val) :-
|
||||||
|
'$nb_getval'(GlobalVariable, Val, Error),
|
||||||
|
(var(Error)
|
||||||
|
->
|
||||||
|
true
|
||||||
|
;
|
||||||
|
'$getval_exception'(GlobalVariable, Val, b_getval(GlobalVariable, Val)) ->
|
||||||
|
true
|
||||||
|
;
|
||||||
|
'$do_error'(existence_error(variable, GlobalVariable),b_getval(GlobalVariable, Val))
|
||||||
|
).
|
||||||
|
|
||||||
|
|
||||||
|
/* This is the break predicate,
|
||||||
|
it saves the importante data about current streams and
|
||||||
|
debugger state */
|
||||||
|
|
||||||
|
break :-
|
||||||
|
nb_getval('$system_mode',SystemMode),
|
||||||
|
nb_getval('$trace',Trace),
|
||||||
|
nb_setval('$trace',off),
|
||||||
|
nb_getval('$debug_jump',Jump),
|
||||||
|
nb_getval('$debug_run',Run),
|
||||||
|
'$debug_on'(Debug),
|
||||||
|
'$debug_on'(false),
|
||||||
|
nb_getval('$break',BL), NBL is BL+1,
|
||||||
|
nb_getval('$spy_gn',SPY_GN),
|
||||||
|
b_getval('$spy_glist',GList),
|
||||||
|
b_setval('$spy_glist',[]),
|
||||||
|
nb_setval('$break',NBL),
|
||||||
|
current_output(OutStream), current_input(InpStream),
|
||||||
|
format(user_error, '% Break (level ~w)~n', [NBL]),
|
||||||
|
'$do_live',
|
||||||
|
!,
|
||||||
|
set_value('$live','$true'),
|
||||||
|
b_setval('$spy_glist',GList),
|
||||||
|
nb_setval('$spy_gn',SPY_GN),
|
||||||
|
set_input(InpStream),
|
||||||
|
set_output(OutStream),
|
||||||
|
'$debug_on'(Debug),
|
||||||
|
nb_setval('$debug_jump',Jump),
|
||||||
|
nb_setval('$debug_run',Run),
|
||||||
|
nb_setval('$trace',Trace),
|
||||||
|
nb_setval('$break',BL),
|
||||||
|
nb_setval('$system_mode',SystemMode).
|
||||||
|
|
||||||
|
|
||||||
|
at_halt(G) :-
|
||||||
|
recorda('$halt', G, _),
|
||||||
|
fail.
|
||||||
|
at_halt(_).
|
||||||
|
|
||||||
halt :-
|
halt :-
|
||||||
print_message(informational, halt),
|
print_message(informational, halt),
|
||||||
|
fail.
|
||||||
|
halt :-
|
||||||
'$halt'(0).
|
'$halt'(0).
|
||||||
|
|
||||||
|
halt(_) :-
|
||||||
|
recorded('$halt', G, _),
|
||||||
|
call(G),
|
||||||
|
fail.
|
||||||
halt(X) :-
|
halt(X) :-
|
||||||
|
'$sync_mmapped_arrays',
|
||||||
|
set_value('$live','$false'),
|
||||||
'$halt'(X).
|
'$halt'(X).
|
||||||
|
|
||||||
prolog_current_frame(Env) :-
|
prolog_current_frame(Env) :-
|
||||||
|
@ -248,7 +248,7 @@ print_message(Severity, Term) :-
|
|||||||
% first step at hook processing
|
% first step at hook processing
|
||||||
'$message_to_lines'(Term, Lines),
|
'$message_to_lines'(Term, Lines),
|
||||||
( nonvar(Term),
|
( nonvar(Term),
|
||||||
'$oncenotrace'(user:message_hook(Term, Severity, Lines))
|
'$once0'(message_hook(Term, Severity, Lines), user)
|
||||||
->
|
->
|
||||||
true
|
true
|
||||||
;
|
;
|
||||||
@ -263,9 +263,9 @@ print_message(_, Term) :-
|
|||||||
format(user_error,'~q~n',[Term]).
|
format(user_error,'~q~n',[Term]).
|
||||||
|
|
||||||
'$message_to_lines'(Term, Lines) :-
|
'$message_to_lines'(Term, Lines) :-
|
||||||
'$oncenotrace'(user:generate_message_hook(Term, [], Lines)), !.
|
'$once0'(generate_message_hook(Term, [], Lines), user), !.
|
||||||
'$message_to_lines'(Term, Lines) :-
|
'$message_to_lines'(Term, Lines) :-
|
||||||
'$oncenotrace'(prolog:message(Term, Lines, [])), !.
|
'$once0'(message(Term, Lines, []), prolog), !.
|
||||||
'$message_to_lines'(Term, Lines) :-
|
'$message_to_lines'(Term, Lines) :-
|
||||||
'$messages':generate_message(Term, Lines, []), !.
|
'$messages':generate_message(Term, Lines, []), !.
|
||||||
|
|
||||||
|
13
pl/flags.yap
13
pl/flags.yap
@ -118,6 +118,18 @@ yap_flag(agc_margin,Margin) :-
|
|||||||
%
|
%
|
||||||
% SWI compatibility flag
|
% SWI compatibility flag
|
||||||
%
|
%
|
||||||
|
yap_flag(debug_on_error,X) :-
|
||||||
|
var(X), !,
|
||||||
|
X = false.
|
||||||
|
yap_flag(debug_on_error,true) :- !,
|
||||||
|
X = true,
|
||||||
|
'$do_error'(domain_error(flag_value,debug_on_error+X),yap_flag(debug_on_error,X)).
|
||||||
|
yap_flag(debug_on_error,false) :- !.
|
||||||
|
yap_flag(debug_on_error,X) :-
|
||||||
|
'$do_error'(domain_error(flag_value,debug_on_error+X),yap_flag(debug_on_error,X)).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
yap_flag(generate_debug_info,X) :-
|
yap_flag(generate_debug_info,X) :-
|
||||||
var(X), !,
|
var(X), !,
|
||||||
'$access_yap_flags'(18,Options),
|
'$access_yap_flags'(18,Options),
|
||||||
@ -830,6 +842,7 @@ yap_flag(dialect,yap).
|
|||||||
'$yap_system_flag'(character_escapes).
|
'$yap_system_flag'(character_escapes).
|
||||||
'$yap_system_flag'(chr_toplevel_show_store).
|
'$yap_system_flag'(chr_toplevel_show_store).
|
||||||
'$yap_system_flag'(debug).
|
'$yap_system_flag'(debug).
|
||||||
|
'$yap_system_flag'(debug_on_error ).
|
||||||
'$yap_system_flag'(debugger_print_options).
|
'$yap_system_flag'(debugger_print_options).
|
||||||
'$yap_system_flag'(dialect).
|
'$yap_system_flag'(dialect).
|
||||||
'$yap_system_flag'(discontiguous_warnings).
|
'$yap_system_flag'(discontiguous_warnings).
|
||||||
|
@ -35,7 +35,7 @@ listing(V) :-
|
|||||||
|
|
||||||
'$listing'(V,Mod,Stream) :- var(V), !,
|
'$listing'(V,Mod,Stream) :- var(V), !,
|
||||||
'$current_predicate_no_modules'(Mod,_,Pred),
|
'$current_predicate_no_modules'(Mod,_,Pred),
|
||||||
'$list_clauses'(Stream,Mod,Pred).
|
( '$list_clauses'(Stream,Mod,Pred) ; true ).
|
||||||
'$listing'(M:V,_,Stream) :- !,
|
'$listing'(M:V,_,Stream) :- !,
|
||||||
'$listing'(V,M,Stream).
|
'$listing'(V,M,Stream).
|
||||||
'$listing'([],_,_) :- !.
|
'$listing'([],_,_) :- !.
|
||||||
|
@ -396,11 +396,7 @@ expand_goal(G, G).
|
|||||||
% make built-in processing transparent.
|
% make built-in processing transparent.
|
||||||
'$match_mod'(G, M, ORIG, HM, G1),
|
'$match_mod'(G, M, ORIG, HM, G1),
|
||||||
'$c_built_in'(G1, M, Gi),
|
'$c_built_in'(G1, M, Gi),
|
||||||
(Gi \== G1 ->
|
G1 = G2.
|
||||||
'$module_expansion'(Gi, G2, _, M, CM, HM, HVars)
|
|
||||||
;
|
|
||||||
G2 = G1
|
|
||||||
).
|
|
||||||
'$complete_goal_expansion'(G, GMod, _, HM, NG, NG, _) :-
|
'$complete_goal_expansion'(G, GMod, _, HM, NG, NG, _) :-
|
||||||
'$match_mod'(G, GMod, GMod, HM, NG).
|
'$match_mod'(G, GMod, GMod, HM, NG).
|
||||||
|
|
||||||
@ -586,6 +582,7 @@ source_module(Mod) :-
|
|||||||
assertz(:),
|
assertz(:),
|
||||||
assertz(:,+),
|
assertz(:,+),
|
||||||
assertz_static(:),
|
assertz_static(:),
|
||||||
|
at_halt(0),
|
||||||
bagof(?,0,-),
|
bagof(?,0,-),
|
||||||
bb_get(:,-),
|
bb_get(:,-),
|
||||||
bb_put(:,+),
|
bb_put(:,+),
|
||||||
@ -650,6 +647,7 @@ source_module(Mod) :-
|
|||||||
setup_call_cleanup(0,0,0),
|
setup_call_cleanup(0,0,0),
|
||||||
setup_call_catcher_cleanup(0,0,?,0),
|
setup_call_catcher_cleanup(0,0,?,0),
|
||||||
spy(:),
|
spy(:),
|
||||||
|
stash_predicate(:),
|
||||||
unknown(+,:),
|
unknown(+,:),
|
||||||
use_module(:),
|
use_module(:),
|
||||||
use_module(:,?),
|
use_module(:,?),
|
||||||
|
17
pl/preds.yap
17
pl/preds.yap
@ -791,6 +791,23 @@ dynamic_predicate(P,Sem) :-
|
|||||||
'$flags'(T,Mod,F,F),
|
'$flags'(T,Mod,F,F),
|
||||||
F\/0x00400000 =\= 0.
|
F\/0x00400000 =\= 0.
|
||||||
|
|
||||||
|
stash_predicate(V) :- var(V), !,
|
||||||
|
'$do_error'(instantiation_error,stash_predicate(V)).
|
||||||
|
stash_predicate(M:P) :- !,
|
||||||
|
'$stash_predicate2'(P, M).
|
||||||
|
stash_predicate(P) :-
|
||||||
|
'$current_module'(M),
|
||||||
|
'$stash_predicate2'(P, M).
|
||||||
|
|
||||||
|
'$stash_predicate2'(V, M) :- var(V), !,
|
||||||
|
'$do_error'(instantiation_error,stash_predicate(M:V)).
|
||||||
|
'$stash_predicate2'(N/A, M) :- !,
|
||||||
|
functor(S,N,A),
|
||||||
|
'$stash_predicate'(S, M) .
|
||||||
|
'$stash_predicate2'(PredDesc, M) :-
|
||||||
|
'$do_error'(type_error(predicate_indicator,PredDesc),stash_predicate(M:PredDesc)).
|
||||||
|
|
||||||
|
|
||||||
hide_predicate(V) :- var(V), !,
|
hide_predicate(V) :- var(V), !,
|
||||||
'$do_error'(instantiation_error,hide_predicate(V)).
|
'$do_error'(instantiation_error,hide_predicate(V)).
|
||||||
hide_predicate(M:P) :- !,
|
hide_predicate(M:P) :- !,
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
'$do_signal'(sig_creep, [M|G]) :-
|
'$do_signal'(sig_creep, [M|G]) :-
|
||||||
'$creep_allowed', !,
|
'$creep_allowed', !,
|
||||||
(
|
(
|
||||||
( G = '$notrace'(G0) ; G = '$oncenotrace'(G0) ; G = '$execute0'(G0,M) ; '$system_module'(M), G = G0 )
|
( G = '$notrace'(G0) ; G = '$oncenotrace'(G0) ; G = '$once0'(G0) ; G = '$execute0'(G0,M) ; '$system_module'(M), G = G0 )
|
||||||
->
|
->
|
||||||
(
|
(
|
||||||
'$execute_nonstop'(G0,M),
|
'$execute_nonstop'(G0,M),
|
||||||
@ -50,7 +50,7 @@
|
|||||||
).
|
).
|
||||||
%
|
%
|
||||||
'$do_signal'(sig_creep, [M|G]) :-
|
'$do_signal'(sig_creep, [M|G]) :-
|
||||||
( G = '$notrace'(G0) ; G = '$oncenotrace'(G0) ; G = '$execute0'(G0,M) ; '$system_module'(M), G = G0 ),
|
( G = '$notrace'(G0) ; G = '$oncenotrace'(G0) ; G = '$once0'(G0) ; G = '$execute0'(G0,M) ; '$system_module'(M), G = G0 ),
|
||||||
!,
|
!,
|
||||||
(
|
(
|
||||||
'$execute_nonstop'(G0,M),
|
'$execute_nonstop'(G0,M),
|
||||||
@ -168,6 +168,18 @@
|
|||||||
'$creep',
|
'$creep',
|
||||||
fail
|
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.
|
% do not debug if we are not in debug mode.
|
||||||
'$start_creep'([Mod|G]) :-
|
'$start_creep'([Mod|G]) :-
|
||||||
'$debug_on'(DBON), DBON = false, !,
|
'$debug_on'(DBON), DBON = false, !,
|
||||||
|
Reference in New Issue
Block a user