reset excess change

This commit is contained in:
Vitor Santos Costa 2019-04-24 12:10:06 +01:00
parent a87654b0b0
commit b97338f84d
17 changed files with 337 additions and 385 deletions

1
.gitignore vendored
View File

@ -215,4 +215,3 @@ cmake/docs/Doxyfile
*.stackdump
*.gz
.Rproj.user

View File

@ -916,26 +916,24 @@ static int interrupt_dexecute(USES_REGS1) {
static void undef_goal(USES_REGS1) {
PredEntry *pe = PredFromDefCode(P);
/* avoid trouble with undefined dynamic procedures */
/* I assume they were not locked beforehand */
#if defined(YAPOR) || defined(THREADS)
BEGD(d0);
/* avoid trouble with undefined dynamic procedures */
/* I assume they were not locked beforehand */
#if defined(YAPOR) || defined(THREADS)
if (!PP) {
PELOCK(19, pe);
PP = pe;
}
#endif
BACKUP_MACHINE_REGS();
if (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MultiFileFlag) ) {
if (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MultiFileFlag) ) {
#if defined(YAPOR) || defined(THREADS)
UNLOCKPE(19, PP);
PP = NULL;
#endif
CalculateStackGap(PASS_REGS1);
P = FAILCODE;
RECOVER_MACHINE_REGS();
return;
}
#if DEBUG
if (UndefCode == NULL || UndefCode->OpcodeOfPred == UNDEF_OPCODE) {
fprintf(stderr,"call to undefined Predicates %s ->", IndicatorOfPred(pe));
Yap_DebugPlWriteln(ARG1);
@ -948,28 +946,16 @@ if (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MultiFileFlag) ) {
#endif
CalculateStackGap(PASS_REGS1);
P = FAILCODE;
RECOVER_MACHINE_REGS();
return;
}
#endif
#if defined(YAPOR) || defined(THREADS)
UNLOCKPE(19, PP);
PP = NULL;
#endif
CELL o = AbsPair(HR);
if (pe->ModuleOfPred == PROLOG_MODULE) {
if (CurrentModule == PROLOG_MODULE)
HR[0] = TermProlog;
else
HR[0] = CurrentModule;
} else {
HR[0] = Yap_Module_Name(pe);
}
HR += 2;
#endif
if (pe->ArityOfPE == 0) {
HR[-1] = MkAtomTerm((Atom)(pe->FunctorOfPred));
d0 = MkAtomTerm((Atom)(pe->FunctorOfPred));
} else {
HR[-1] = AbsAppl(HR);
d0 = AbsAppl(HR);
*HR++ = (CELL)pe->FunctorOfPred;
CELL *ip=HR;
UInt imax = pe->ArityOfPE;
@ -998,20 +984,30 @@ if (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MultiFileFlag) ) {
ENDD(d1);
}
}
ARG1 = o;
ARG2 = MkVarTerm();
ARG1 = AbsPair(HR);
HR[1] = d0;
ENDD(d0);
if (pe->ModuleOfPred == PROLOG_MODULE) {
if (CurrentModule == PROLOG_MODULE)
HR[0] = TermProlog;
else
HR[0] = CurrentModule;
} else {
HR[0] = Yap_Module_Name(pe);
}
ARG2 = Yap_getUnknownModule(Yap_GetModuleEntry(HR[0]));
HR += 2;
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace)
low_level_trace(enter_pred, UndefCode, XREGS + 1);
#endif /* LOW_LEVEL_TRACE */
P = UndefCode->CodeOfPred;
RECOVER_MACHINE_REGS();
}
static void spy_goal(USES_REGS1) {
PredEntry *pe = PredFromDefCode(P);
BACKUP_MACHINE_REGS();
#if defined(YAPOR) || defined(THREADS)
if (!PP) {
PELOCK(14, pe);
@ -1031,7 +1027,6 @@ static void spy_goal(USES_REGS1) {
PP = NULL;
}
#endif
RECOVER_MACHINE_REGS();
return;
}
}
@ -1049,7 +1044,6 @@ static void spy_goal(USES_REGS1) {
}
#endif
Yap_NilError(CALL_COUNTER_UNDERFLOW_EVENT, "");
RECOVER_MACHINE_REGS();
return;
}
LOCAL_PredEntriesCounter--;
@ -1061,7 +1055,6 @@ static void spy_goal(USES_REGS1) {
}
#endif
Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, "");
RECOVER_MACHINE_REGS();
return;
}
if ((pe->PredFlags & (CountPredFlag | ProfiledPredFlag | SpiedPredFlag)) ==
@ -1073,7 +1066,6 @@ static void spy_goal(USES_REGS1) {
}
#endif
P = pe->cs.p_code.TrueCodeOfPred;
RECOVER_MACHINE_REGS();
return;
}
}
@ -1092,7 +1084,6 @@ static void spy_goal(USES_REGS1) {
PP = NULL;
}
#endif
RECOVER_MACHINE_REGS();
return;
}
}
@ -1162,7 +1153,6 @@ static void spy_goal(USES_REGS1) {
low_level_trace(enter_pred, pt0, XREGS + 1);
#endif /* LOW_LEVEL_TRACE */
}
RECOVER_MACHINE_REGS();
}
Int Yap_absmi(int inp) {
@ -1323,10 +1313,11 @@ Int Yap_absmi(int inp) {
#endif /* USE_THREADED_CODE */
#if PUSH_REGS
old_regs = Yap_regp;
old_regs = &Yap_REGS;
/* done, let us now initialize this space */
init_absmi_regs(&absmi_regs);
/* the registers are all set up, let's swap */
#ifdef THREADS
pthread_setspecific(Yap_yaamregs_key, (const void *)&absmi_regs);

View File

@ -9,8 +9,8 @@
#endif /* INDENT_CODE */
BOp(Ystop, l);
//LOCAL_CBorder = 0;
//SET_ASP(YREG, E_CB * sizeof(CELL));
LOCAL_CBorder = 0;
SET_ASP(YREG, E_CB * sizeof(CELL));
/* make sure ASP is initialized */
saveregs();
@ -20,13 +20,12 @@
#if BP_FREE
P1REG = PCBACKUP;
#endif
//LOCAL_CBorder = 0;
LOCAL_CBorder = 0;
return 1;
ENDBOp();
BOp(Nstop, e);
//B= B->cp_b;
//SET_ASP(YREG, E_CB * sizeof(CELL));
SET_ASP(YREG, E_CB * sizeof(CELL));
saveregs();
#if PUSH_REGS
restore_absmi_regs(old_regs);

View File

@ -421,25 +421,8 @@ X_API void *YAP_BlobOfTerm(Term t) {
if (IsVarTerm(t))
return NULL;
if (!IsBigIntTerm(t)) {
if (IsAtomTerm(t)) {
AtomEntry *ae = RepAtom(AtomOfTerm(t));
StaticArrayEntry *pp;
READ_LOCK(ae->ARWLock);
pp = RepStaticArrayProp(ae->PropsOfAE);
while (!EndOfPAEntr(pp) && pp->KindOfPE != ArrayProperty)
pp = RepStaticArrayProp(pp->NextOfPE);
if (EndOfPAEntr(pp) || pp->ValueOfVE.ints == NULL) {
READ_UNLOCK(ae->ARWLock);
return NULL;
} else {
READ_UNLOCK(ae->ARWLock);
return pp->ValueOfVE.ints;
}
}
if (!IsBigIntTerm(t))
return NULL;
}
src = (MP_INT *)(RepAppl(t) + 2);
return (void *)(src + 1);
}
@ -994,10 +977,6 @@ static Int execute_cargs(PredEntry *pe, CPredicate exec_code USES_REGS) {
"YAP only supports SWI C-call with arity =< 10");
return false;
}
arity_t i;
for (i = 0; i < pe->ArityOfPE; i++) {
XREGS[i+1] = Yap_GetFromSlot(a1+i);
}
Yap_RecoverSlots(pe->ArityOfPE, a1);
return rc;
}
@ -1759,35 +1738,35 @@ static int run_emulator(USES_REGS1) {
X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
CACHE_REGS
PredEntry *pe = ape;
bool out;
fprintf(stderr,"EnterGoal: H=%ld ENV=%ld B=%ld TR=%ld P=%p CP=%p, Slots=%ld\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
LOCAL_CurSlot);
bool out;
// fprintf(stderr,"EnterGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
BACKUP_MACHINE_REGS();
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
LOCAL_PrologMode = UserMode;
dgi->p = P;
dgi->cp = CP;
dgi->b_top = LCL0 - (CELL *)B;
dgi->e = LCL0-ENV;
dgi->b0 = LCL0 - (CELL *)B;
dgi->CurSlot = LOCAL_CurSlot;
// ensure our current ENV receives current P.
Yap_PrepGoal(pe->ArityOfPE, nullptr, dgi PASS_REGS);
Yap_PrepGoal(pe->ArityOfPE, nullptr, B PASS_REGS);
P = pe->CodeOfPred;
// __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %ld %x %x args=%x,%x
// slot=%ld", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
// __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %d %x %x args=%x,%x
// slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
// LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B;
dgi->h = HR - H0;
dgi->tr = (CELL *)TR - LCL0;
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P11= (LCL0 - (CELL*)B);
out = Yap_exec_absmi(true, false);
// fprintf(stderr,"EnterGoal success=%ld: H=%ld ENV=%p B=%ld TR=%ld P=%p CP=%p
// Slots=%ld\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
dgi->b_bottom = (LCL0 - (CELL*)B);
dgi->e = LCL0 - (CELL *)ENV;
dgi->y = LCL0 - (CELL *)YENV;
// fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
out = Yap_exec_absmi(true, false);
// fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B;
if (out) {
dgi->EndSlot = LOCAL_CurSlot;
Yap_StartSlots();
@ -1805,8 +1784,8 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
bool out;
BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b_top);
myB0 = (choiceptr)(LCL0 - dgi->b_bottom);
myB = (choiceptr)(LCL0 - dgi->b);
myB0 = (choiceptr)(LCL0 - dgi->b0);
CP = myB->cp_cp;
/* sanity check */
if (B >= myB0) {
@ -1816,15 +1795,16 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
// get rid of garbage choice-points
B = myB;
}
// fprintf(stderr,"RetryGoal: H=%ld ENV=%p B=%ld TR=%ld P=%p CP=%p Slots=%ld\n",
// fprintf(stderr,"RetryGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
P = FAILCODE;
/* make sure we didn't leave live slots when we backtrack */
ASP = (CELL *)B;
LOCAL_CurSlot = dgi->EndSlot;
out = Yap_exec_absmi(true, true );
if (out) {
dgi->EndSlot = LOCAL_CurSlot;
dgi->b_bottom = LCL0-CellPtr(myB);
dgi->b = LCL0 - (CELL *)B;
} else {
LOCAL_CurSlot =
dgi->CurSlot; // ignore any slots created within the called goal
@ -1837,12 +1817,12 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
CACHE_REGS
choiceptr myB, handler;
// fprintf(stderr,"LeaveGoal success=%ld: H=%d ENV=%p B=%ldd myB=%ldd TR=%ld
// P=%p CP=%p Slots=%ld\n",
// fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d
// P=%p CP=%p Slots=%d\n",
// successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b_bottom);
myB = (choiceptr)(LCL0 - dgi->b);
if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
@ -1868,39 +1848,25 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
}
P = dgi->p;
CP = dgi->cp;
ENV = LCL0-dgi->e;
YENV = LCL0-dgi->y;
/* ASP should be set to the top of the local stack when we
did the call */
SET_ASP(YENV, E_CB * sizeof(CELL));
B = (choiceptr)(LCL0-dgi->b_top)
RECOVER_MACHINE_REGS();
fprintf(stderr,"LeftGoal success=%d: H=%ld ENV=%ld B=%ld TR=%ld P=%p CP=%p, Slots=%ld\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P,
CP, LOCAL_CurSlot);
// fprintf(stderr,"LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P,
// CP, LOCAL_CurSlot);
return TRUE;
}
X_API Int YAP_RunGoal(Term t) {
CACHE_REGS
Term out;
YAP_dogoalinfo gi;
gi.p = P;
gi.cp = CP;
gi.b_top = LCL0-CellPtr(B);
gi.CurSlot = Yap_CurrentHandle();
gi.y = LCL0-YENV;
gi.e = LCL0-ENV;
yhandle_t cslot = LOCAL_CurSlot;
yhandle_t cslot = LOCAL_CurSlot;
BACKUP_MACHINE_REGS();
LOCAL_AllowRestart = FALSE;
LOCAL_PrologMode = UserMode;
out = Yap_RunTopGoal(t, &gi, true);
out = Yap_RunTopGoal(t, true);
LOCAL_PrologMode = UserCCallMode;
// should we catch the exception or pass it through?
// We'll pass it through
SET_ASP(YENV, E_CB * sizeof(CELL));
RECOVER_MACHINE_REGS();
LOCAL_CurSlot = cslot;
return out;
@ -1976,17 +1942,17 @@ X_API CELL *YAP_HeapStoreOpaqueTerm(Term t) {
X_API Int YAP_RunGoalOnce(Term t) {
CACHE_REGS
Term out;
YAP_dogoalinfo gi;
Int oldPrologMode = LOCAL_PrologMode;
yamop *old_CP = CP;
Int oldPrologMode = LOCAL_PrologMode;
yhandle_t CSlot;
BACKUP_MACHINE_REGS();
Yap_push_state(&gi PASS_REGS);
CSlot = Yap_StartSlots();
LOCAL_PrologMode = UserMode;
// Yap_heap_regs->yap_do_low_level_trace=true;
out = Yap_RunTopGoal(t, &gi, true);
out = Yap_RunTopGoal(t, true);
LOCAL_PrologMode = oldPrologMode;
// Yap_CloseSlots(CSlot);
Yap_pop_state(out, &gi PASS_REGS);
if (!(oldPrologMode & UserCCallMode)) {
/* called from top-level */
LOCAL_AllowRestart = FALSE;
@ -1996,6 +1962,38 @@ X_API Int YAP_RunGoalOnce(Term t) {
// should we catch the exception or pass it through?
// We'll pass it through
// Yap_RaiseException();
if (out) {
choiceptr cut_pt, ob;
ob = NULL;
cut_pt = B;
while (cut_pt->cp_ap != NOCODE) {
/* make sure we prune C-choicepoints */
if (POP_CHOICE_POINT(cut_pt->cp_b)) {
POP_EXECUTE();
}
ob = cut_pt;
cut_pt = cut_pt->cp_b;
}
#ifdef YAPOR
CUT_prune_to(cut_pt);
#endif
if (ob) {
B = ob;
Yap_TrimTrail();
}
B = cut_pt;
} else {
Yap_CloseSlots(CSlot);
}
ASP = B->cp_env;
ENV = (CELL *)ASP[E_E];
B = (choiceptr)ASP[E_CB];
#ifdef DEPTH_LIMITxs
DEPTH = ASP[E_DEPTH];
#endif
P = (yamop *)ASP[E_CP];
CP = old_CP;
LOCAL_AllowRestart = FALSE;
RECOVER_MACHINE_REGS();
return out;
@ -2080,7 +2078,7 @@ X_API void YAP_PruneGoal(YAP_dogoalinfo *gi) {
CACHE_REGS
BACKUP_B();
choiceptr myB = (choiceptr)(LCL0 - gi->b_top);
choiceptr myB = (choiceptr)(LCL0 - gi->b);
while (B != myB) {
/* make sure we prune C-choicepoints */
if (POP_CHOICE_POINT(B->cp_b)) {
@ -2137,7 +2135,7 @@ int lvl = push_text_stack();
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
LOCAL_encoding);
__android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "OpenStream got %ld ",sno);
ANDROID_LOG_INFO, "YAPDroid", "OpenStream got %d ",sno);
if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
*full = NULL;
pop_text_stack(lvl);
@ -2179,7 +2177,7 @@ X_API void YAP_EndConsult(int sno, int *osnop, const char *full) {
if (osnop >= 0)
Yap_AddAlias(AtomLoopStream, *osnop);
Yap_end_consult();
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%ld), %ld",
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%d), %d",
CurrentModule == 0
? "prolog"
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
@ -2209,7 +2207,7 @@ X_API Term YAP_ReadFromStream(int sno) {
if (sigsetjmp(signew, 0)) {
Yap_syntax_error(LOCAL_toktide, sno, "ReadFromStream");
RECOVER_MACHINE_REGS();
return 0;
return 0;
} else {
o = Yap_read_term(sno, TermNil, false);
}

View File

@ -1,4 +1,4 @@
/************************************************************************ \
/************************************************************************\
* Cut & Commit Inst
ructions *

157
C/exec.c
View File

@ -801,13 +801,14 @@ static Int execute_in_mod(USES_REGS1) { /* '$execute'(Goal) */
*
* @method prune_inner_computation
*/
static void prune_inner_computation(choiceptr parent, YAP_dogoalinfo *gi) {
static void prune_inner_computation(choiceptr parent) {
/* code */
choiceptr cut_pt;
yamop *oP = P, *oCP = CP;
Int oENV = LCL0 - ENV;
cut_pt = B;
while (cut_pt && cut_pt->cp_b
&& cut_pt->cp_ap != NOCODE &&
cut_pt->cp_b <= parent) {
while (cut_pt && cut_pt->cp_b < parent) {
cut_pt = cut_pt->cp_b;
}
if (!cut_pt)
@ -818,9 +819,9 @@ static void prune_inner_computation(choiceptr parent, YAP_dogoalinfo *gi) {
B = cut_pt;
Yap_TrimTrail();
LOCAL_AllowRestart = FALSE;
P = gi->p;
CP = gi->cp;
ENV = LCL0-gi->e;
P = oP;
CP = oCP;
ENV = LCL0 - oENV;
B = parent;
}
@ -829,7 +830,7 @@ static void prune_inner_computation(choiceptr parent, YAP_dogoalinfo *gi) {
* after completing a computation.
* @method complete_inner_computation
*/
static void complete_inner_computation(choiceptr old_B, YAP_dogoalinfo *gi) {
static void complete_inner_computation(choiceptr old_B) {
choiceptr myB = B;
if (myB == NULL) {
return;
@ -847,30 +848,30 @@ static void complete_inner_computation(choiceptr old_B, YAP_dogoalinfo *gi) {
return;
}
// restore environment at call...
CP = gi->cp;
P = gi->p;
ENV = LCL0-gi->e;
YENV = LCL0-gi->y;
CP = myB->cp_cp;
ENV = myB->cp_env;
}
static Int Yap_ignore(Term t, bool fail USES_REGS) {
YAP_dogoalinfo gi;
Yap_push_state(&gi);
yamop *oP = P, *oCP = CP;
Int oENV = LCL0 - ENV;
Int oYENV = LCL0 - YENV;
Int oB = LCL0 - (CELL *)B;
yap_error_descriptor_t *ctx = malloc(sizeof(yap_error_descriptor_t));
bool newxp = Yap_pushErrorContext(true, ctx);
bool rc = Yap_RunTopGoal(t, &gi, false);
choiceptr B0 = (choiceptr)(LCL0-gi.b_top);
bool rc = Yap_RunTopGoal(t, false);
if (!rc) {
complete_inner_computation(B0, &gi);
complete_inner_computation((choiceptr)(LCL0 - oB));
// We'll pass it through
} else {
prune_inner_computation(B0, &gi);
prune_inner_computation((choiceptr)(LCL0 - oB));
}
Yap_popErrorContext(newxp, true);
P = gi.p;
CP = gi.cp;
//YENV?
P = oP;
CP = oCP;
ENV = LCL0 - oENV;
YENV = LCL0 - oYENV;
B = (choiceptr)(LCL0 - oB);
return true;
}
@ -1000,39 +1001,30 @@ static bool watch_retry(Term d0 USES_REGS) {
static Int setup_call_catcher_cleanup(USES_REGS1) {
Term Setup = Deref(ARG1);
YAP_dogoalinfo gi;
gi.p = P;
gi.cp = CP;
gi.b_top = LCL0-CellPtr(B);
gi.CurSlot = Yap_CurrentHandle();
gi.y = LCL0-YENV;
gi.e = LCL0-ENV;
bool rc;
choiceptr B0 = B;
yamop *oP = P, *oCP = CP;
Int oENV = LCL0 - ENV;
Int oYENV = LCL0 - YENV;
bool rc;
Yap_DisableInterrupts(worker_id);
rc = Yap_RunTopGoal(Setup, &gi, false);
rc = Yap_RunTopGoal(Setup, false);
Yap_EnableInterrupts(worker_id);
if (Yap_RaiseException()) {
return false;
}
choiceptr B0=(choiceptr)(LCL0-gi.b_top);
if (!rc) {
complete_inner_computation(B0, &gi);
complete_inner_computation(B0);
// We'll pass it throughs
return false;
} else {
prune_inner_computation(B0, &gi);
prune_inner_computation(B0);
}
YENV = LCL0-gi.y;
ENV = LCL0-gi.e;
B = (choiceptr)(LCL0-gi.b_top);
SET_ASP(YENV, E_CB * sizeof(CELL));
#ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH];
#endif
P = gi.p;
CP = gi.cp;
P = oP;
CP = oCP;
ENV = LCL0 - oENV;
YENV = LCL0 - oYENV;
return rc;
}
@ -1606,7 +1598,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
ASP = (CELL *)PROTECT_FROZEN_B(B);
if (B == NULL || B->cp_b == NULL ||
(CELL *)(B->cp_b) >= LCL0 - LOCAL_CBorder) {
(CELL *)(B->cp_b) > LCL0 - LOCAL_CBorder) {
LOCAL_RestartEnv = sighold;
LOCAL_CBorder = OldBorder;
pop_text_stack(i + 1);
@ -1617,8 +1609,8 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
}
YENV = ASP;
YENV[E_CB] = Unsigned(B);
pop_text_stack(i + 1);
out = Yap_absmi(0);
/* make sure we don't leave a FAIL signal hanging around */
Yap_get_signal(YAP_FAIL_SIGNAL);
if (!Yap_has_a_signal())
@ -1628,15 +1620,15 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
pop_text_stack(i + 1);
return out;
}
void Yap_PrepGoal(arity_t arity, CELL *pt, YAP_dogoalinfo *gip USES_REGS) {
void Yap_PrepGoal(arity_t arity, CELL *pt, choiceptr saved_b USES_REGS) {
/* create an initial pseudo environment so that when garbage
collection is going up in the environment chain it doesn't ge t
collection is going up in the environment chain it doesn't get
confused */
Yap_ResetException(worker_id);
// sl = Yap_InitSlot(t);
YENV = ASP;
YENV[E_CP] = (CELL)CP;
YENV[E_CP] = (CELL)YESCODE;
YENV[E_CB] = (CELL)B;
YENV[E_E] = (CELL)ENV;
#ifdef TABLING
@ -1652,33 +1644,31 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
/* keep a place where you can inform you had an exception */
if (pt) {
int i;
for (i = 0; i < 3; i++) {
for (i = 0; i < arity; i++) {
XREGS[i + 1] = *pt++;
}
}
choiceptr oB = B;
B = (choiceptr)ASP;
B--;
B->cp_h = HR;
B->cp_tr = TR;
B->cp_cp = YESCODE;
B->cp_cp = CP;
B->cp_ap = NOCODE;
B->cp_env = ENV;
B->cp_b = oB;
B->cp_b = saved_b;
#ifdef DEPTH_LIMIT
B->cp_depth = DEPTH;
#endif /* DEPTH_LIMIT */
ASP = (CELL *)B;
ASP[E_CB] = (CELL)B;
YENV = ASP = (CELL *)B;
YENV[E_CB] = (CELL)B;
HB = HR;
CP = YESCODE;
ASP -= EnvSizeInCells;
gip->b_bottom = LCL0-CellPtr(B);
}
static bool do_goal(yamop *CodeAdr, int arity, CELL *pt, YAP_dogoalinfo *gi, bool top USES_REGS) {
static bool do_goal(yamop *CodeAdr, int arity, CELL *pt, bool top USES_REGS) {
choiceptr saved_b = B;
bool out;
Yap_PrepGoal(arity, pt, gi PASS_REGS);
Yap_PrepGoal(arity, pt, saved_b PASS_REGS);
// CACHE_A1();
P = (yamop *)CodeAdr;
// S = CellPtr(RepPredProp(
@ -1750,21 +1740,18 @@ void Yap_fail_all(choiceptr bb USES_REGS) {
}
bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
yamop *saved_p, *saved_cp;
yamop *CodeAdr;
bool out;
YAP_dogoalinfo gi;
gi.p = P;
gi.cp = CP;
gi.b_top = LCL0-CellPtr(B);
gi.CurSlot = Yap_CurrentHandle();
gi.y = LCL0-YENV;
gi.e = LCL0-ENV;
saved_p = P;
saved_cp = CP;
LOCAL_PrologMode |= TopGoalMode;
PELOCK(81, ppe);
CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock);
out = do_goal(CodeAdr, ppe->ArityOfPE, pt, &gi, false PASS_REGS);
out = do_goal(CodeAdr, ppe->ArityOfPE, pt, false PASS_REGS);
if (out) {
choiceptr cut_B;
@ -1785,13 +1772,14 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
#endif
}
#endif /* TABLING */
B = (choiceptr)(LCL0-gi.b_top);
CP = gi.cp;
P = gi.p;
B = cut_B;
CP = saved_cp;
P = saved_p;
ASP = ENV;
#ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH];
#endif
ENV = LCL0-gi.e;
ENV = (CELL *)(ENV[E_E]);
/* we have failed, and usually we would backtrack to this B,
trouble is, we may also have a delayed cut to do */
if (B != NULL)
@ -1810,18 +1798,18 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
}
return true;
} else if (out == 0) {
P = gi.p;
CP = gi.cp;
P = saved_p;
CP = saved_cp;
HR = B->cp_h;
#ifdef DEPTH_LIMIT
DEPTH = B->cp_depth;
#endif
/* YENV should be set to the current environment */
YENV = ENV = LCL0-gi.e;
/* ASP should be set to the top of the local stack when we
did the call */
SET_ASP(YENV, E_CB * sizeof(CELL));
B =(choiceptr)(LCL0-gi.b_top);
ASP = B->cp_env;
/* YENV should be set to the current environment */
YENV = ENV = (CELL *)((B->cp_env)[E_E]);
B = B->cp_b;
SET_BB(B);
HB = PROTECT_FROZEN_H(B);
// should we catch the exception or pass it through?
@ -1896,7 +1884,7 @@ void Yap_trust_last(void) {
}
}
Term Yap_RunTopGoal(Term t, YAP_dogoalinfo *gip, bool handle_errors) {
Term Yap_RunTopGoal(Term t, bool handle_errors) {
CACHE_REGS
yamop *CodeAdr;
Prop pe;
@ -1905,7 +1893,7 @@ Term Yap_RunTopGoal(Term t, YAP_dogoalinfo *gip, bool handle_errors) {
UInt arity;
Term tmod = CurrentModule;
Term goal_out = 0;
LOCAL_PrologMode |= TopGoalMode;
LOCAL_PrologMode |= TopGoalMode;
t = Yap_YapStripModule(t, &tmod);
if (IsVarTerm(t)) {
@ -1975,7 +1963,7 @@ Term Yap_RunTopGoal(Term t, YAP_dogoalinfo *gip, bool handle_errors) {
"unable to boot because of too little Trail space");
}
#endif
goal_out = do_goal(CodeAdr, arity, pt, gip, handle_errors PASS_REGS);
goal_out = do_goal(CodeAdr, arity, pt, handle_errors PASS_REGS);
return goal_out;
}
@ -2141,13 +2129,11 @@ bool Yap_Reset(yap_reset_t mode, bool hard) {
Yap_ResetException(worker_id);
/* first, backtrack to the root */
while (B->cp_b) {
if (B->cp_ap == NOCODE)
break;
B = B->cp_b;
}
while (B) {
P = FAILCODE;
Yap_exec_absmi(true, mode);
B = B->cp_b;
}
/* reinitialize the engine */
Yap_InitYaamRegs(worker_id, false);
GLOBAL_Initialised = true;
@ -2241,7 +2227,6 @@ static Int generate_pred_info(USES_REGS1) {
void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
Term h0var;
YAP_dogoalinfo gi;
// getchar();
#if PUSH_REGS
/* Guarantee that after a longjmp we go back to the original abstract
@ -2313,7 +2298,7 @@ void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
PREG_ADDR = NULL;
#endif
cut_c_initialize(myworker_id);
Yap_PrepGoal(0, NULL, &gi PASS_REGS);
Yap_PrepGoal(0, NULL, NULL PASS_REGS);
#ifdef FROZEN_STACKS
H_FZ = HR;
#ifdef YAPOR_SBA

View File

@ -470,6 +470,7 @@
LogUpdClause *lcl = PREG->y_u.OtILl.d;
UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]);
/* fprintf(stderr,"- %p/%p %d %d %p\n",PREG,ap,timestamp,ap->TimeStampOfPred,PREG->y_u.OtILl.d->ClCode);*/
#if defined(YAPOR) || defined(THREADS)
if (PP != ap) {
if (PP) UNLOCKPE(16,PP);

View File

@ -1949,12 +1949,11 @@
Op(p_arg_vv, xxx);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
HRs[0] = XREG(PREG->y_u.xxx.x1);
HRs[1] = XREG(PREG->y_u.xxx.x2);
HRs[2] = TermNil;
HR[0] = XREG(PREG->y_u.xxx.x1);
HR[1] = XREG(PREG->y_u.xxx.x2);
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HRs);
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
@ -2045,14 +2044,15 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
Op(p_arg_cv, xxn);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
CELL *Ho = HR;
Term t = MkIntegerTerm(PREG->y_u.xxn.c);
HRs[0] = t;
HRs[1] = XREG(PREG->y_u.xxn.xi);
HRs[2] = TermFoundVar;
HR[0] = t;
HR[1] = XREG(PREG->y_u.xxn.xi);
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HRs);
}
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
HR = Ho;
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
d0 = PREG->y_u.xxn.c;
@ -2118,13 +2118,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
Op(p_arg_y_vv, yxx);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
HRs[0] = XREG(PREG->y_u.yxx.x1);
HRs[1] = XREG(PREG->y_u.yxx.x2);
HRs[2] = TermFoundVar;
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HRs);
HR[0] = XREG(PREG->y_u.yxx.x1);
HR[1] = XREG(PREG->y_u.yxx.x2);
HR[2] = YREG[PREG->y_u.yxx.y];
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
@ -2216,13 +2215,15 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
Op(p_arg_y_cv, yxn);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
CELL *Ho = HR;
Term t = MkIntegerTerm(PREG->y_u.yxn.c);
HRs[0] = t;
HRs[1] = XREG(PREG->y_u.yxn.xi);
HRs[2] = TermNil;
HR[0] = t;
HR[1] = XREG(PREG->y_u.yxn.xi);
HR[2] = YREG[PREG->y_u.yxn.y];
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HRs);
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
HR = Ho;
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
@ -2294,13 +2295,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
restart_func2s:
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
HRs[0] = TermNil;
HRs[1] = XREG(PREG->y_u.xxx.x1);
HRs[2] = XREG(PREG->y_u.xxx.x2);
RESET_VARIABLE(HR);
HR[1] = XREG(PREG->y_u.xxx.x1);
HR[2] = XREG(PREG->y_u.xxx.x2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
/* We have to build the structure */
@ -2412,13 +2412,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
restart_func2s_cv:
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
HRs[0] = TermNil;
HRs[1] = PREG->y_u.xxc.c;
HRs[2] = XREG(PREG->y_u.xxc.xi);
RESET_VARIABLE(HR);
HR[1] = PREG->y_u.xxc.c;
HR[2] = XREG(PREG->y_u.xxc.xi);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
@ -2518,14 +2517,16 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
Term ti;
CELL HRs[3];
HRs[0] = TermNil;
CELL *hi = HR;
ti = MkIntegerTerm(PREG->y_u.xxn.c);
HRs[1] = XREG(PREG->y_u.xxn.xi);
HRs[2] = ti;
RESET_VARIABLE(HR);
HR[1] = XREG(PREG->y_u.xxn.xi);
HR[2] = ti;
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
HR = hi;
}
#endif /* LOW_LEVEL_TRACE */
/* We have to build the structure */
@ -2610,13 +2611,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
restart_func2s_y:
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
HRs[0] = TermNil;
HRs[1] = XREG(PREG->y_u.yxx.x1);
HRs[2] = XREG(PREG->y_u.yxx.x2);
RESET_VARIABLE(HR);
HR[1] = XREG(PREG->y_u.yxx.x1);
HR[2] = XREG(PREG->y_u.yxx.x2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
/* We have to build the structure */
@ -2735,13 +2735,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
restart_func2s_y_cv:
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
HRs[0] = TermNil;
HRs[1] = PREG->y_u.yxc.c;
HRs[2] = XREG(PREG->y_u.yxc.xi);
RESET_VARIABLE(HR);
HR[1] = PREG->y_u.yxc.c;
HR[2] = XREG(PREG->y_u.yxc.xi);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
/* We have to build the structure */
@ -2847,15 +2846,16 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
Term ti;
CELL HRs[3];
CELL *hi = HR;
ti = MkIntegerTerm((Int)(PREG->y_u.yxn.c));
HRs[0] = TermFoundVar;
HRs[1] = XREG(PREG->y_u.yxn.xi);
HRs[2] = ti;
RESET_VARIABLE(HR);
HR[1] = XREG(PREG->y_u.yxn.xi);
HR[2] = ti;
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
HR = hi;
}
#endif /* LOW_LEVEL_TRACE */
/* We have to build the structure */
@ -2952,12 +2952,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
Op(p_func2f_xx, xxx);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
Term HRs[3];
HRs[0] = XREG(PREG->y_u.xxx.x);
HRs[1] = HRs[2] = TermFoundVar;
HR[0] = XREG(PREG->y_u.xxx.x);
RESET_VARIABLE(HR + 1);
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
@ -3000,12 +3000,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
Op(p_func2f_xy, xxy);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
Term HRs[3];
HRs[0] = XREG(PREG->y_u.xxy.x);
HRs[1] = HRs[2] = TermFoundVar;
HR[0] = XREG(PREG->y_u.xxy.x);
RESET_VARIABLE(HR + 1);
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
@ -3051,12 +3051,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
Op(p_func2f_yx, yxx);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
Term HRs[3];
HRs[0] = XREG(PREG->y_u.yxx.x2);
HRs[1] = HRs[2] = TermFoundVar;
HR[0] = XREG(PREG->y_u.yxx.x2);
RESET_VARIABLE(HR + 1);
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);
@ -3102,12 +3102,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
Op(p_func2f_yy, yyx);
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
CELL HRs[3];
HRs[0] = XREG(PREG->y_u.yyx.x);
HRs[1] = HRs[2] = TermFoundVar;
HR[0] = XREG(PREG->y_u.yyx.x);
RESET_VARIABLE(HR + 1);
RESET_VARIABLE(HR + 2);
low_level_trace(enter_pred,
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
HRs);
HR);
}
#endif /* LOW_LEVEL_TRACE */
BEGD(d0);

View File

@ -151,9 +151,8 @@ clean_complex_tr(tr_fr_ptr TR0 USES_REGS) {
}
#define expand_stack(S0,SP,SF,TYPE) \
{ size_t sz = SF-S0, used = SP-S0;\
sz = 1024+sz; \
S0 = Realloc(S0, sz*sizeof(TYPE) PASS_REGS); \
{ size_t sz = SF-S0, used = SP-S0; \
S0 = Realloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \
SP = S0+used; SF = S0+sz; }
#define MIN_ARENA_SIZE (1048L)

View File

@ -1,3 +1,4 @@
# value of 3.4.0 or lower.
cmake_minimum_required(VERSION 3.4)
@ -904,7 +905,11 @@ add_subDIRECTORY(packages/ProbLog)
endif()
add_subDIRECTORY(packages/bee)
if (WITH_MINISAT)
add_subDIRECTORY(packages/swi-minisat2)
endif()
if (WITH_CLPQR)

View File

@ -252,10 +252,10 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len)
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) {
BACKUP_H();
arity_t arity = ArityOfFunctor(f.f);
Term o = AbsAppl(HR);
*HR++ = (CELL)f.f;
Term o = Yap_MkNewApplTerm(f.f, arity);
Term *tt = RepAppl(o) + 1;
for (arity_t i = 0; i < arity; i++)
*HR++ = ts[i].term();
tt[i] = ts[i].term();
mk(o);
RECOVER_H();
}
@ -411,23 +411,6 @@ std::vector<Term> YAPPairTerm::listToArray() {
return o;
}
std::vector<YAPTerm> YAPPairTerm::listToVector() {
Term *tailp;
Term t1 = gt();
Int l = Yap_SkipList(&t1, &tailp);
if (l < 0) {
throw YAPError(SOURCE(), TYPE_ERROR_LIST, (t), nullptr);
}
std::vector<YAPTerm> o = *new std::vector<YAPTerm>(l);
int i = 0;
Term t = gt();
while (t != TermNil) {
o[i++] = YAPTerm(HeadOfTerm(t));
t = TailOfTerm(t);
}
return o;
}
YAP_tag_t YAPTerm::tag() {
Term tt = gt();
if (IsVarTerm(tt)) {
@ -612,9 +595,43 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
#endif
CACHE_REGS
BACKUP_MACHINE_REGS();
bool rc = YAP_RunGoalOnce(t);
Term *ts = nullptr;
q.CurSlot = Yap_StartSlots();
q.p = P;
q.cp = CP;
Term omod = CurrentModule;
PredEntry *ap = nullptr;
if (IsStringTerm(tmod))
tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod)));
ap = Yap_get_pred(t, tmod, "C++");
if (ap == nullptr ||
ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefEngineQuery(ap, t, tmod);
}
if (IsApplTerm(t))
ts = RepAppl(t) + 1;
else if (IsPairTerm(t))
ts = RepPair(t);
/* legal ap */
arity_t arity = ap->ArityOfPE;
for (arity_t i = 0; i < arity; i++) {
XREGS[i + 1] = ts[i];
}
ts = nullptr;
bool result;
// allow Prolog style exception handling
// don't forget, on success these guys may create slots
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
result = (bool)YAP_EnterGoal(ap, nullptr, &q);
// std::cerr << "mgoal " << YAPTerm(tmod).text() << ":" << YAPTerm(t).text() << "\n";
YAP_LeaveGoal(result && !release, &q);
CurrentModule = LOCAL_SourceModule = omod;
// PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS();
return rc;
return result;
}
/**
* called when a query must be terminated and its state fully recovered,
@ -631,51 +648,61 @@ Term YAPEngine::fun(Term t) {
CACHE_REGS
BACKUP_MACHINE_REGS();
Term tmod = Yap_CurrentModule(), *ts = nullptr;
PredEntry *ap;
arity_t arity;
Functor f;
Atom name;
yhandle_t yt = Yap_NewHandles(1);
if (IsApplTerm(t)) {
ts = RepAppl(t) + 1;
f = (Functor)ts[-1];
name = NameOfFunctor(f);
arity = ArityOfFunctor(f);
t = AbsAppl(HR);
HR[0] = (CELL)Yap_MkFunctor(name, arity+1);
for (arity_t i = 0; i < arity; i++) {
HR[i + 1] = ts[i];
}
HR += (arity+2);
arity++;
for (arity_t i = 0; i < arity; i++)
XREGS[i + 1] = ts[i];
} else if (IsAtomTerm(t)) {
name = AtomOfTerm(t);
t = AbsAppl(HR);
HR[0] = (CELL)Yap_MkFunctor(name, 1);
HR += 2;
arity = 1;
f = nullptr;
arity = 0;
} else if (IsPairTerm(t)) {
HR[0] = (CELL)Yap_MkFunctor(AtomDot, 3);
HR[1] = ts[0];
HR[2] = ts[1];
HR += 4;
arity = 3;
XREGS[1] = ts[0];
XREGS[2] = ts[1];
arity = 2;
name = AtomDot;
f = FunctorDot;
} else {
throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t, 0);
return 0L;
}
RESET_VARIABLE(HR-1);
yt = Yap_InitHandle(t);
CACHE_REGS
BACKUP_MACHINE_REGS();
bool rc = YAP_RunGoalOnce(t);
Term ot;
if (rc)
ot = ArgOfTerm(arity,Yap_GetFromHandle(yt));
else
ot = TermNone;
RECOVER_MACHINE_REGS();
return ot;
Term ot = XREGS[arity + 1] = MkVarTerm();
yhandle_t h = Yap_InitHandle(ot);
arity++;
HR += arity;
f = Yap_MkFunctor(name, arity);
ap = (PredEntry *)(PredPropByFunc(f, tmod));
if (ap == nullptr || ap->OpcodeOfPred == UNDEF_OPCODE) {
Term g = (Yap_MkApplTerm(f, arity, ts));
ap = rewriteUndefEngineQuery(ap, g, (ap->ModuleOfPred));
}
q.CurSlot = Yap_StartSlots();
q.p = P;
q.cp = CP;
// make sure this is safe
// allow Prolog style exception handling
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
bool result = (bool)YAP_EnterGoal(ap, nullptr, &q);
if (result)
ot = Yap_GetFromHandle(h);
else
ot = TermNone;
YAPCatchError();
{
YAP_LeaveGoal(result, &q);
// PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS();
return ot;
}
}
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
@ -700,27 +727,6 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
RECOVER_MACHINE_REGS();
}
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, Term ts[])
: YAPPredicate(f, mod) {
/* ignore flags for now */
BACKUP_MACHINE_REGS();
Term goal;
if (ts) {
size_t arity = f.arity();
goal = Yap_MkApplTerm(Yap_MkFunctor(f.name().asAtom(),arity), arity, ts);
nts = RepAppl(goal) + 1;
for (arity_t i = 0; i < arity; i++)
XREGS[i + 1] = ts[i];
} else {
goal = MkVarTerm();
}
openQuery();
names = YAPPairTerm(TermNil);
RECOVER_MACHINE_REGS();
}
#if 0
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) {
/* ignore flags for now */
@ -821,7 +827,7 @@ bool YAPQuery::deterministic() {
BACKUP_MACHINE_REGS();
if (!q_open || q_state == 0)
return false;
choiceptr myB = (choiceptr)(LCL0 - q_h.b_top);
choiceptr myB = (choiceptr)(LCL0 - q_h.b);
return (B >= myB);
RECOVER_MACHINE_REGS();
}

View File

@ -304,35 +304,4 @@ static inline Term Yap_PopHandle__(yhandle_t topHandle USES_REGS) {
return Deref(LOCAL_HandleBase[topHandle]);
}
}
INLINE_ONLY void Yap_push_state(YAP_dogoalinfo *gi USES_REGS);
INLINE_ONLY void Yap_push_state(YAP_dogoalinfo *gi USES_REGS)
{
gi->p = P;
gi->cp = CP;
gi->b_top = LCL0-CellPtr(B);
gi->CurSlot = Yap_CurrentHandle();
gi->y = LCL0-YENV;
gi->e = LCL0-ENV;
gi->a = LCL0-ASP;
}
INLINE_ONLY void Yap_pop_state(bool out, YAP_dogoalinfo *gi USES_REGS);
INLINE_ONLY void Yap_pop_state(bool out, YAP_dogoalinfo *gi USES_REGS)
{
B = (choiceptr)(LCL0-gi->b_top);
YENV = LCL0-gi->y;
ENV = LCL0-gi->e;
if (out) {
Yap_TrimTrail();
}
ASP = LCL0-gi->a;
Yap_CloseHandles(gi->CurSlot);
SET_ASP(YENV, E_CB * sizeof(CELL));
#ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH];
#endif
}
#endif

View File

@ -203,12 +203,12 @@ extern void Yap_fail_all(choiceptr bb USES_REGS);
extern Term Yap_ExecuteCallMetaCall(Term,Term);
extern void Yap_InitExecFs(void);
extern bool Yap_JumpToEnv(void);
extern Term Yap_RunTopGoal(Term, YAP_dogoalinfo *gip,bool);
extern Term Yap_RunTopGoal(Term, bool);
extern bool Yap_execute_goal(Term, int, Term, bool);
extern bool Yap_exec_absmi(bool, yap_reset_t);
extern void Yap_trust_last(void);
extern void Yap_closeGoal(bool out, yamop *saved_p, yamop * saved_cp, Int saved_e, Int saved_b, yhandle_t hdl, bool pass_ex);
extern void Yap_PrepGoal(arity_t arity, CELL *pt, YAP_dogoalinfo *gip USES_REGS);
extern void Yap_PrepGoal(UInt, CELL *, choiceptr USES_REGS);
extern bool Yap_execute_pred(struct pred_entry *ppe, CELL *pt,
bool pass_exception USES_REGS);
extern int Yap_dogc(int extra_args, Term *tp USES_REGS);

View File

@ -34,7 +34,7 @@
#define HENVYOP(N, NAME, op, NEXTNAME, PFAIL) DEF NAME Yap_heap_regs->NAME##_
#define HCPYOP(N, NAME, OP, FAILP) DEF NAME Yap_heap_regs->NAME##_
#include "YapHeap.h"
#include "heap.h"
#undef HM
#undef HSPACE
@ -72,7 +72,7 @@
DEF GLOBAL_##NAME Yap_heap_regs->NAME##_
#define HCPYOP(N, NAME, OP, FAILP) DEF GLOBAL_##NAME Yap_heap_regs->NAME##_
#include "YapHeap.h"
#include "heap.h"
#undef LOC
#undef LOCL

View File

@ -3,7 +3,7 @@
// Macro support
#ifndef LOCAL
#include "Yap.h"
#include "YapHeap.h"
#include "heap.h"
#define LOCAL(A, B) A B
#define LOCAL_INIT(A, B, C) \
A B; \

View File

@ -137,8 +137,8 @@ typedef enum {
#include "YapInit.h"
/* this should be opaque to the user */
typedef struct goal_info {
unsigned long b_top, b_bottom, m, e, y, a; //> choice-point at entry
typedef struct {
unsigned long b, b0; //> choice-point at entry
YAP_handle_t CurSlot; //> variables at entry
YAP_handle_t EndSlot; //> variables at successful execution
struct yami *p; //> Program Counter at entry

View File

@ -267,7 +267,7 @@ initialize_prolog :-
:- c_compile( 'protect.yap' ).
:- ['absf.yap'].
%:- ..............................lp------------------------------------------------------------------.
%:- stop_low_level_trace.
:- use_module('error.yap').
:- [