diff --git a/C/absmi.c b/C/absmi.c index 1ec017858..0f07a5186 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -1323,11 +1323,10 @@ Int Yap_absmi(int inp) { #endif /* USE_THREADED_CODE */ #if PUSH_REGS - old_regs = &Yap_REGS; + old_regs = Yap_regp; /* 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); diff --git a/C/absmi_insts.h b/C/absmi_insts.h index 5499274c2..abc14b919 100644 --- a/C/absmi_insts.h +++ b/C/absmi_insts.h @@ -9,7 +9,7 @@ #endif /* INDENT_CODE */ BOp(Ystop, l); - LOCAL_CBorder = 0; + // LOCAL_CBorder = 0; SET_ASP(YREG, E_CB * sizeof(CELL)); /* make sure ASP is initialized */ saveregs(); @@ -23,9 +23,10 @@ LOCAL_CBorder = 0; return 1; ENDBOp(); - + BOp(Nstop, e); SET_ASP(YREG, E_CB * sizeof(CELL)); + B = B->cp_b; saveregs(); #if PUSH_REGS restore_absmi_regs(old_regs); diff --git a/C/c_interface.c b/C/c_interface.c index 6d8c8549f..286e6ad61 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -1154,6 +1154,10 @@ static uintptr_t complete_exit(choiceptr ptr, int has_cp, X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) { CACHE_REGS Int ret; + yamop *saved_p =P, *saved_cp = CP; + yhandle_t s0; + + Int saved_b = LCL0-(CELL*)B, saved_e = LCL0-ENV; Int OASP = LCL0 - (CELL *)B; // Term omod = CurrentModule; // if (pe->PredFlags & CArgsPredFlag) { @@ -1164,21 +1168,25 @@ X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) { struct foreign_context ctx; ctx.engine = NULL; - yhandle_t s0 = Yap_InitSlots(pe->ArityOfPE, &ARG1); + s0 = Yap_InitSlots(pe->ArityOfPE, &ARG1); PP = pe; ret = codev(s0, 0, &ctx); } else if (pe->PredFlags & CArgsPredFlag) { PP = pe; + s0 = Yap_CurrentHandle(); ret = execute_cargs(pe, exec_code PASS_REGS); } else { + s0 = Yap_CurrentHandle(); PP = pe; ret = (exec_code)(PASS_REGS1); } PP = NULL; // check for junk: open frames, etc */ + Yap_closeGoal( ret, saved_p, saved_cp, saved_e, saved_b, s0, true); + return ret; if (ret) - complete_exit(((choiceptr)(LCL0 - OASP)), FALSE, FALSE PASS_REGS); - else + complete_exit(((choiceptr)(LCL0 - OASP)), FALSE, FALSE PASS_REGS); + else complete_fail(((choiceptr)(LCL0 - OASP)), FALSE PASS_REGS); // CurrentModule = omod; if (!ret) { @@ -1195,7 +1203,8 @@ X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) { X_API Int YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) { CACHE_REGS CELL ocp = LCL0 - (CELL *)B; - /* for slots to work */ + + /* for slots to work */ Int CurSlot = Yap_StartSlots(); if (pe->PredFlags & (SWIEnvPredFlag | CArgsPredFlag | ModuleTransparentPredFlag)) { @@ -1213,30 +1222,29 @@ X_API Int YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) { } else { val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1), 0, ctx); } - Yap_CloseSlots(CurSlot); PP = NULL; - if (val == 0) { - if (Yap_RaiseException()) { - return false; + if (val == 0) { + if (Yap_RaiseException()) { + return false; + } + return complete_fail(((choiceptr)(LCL0 - ocp)), TRUE PASS_REGS); + } else if (val == 1) { /* TRUE */ + return complete_exit(((choiceptr)(LCL0 - ocp)), TRUE, FALSE PASS_REGS); + } else { + if ((val & REDO_PTR) == REDO_PTR) + ctx->context = (uintptr_t)(val & ~REDO_PTR); + else + ctx->context = (uintptr_t)((val & ~REDO_PTR) >> FRG_REDO_BITS); + /* fix dropped cps */ + return complete_exit(((choiceptr)(LCL0 - ocp)), FALSE, FALSE PASS_REGS); } - return complete_fail(((choiceptr)(LCL0 - ocp)), TRUE PASS_REGS); - } else if (val == 1) { /* TRUE */ - return complete_exit(((choiceptr)(LCL0 - ocp)), TRUE, FALSE PASS_REGS); - } else { - if ((val & REDO_PTR) == REDO_PTR) - ctx->context = (uintptr_t)(val & ~REDO_PTR); - else - ctx->context = (uintptr_t)((val & ~REDO_PTR) >> FRG_REDO_BITS); - /* fix dropped cps */ - return complete_exit(((choiceptr)(LCL0 - ocp)), FALSE, FALSE PASS_REGS); - } } else { - Int ret = (exec_code)(PASS_REGS1); - Yap_CloseSlots(CurSlot); - if (!ret) { - Yap_RaiseException(); - } - return ret; + Int ret = (exec_code)(PASS_REGS1); + Yap_CloseSlots(CurSlot); + if (!ret) { + Yap_RaiseException(); + } + return ret; } } @@ -1756,8 +1764,8 @@ 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); +// 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); BACKUP_MACHINE_REGS(); LOCAL_ActiveError->errorNo = YAP_NO_ERROR; @@ -1822,7 +1830,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) { out = Yap_exec_absmi(true, true ); if (out) { dgi->EndSlot = LOCAL_CurSlot; - dgi->b = myB; + dgi->b = LCL0-(CELL*)myB; } else { LOCAL_CurSlot = dgi->CurSlot; // ignore any slots created within the called goal @@ -1833,45 +1841,16 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) { 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", // 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); - if (LOCAL_PrologMode & AsyncIntMode) { - Yap_signal(YAP_FAIL_SIGNAL); - } - handler = B; - while (handler && - LCL0 - LOCAL_CBorder > (CELL *)handler - //&& handler->cp_ap != NOCODE - && handler->cp_b != NULL && handler != myB) { - if (handler < myB) { - handler->cp_ap = TRUSTFAILCODE; - } - B = handler; - handler = handler->cp_b; - if (successful) { - Yap_TrimTrail(); - } else if (!(LOCAL_PrologMode & AsyncIntMode)) { - P = FAILCODE; - Yap_exec_absmi(true, YAP_EXEC_ABSMI); - } - } - if (LOCAL_PrologMode & AsyncIntMode) { - Yap_signal(YAP_FAIL_SIGNAL); - } - P = dgi->p; - CP = dgi->cp; - ENV = LCL0-dgi->e; - ASP = LCL0-dgi->a; - B = (choiceptr)(LCL0-dgi->b) + Yap_closeGoal(successful, dgi->p, dgi->cp, dgi->b, dgi->e, dgi->CurSlot, true); RECOVER_MACHINE_REGS(); - fprintf(stderr,"LeftGoal success=%ld: 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=%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); return TRUE; } @@ -1963,12 +1942,15 @@ X_API Int YAP_RunGoalOnce(Term t) { CACHE_REGS Term out; yamop *old_CP = CP; + yamop *old_P = P; + Int old_ENV = LCL0-ENV; + Int old_B =LCL0-(CELL*) B; + /* Int old_B = LCL0-(CELL*)B */; Int oldPrologMode = LOCAL_PrologMode; - yhandle_t CSlot; + yhandle_t h = Yap_CurrentHandle(); BACKUP_MACHINE_REGS(); - CSlot = Yap_StartSlots(); - LOCAL_PrologMode = UserMode; + LOCAL_PrologMode = UserMode; // Yap_heap_regs->yap_do_low_level_trace=true; out = Yap_RunTopGoal(t, true); LOCAL_PrologMode = oldPrologMode; @@ -1979,47 +1961,13 @@ X_API Int YAP_RunGoalOnce(Term t) { RECOVER_MACHINE_REGS(); return out; } - // 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(); + Yap_closeGoal( out, old_P, old_CP, old_ENV, old_B, h, true); return out; } -X_API bool YAP_RestartGoal(void) { + + X_API +bool YAP_RestartGoal(void) { CACHE_REGS BACKUP_MACHINE_REGS(); bool out; diff --git a/C/control_absmi_insts.h b/C/control_absmi_insts.h index 59469248e..483609e1b 100644 --- a/C/control_absmi_insts.h +++ b/C/control_absmi_insts.h @@ -1,4 +1,4 @@ -/************************************************************************\ +/************************************************************************ \ * Cut & Commit Inst ructions * diff --git a/C/errors.c b/C/errors.c index 791113072..dae0a41bb 100755 --- a/C/errors.c +++ b/C/errors.c @@ -1254,7 +1254,7 @@ static Int is_callable(USES_REGS1) { // Term Context = Deref(ARG2); while (true) { if (IsVarTerm(G)) { - Yap_ThrowError(INSTANTIATION_ERROR, G, NULL); + //Yap_ThrowError(INSTANTIATION_ERROR, G, NULL); return false; } if (IsApplTerm(G)) { diff --git a/C/exec.c b/C/exec.c index f332fd307..2f10a7794 100755 --- a/C/exec.c +++ b/C/exec.c @@ -831,6 +831,7 @@ static void prune_inner_computation(choiceptr parent) { * @method complete_inner_computation */ static void complete_inner_computation(choiceptr old_B) { + return; choiceptr myB = B; if (myB == NULL) { return; @@ -1062,9 +1063,7 @@ static Int cleanup_on_exit(USES_REGS1) { complete_pt[0] = TermExit; } Yap_ignore(cleanup, false); - if (B0->cp_ap == NOCODE) - B0->cp_ap = TRUSTFAILCODE; - if (Yap_RaiseException()) { + if (Yap_RaiseException()) { return false; } return true; @@ -1097,7 +1096,7 @@ static Int _user_expand_goal(USES_REGS1) { pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && Yap_execute_pred(pe, NULL, false PASS_REGS)) { return complete_ge(true , omod, sl, creeping); - } + }; /* system:goal_expansion(A,B) */ mg_args[0] = cmod; mg_args[1] = Yap_GetFromSlot(h1); @@ -1567,11 +1566,9 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) { /* can be called from anywhere, must reset registers, */ // LOCAL_ActiveError = err_info; - while (B) { + if (B) { LOCAL_ActiveError->errorNo = ABORT_EVENT; - pop_text_stack(i + 1); - Yap_CloseSlots(sls); - Yap_JumpToEnv(); + Yap_JumpToEnv(); } LOCAL_PrologMode = UserMode; LOCAL_DoingUndefp = false; @@ -1739,20 +1736,7 @@ void Yap_fail_all(choiceptr bb USES_REGS) { P = saved_p; } -bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) { - yamop *saved_p, *saved_cp; - yamop *CodeAdr; - bool out; - - 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, false PASS_REGS); - +void Yap_closeGoal(bool out, yamop *saved_p, yamop * saved_cp, Int saved_e, Int saved_b, yhandle_t bnd, bool pass_ex) { if (out) { choiceptr cut_B; /* we succeeded, let's prune */ @@ -1764,69 +1748,89 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) { #endif /* YAPOR */ #ifdef TABLING if (B != cut_B) { + while (B->cp_b < cut_B) { - B = B->cp_b; - } + if (B->cp_ap == NOCODE) + break; + B = B->cp_b; #ifdef TABLING abolish_incomplete_subgoals(B); #endif } + } #endif /* TABLING */ - B = cut_B; + B = (choiceptr)(LCL0-saved_b); CP = saved_cp; P = saved_p; ASP = ENV; + ENV = LCL0-saved_e; #ifdef DEPTH_LIMIT DEPTH = ENV[E_DEPTH]; #endif - 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) - HB = B->cp_h; + if (B != NULL) { + HB = B->cp_h; + Yap_TrimTrail(); + } YENV = ENV; + } else if (out == 0) { + /* ASP should be set to the top of the local stack when we + did the call */ + choiceptr b0 =(choiceptr)(LCL0-saved_b); + while (B && B < b0 && B->cp_ap !=NOCODE) { + B->cp_ap = TRUSTFAILCODE; + B = B->cp_b; + } + if (Bcp_depth; +#endif + P = saved_p; + CP = saved_cp; + + /* YENV should be set to the current environment */ + YENV = ENV = LCL0-saved_e; + SET_BB(B); + HB = PROTECT_FROZEN_H(B); + } else { + Yap_ThrowError(SYSTEM_ERROR_INTERNAL, TermNil, "emulator crashed"); + } // should we catch the exception or pass it through? // We'll pass it through if ( Yap_HasException()) { - if (pass_ex && - ((LOCAL_PrologMode & BootMode) || !CurrentModule )) { - Yap_ResetException(LOCAL_ActiveError); - } else { - Yap_RaiseException(); - } - return false; + if (pass_ex) { + if ((LOCAL_PrologMode & BootMode) || !CurrentModule) { + Yap_ResetException(LOCAL_ActiveError); + } else { + Yap_RaiseException(); + } + } else { + Yap_ResetException(LOCAL_ActiveError); + } } - return true; - } else if (out == 0) { - P = saved_p; - CP = saved_cp; - HR = B->cp_h; -#ifdef DEPTH_LIMIT - DEPTH = B->cp_depth; -#endif - /* ASP should be set to the top of the local stack when we - did the call */ - 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? - // We'll pass it through - if ( Yap_HasException()) { - if (pass_ex && - ((LOCAL_PrologMode & BootMode) || !CurrentModule )) { - Yap_ResetException(LOCAL_ActiveError); - } else { - Yap_RaiseException(); - } - } - return false; - } else { - Yap_ThrowError(SYSTEM_ERROR_INTERNAL, TermNil, "emulator crashed"); - return false; - } +} + +bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) { + yamop *saved_p, *saved_cp; + yamop *CodeAdr; + + yhandle_t curh = Yap_CurrentHandle( ); + Int saved_b = LCL0-(CELL*)B, saved_e = LCL0-ENV; + saved_p = P; + saved_cp = CP; + LOCAL_PrologMode |= TopGoalMode; + + PELOCK(81, ppe); + CodeAdr = ppe->CodeOfPred; + UNLOCK(ppe->PELock); + bool out = do_goal(CodeAdr, ppe->ArityOfPE, pt, false PASS_REGS); + Yap_closeGoal( out, saved_p, saved_cp, saved_e, saved_b, curh, pass_ex); + return out; } bool Yap_execute_goal(Term t, int nargs, Term mod, bool pass_ex) { @@ -2078,7 +2082,7 @@ static Int clean_ifcp(USES_REGS1) { } B = B->cp_b; HB = B->cp_h; - } else { + } else if (pt0->cp_ap != NOCODE){ pt0->cp_ap = (yamop *)TRUSTFAILCODE; } return TRUE; @@ -2129,11 +2133,18 @@ bool Yap_Reset(yap_reset_t mode, bool hard) { Yap_ResetException(worker_id); /* first, backtrack to the root */ + choiceptr ob; + while (B) { - P = FAILCODE; - Yap_exec_absmi(true, mode); + ob = B; B = B->cp_b; } + + if (ob) { + B = ob; + P = FAILCODE; + Yap_exec_absmi(true, mode); + } /* reinitialize the engine */ Yap_InitYaamRegs(worker_id, false); GLOBAL_Initialised = true; @@ -2166,6 +2177,8 @@ bool is_cleanup_cp(choiceptr cp_b) { static Int JumpToEnv(USES_REGS1) { choiceptr handler = B; + if (B->cp_ap == NOCODE) + return false; /* just keep the throwm object away, we don't need to care about it */ /* careful, previous step may have caused a stack shift, @@ -2175,7 +2188,7 @@ static Int JumpToEnv(USES_REGS1) { while (handler && Yap_PredForChoicePt(handler, NULL) != PredDollarCatch && LOCAL_CBorder < LCL0 - (CELL *)handler && handler->cp_ap != NOCODE && handler->cp_b != NULL) { - handler->cp_ap = TRUSTFAILCODE; + handler->cp_ap = FAILCODE; handler = handler->cp_b; } if (LOCAL_PrologMode & AsyncIntMode) { diff --git a/H/Yapproto.h b/H/Yapproto.h index 1d2a87302..5e1999050 100755 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -207,7 +207,7 @@ 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(UInt, CELL *, choiceptr USES_REGS); extern bool Yap_execute_pred(struct pred_entry *ppe, CELL *pt, bool pass_exception USES_REGS); diff --git a/info/build.sh b/info/build.sh index 98ccbf15e..bba74fa52 100644 --- a/info/build.sh +++ b/info/build.sh @@ -15,7 +15,7 @@ cd $PREFIX/conda $CMAKE --build=. --target=install \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX="$PREFIX" \ - $RECIPE_DIR/.. + $RECIPE_DIR/.. -DWITH_CUDD=NO -DWITH_GECODE=NO -DWITH_JAVA=NO -DWITH_RAPTOR=NO make -j install