From 1739529c8b43e08fe05d0af18c6a54465e8862b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 10 Apr 2019 18:51:40 +0100 Subject: [PATCH 1/6] recursuve_calling --- C/absmi.c | 3 +- C/absmi_insts.h | 5 +- C/c_interface.c | 150 +++++++++++++-------------------------- C/control_absmi_insts.h | 2 +- C/errors.c | 2 +- C/exec.c | 153 ++++++++++++++++++++++------------------ H/Yapproto.h | 2 +- info/build.sh | 2 +- 8 files changed, 140 insertions(+), 179 deletions(-) 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 From 91016209748d81f8285e96bcdc5c687a6f57546b Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 20 Apr 2019 03:25:12 -0500 Subject: [PATCH 2/6] conda --- info/build.sh | 4 ++-- info/meta.yaml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/info/build.sh b/info/build.sh index bba74fa52..cc1fdc7c9 100644 --- a/info/build.sh +++ b/info/build.sh @@ -13,11 +13,11 @@ mkdir $PREFIX/conda cd $PREFIX/conda # The datarootdir option places the docs into a temp folder that won't $CMAKE --build=. --target=install \ - -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_BUILD_TYPE=Debug -GNinja \ -DCMAKE_INSTALL_PREFIX="$PREFIX" \ $RECIPE_DIR/.. -DWITH_CUDD=NO -DWITH_GECODE=NO -DWITH_JAVA=NO -DWITH_RAPTOR=NO - make -j install + ninja install # Remove the created lib64 directory diff --git a/info/meta.yaml b/info/meta.yaml index 8a51f5bbd..25d2122e3 100644 --- a/info/meta.yaml +++ b/info/meta.yaml @@ -15,7 +15,6 @@ requirements: - r - notebook - pkgconfig - - make - libxml2 run: - jupyterlab From b1b6afe801ff734a74b8672293f80a48c93a6823 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 22 Apr 2019 12:17:00 +0100 Subject: [PATCH 3/6] bee --- packages/real/yap4r/src/Makevars.in | 4 +- packages/swi-minisat2/C/Alg.h | 57 -- packages/swi-minisat2/C/BasicHeap.h | 98 --- packages/swi-minisat2/C/BoxedVec.h | 147 ---- packages/swi-minisat2/C/CMakeLists.txt | 51 -- packages/swi-minisat2/C/Heap.h | 169 ---- packages/swi-minisat2/C/Makefile.in | 96 --- packages/swi-minisat2/C/Map.h | 118 --- packages/swi-minisat2/C/Queue.h | 82 -- packages/swi-minisat2/C/Solver.C | 791 ------------------ packages/swi-minisat2/C/Solver.h | 311 ------- packages/swi-minisat2/C/SolverTypes.h | 199 ----- packages/swi-minisat2/C/Sort.h | 93 -- packages/swi-minisat2/C/Vec.h | 133 --- packages/swi-minisat2/C/pl-minisat.C | 175 ---- packages/swi-minisat2/CMakeLists.txt | 18 - packages/swi-minisat2/Makefile.in | 51 -- packages/swi-minisat2/README | 8 - packages/swi-minisat2/README.YAP | 13 - packages/swi-minisat2/cnf.pl | 100 --- packages/swi-minisat2/examples/adder.pl | 23 - .../swi-minisat2/examples/pearl_examples.pl | 54 -- packages/swi-minisat2/minisat.pl | 361 -------- 23 files changed, 2 insertions(+), 3150 deletions(-) delete mode 100644 packages/swi-minisat2/C/Alg.h delete mode 100644 packages/swi-minisat2/C/BasicHeap.h delete mode 100644 packages/swi-minisat2/C/BoxedVec.h delete mode 100644 packages/swi-minisat2/C/CMakeLists.txt delete mode 100644 packages/swi-minisat2/C/Heap.h delete mode 100644 packages/swi-minisat2/C/Makefile.in delete mode 100644 packages/swi-minisat2/C/Map.h delete mode 100644 packages/swi-minisat2/C/Queue.h delete mode 100644 packages/swi-minisat2/C/Solver.C delete mode 100644 packages/swi-minisat2/C/Solver.h delete mode 100644 packages/swi-minisat2/C/SolverTypes.h delete mode 100644 packages/swi-minisat2/C/Sort.h delete mode 100644 packages/swi-minisat2/C/Vec.h delete mode 100644 packages/swi-minisat2/C/pl-minisat.C delete mode 100644 packages/swi-minisat2/CMakeLists.txt delete mode 100644 packages/swi-minisat2/Makefile.in delete mode 100644 packages/swi-minisat2/README delete mode 100644 packages/swi-minisat2/README.YAP delete mode 100644 packages/swi-minisat2/cnf.pl delete mode 100644 packages/swi-minisat2/examples/adder.pl delete mode 100644 packages/swi-minisat2/examples/pearl_examples.pl delete mode 100644 packages/swi-minisat2/minisat.pl diff --git a/packages/real/yap4r/src/Makevars.in b/packages/real/yap4r/src/Makevars.in index 18c55bee1..c22fda795 100644 --- a/packages/real/yap4r/src/Makevars.in +++ b/packages/real/yap4r/src/Makevars.in @@ -1,5 +1,5 @@ -PKG_LIBS=-Wl,-rpath=${YAP_LIBDIR} -Wl,-rpath=${YAP_DLLDIR} \ - -L${YAP_LIBDIR} -L${YAP_DLLDIR} -lreal -lYAP++ -lYap +PKG_LIBS=${CMAKE_SHARED_LINKER_FLAGS} #-Wl,-rpath=${YAP_LIBDIR} -Wl,-rpath=${YAP_DLLDIR} \ + #-L${YAP_LIBDIR} -L${YAP_DLLDIR} -lreal -lYAP++ -lYap PKG_CXXFLAGS=-I${YAP_SOURCE_DIR}/CXX -I${YAP_BINARY_DIR}\ -I${YAP_SOURCE_DIR}/include -I${YAP_SOURCE_DIR}/H\ -I${YAP_SOURCE_DIR}/OPTYap -I${YAP_SOURCE_DIR}/os\ diff --git a/packages/swi-minisat2/C/Alg.h b/packages/swi-minisat2/C/Alg.h deleted file mode 100644 index 240962dfc..000000000 --- a/packages/swi-minisat2/C/Alg.h +++ /dev/null @@ -1,57 +0,0 @@ -/*******************************************************************************************[Alg.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef Alg_h -#define Alg_h - -//================================================================================================= -// Useful functions on vectors - - -#if 1 -template -static inline void remove(V& ts, const T& t) -{ - int j = 0; - for (; j < ts.size() && ts[j] != t; j++); - assert(j < ts.size()); - for (; j < ts.size()-1; j++) ts[j] = ts[j+1]; - ts.pop(); -} -#else -template -static inline void remove(V& ts, const T& t) -{ - int j = 0; - for (; j < ts.size() && ts[j] != t; j++); - assert(j < ts.size()); - ts[j] = ts.last(); - ts.pop(); -} -#endif - -template -static inline bool find(V& ts, const T& t) -{ - int j = 0; - for (; j < ts.size() && ts[j] != t; j++); - return j < ts.size(); -} - -#endif diff --git a/packages/swi-minisat2/C/BasicHeap.h b/packages/swi-minisat2/C/BasicHeap.h deleted file mode 100644 index 556d98f84..000000000 --- a/packages/swi-minisat2/C/BasicHeap.h +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************************[Heap.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef BasicHeap_h -#define BasicHeap_h - -#include "Vec.h" - -//================================================================================================= -// A heap implementation with support for decrease/increase key. - - -template -class BasicHeap { - Comp lt; - vec heap; // heap of ints - - // Index "traversal" functions - static inline int left (int i) { return i*2+1; } - static inline int right (int i) { return (i+1)*2; } - static inline int parent(int i) { return (i-1) >> 1; } - - inline void percolateUp(int i) - { - int x = heap[i]; - while (i != 0 && lt(x, heap[parent(i)])){ - heap[i] = heap[parent(i)]; - i = parent(i); - } - heap [i] = x; - } - - - inline void percolateDown(int i) - { - int x = heap[i]; - while (left(i) < heap.size()){ - int child = right(i) < heap.size() && lt(heap[right(i)], heap[left(i)]) ? right(i) : left(i); - if (!lt(heap[child], x)) break; - heap[i] = heap[child]; - i = child; - } - heap[i] = x; - } - - - bool heapProperty(int i) { - return i >= heap.size() - || ((i == 0 || !lt(heap[i], heap[parent(i)])) && heapProperty(left(i)) && heapProperty(right(i))); } - - - public: - BasicHeap(const C& c) : comp(c) { } - - int size () const { return heap.size(); } - bool empty () const { return heap.size() == 0; } - int operator[](int index) const { return heap[index+1]; } - void clear (bool dealloc = false) { heap.clear(dealloc); } - void insert (int n) { heap.push(n); percolateUp(heap.size()-1); } - - - int removeMin() { - int r = heap[0]; - heap[0] = heap.last(); - heap.pop(); - if (heap.size() > 1) percolateDown(0); - return r; - } - - - // DEBUG: consistency checking - bool heapProperty() { - return heapProperty(1); } - - - // COMPAT: should be removed - int getmin () { return removeMin(); } -}; - - -//================================================================================================= -#endif diff --git a/packages/swi-minisat2/C/BoxedVec.h b/packages/swi-minisat2/C/BoxedVec.h deleted file mode 100644 index bddf41008..000000000 --- a/packages/swi-minisat2/C/BoxedVec.h +++ /dev/null @@ -1,147 +0,0 @@ -/*******************************************************************************************[Vec.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef BoxedVec_h -#define BoxedVec_h - -#include -#include -#include - -//================================================================================================= -// Automatically resizable arrays -// -// NOTE! Don't use this vector on datatypes that cannot be re-located in memory (with realloc) - -template -class bvec { - - static inline int imin(int x, int y) { - int mask = (x-y) >> (sizeof(int)*8-1); - return (x&mask) + (y&(~mask)); } - - static inline int imax(int x, int y) { - int mask = (y-x) >> (sizeof(int)*8-1); - return (x&mask) + (y&(~mask)); } - - struct Vec_t { - int sz; - int cap; - T data[0]; - - static Vec_t* alloc(Vec_t* x, int size){ - x = (Vec_t*)realloc((void*)x, sizeof(Vec_t) + sizeof(T)*size); - x->cap = size; - return x; - } - - }; - - Vec_t* ref; - - static const int init_size = 2; - static int nextSize (int current) { return (current * 3 + 1) >> 1; } - static int fitSize (int needed) { int x; for (x = init_size; needed > x; x = nextSize(x)); return x; } - - void fill (int size) { - assert(ref != NULL); - for (T* i = ref->data; i < ref->data + size; i++) - new (i) T(); - } - - void fill (int size, const T& pad) { - assert(ref != NULL); - for (T* i = ref->data; i < ref->data + size; i++) - new (i) T(pad); - } - - // Don't allow copying (error prone): - altvec& operator = (altvec& other) { assert(0); } - altvec (altvec& other) { assert(0); } - -public: - void clear (bool dealloc = false) { - if (ref != NULL){ - for (int i = 0; i < ref->sz; i++) - (*ref).data[i].~T(); - - if (dealloc) { - free(ref); ref = NULL; - }else - ref->sz = 0; - } - } - - // Constructors: - altvec(void) : ref (NULL) { } - altvec(int size) : ref (Vec_t::alloc(NULL, fitSize(size))) { fill(size); ref->sz = size; } - altvec(int size, const T& pad) : ref (Vec_t::alloc(NULL, fitSize(size))) { fill(size, pad); ref->sz = size; } - ~altvec(void) { clear(true); } - - // Ownership of underlying array: - operator T* (void) { return ref->data; } // (unsafe but convenient) - operator const T* (void) const { return ref->data; } - - // Size operations: - int size (void) const { return ref != NULL ? ref->sz : 0; } - - void pop (void) { assert(ref != NULL && ref->sz > 0); int last = --ref->sz; ref->data[last].~T(); } - void push (const T& elem) { - int size = ref != NULL ? ref->sz : 0; - int cap = ref != NULL ? ref->cap : 0; - if (size == cap){ - cap = cap != 0 ? nextSize(cap) : init_size; - ref = Vec_t::alloc(ref, cap); - } - //new (&ref->data[size]) T(elem); - ref->data[size] = elem; - ref->sz = size+1; - } - - void push () { - int size = ref != NULL ? ref->sz : 0; - int cap = ref != NULL ? ref->cap : 0; - if (size == cap){ - cap = cap != 0 ? nextSize(cap) : init_size; - ref = Vec_t::alloc(ref, cap); - } - new (&ref->data[size]) T(); - ref->sz = size+1; - } - - void shrink (int nelems) { for (int i = 0; i < nelems; i++) pop(); } - void shrink_(int nelems) { for (int i = 0; i < nelems; i++) pop(); } - void growTo (int size) { while (this->size() < size) push(); } - void growTo (int size, const T& pad) { while (this->size() < size) push(pad); } - void capacity (int size) { growTo(size); } - - const T& last (void) const { return ref->data[ref->sz-1]; } - T& last (void) { return ref->data[ref->sz-1]; } - - // Vector interface: - const T& operator [] (int index) const { return ref->data[index]; } - T& operator [] (int index) { return ref->data[index]; } - - void copyTo(altvec& copy) const { copy.clear(); for (int i = 0; i < size(); i++) copy.push(ref->data[i]); } - void moveTo(altvec& dest) { dest.clear(true); dest.ref = ref; ref = NULL; } - -}; - - -#endif diff --git a/packages/swi-minisat2/C/CMakeLists.txt b/packages/swi-minisat2/C/CMakeLists.txt deleted file mode 100644 index 455a145d3..000000000 --- a/packages/swi-minisat2/C/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ - -#cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) - - set ( MINISAT2_HEADERS -Alg.h -BasicHeap.h -BoxedVec.h -Heap.h -Map.h -Queue.h -Solver.h -SolverTypes.h -Sort.h -Vec.h -) - -set ( MINISAT2_SOURCES -Solver.C -pl-minisat.C -) - - - INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_SOURCE_DIR} - ) - - add_library(minisat2 ${MINISAT2_SOURCES} ${MINISAT2_HEADERS} ) - - set_target_properties (minisat2 PROPERTIES OUTPUT_NAME pl-minisat) - set_target_properties (minisat2 PROPERTIES PREFIX "") - - - if(DEFINED YAP_MAJOR_VERSION) - TARGET_LINK_LIBRARIES(minisat2 - libYap - ) - else() - ADD_LIBRARY(minisat2 SHARED ${MINISAT2_SOURCES} ) - endif() - - #set_property(TARGET minisat2 PROPERTY CXX_STANDARD 11) - #set_property(TARGET minisat2 PROPERTY CXX_STANDARD_REQUIRED ON) - - install ( - TARGETS minisat2 - RUNTIME DESTINATION ${CMAKE_INSTALL_BIINDIR} - ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR} - LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR} - ) - - diff --git a/packages/swi-minisat2/C/Heap.h b/packages/swi-minisat2/C/Heap.h deleted file mode 100644 index b07ccd152..000000000 --- a/packages/swi-minisat2/C/Heap.h +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************************[Heap.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef Heap_h -#define Heap_h - -#include "Vec.h" - -//================================================================================================= -// A heap implementation with support for decrease/increase key. - - -template -class Heap { - Comp lt; - vec heap; // heap of ints - vec indices; // int -> index in heap - - // Index "traversal" functions - static inline int left (int i) { return i*2+1; } - static inline int right (int i) { return (i+1)*2; } - static inline int parent(int i) { return (i-1) >> 1; } - - - inline void percolateUp(int i) - { - int x = heap[i]; - while (i != 0 && lt(x, heap[parent(i)])){ - heap[i] = heap[parent(i)]; - indices[heap[i]] = i; - i = parent(i); - } - heap [i] = x; - indices[x] = i; - } - - - inline void percolateDown(int i) - { - int x = heap[i]; - while (left(i) < heap.size()){ - int child = right(i) < heap.size() && lt(heap[right(i)], heap[left(i)]) ? right(i) : left(i); - if (!lt(heap[child], x)) break; - heap[i] = heap[child]; - indices[heap[i]] = i; - i = child; - } - heap [i] = x; - indices[x] = i; - } - - - bool heapProperty (int i) const { - return i >= heap.size() - || ((i == 0 || !lt(heap[i], heap[parent(i)])) && heapProperty(left(i)) && heapProperty(right(i))); } - - - public: - Heap(const Comp& c) : lt(c) { } - - int size () const { return heap.size(); } - bool empty () const { return heap.size() == 0; } - bool inHeap (int n) const { return n < indices.size() && indices[n] >= 0; } - int operator[](int index) const { assert(index < heap.size()); return heap[index]; } - - void decrease (int n) { assert(inHeap(n)); percolateUp(indices[n]); } - - // RENAME WHEN THE DEPRECATED INCREASE IS REMOVED. - void increase_ (int n) { assert(inHeap(n)); percolateDown(indices[n]); } - - - void insert(int n) - { - indices.growTo(n+1, -1); - assert(!inHeap(n)); - - indices[n] = heap.size(); - heap.push(n); - percolateUp(indices[n]); - } - - - int removeMin() - { - int x = heap[0]; - heap[0] = heap.last(); - indices[heap[0]] = 0; - indices[x] = -1; - heap.pop(); - if (heap.size() > 1) percolateDown(0); - return x; - } - - - void clear(bool dealloc = false) - { - for (int i = 0; i < heap.size(); i++) - indices[heap[i]] = -1; -#ifdef NDEBUG - for (int i = 0; i < indices.size(); i++) - assert(indices[i] == -1); -#endif - heap.clear(dealloc); - } - - - // Fool proof variant of insert/decrease/increase - void update (int n) - { - if (!inHeap(n)) - insert(n); - else { - percolateUp(indices[n]); - percolateDown(indices[n]); - } - } - - - // Delete elements from the heap using a given filter function (-object). - // *** this could probaly be replaced with a more general "buildHeap(vec&)" method *** - template - void filter(const F& filt) { - int i,j; - for (i = j = 0; i < heap.size(); i++) - if (filt(heap[i])){ - heap[j] = heap[i]; - indices[heap[i]] = j++; - }else - indices[heap[i]] = -1; - - heap.shrink(i - j); - for (int i = heap.size() / 2 - 1; i >= 0; i--) - percolateDown(i); - - assert(heapProperty()); - } - - - // DEBUG: consistency checking - bool heapProperty() const { - return heapProperty(1); } - - - // COMPAT: should be removed - void setBounds (int n) { } - void increase (int n) { decrease(n); } - int getmin () { return removeMin(); } - -}; - - -//================================================================================================= -#endif diff --git a/packages/swi-minisat2/C/Makefile.in b/packages/swi-minisat2/C/Makefile.in deleted file mode 100644 index 7469cadb2..000000000 --- a/packages/swi-minisat2/C/Makefile.in +++ /dev/null @@ -1,96 +0,0 @@ -# -# default base directory for YAP installation -# (EROOT for architecture-dependent files) -# -GCC=@GCC@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ -ROOTDIR = $(prefix) -EROOTDIR = @exec_prefix@ -abs_top_builddir = @abs_top_builddir@ -# -# where the binary should be -# -BINDIR = $(EROOTDIR)/bin -# -# where YAP should look for libraries -# -LIBDIR=@libdir@ -YAPLIBDIR=@libdir@/Yap -# -# -DEFS=@DEFS@ -D_YAP_NOT_INSTALLED_=1 -CC=@CC@ -CXX=@CXX@ -CXXFLAGS= @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../../.. -I$(srcdir)/../../../os -I$(srcdir)/../../../include @CPPFLAGS@ -LDFLAGS=@LDFLAGS@ -# -# -# You shouldn't need to change what follows. -# -INSTALL=@INSTALL@ -INSTALL_DATA=@INSTALL_DATA@ -INSTALL_PROGRAM=@INSTALL_PROGRAM@ -SHELL=/bin/sh -RANLIB=@RANLIB@ -srcdir=@srcdir@ -SO=@SO@ -#4.1VPATH=@srcdir@:@srcdir@/OPTYap -CWD=$(PWD) -# - -HEADERS= \ - $(srcdir)/Alg.h \ - $(srcdir)/BasicHeap.h \ - $(srcdir)/BoxedVec.h \ - $(srcdir)/Heap.h \ - $(srcdir)/Map.h \ - $(srcdir)/Queue.h \ - $(srcdir)/Solver.h \ - $(srcdir)/SolverTypes.h \ - $(srcdir)/Sort.h \ - $(srcdir)/Vec.h -C_SOURCES=$(srcdir)/pl-minisat.C $(srcdir)/Solver.C - -OBJS = \ - Solver.o \ - pl-minisat.o - -SOBJS=pl-minisat.@SO@ - -#in some systems we just create a single object, in others we need to -# create a libray - -all: $(SOBJS) - -# default rule -Solver.o : $(srcdir)/Solver.C - $(CXX) -c $(CXXFLAGS) $(srcdir)/Solver.C -o Solver.o - -pl-minisat.o : $(srcdir)/pl-minisat.C - $(CXX) -c $(CXXFLAGS) $(srcdir)/pl-minisat.C -o pl-minisat.o - -@DO_SECOND_LD@pl-minisat.@SO@: $(OBJS) -@DO_SECOND_LD@ @SHLIB_CXX_LD@ $(LDFLAGS) -o pl-minisat.@SO@ $(OBJS) @EXTRA_LIBS_FOR_SWIDLLS@ - -install: all - $(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(YAPLIBDIR) - -install-examples: - -clean: - rm -f *.o *~ $(OBJS) $(SOBJS) *.BAK - -distclean: - rm -f Makefile $(OBJS) - - -depend: $(HEADERS) $(C_SOURCES) - -@if test "$(GCC)" = yes; then\ - $(CC) -MM -MG $(CFLAGS) -I$(srcdir) -I$(srcdir)/../../../include -I$(srcdir)/../../../H $(C_SOURCES) >> Makefile;\ - else\ - makedepend -f - -- $(CFLAGS) -I$(srcdir)/../../../H -I$(srcdir)/../../../include -- $(C_SOURCES) |\ - sed 's|.*/\([^:]*\):|\1:|' >> Makefile ;\ - fi - -# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/packages/swi-minisat2/C/Map.h b/packages/swi-minisat2/C/Map.h deleted file mode 100644 index b6d76a31c..000000000 --- a/packages/swi-minisat2/C/Map.h +++ /dev/null @@ -1,118 +0,0 @@ -/*******************************************************************************************[Map.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef Map_h -#define Map_h - -#include - -#include "Vec.h" - -//================================================================================================= -// Default hash/equals functions -// - -template struct Hash { uint32_t operator()(const K& k) const { return hash(k); } }; -template struct Equal { bool operator()(const K& k1, const K& k2) const { return k1 == k2; } }; - -template struct DeepHash { uint32_t operator()(const K* k) const { return hash(*k); } }; -template struct DeepEqual { bool operator()(const K* k1, const K* k2) const { return *k1 == *k2; } }; - -//================================================================================================= -// Some primes -// - -static const int nprimes = 25; -static const int primes [nprimes] = { 31, 73, 151, 313, 643, 1291, 2593, 5233, 10501, 21013, 42073, 84181, 168451, 337219, 674701, 1349473, 2699299, 5398891, 10798093, 21596719, 43193641, 86387383, 172775299, 345550609, 691101253 }; - -//================================================================================================= -// Hash table implementation of Maps -// - -template, class E = Equal > -class Map { - struct Pair { K key; D data; }; - - H hash; - E equals; - - vec* table; - int cap; - int size; - - // Don't allow copying (error prone): - Map& operator = (Map& other) { assert(0); } - Map (Map& other) { assert(0); } - - int32_t index (const K& k) const { return hash(k) % cap; } - void _insert (const K& k, const D& d) { table[index(k)].push(); table[index(k)].last().key = k; table[index(k)].last().data = d; } - void rehash () { - const vec* old = table; - - int newsize = primes[0]; - for (int i = 1; newsize <= cap && i < nprimes; i++) - newsize = primes[i]; - - table = new vec[newsize]; - - for (int i = 0; i < cap; i++){ - for (int j = 0; j < old[i].size(); j++){ - _insert(old[i][j].key, old[i][j].data); }} - - delete [] old; - - cap = newsize; - } - - - public: - - Map () : table(NULL), cap(0), size(0) {} - Map (const H& h, const E& e) : Map(), hash(h), equals(e) {} - ~Map () { delete [] table; } - - void insert (const K& k, const D& d) { if (size+1 > cap / 2) rehash(); _insert(k, d); size++; } - bool peek (const K& k, D& d) { - if (size == 0) return false; - const vec& ps = table[index(k)]; - for (int i = 0; i < ps.size(); i++) - if (equals(ps[i].key, k)){ - d = ps[i].data; - return true; } - return false; - } - - void remove (const K& k) { - assert(table != NULL); - vec& ps = table[index(k)]; - int j = 0; - for (; j < ps.size() && !equals(ps[j].key, k); j++); - assert(j < ps.size()); - ps[j] = ps.last(); - ps.pop(); - } - - void clear () { - cap = size = 0; - delete [] table; - table = NULL; - } -}; - -#endif diff --git a/packages/swi-minisat2/C/Queue.h b/packages/swi-minisat2/C/Queue.h deleted file mode 100644 index 2cc110ce9..000000000 --- a/packages/swi-minisat2/C/Queue.h +++ /dev/null @@ -1,82 +0,0 @@ -/*****************************************************************************************[Queue.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef Queue_h -#define Queue_h - -#include "Vec.h" - -//================================================================================================= - - -template -class Queue { - vec elems; - int first; - -public: - Queue(void) : first(0) { } - - void insert(T x) { elems.push(x); } - T peek () const { return elems[first]; } - void pop () { first++; } - - void clear(bool dealloc = false) { elems.clear(dealloc); first = 0; } - int size(void) { return elems.size() - first; } - - //bool has(T x) { for (int i = first; i < elems.size(); i++) if (elems[i] == x) return true; return false; } - - const T& operator [] (int index) const { return elems[first + index]; } - -}; - -//template -//class Queue { -// vec buf; -// int first; -// int end; -// -//public: -// typedef T Key; -// -// Queue() : buf(1), first(0), end(0) {} -// -// void clear () { buf.shrinkTo(1); first = end = 0; } -// int size () { return (end >= first) ? end - first : end - first + buf.size(); } -// -// T peek () { assert(first != end); return buf[first]; } -// void pop () { assert(first != end); first++; if (first == buf.size()) first = 0; } -// void insert(T elem) { // INVARIANT: buf[end] is always unused -// buf[end++] = elem; -// if (end == buf.size()) end = 0; -// if (first == end){ // Resize: -// vec tmp((buf.size()*3 + 1) >> 1); -// //**/printf("queue alloc: %d elems (%.1f MB)\n", tmp.size(), tmp.size() * sizeof(T) / 1000000.0); -// int i = 0; -// for (int j = first; j < buf.size(); j++) tmp[i++] = buf[j]; -// for (int j = 0 ; j < end ; j++) tmp[i++] = buf[j]; -// first = 0; -// end = buf.size(); -// tmp.moveTo(buf); -// } -// } -//}; - -//================================================================================================= -#endif diff --git a/packages/swi-minisat2/C/Solver.C b/packages/swi-minisat2/C/Solver.C deleted file mode 100644 index 4b61c6de6..000000000 --- a/packages/swi-minisat2/C/Solver.C +++ /dev/null @@ -1,791 +0,0 @@ -/****************************************************************************************[Solver.C] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#include "Solver.h" -#include "Sort.h" -#include -#include - - -//================================================================================================= -// Constructor/Destructor: - - -Solver::Solver() : - - // Parameters: (formerly in 'SearchParams') - var_decay(1 / 0.95), clause_decay(1 / 0.999), random_var_freq(0.02) - , restart_first(100), restart_inc(1.5), learntsize_factor((double)1/(double)3), learntsize_inc(1.1) - - // More parameters: - // - , expensive_ccmin (true) - , polarity_mode (polarity_false) - , verbosity (0) - - // Statistics: (formerly in 'SolverStats') - // - , starts(0), decisions(0), rnd_decisions(0), propagations(0), conflicts(0) - , clauses_literals(0), learnts_literals(0), max_literals(0), tot_literals(0) - - //*************** - , allMinVarsAssigned(false) - //*************** - - , ok (true) - , cla_inc (1) - , var_inc (1) - , qhead (0) - , simpDB_assigns (-1) - , simpDB_props (0) - , order_heap (VarOrderLt(activity)) - , random_seed (91648253) - , progress_estimate(0) - , remove_satisfied (true) -{} - - -Solver::~Solver() -{ - for (int i = 0; i < learnts.size(); i++) std::free(learnts[i]); - for (int i = 0; i < clauses.size(); i++) std::free(clauses[i]); -} - - -//================================================================================================= -// Minor methods: - - -// Creates a new SAT variable in the solver. If 'decision_var' is cleared, variable will not be -// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result). -// -Var Solver::newVar(bool sign, bool dvar) -{ - int v = nVars(); - watches .push(); // (list for positive literal) - watches .push(); // (list for negative literal) - reason .push(NULL); - assigns .push(toInt(l_Undef)); - level .push(-1); - activity .push(0); - seen .push(0); - - polarity .push((char)sign); - decision_var.push((char)dvar); - - insertVarOrder(v); - return v; -} - - - -bool Solver::addClause(vec& ps) -{ - assert(decisionLevel() == 0); - - if (!ok) - return false; - else{ - // Check if clause is satisfied and remove false/duplicate literals: - sort(ps); - Lit p; int i, j; - for (i = j = 0, p = lit_Undef; i < ps.size(); i++) - if (value(ps[i]) == l_True || ps[i] == ~p) - return true; - else if (value(ps[i]) != l_False && ps[i] != p) - ps[j++] = p = ps[i]; - ps.shrink(i - j); - } - - if (ps.size() == 0) - return ok = false; - else if (ps.size() == 1){ - assert(value(ps[0]) == l_Undef); - uncheckedEnqueue(ps[0]); - return ok = (propagate() == NULL); - }else{ - Clause* c = Clause_new(ps, false); - clauses.push(c); - attachClause(*c); - } - - return true; -} - - -//**************** -bool Solver::setminVars(vec& ps) -{ - minVars.clear(); - for (int i=0; i < ps.size(); i++){ - minVars.push(ps[i]); - } - allMinVarsAssigned = false; - - return true; -} -//**************** - - -void Solver::attachClause(Clause& c) { - assert(c.size() > 1); - watches[toInt(~c[0])].push(&c); - watches[toInt(~c[1])].push(&c); - if (c.learnt()) learnts_literals += c.size(); - else clauses_literals += c.size(); } - - -void Solver::detachClause(Clause& c) { - assert(c.size() > 1); - assert(find(watches[toInt(~c[0])], &c)); - assert(find(watches[toInt(~c[1])], &c)); - remove(watches[toInt(~c[0])], &c); - remove(watches[toInt(~c[1])], &c); - if (c.learnt()) learnts_literals -= c.size(); - else clauses_literals -= c.size(); } - - -void Solver::removeClause(Clause& c) { - detachClause(c); - std::free(&c); } - - -bool Solver::satisfied(const Clause& c) const { - for (int i = 0; i < c.size(); i++) - if (value(c[i]) == l_True) - return true; - return false; } - - -// Revert to the state at given level (keeping all assignment at 'level' but not beyond). -// -void Solver::cancelUntil(int level) { - if (decisionLevel() > level){ - for (int c = trail.size()-1; c >= trail_lim[level]; c--){ - Var x = var(trail[c]); - assigns[x] = toInt(l_Undef); - insertVarOrder(x); } - qhead = trail_lim[level]; - trail.shrink(trail.size() - trail_lim[level]); - trail_lim.shrink(trail_lim.size() - level); - } - - //************************** - if (lastMinVarDL > level){ - allMinVarsAssigned = false; - } - //************************** -} - - -//================================================================================================= -// Major methods: - - -Lit Solver::pickBranchLit(int polarity_mode, double random_var_freq) -{ - Var next = var_Undef; - - // Random decision: - if (drand(random_seed) < random_var_freq && !order_heap.empty()){ - next = order_heap[irand(random_seed,order_heap.size())]; - if (toLbool(assigns[next]) == l_Undef && decision_var[next]) - rnd_decisions++; } - - // Activity based decision: - while (next == var_Undef || toLbool(assigns[next]) != l_Undef || !decision_var[next]) - if (order_heap.empty()){ - next = var_Undef; - break; - }else - next = order_heap.removeMin(); - - bool sign = false; - switch (polarity_mode){ - case polarity_true: sign = false; break; - case polarity_false: sign = true; break; - case polarity_user: sign = polarity[next]; break; - case polarity_rnd: sign = irand(random_seed, 2); break; - default: assert(false); } - - return next == var_Undef ? lit_Undef : Lit(next, sign); -} - - -/*_________________________________________________________________________________________________ -| -| analyze : (confl : Clause*) (out_learnt : vec&) (out_btlevel : int&) -> [void] -| -| Description: -| Analyze conflict and produce a reason clause. -| -| Pre-conditions: -| * 'out_learnt' is assumed to be cleared. -| * Current decision level must be greater than root level. -| -| Post-conditions: -| * 'out_learnt[0]' is the asserting literal at level 'out_btlevel'. -| -| Effect: -| Will undo part of the trail, upto but not beyond the assumption of the current decision level. -|________________________________________________________________________________________________@*/ -void Solver::analyze(Clause* confl, vec& out_learnt, int& out_btlevel) -{ - int pathC = 0; - Lit p = lit_Undef; - - // Generate conflict clause: - // - out_learnt.push(); // (leave room for the asserting literal) - int index = trail.size() - 1; - out_btlevel = 0; - - do{ - assert(confl != NULL); // (otherwise should be UIP) - Clause& c = *confl; - - if (c.learnt()) - claBumpActivity(c); - - for (int j = (p == lit_Undef) ? 0 : 1; j < c.size(); j++){ - Lit q = c[j]; - - if (!seen[var(q)] && level[var(q)] > 0){ - varBumpActivity(var(q)); - seen[var(q)] = 1; - if (level[var(q)] >= decisionLevel()) - pathC++; - else{ - out_learnt.push(q); - if (level[var(q)] > out_btlevel) - out_btlevel = level[var(q)]; - } - } - } - - // Select next clause to look at: - while (!seen[var(trail[index--])]); - p = trail[index+1]; - confl = reason[var(p)]; - seen[var(p)] = 0; - pathC--; - - }while (pathC > 0); - out_learnt[0] = ~p; - - // Simplify conflict clause: - // - int i, j; - if (expensive_ccmin){ - uint32_t abstract_level = 0; - for (i = 1; i < out_learnt.size(); i++) - abstract_level |= abstractLevel(var(out_learnt[i])); // (maintain an abstraction of levels involved in conflict) - - out_learnt.copyTo(analyze_toclear); - for (i = j = 1; i < out_learnt.size(); i++) - if (reason[var(out_learnt[i])] == NULL || !litRedundant(out_learnt[i], abstract_level)) - out_learnt[j++] = out_learnt[i]; - }else{ - out_learnt.copyTo(analyze_toclear); - for (i = j = 1; i < out_learnt.size(); i++){ - Clause& c = *reason[var(out_learnt[i])]; - for (int k = 1; k < c.size(); k++) - if (!seen[var(c[k])] && level[var(c[k])] > 0){ - out_learnt[j++] = out_learnt[i]; - break; } - } - } - max_literals += out_learnt.size(); - out_learnt.shrink(i - j); - tot_literals += out_learnt.size(); - - // Find correct backtrack level: - // - if (out_learnt.size() == 1) - out_btlevel = 0; - else{ - int max_i = 1; - for (int i = 2; i < out_learnt.size(); i++) - if (level[var(out_learnt[i])] > level[var(out_learnt[max_i])]) - max_i = i; - Lit p = out_learnt[max_i]; - out_learnt[max_i] = out_learnt[1]; - out_learnt[1] = p; - out_btlevel = level[var(p)]; - } - - - for (int j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0; // ('seen[]' is now cleared) -} - - -// Check if 'p' can be removed. 'abstract_levels' is used to abort early if the algorithm is -// visiting literals at levels that cannot be removed later. -bool Solver::litRedundant(Lit p, uint32_t abstract_levels) -{ - analyze_stack.clear(); analyze_stack.push(p); - int top = analyze_toclear.size(); - while (analyze_stack.size() > 0){ - assert(reason[var(analyze_stack.last())] != NULL); - Clause& c = *reason[var(analyze_stack.last())]; analyze_stack.pop(); - - for (int i = 1; i < c.size(); i++){ - Lit p = c[i]; - if (!seen[var(p)] && level[var(p)] > 0){ - if (reason[var(p)] != NULL && (abstractLevel(var(p)) & abstract_levels) != 0){ - seen[var(p)] = 1; - analyze_stack.push(p); - analyze_toclear.push(p); - }else{ - for (int j = top; j < analyze_toclear.size(); j++) - seen[var(analyze_toclear[j])] = 0; - analyze_toclear.shrink(analyze_toclear.size() - top); - return false; - } - } - } - } - - return true; -} - - -/*_________________________________________________________________________________________________ -| -| analyzeFinal : (p : Lit) -> [void] -| -| Description: -| Specialized analysis procedure to express the final conflict in terms of assumptions. -| Calculates the (possibly empty) set of assumptions that led to the assignment of 'p', and -| stores the result in 'out_conflict'. -|________________________________________________________________________________________________@*/ -void Solver::analyzeFinal(Lit p, vec& out_conflict) -{ - out_conflict.clear(); - out_conflict.push(p); - - if (decisionLevel() == 0) - return; - - seen[var(p)] = 1; - - for (int i = trail.size()-1; i >= trail_lim[0]; i--){ - Var x = var(trail[i]); - if (seen[x]){ - if (reason[x] == NULL){ - assert(level[x] > 0); - out_conflict.push(~trail[i]); - }else{ - Clause& c = *reason[x]; - for (int j = 1; j < c.size(); j++) - if (level[var(c[j])] > 0) - seen[var(c[j])] = 1; - } - seen[x] = 0; - } - } - - seen[var(p)] = 0; -} - - -void Solver::uncheckedEnqueue(Lit p, Clause* from) -{ - assert(value(p) == l_Undef); - assigns [var(p)] = toInt(lbool(!sign(p))); // <<== abstract but not uttermost effecient - level [var(p)] = decisionLevel(); - reason [var(p)] = from; - trail.push(p); -} - - -/*_________________________________________________________________________________________________ -| -| propagate : [void] -> [Clause*] -| -| Description: -| Propagates all enqueued facts. If a conflict arises, the conflicting clause is returned, -| otherwise NULL. -| -| Post-conditions: -| * the propagation queue is empty, even if there was a conflict. -|________________________________________________________________________________________________@*/ -Clause* Solver::propagate() -{ - Clause* confl = NULL; - int num_props = 0; - - while (qhead < trail.size()){ - Lit p = trail[qhead++]; // 'p' is enqueued fact to propagate. - vec& ws = watches[toInt(p)]; - Clause **i, **j, **end; - num_props++; - - for (i = j = (Clause**)ws, end = i + ws.size(); i != end;){ - Clause& c = **i++; - - // Make sure the false literal is data[1]: - Lit false_lit = ~p; - if (c[0] == false_lit) - c[0] = c[1], c[1] = false_lit; - - assert(c[1] == false_lit); - - // If 0th watch is true, then clause is already satisfied. - Lit first = c[0]; - if (value(first) == l_True){ - *j++ = &c; - }else{ - // Look for new watch: - for (int k = 2; k < c.size(); k++) - if (value(c[k]) != l_False){ - c[1] = c[k]; c[k] = false_lit; - watches[toInt(~c[1])].push(&c); - goto FoundWatch; } - - // Did not find watch -- clause is unit under assignment: - *j++ = &c; - if (value(first) == l_False){ - confl = &c; - qhead = trail.size(); - // Copy the remaining watches: - while (i < end) - *j++ = *i++; - }else - uncheckedEnqueue(first, &c); - } - FoundWatch:; - } - ws.shrink(i - j); - } - propagations += num_props; - simpDB_props -= num_props; - - return confl; -} - -/*_________________________________________________________________________________________________ -| -| reduceDB : () -> [void] -| -| Description: -| Remove half of the learnt clauses, minus the clauses locked by the current assignment. Locked -| clauses are clauses that are reason to some assignment. Binary clauses are never removed. -|________________________________________________________________________________________________@*/ -struct reduceDB_lt { bool operator () (Clause* x, Clause* y) { return x->size() > 2 && (y->size() == 2 || x->activity() < y->activity()); } }; -void Solver::reduceDB() -{ - int i, j; - double extra_lim = cla_inc / learnts.size(); // Remove any clause below this activity - - sort(learnts, reduceDB_lt()); - for (i = j = 0; i < learnts.size() / 2; i++){ - if (learnts[i]->size() > 2 && !locked(*learnts[i])) - removeClause(*learnts[i]); - else - learnts[j++] = learnts[i]; - } - for (; i < learnts.size(); i++){ - if (learnts[i]->size() > 2 && !locked(*learnts[i]) && learnts[i]->activity() < extra_lim) - removeClause(*learnts[i]); - else - learnts[j++] = learnts[i]; - } - learnts.shrink(i - j); -} - - -void Solver::removeSatisfied(vec& cs) -{ - int i,j; - for (i = j = 0; i < cs.size(); i++){ - if (satisfied(*cs[i])) - removeClause(*cs[i]); - else - cs[j++] = cs[i]; - } - cs.shrink(i - j); -} - - -/*_________________________________________________________________________________________________ -| -| simplify : [void] -> [bool] -| -| Description: -| Simplify the clause database according to the current top-level assigment. Currently, the only -| thing done here is the removal of satisfied clauses, but more things can be put here. -|________________________________________________________________________________________________@*/ -bool Solver::simplify() -{ - assert(decisionLevel() == 0); - - if (!ok || propagate() != NULL) - return ok = false; - - if (nAssigns() == simpDB_assigns || (simpDB_props > 0)) - return true; - - // Remove satisfied clauses: - removeSatisfied(learnts); - if (remove_satisfied) // Can be turned off. - removeSatisfied(clauses); - - // Remove fixed variables from the variable heap: - order_heap.filter(VarFilter(*this)); - - simpDB_assigns = nAssigns(); - simpDB_props = clauses_literals + learnts_literals; // (shouldn't depend on stats really, but it will do for now) - - return true; -} - - -/*_________________________________________________________________________________________________ -| -| search : (nof_conflicts : int) (nof_learnts : int) (params : const SearchParams&) -> [lbool] -| -| Description: -| Search for a model the specified number of conflicts, keeping the number of learnt clauses -| below the provided limit. NOTE! Use negative value for 'nof_conflicts' or 'nof_learnts' to -| indicate infinity. -| -| Output: -| 'l_True' if a partial assigment that is consistent with respect to the clauseset is found. If -| all variables are decision variables, this means that the clause set is satisfiable. 'l_False' -| if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached. -|________________________________________________________________________________________________@*/ -lbool Solver::search(int nof_conflicts, int nof_learnts) -{ - assert(ok); - int backtrack_level; - int conflictC = 0; - vec learnt_clause; - - starts++; - - // bool first = true; - - for (;;){ - Clause* confl = propagate(); - if (confl != NULL){ - // CONFLICT - conflicts++; conflictC++; - if (decisionLevel() == 0) return l_False; - - // first = false; - - learnt_clause.clear(); - analyze(confl, learnt_clause, backtrack_level); - cancelUntil(backtrack_level); - assert(value(learnt_clause[0]) == l_Undef); - - if (learnt_clause.size() == 1){ - uncheckedEnqueue(learnt_clause[0]); - }else{ - Clause* c = Clause_new(learnt_clause, true); - learnts.push(c); - attachClause(*c); - claBumpActivity(*c); - uncheckedEnqueue(learnt_clause[0], c); - } - - varDecayActivity(); - claDecayActivity(); - - }else{ - // NO CONFLICT - - if (nof_conflicts >= 0 && conflictC >= nof_conflicts){ - // Reached bound on number of conflicts: - progress_estimate = progressEstimate(); - cancelUntil(0); - return l_Undef; } - - // Simplify the set of problem clauses: - if (decisionLevel() == 0 && !simplify()) - return l_False; - - if (nof_learnts >= 0 && learnts.size()-nAssigns() >= nof_learnts) - // Reduce the set of learnt clauses: - reduceDB(); - - Lit next = lit_Undef; - while (decisionLevel() < assumptions.size()){ - // Perform user provided assumption: - Lit p = assumptions[decisionLevel()]; - if (value(p) == l_True){ - // Dummy decision level: - newDecisionLevel(); - }else if (value(p) == l_False){ - analyzeFinal(~p, conflict); - return l_False; - }else{ - next = p; - break; - } - } - - - //************************** - if (next == lit_Undef){ - // New variable decision: - decisions++; - - if (!allMinVarsAssigned){ - for (int i=0; i& assumps) -{ - model.clear(); - conflict.clear(); - - allMinVarsAssigned = false; - - if (!ok) return false; - - assumps.copyTo(assumptions); - - double nof_conflicts = restart_first; - double nof_learnts = nClauses() * learntsize_factor; - lbool status = l_Undef; - - if (verbosity >= 1){ - reportf("============================[ Search Statistics ]==============================\n"); - reportf("| Conflicts | ORIGINAL | LEARNT | Progress |\n"); - reportf("| | Vars Clauses Literals | Limit Clauses Lit/Cl | |\n"); - reportf("===============================================================================\n"); - } - - // Search: - while (status == l_Undef){ - if (verbosity >= 1) - reportf("| %9d | %7d %8d %8d | %8d %8d %6.0f | %6.3f %% |\n", (int)conflicts, order_heap.size(), nClauses(), (int)clauses_literals, (int)nof_learnts, nLearnts(), (double)learnts_literals/nLearnts(), progress_estimate*100), fflush(stdout); - status = search((int)nof_conflicts, (int)nof_learnts); - nof_conflicts *= restart_inc; - nof_learnts *= learntsize_inc; - } - - if (verbosity >= 1) - reportf("===============================================================================\n"); - - - if (status == l_True){ - // Extend & copy model: - model.growTo(nVars()); - for (int i = 0; i < nVars(); i++) model[i] = value(i); -#ifndef NDEBUG - verifyModel(); -#endif - }else{ - assert(status == l_False); - if (conflict.size() == 0) - ok = false; - } - - cancelUntil(0); - return status == l_True; -} - - - - -void Solver::verifyModel() -{ - bool failed = false; - for (int i = 0; i < clauses.size(); i++){ - assert(clauses[i]->mark() == 0); - Clause& c = *clauses[i]; - for (int j = 0; j < c.size(); j++) - if (modelValue(c[j]) == l_True) - goto next; - - reportf("unsatisfied clause: "); - printClause(*clauses[i]); - reportf("\n"); - failed = true; - next:; - } - - assert(!failed); - - // reportf("Verified %d original clauses.\n", clauses.size()); -} - - -void Solver::checkLiteralCount() -{ - // Check that sizes are calculated correctly: - int cnt = 0; - for (int i = 0; i < clauses.size(); i++) - if (clauses[i]->mark() == 0) - cnt += clauses[i]->size(); - - if ((int)clauses_literals != cnt){ - fprintf(stderr, "literal count: %d, real value = %d\n", (int)clauses_literals, cnt); - assert((int)clauses_literals == cnt); - } -} diff --git a/packages/swi-minisat2/C/Solver.h b/packages/swi-minisat2/C/Solver.h deleted file mode 100644 index fc41a7e0b..000000000 --- a/packages/swi-minisat2/C/Solver.h +++ /dev/null @@ -1,311 +0,0 @@ -/****************************************************************************************[Solver.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef Solver_h -#define Solver_h - -#include - -#include "Vec.h" -#include "Heap.h" -#include "Alg.h" - -#include "SolverTypes.h" - - -//================================================================================================= -// Solver -- the main class: - - -class Solver { -public: - - // Constructor/Destructor: - // - Solver(); - ~Solver(); - - // Problem specification: - // - Var newVar (bool polarity = true, bool dvar = true); // Add a new variable with parameters specifying variable mode. - bool addClause (vec& ps); // Add a clause to the solver. NOTE! 'ps' may be shrunk by this method! - bool setminVars(vec& ps); - - // Solving: - // - bool simplify (); // Removes already satisfied clauses. - bool solve (const vec& assumps); // Search for a model that respects a given set of assumptions. - bool solve (); // Search without assumptions. - bool okay () const; // FALSE means solver is in a conflicting state - - // Variable mode: - // - void setPolarity (Var v, bool b); // Declare which polarity the decision heuristic should use for a variable. Requires mode 'polarity_user'. - void setDecisionVar (Var v, bool b); // Declare if a variable should be eligible for selection in the decision heuristic. - - // Read state: - // - lbool value (Var x) const; // The current value of a variable. - lbool value (Lit p) const; // The current value of a literal. - lbool modelValue (Lit p) const; // The value of a literal in the last model. The last call to solve must have been satisfiable. - int nAssigns () const; // The current number of assigned literals. - int nClauses () const; // The current number of original clauses. - int nLearnts () const; // The current number of learnt clauses. - int nVars () const; // The current number of variables. - - // Extra results: (read-only member variable) - // - vec model; // If problem is satisfiable, this vector contains the model (if any). - vec conflict; // If problem is unsatisfiable (possibly under assumptions), - // this vector represent the final conflict clause expressed in the assumptions. - - // Mode of operation: - // - double var_decay; // Inverse of the variable activity decay factor. (default 1 / 0.95) - double clause_decay; // Inverse of the clause activity decay factor. (1 / 0.999) - double random_var_freq; // The frequency with which the decision heuristic tries to choose a random variable. (default 0.02) - int restart_first; // The initial restart limit. (default 100) - double restart_inc; // The factor with which the restart limit is multiplied in each restart. (default 1.5) - double learntsize_factor; // The intitial limit for learnt clauses is a factor of the original clauses. (default 1 / 3) - double learntsize_inc; // The limit for learnt clauses is multiplied with this factor each restart. (default 1.1) - bool expensive_ccmin; // Controls conflict clause minimization. (default TRUE) - int polarity_mode; // Controls which polarity the decision heuristic chooses. See enum below for allowed modes. (default polarity_false) - int verbosity; // Verbosity level. 0=silent, 1=some progress report (default 0) - - enum { polarity_true = 0, polarity_false = 1, polarity_user = 2, polarity_rnd = 3 }; - - // Statistics: (read-only member variable) - // - uint64_t starts, decisions, rnd_decisions, propagations, conflicts; - uint64_t clauses_literals, learnts_literals, max_literals, tot_literals; - -protected: - - // Helper structures: - // - struct VarOrderLt { - const vec& activity; - bool operator () (Var x, Var y) const { return activity[x] > activity[y]; } - VarOrderLt(const vec& act) : activity(act) { } - }; - - friend class VarFilter; - struct VarFilter { - const Solver& s; - VarFilter(const Solver& _s) : s(_s) {} - bool operator()(Var v) const { return toLbool(s.assigns[v]) == l_Undef && s.decision_var[v]; } - }; - - // Solver state: - // - - //**************** - bool allMinVarsAssigned; - int lastMinVarDL; - vec minVars; - //**************** - - - bool ok; // If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used! - vec clauses; // List of problem clauses. - vec learnts; // List of learnt clauses. - double cla_inc; // Amount to bump next clause with. - vec activity; // A heuristic measurement of the activity of a variable. - double var_inc; // Amount to bump next variable with. - vec > watches; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true). - vec assigns; // The current assignments (lbool:s stored as char:s). - vec polarity; // The preferred polarity of each variable. - vec decision_var; // Declares if a variable is eligible for selection in the decision heuristic. - vec trail; // Assignment stack; stores all assigments made in the order they were made. - vec trail_lim; // Separator indices for different decision levels in 'trail'. - vec reason; // 'reason[var]' is the clause that implied the variables current value, or 'NULL' if none. - vec level; // 'level[var]' contains the level at which the assignment was made. - int qhead; // Head of queue (as index into the trail -- no more explicit propagation queue in MiniSat). - int simpDB_assigns; // Number of top-level assignments since last execution of 'simplify()'. - int64_t simpDB_props; // Remaining number of propagations that must be made before next execution of 'simplify()'. - vec assumptions; // Current set of assumptions provided to solve by the user. - Heap order_heap; // A priority queue of variables ordered with respect to the variable activity. - double random_seed; // Used by the random variable selection. - double progress_estimate;// Set by 'search()'. - bool remove_satisfied; // Indicates whether possibly inefficient linear scan for satisfied clauses should be performed in 'simplify'. - - // Temporaries (to reduce allocation overhead). Each variable is prefixed by the method in which it is - // used, exept 'seen' wich is used in several places. - // - vec seen; - vec analyze_stack; - vec analyze_toclear; - vec add_tmp; - - // Main internal methods: - // - void insertVarOrder (Var x); // Insert a variable in the decision order priority queue. - Lit pickBranchLit (int polarity_mode, double random_var_freq); // Return the next decision variable. - void newDecisionLevel (); // Begins a new decision level. - void uncheckedEnqueue (Lit p, Clause* from = NULL); // Enqueue a literal. Assumes value of literal is undefined. - bool enqueue (Lit p, Clause* from = NULL); // Test if fact 'p' contradicts current state, enqueue otherwise. - Clause* propagate (); // Perform unit propagation. Returns possibly conflicting clause. - void cancelUntil (int level); // Backtrack until a certain level. - void analyze (Clause* confl, vec& out_learnt, int& out_btlevel); // (bt = backtrack) - void analyzeFinal (Lit p, vec& out_conflict); // COULD THIS BE IMPLEMENTED BY THE ORDINARIY "analyze" BY SOME REASONABLE GENERALIZATION? - bool litRedundant (Lit p, uint32_t abstract_levels); // (helper method for 'analyze()') - lbool search (int nof_conflicts, int nof_learnts); // Search for a given number of conflicts. - void reduceDB (); // Reduce the set of learnt clauses. - void removeSatisfied (vec& cs); // Shrink 'cs' to contain only non-satisfied clauses. - - // Maintaining Variable/Clause activity: - // - void varDecayActivity (); // Decay all variables with the specified factor. Implemented by increasing the 'bump' value instead. - void varBumpActivity (Var v); // Increase a variable with the current 'bump' value. - void claDecayActivity (); // Decay all clauses with the specified factor. Implemented by increasing the 'bump' value instead. - void claBumpActivity (Clause& c); // Increase a clause with the current 'bump' value. - - // Operations on clauses: - // - void attachClause (Clause& c); // Attach a clause to watcher lists. - void detachClause (Clause& c); // Detach a clause to watcher lists. - void removeClause (Clause& c); // Detach and free a clause. - bool locked (const Clause& c) const; // Returns TRUE if a clause is a reason for some implication in the current state. - bool satisfied (const Clause& c) const; // Returns TRUE if a clause is satisfied in the current state. - - // Misc: - // - int decisionLevel () const; // Gives the current decisionlevel. - uint32_t abstractLevel (Var x) const; // Used to represent an abstraction of sets of decision levels. - double progressEstimate () const; // DELETE THIS ?? IT'S NOT VERY USEFUL ... - - // Debug: - void printLit (Lit l); - template - void printClause (const C& c); - void verifyModel (); - void checkLiteralCount(); - - // Static helpers: - // - - // Returns a random float 0 <= x < 1. Seed must never be 0. - static inline double drand(double& seed) { - seed *= 1389796; - int q = (int)(seed / 2147483647); - seed -= (double)q * 2147483647; - return seed / 2147483647; } - - // Returns a random integer 0 <= x < size. Seed must never be 0. - static inline int irand(double& seed, int size) { - return (int)(drand(seed) * size); } -}; - - -//================================================================================================= -// Implementation of inline methods: - - -inline void Solver::insertVarOrder(Var x) { - if (!order_heap.inHeap(x) && decision_var[x]) order_heap.insert(x); } - -inline void Solver::varDecayActivity() { var_inc *= var_decay; } -inline void Solver::varBumpActivity(Var v) { - if ( (activity[v] += var_inc) > 1e100 ) { - // Rescale: - for (int i = 0; i < nVars(); i++) - activity[i] *= 1e-100; - var_inc *= 1e-100; } - - // Update order_heap with respect to new activity: - if (order_heap.inHeap(v)) - order_heap.decrease(v); } - -inline void Solver::claDecayActivity() { cla_inc *= clause_decay; } -inline void Solver::claBumpActivity (Clause& c) { - if ( (c.activity() += cla_inc) > 1e20 ) { - // Rescale: - for (int i = 0; i < learnts.size(); i++) - learnts[i]->activity() *= 1e-20; - cla_inc *= 1e-20; } } - -inline bool Solver::enqueue (Lit p, Clause* from) { return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, from), true); } -inline bool Solver::locked (const Clause& c) const { return reason[var(c[0])] == &c && value(c[0]) == l_True; } -inline void Solver::newDecisionLevel() { trail_lim.push(trail.size()); } - -inline int Solver::decisionLevel () const { return trail_lim.size(); } -inline uint32_t Solver::abstractLevel (Var x) const { return 1 << (level[x] & 31); } -inline lbool Solver::value (Var x) const { return toLbool(assigns[x]); } -inline lbool Solver::value (Lit p) const { return toLbool(assigns[var(p)]) ^ sign(p); } -inline lbool Solver::modelValue (Lit p) const { return model[var(p)] ^ sign(p); } -inline int Solver::nAssigns () const { return trail.size(); } -inline int Solver::nClauses () const { return clauses.size(); } -inline int Solver::nLearnts () const { return learnts.size(); } -inline int Solver::nVars () const { return assigns.size(); } -inline void Solver::setPolarity (Var v, bool b) { polarity [v] = (char)b; } -inline void Solver::setDecisionVar(Var v, bool b) { decision_var[v] = (char)b; if (b) { insertVarOrder(v); } } -inline bool Solver::solve () { vec tmp; return solve(tmp); } -inline bool Solver::okay () const { return ok; } - - - -//================================================================================================= -// Debug + etc: - - -#define reportf(...) ( fflush(stdout), fprintf(stderr, __VA_ARGS__), fflush(stderr) ) - -static inline void logLit(FILE* f, Lit l) -{ - fprintf(f, "%sx%d", sign(l) ? "~" : "", var(l)+1); -} - -static inline void logLits(FILE* f, const vec& ls) -{ - fprintf(f, "[ "); - if (ls.size() > 0){ - logLit(f, ls[0]); - for (int i = 1; i < ls.size(); i++){ - fprintf(f, ", "); - logLit(f, ls[i]); - } - } - fprintf(f, "] "); -} - -static inline const char* showBool(bool b) { return b ? "true" : "false"; } - - -// Just like 'assert()' but expression will be evaluated in the release version as well. -static inline void check(bool expr) { assert(expr); } - - -inline void Solver::printLit(Lit l) -{ - reportf("%s%d:%c", sign(l) ? "-" : "", var(l)+1, value(l) == l_True ? '1' : (value(l) == l_False ? '0' : 'X')); -} - - -template -inline void Solver::printClause(const C& c) -{ - for (int i = 0; i < c.size(); i++){ - printLit(c[i]); - fprintf(stderr, " "); - } -} - - -//================================================================================================= -#endif diff --git a/packages/swi-minisat2/C/SolverTypes.h b/packages/swi-minisat2/C/SolverTypes.h deleted file mode 100644 index 567e57f1d..000000000 --- a/packages/swi-minisat2/C/SolverTypes.h +++ /dev/null @@ -1,199 +0,0 @@ -/***********************************************************************************[SolverTypes.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - - -#ifndef SolverTypes_h -#define SolverTypes_h - -#include -#include - -//================================================================================================= -// Variables, literals, lifted booleans, clauses: - - -// NOTE! Variables are just integers. No abstraction here. They should be chosen from 0..N, -// so that they can be used as array indices. - -typedef int Var; -#define var_Undef (-1) - - -class Lit { - int x; - public: - Lit() : x(2*var_Undef) { } // (lit_Undef) - explicit Lit(Var var, bool sign = false) : x((var+var) + (int)sign) { } - - // Don't use these for constructing/deconstructing literals. Use the normal constructors instead. - friend int toInt (Lit p); // Guarantees small, positive integers suitable for array indexing. - friend Lit toLit (int i); // Inverse of 'toInt()' - friend Lit operator ~(Lit p); - friend bool sign (Lit p); - friend int var (Lit p); - friend Lit unsign (Lit p); - friend Lit id (Lit p, bool sgn); - - bool operator == (Lit p) const { return x == p.x; } - bool operator != (Lit p) const { return x != p.x; } - bool operator < (Lit p) const { return x < p.x; } // '<' guarantees that p, ~p are adjacent in the ordering. -}; - -inline int toInt (Lit p) { return p.x; } -inline Lit toLit (int i) { Lit p; p.x = i; return p; } -inline Lit operator ~(Lit p) { Lit q; q.x = p.x ^ 1; return q; } -inline bool sign (Lit p) { return p.x & 1; } -inline int var (Lit p) { return p.x >> 1; } -inline Lit unsign (Lit p) { Lit q; q.x = p.x & ~1; return q; } -inline Lit id (Lit p, bool sgn) { Lit q; q.x = p.x ^ (int)sgn; return q; } - -const Lit lit_Undef(var_Undef, false); // }- Useful special constants. -const Lit lit_Error(var_Undef, true ); // } - - -//================================================================================================= -// Lifted booleans: - - -class lbool { - char value; - explicit lbool(int v) : value(v) { } - -public: - lbool() : value(0) { } - lbool(bool x) : value((int)x*2-1) { } - int toInt(void) const { return value; } - - bool operator == (lbool b) const { return value == b.value; } - bool operator != (lbool b) const { return value != b.value; } - lbool operator ^ (bool b) const { return b ? lbool(-value) : lbool(value); } - - friend int toInt (lbool l); - friend lbool toLbool(int v); -}; -inline int toInt (lbool l) { return l.toInt(); } -inline lbool toLbool(int v) { return lbool(v); } - -const lbool l_True = toLbool( 1); -const lbool l_False = toLbool(-1); -const lbool l_Undef = toLbool( 0); - -//================================================================================================= -// Clause -- a simple class for representing a clause: - - -class Clause { - uint32_t size_etc; - union { float act; uint32_t abst; } extra; - Lit data[0]; - -public: - void calcAbstraction() { - uint32_t abstraction = 0; - for (int i = 0; i < size(); i++) - abstraction |= 1 << (var(data[i]) & 31); - extra.abst = abstraction; } - - // NOTE: This constructor cannot be used directly (doesn't allocate enough memory). - template - Clause(const V& ps, bool learnt) { - size_etc = (ps.size() << 3) | (uint32_t)learnt; - for (int i = 0; i < ps.size(); i++) data[i] = ps[i]; - if (learnt) extra.act = 0; else calcAbstraction(); } - - // -- use this function instead: - template - friend Clause* Clause_new(const V& ps, bool learnt); - - int size () const { return size_etc >> 3; } - void shrink (int i) { assert(i <= size()); size_etc = (((size_etc >> 3) - i) << 3) | (size_etc & 7); } - void pop () { shrink(1); } - bool learnt () const { return size_etc & 1; } - uint32_t mark () const { return (size_etc >> 1) & 3; } - void mark (uint32_t m) { size_etc = (size_etc & ~6) | ((m & 3) << 1); } - const Lit& last () const { return data[size()-1]; } - - // NOTE: somewhat unsafe to change the clause in-place! Must manually call 'calcAbstraction' afterwards for - // subsumption operations to behave correctly. - Lit& operator [] (int i) { return data[i]; } - Lit operator [] (int i) const { return data[i]; } - operator const Lit* (void) const { return data; } - - float& activity () { return extra.act; } - uint32_t abstraction () const { return extra.abst; } - - Lit subsumes (const Clause& other) const; - void strengthen (Lit p); -}; - - -template -Clause* Clause_new(const V& ps, bool learnt) { - assert(sizeof(Lit) == sizeof(uint32_t)); - assert(sizeof(float) == sizeof(uint32_t)); - void* mem = std::malloc(sizeof(Clause) + sizeof(uint32_t)*(ps.size())); - return new (mem) Clause(ps, learnt); } -/*_________________________________________________________________________________________________ -| -| subsumes : (other : const Clause&) -> Lit -| -| Description: -| Checks if clause subsumes 'other', and at the same time, if it can be used to simplify 'other' -| by subsumption resolution. -| -| Result: -| lit_Error - No subsumption or simplification -| lit_Undef - Clause subsumes 'other' -| p - The literal p can be deleted from 'other' -|________________________________________________________________________________________________@*/ -inline Lit Clause::subsumes(const Clause& other) const -{ - if (other.size() < size() || (extra.abst & ~other.extra.abst) != 0) - return lit_Error; - - Lit ret = lit_Undef; - const Lit* c = (const Lit*)(*this); - const Lit* d = (const Lit*)other; - - for (int i = 0; i < size(); i++) { - // search for c[i] or ~c[i] - for (int j = 0; j < other.size(); j++) - if (c[i] == d[j]) - goto ok; - else if (ret == lit_Undef && c[i] == ~d[j]){ - ret = c[i]; - goto ok; - } - - // did not find it - return lit_Error; - ok:; - } - - return ret; -} - - -inline void Clause::strengthen(Lit p) -{ - remove(*this, p); - calcAbstraction(); -} - -#endif diff --git a/packages/swi-minisat2/C/Sort.h b/packages/swi-minisat2/C/Sort.h deleted file mode 100644 index 1f301f5c2..000000000 --- a/packages/swi-minisat2/C/Sort.h +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************************[Sort.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef Sort_h -#define Sort_h - -#include "Vec.h" - -//================================================================================================= -// Some sorting algorithms for vec's - - -template -struct LessThan_default { - bool operator () (T x, T y) { return x < y; } -}; - - -template -void selectionSort(T* array, int size, LessThan lt) -{ - int i, j, best_i; - T tmp; - - for (i = 0; i < size-1; i++){ - best_i = i; - for (j = i+1; j < size; j++){ - if (lt(array[j], array[best_i])) - best_i = j; - } - tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp; - } -} -template static inline void selectionSort(T* array, int size) { - selectionSort(array, size, LessThan_default()); } - -template -void sort(T* array, int size, LessThan lt) -{ - if (size <= 15) - selectionSort(array, size, lt); - - else{ - T pivot = array[size / 2]; - T tmp; - int i = -1; - int j = size; - - for(;;){ - do i++; while(lt(array[i], pivot)); - do j--; while(lt(pivot, array[j])); - - if (i >= j) break; - - tmp = array[i]; array[i] = array[j]; array[j] = tmp; - } - - sort(array , i , lt); - sort(&array[i], size-i, lt); - } -} -template static inline void sort(T* array, int size) { - sort(array, size, LessThan_default()); } - - -//================================================================================================= -// For 'vec's: - - -template void sort(vec& v, LessThan lt) { - sort((T*)v, v.size(), lt); } -template void sort(vec& v) { - sort(v, LessThan_default()); } - - -//================================================================================================= -#endif diff --git a/packages/swi-minisat2/C/Vec.h b/packages/swi-minisat2/C/Vec.h deleted file mode 100644 index 14e00adbc..000000000 --- a/packages/swi-minisat2/C/Vec.h +++ /dev/null @@ -1,133 +0,0 @@ -/*******************************************************************************************[Vec.h] -MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT -OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**************************************************************************************************/ - -#ifndef Vec_h -#define Vec_h - -#include -#include -#include - -//================================================================================================= -// Automatically resizable arrays -// -// NOTE! Don't use this vector on datatypes that cannot be re-located in memory (with std::realloc) - -template -class vec { - T* data; - int sz; - int cap; - - void init(int size, const T& pad); - void grow(int min_cap); - - // Don't allow copying (error prone): - vec& operator = (vec& other) { assert(0); return *this; } - vec (vec& other) { assert(0); } - - static inline int imin(int x, int y) { - int mask = (x-y) >> (sizeof(int)*8-1); - return (x&mask) + (y&(~mask)); } - - static inline int imax(int x, int y) { - int mask = (y-x) >> (sizeof(int)*8-1); - return (x&mask) + (y&(~mask)); } - -public: - // Types: - typedef int Key; - typedef T Datum; - - // Constructors: - vec(void) : data(NULL) , sz(0) , cap(0) { } - vec(int size) : data(NULL) , sz(0) , cap(0) { growTo(size); } - vec(int size, const T& pad) : data(NULL) , sz(0) , cap(0) { growTo(size, pad); } - vec(T* array, int size) : data(array), sz(size), cap(size) { } // (takes ownership of array -- will be deallocated with 'free()') - ~vec(void) { clear(true); } - - // Ownership of underlying array: - T* release (void) { T* ret = data; data = NULL; sz = 0; cap = 0; return ret; } - operator T* (void) { return data; } // (unsafe but convenient) - operator const T* (void) const { return data; } - - // Size operations: - int size (void) const { return sz; } - void shrink (int nelems) { assert(nelems <= sz); for (int i = 0; i < nelems; i++) sz--, data[sz].~T(); } - void shrink_(int nelems) { assert(nelems <= sz); sz -= nelems; } - void pop (void) { sz--, data[sz].~T(); } - void growTo (int size); - void growTo (int size, const T& pad); - void clear (bool dealloc = false); - void capacity (int size) { grow(size); } - - // Stack interface: -#if 1 - void push (void) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)std::realloc(data, cap * sizeof(T)); } new (&data[sz]) T(); sz++; } - //void push (const T& elem) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)std::realloc(data, cap * sizeof(T)); } new (&data[sz]) T(elem); sz++; } - void push (const T& elem) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)std::realloc(data, cap * sizeof(T)); } data[sz++] = elem; } - void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; } -#else - void push (void) { if (sz == cap) grow(sz+1); new (&data[sz]) T() ; sz++; } - void push (const T& elem) { if (sz == cap) grow(sz+1); new (&data[sz]) T(elem); sz++; } -#endif - - const T& last (void) const { return data[sz-1]; } - T& last (void) { return data[sz-1]; } - - // Vector interface: - const T& operator [] (int index) const { return data[index]; } - T& operator [] (int index) { return data[index]; } - - - // Duplicatation (preferred instead): - void copyTo(vec& copy) const { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) new (©[i]) T(data[i]); } - void moveTo(vec& dest) { dest.clear(true); dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; } -}; - -template -void vec::grow(int min_cap) { - if (min_cap <= cap) return; - if (cap == 0) cap = (min_cap >= 2) ? min_cap : 2; - else do cap = (cap*3+1) >> 1; while (cap < min_cap); - data = (T*)std::realloc(data, cap * sizeof(T)); } - -template -void vec::growTo(int size, const T& pad) { - if (sz >= size) return; - grow(size); - for (int i = sz; i < size; i++) new (&data[i]) T(pad); - sz = size; } - -template -void vec::growTo(int size) { - if (sz >= size) return; - grow(size); - for (int i = sz; i < size; i++) new (&data[i]) T(); - sz = size; } - -template -void vec::clear(bool dealloc) { - if (data != NULL){ - for (int i = 0; i < sz; i++) data[i].~T(); - sz = 0; - if (dealloc) std::free(data), data = NULL, cap = 0; } } - - -#endif diff --git a/packages/swi-minisat2/C/pl-minisat.C b/packages/swi-minisat2/C/pl-minisat.C deleted file mode 100644 index dca924705..000000000 --- a/packages/swi-minisat2/C/pl-minisat.C +++ /dev/null @@ -1,175 +0,0 @@ -//#include -#include -#include -#include - -#include "Solver.h" - -#define val(i) ((s->model[i] != l_Undef) ? ((s->model[i]==l_True)? i+1:-1*(i+1)):0) - -Solver *s = NULL; - - -extern "C" foreign_t minisat_new_solver() -{ - s = new Solver; - PL_succeed; -} - - -extern "C" foreign_t minisat_delete_solver() -{ - if (s) { - delete s; - s = NULL; - } - PL_succeed; -} - -static inline Lit pl2lit(term_t pl_literal) -{ - int pl_lit_int, var; - PL_get_integer(pl_literal,&pl_lit_int); - var = abs(pl_lit_int)-1; - while (var >= s->nVars()) s->newVar(); - return (pl_lit_int > 0) ? Lit(var) : ~Lit(var); -} - - -extern "C" foreign_t minisat_set_minvars(term_t l) -{ - term_t head = PL_new_term_ref(); /* variable for the elements */ - term_t list = PL_copy_term_ref(l); /* copy as we need to write */ - - vec lits; - - while( PL_get_list(list, head, list) ) { - lits.push( pl2lit(head) ); - } - - assert(PL_get_nil(list)); - - if (s->setminVars(lits)) PL_succeed; else PL_fail; -} - -extern "C" foreign_t minisat_add_clause(term_t l) -{ - term_t head = PL_new_term_ref(); /* variable for the elements */ - term_t list = PL_copy_term_ref(l); /* copy as we need to write */ - - vec lits; - - while( PL_get_list(list, head, list) ) { - lits.push( pl2lit(head) ); - } - - assert(PL_get_nil(list)); - - if (s->addClause(lits)) PL_succeed; else PL_fail; -} - - -extern "C" foreign_t minisat_solve(term_t assum) { - - term_t head = PL_new_term_ref(); /* variable for the elements */ - term_t list = PL_copy_term_ref(assum); /* copy as we need to write */ - - vec assumptions; - - while( PL_get_list(list, head, list) ) { - assumptions.push( pl2lit(head) ); - } - - if (s->solve(assumptions)) PL_succeed; else PL_fail; -} - - -extern "C" foreign_t minisat_get_var_assignment(term_t var, term_t res) -{ - int i; - - PL_get_integer(var,&i); - i--; - - if (i < s->nVars()) { - term_t a = PL_new_term_ref(); /* variable for the elements */ - PL_put_integer(a, val(i)); - return PL_unify(a,res); - } else { - PL_fail; - } -} - -extern "C" foreign_t minisat_nvars(term_t res) -{ - term_t a = PL_new_term_ref(); /* variable for the elements */ - PL_put_integer(a, s->nVars()); - return PL_unify(a,res); -} - - - - - - - - -//============================================================================= -static const PL_extension predicates[] = - { - // - // { "name", arity, function, PL_FA_ }, - // - - { "minisat_new_solver", 0, (void*)minisat_new_solver, 0 }, - { "minisat_delete_solver", 0, (void*)minisat_delete_solver, 0 }, - { "minisat_add_clause", 1, (void*)minisat_add_clause, 0 }, - { "minisat_solve", 1, (void*)minisat_solve, 0 }, - { "minisat_get_var_assignment", 2, (void*)minisat_get_var_assignment, 0 }, - { "minisat_nvars", 1, (void*)minisat_nvars, 0 }, - { NULL, 0, NULL, 0 } // terminating line - }; - -//----------------------------------------------------------------------------- -extern "C" install_t install() -{ - //Sdprintf("%% SWI-Prolog interface to MiniSat"); - //Sdprintf(" - built on "); - //Sdprintf(__DATE__); - //Sdprintf(", "); - //Sdprintf(__TIME__); - //Sdprintf(" ... "); - PL_register_extensions(predicates); /* This is the only PL_ call allowed */ - /* before PL_initialise(). It */ - /* ensures the foreign predicates */ - /* are available before loading */ - /* Prolog code */ - - //Sdprintf("OK\n"); -} - -//----------------------------------------------------------------------------- -// This part is for compiling into a standalone executable - -#ifdef READLINE -static void install_readline(int argc, char**argv) -{ - PL_install_readline(); -} -#endif - -int main(int argc, char **argv) -{ - -#ifdef READLINE - PL_initialise_hook(install_readline); -#endif - - install(); - if ( !PL_initialise(argc, argv) ) - PL_halt(1); - - PL_halt(PL_toplevel() ? 0 : 1); - - return 0; -} diff --git a/packages/swi-minisat2/CMakeLists.txt b/packages/swi-minisat2/CMakeLists.txt deleted file mode 100644 index b39ad2491..000000000 --- a/packages/swi-minisat2/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ - -set (PROGRAMS - cnf.pl - minisat.pl - ) - -set (EXAMPLE_PROGRAMS - examples/adder.pl - examples/pearl_examples.pl - ) - -install(FILES - ${PROGRAMS} - DESTINATION ${YAP_INSTALL_DATADIR} - ) - -add_subDIRECTORY (C) - diff --git a/packages/swi-minisat2/Makefile.in b/packages/swi-minisat2/Makefile.in deleted file mode 100644 index 1131ac9b2..000000000 --- a/packages/swi-minisat2/Makefile.in +++ /dev/null @@ -1,51 +0,0 @@ -# -# default base directory for YAP installation -# -# -ROOTDIR = @prefix@ -# -# where the binary should be -# -BINDIR = $(ROOTDIR)/bin -# -# where YAP should look for binary libraries -# -LIBDIR=@libdir@ -YAPLIBDIR=@libdir@/Yap -# -# where YAP should look for architecture-independent Prolog libraries -# -SHAREDIR=$(ROOTDIR)/share -# -# -# You shouldn't need to change what follows. -# -INSTALL=@INSTALL@ -INSTALL_DATA=@INSTALL_DATA@ -INSTALL_PROGRAM=@INSTALL_PROGRAM@ -srcdir=@srcdir@ -YAP_EXTRAS=@YAP_EXTRAS@ - -PROGRAMS= \ - $(srcdir)/cnf.pl \ - $(srcdir)/minisat.pl - -EXAMPLE_PROGRAMS= \ - $(srcdir)/examples/adder.pl \ - $(srcdir)/examples/pearl_examples.pl - -all: - -install: $(PROGRAMS) install-examples - mkdir -p $(DESTDIR)$(SHAREDIR)/Yap - mkdir -p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/minisat - for p in $(PROGRAMS); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap; done - for p in $(EXAMPLE_PROGRAMS); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/minisat; done - -install-examples: - -clean: - -distclean: - rm Makefile - diff --git a/packages/swi-minisat2/README b/packages/swi-minisat2/README deleted file mode 100644 index 110f81236..000000000 --- a/packages/swi-minisat2/README +++ /dev/null @@ -1,8 +0,0 @@ -You need to put the file swi-minisat2.tgz in a directory where you want -the solver and the interface and then do: - -% tar zxvf swi-minisat2.tgz -% ./configure.sh -% make -% make clean - diff --git a/packages/swi-minisat2/README.YAP b/packages/swi-minisat2/README.YAP deleted file mode 100644 index 27a2d12c6..000000000 --- a/packages/swi-minisat2/README.YAP +++ /dev/null @@ -1,13 +0,0 @@ -This is the minisat package as described in - -Michael Codish, Vitaly Lagoon, Peter J. Stuckey: Logic programming -with satisfiability. TPLP 8(1): 121-128 (2008) - -We thank the authors for kindly allowing us to use this package in YAP. - -Please check the examples in $install/share/Yap/minisat/examples and -the TPLP paper to understand how the system can be used. - -Last, please contact yap-users AT sf.net for any bugs first, as they -may have been caused by the YAP port. - diff --git a/packages/swi-minisat2/cnf.pl b/packages/swi-minisat2/cnf.pl deleted file mode 100644 index b2e10e78e..000000000 --- a/packages/swi-minisat2/cnf.pl +++ /dev/null @@ -1,100 +0,0 @@ -%%============================================================================ -%% CNF.pl -%% Convertor of Boolean formulae to CNF -%% Copyright (c) 2006, Michael Codish, Vitaly Lagoon, and Peter J. Stuckey -%% -%% Permission is hereby granted, free of charge, to any person obtaining a -%% copy of this software and associated documentation files (the -%% "Software"), to deal in the Software without restriction, including -%% without limitation the rights to use, copy, modify, merge, publish, -%% distribute, sublicense, and/or sell copies of the Software, and to -%% permit persons to whom the Software is furnished to do so, subject to -%% the following conditions: -%% -%% The above copyright notice and this permission notice shall be included -%% in all copies or substantial portions of the Software. -%% -%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -%% OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -%% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -%% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -%% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -%% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -:- module(cnf,[cnf/2,cnf_dl/2]). - -cnf(F,Cnf) :- cnf_dl(F,Cnf-[]). - -cnf_dl(F,[[B]|Cnf1]-Cnf2) :- iff(F,+,B,Cnf2,Cnf1). - - -iff(V,_,B,Acc,Cnf) :- var(V), !, V=B, Cnf=Acc. -iff(1,_,B,Acc,Cnf) :- !, B=1, Cnf=Acc. -iff(0,_,B,Acc,Cnf) :- !, B=0, Cnf=Acc. - -iff(-X,+,B,Acc,Cnf) :- !, iff(X,-,BX,Acc,Cnf), neglit(BX,B). -iff(-X,-,B,Acc,Cnf) :- !, iff(X,+,BX,Acc,Cnf), neglit(BX,B). -iff(-X,*,B,Acc,Cnf) :- !, iff(X,*,BX,Acc,Cnf), neglit(BX,B). - -iff((X+Y),Polarity,B,Acc,Cnf) :- !, - iff(X,Polarity,BX,Acc,AccX), - iff(Y,Polarity,BY,AccX,AccXY), - ( - Polarity == + -> Cnf = [[-B,BX,BY]|AccXY] - ; - Polarity == - -> Cnf = [[B,-BX],[B,-BY]|AccXY] - ; - Cnf = [[-B,BX,BY], [B,-BX], [B,-BY] | AccXY] - ). - -iff((X*Y),Polarity,B,Acc,Cnf) :- !, - iff(X,Polarity,BX,Acc,AccX), - iff(Y,Polarity,BY,AccX,AccXY), - ( - Polarity == + -> Cnf = [[-B,BX],[-B,BY]|AccXY] - ; - Polarity == - -> Cnf = [[B,-BX,-BY]|AccXY] - ; - Cnf = [[B,-BX,-BY], [-B,BX], [-B,BY] | AccXY] - ). - -iff((X==Y),Polarity,B,Acc,Cnf) :- !, - iff(X,*,BX,Acc,AccX), - iff(Y,*,BY,AccX,AccXY), - ( - Polarity == + -> Cnf = [[-BX,BY,-B],[BX,-BY,-B] | AccXY] - ; - Polarity == - -> Cnf = [[-BX,-BY,B],[BX,BY,B] | AccXY] - ; - Cnf = [[-BX,BY,-B],[BX,-BY,-B],[-BX,-BY,B],[BX,BY,B] | AccXY] - ). - -iff((xor(X, Y)),Polarity,B,Acc,Cnf) :- !, - iff(X,*,BX,Acc,AccX), - iff(Y,*,BY,AccX,AccXY), - ( - Polarity == + -> Cnf = [[-BX,-BY,-B],[BX,BY,-B] | AccXY] - ; - Polarity == - -> Cnf = [[-BX,BY,B],[BX,-BY,B] | AccXY] - ; - Cnf = [[-BX,BY,B],[BX,-BY,B],[-BX,-BY,-B],[BX,BY,-B] | AccXY] - ). - -iff((X->Y;Z),Polarity,B,Acc,Cnf) :- !, - iff(X,*,BX,Acc,AccX), - iff(Y,Polarity,BY,AccX,AccXY), - iff(Z,Polarity,BZ,AccXY,AccXYZ), - ( - Polarity == + -> Cnf = [[-BX,BY,-B],[BX,BZ,-B],[BY,BZ,-B]|AccXYZ] - ; - Polarity == - -> Cnf = [[-BX,-BY,B],[BX,-BZ,B],[-BY,-BZ,B]|AccXYZ] - ; - Cnf = [[-BX,BY,-B], [BX,BZ,-B], [BY,BZ,-B], - [-BX,-BY,B], [BX,-BZ,B], [-BY,-BZ,B] | AccXYZ] - ). - -neglit(V,-V) :- var(V), !. -neglit(-V,V). -neglit(0,1). -neglit(1,0). diff --git a/packages/swi-minisat2/examples/adder.pl b/packages/swi-minisat2/examples/adder.pl deleted file mode 100644 index 058e02dce..000000000 --- a/packages/swi-minisat2/examples/adder.pl +++ /dev/null @@ -1,23 +0,0 @@ -:- module(adder,[sum/3]). - -sum([B],[S],(S==B)). -sum([B1,B2|Bs],Sum,F1*F2*F3) :- - split([B1,B2|Bs],Xs,Ys), - sum(Xs,S1,F1), sum(Ys,S2,F2),add(S1,S2,Sum,F3). - -split([],[],[]). -split([X],[X],[0]). -split([X,Y|XYs],[X|Xs],[Y|Ys]) :- split(XYs,Xs,Ys). - -add([X|Xs],[Y|Ys],[Z|Zs],(Z==SumXY)*Sum) :- - halfadder(X,Y,SumXY,CarryXY), - adder(Xs,Ys,CarryXY,Zs,Sum). - -adder([],[],Carry,[Z],Z==Carry). -adder([X|Xs],[Y|Ys],Carry,[Z|Zs],(Z==SumXY)*Rest) :- - fulladder(X,Y,Carry,SumXY,CarryXY), - adder(Xs,Ys,CarryXY,Zs,Rest). - -fulladder(X, Y, C, (X xor Y xor C), (C->(X+Y);(X*Y)) ). -halfadder(X, Y, (X xor Y), X*Y ). - diff --git a/packages/swi-minisat2/examples/pearl_examples.pl b/packages/swi-minisat2/examples/pearl_examples.pl deleted file mode 100644 index 0655e7876..000000000 --- a/packages/swi-minisat2/examples/pearl_examples.pl +++ /dev/null @@ -1,54 +0,0 @@ - -:- use_module(library(cnf)). -:- use_module(library(minisat)). -:- use_module(adder). - -%% Example, pg3 -%% -%% ?- cnf(X==Y,Cnf). -%% Cnf = [[T], [-X, Y, -T], [X, -Y, -T]] -%% ?- cnf((X*Y)+(-X*Z),Cnf). -%% Cnf = [[T], [-T, T1, T2], [-T2, -X], -%% [-T2, Z], [-T1, X], [-T1, Y]] - - -%% Example, pg4 -%% -%% ?- sum([X+Y,X*Y,X==Y,X xor Y],[S1,S2,S3],Psi). -%% Psi = (T1==X+Y)*(T2==(X==Y))*(T3==T1 xor T2)*(T4==T1*T2)*(T5==X*Y)* -%% (T6==X xor Y)*(T7==T5 xor T6)* (T8==T5*T6)*(S1==T3 xor T7)* -%% (S2==T4 xor T8 xor (T3*T7))* (S3==(T3*T7->T4+T8;T4*T8)) - - -%% Examples, pg6 -%% -%% ?- cnf(X==Y,Cnf), solve(Cnf). -%% X=0, Y=0 -%% -%% ?- cnf(X==Y,Cnf), sat(Cnf). -%% Yes -%% -%% ?- sum([X+Y,X*Y,X==Y,X xor Y],Sum,F), cnf(F,Cnf), solve(Cnf). -%% X = 0, Y = 0 -%% Sum = [1, 0, 0] -%% -%% ?- sum([X+Y,X*Y,X==Y,X xor Y],[0,1,0],F), cnf(F,Cnf), solve(Cnf). -%% X = 0, Y = 1 -%% -%% ?- sum([X+Y,X*Y,X==Y,X xor Y],Sum,F), cnf(F,Cnf), -%% maximize(Sum,Cnf), solve(Cnf). -%% Sum=[1,1,0] -%% X=1, Y=1 - - -%% Figure 3, pg 6 -%% -%% partialMaxSat(+,+). -partialMaxSat(Phi,Psi) :- - sum(Psi,Max,SumPsi), cnf(Phi*SumPsi,Cnf), - maximize(Max,Cnf), solve(Cnf). - -%% Example, pg 7 -%% -%% ?- partialMaxSat(X+Y,[X*Y,X==Y,X xor Y,-X+Y, -X, -Y, X]). -%% X = 1, Y = 1 diff --git a/packages/swi-minisat2/minisat.pl b/packages/swi-minisat2/minisat.pl deleted file mode 100644 index 386f70c22..000000000 --- a/packages/swi-minisat2/minisat.pl +++ /dev/null @@ -1,361 +0,0 @@ -%%============================================================================ -%% The SWI-Prolog interface to MiniSat SAT solver -%% http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/MiniSat.html -%% -%% Copyright (c) 2006, Michael Codish, Vitaly Lagoon, and Peter J. Stuckey -%% -%% Permission is hereby granted, free of charge, to any person obtaining a -%% copy of this software and associated documentation files (the -%% "Software"), to deal in the Software without restriction, including -%% without limitation the rights to use, copy, modify, merge, publish, -%% distribute, sublicense, and/or sell copies of the Software, and to -%% permit persons to whom the Software is furnished to do so, subject to -%% the following conditions: -%% -%% The above copyright notice and this permission notice shall be included -%% in all copies or substantial portions of the Software. -%% -%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -%% OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -%% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -%% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -%% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -%% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -:- module(minisat,[ - solve/1, - sat/1, - sat_init/0, - sat_deinit/0, - sat_add_clauses/3, - sat_solve/1, - - minimize/2, - maximize/2, - minimize_v1/2, - maximize_v1/2, - minimize_v2/2, - maximize_v2/2, - minimize_v3/2, - maximize_v3/2 -]). - -:- use_module(library(shlib)). - -:- use_module(library(lists)). - -:- load_foreign_library('pl-minisat',install). - -:- dynamic tmp/1. - - - -%% -%% -sat_init :- - minisat_new_solver, % - create the new solve - minisat_add_clause([-1]), % - add zero - minisat_add_clause([2]). % - add one - -%% -%% -sat_deinit :- - minisat_delete_solver. - - - -%% -%% -sat_add_clauses(Cs, Vs, MiniSat_Vs) :- - term_variables(Cs,CsVars), - \+ \+ ( - bind2index(CsVars), - add_cnf_clauses(Cs), - asserta(tmp(Vs)) - ), - retract(tmp(MiniSat_Vs)). - -add_cnf_clauses([]). -add_cnf_clauses([Cl|Cls]) :- - to_minisat(Cl,MiniSatCl), - minisat_add_clause(MiniSatCl), - add_cnf_clauses(Cls). - -to_minisat([],[]). -to_minisat([L|Ls],[N|Ns]) :- - minisat_aux(L,N), - to_minisat(Ls,Ns). - -minisat_aux(0,1) :- !. -minisat_aux(1,2) :- !. -minisat_aux(-(1),1) :- !. -minisat_aux(-(0),2) :- !. -minisat_aux(N,NN) :- NN is N. - - -bind2index(Vs) :- - minisat_nvars(N), - N1 is N+1, - bind2index_aux(Vs,N1). - -bind2index_aux([],_N). -bind2index_aux([V|Ns],N) :- - var(V), - !, - V=N, - N1 is N+1, bind2index_aux(Ns,N1). -bind2index_aux([V|Ns],N) :- - integer(V), - bind2index_aux(Ns,N). - -%% -%% -sat_solve(As) :- - to_minisat(As,MINISAT_As), - minisat_solve(MINISAT_As). - - -%% -%% -sat_get_values([],[]). -sat_get_values([SAT_V|SVs],[PL_V|PL_Vs]) :- - minisat_get_var_assignment(SAT_V,N), - ( N<0 -> PL_V=0 ; PL_V=1), - sat_get_values(SVs,PL_Vs). - - - - -%% -%% sat(+CNF): succeds if CNF is satisfaiable, it does not bind the variables in CNF -%% - -sat(CNF) :- - sat_init, - sat_add_clauses(CNF,_,_), - sat_solve([]), - sat_deinit, - !. -sat(_CNF) :- - sat_deinit, - !, - fail. - - -%% -%% solve(+CNF): like CNF/1 but bind the variables of CNF to the solution -%% -solve(CNF) :- - sat_init, - term_variables(CNF,CNF_Vs), - sat_add_clauses(CNF,CNF_Vs,SAT_Vs), - sat_solve([]), - sat_get_values(SAT_Vs,CNF_Vs), - sat_deinit, - !. -solve(_) :- - sat_deinit, - !, - fail. - - -%% -%% -%% -minimize(Vec,CNF) :- minimize_v1(Vec,CNF). -maximize(Vec,CNF) :- maximize_v1(Vec,CNF). - - -%% -%% -minimize_v1(Vec,CNF) :- - minimize_v1_aux(Vec,CNF), - sat(CNF). - -minimize_v1_aux([],_CNF). -minimize_v1_aux([B|Bs],CNF) :- - minimize_v1_aux(Bs,CNF), - ( (B=0, sat(CNF)) -> true ; B=1 ). - - -%% -%% -maximize_v1(Vec,CNF) :- - maximize_v1_aux(Vec,CNF), - sat(CNF). - -maximize_v1_aux([],_CNF). -maximize_v1_aux([B|Bs],CNF) :- - maximize_v1_aux(Bs,CNF), - ( (B=1, sat(CNF)) -> true ; B=0 ). - - - - -%% -%% -minimize_v2(Vec,CNF) :- - retractall(tmp(_)), - reverse(Vec,Vec_MSB), - term_variables(CNF,CNF_Vars), - sat_init, - sat_add_clauses(CNF,[Vec_MSB,CNF_Vars],[Vec_MSB_SVars,CNF_SVars]), - minimize_v2_loop(Vec_MSB_SVars), - sat_get_values(CNF_SVars,CNF_Vars), - sat_deinit, - !. - -minimize_v2_loop([]) :- - sat_solve([]). -minimize_v2_loop([V|Vs]) :- - ( sat_solve([-V]) -> - eliminate_prefix(Vs,0,New_Vs) - ; - sat_add_clauses([[V]],_,_), - New_Vs=Vs - ), - minimize_v2_loop(New_Vs). - - - -%% -%% -maximize_v2(Vec,CNF) :- - reverse(Vec,Vec_MSB), - term_variables(CNF,CNF_Vars), - sat_init, - sat_add_clauses(CNF,[Vec_MSB,CNF_Vars],[Vec_MSB_SVars,CNF_SVars]), - maximize_v2_loop(Vec_MSB_SVars), - sat_get_values(CNF_SVars,CNF_Vars), - sat_deinit, - !. - -maximize_v2_loop([]) :- - sat_solve([]). -maximize_v2_loop([V|Vs]) :- - ( sat_solve([V]) -> - eliminate_prefix(Vs,1,New_Vs) - ; - sat_add_clauses([[V]],_,_), - New_Vs=Vs - ), - maximize_v2_loop(New_Vs). - - - - - -%% -%% -minimize_v3(Vec,CNF) :- - retractall(tmp(_)), - term_variables(CNF,CNF_Vars), - sat_init, - sat_add_clauses(CNF,[Vec,CNF_Vars],[Vec_SVars,CNF_SVars]), - sat_solve([]), - sat_get_values(Vec_SVars,Curr_Min), - sat_get_values(CNF_SVars,Curr_Sol), - minimize_v3_loop(Vec_SVars,CNF_SVars,Curr_Min,Curr_Sol,Vec,CNF_Vars), - minisat_delete_solver, - !. - -minimize_v3_loop(Vec,CNF_SVars,Last_Min,_Last_Sol,Final_Min,Final_Sol) :- - xs_gt_ys(Last_Min,Vec,CNF-[]), - sat_add_clauses(CNF,_,_), - sat_solve([]), - sat_get_values(Vec,Curr_Min), - sat_get_values(CNF_SVars,Curr_Sol), - !, - minimize_v3_loop(Vec,CNF_SVars,Curr_Min,Curr_Sol,Final_Min,Final_Sol). -minimize_v3_loop(_Vec,_CNF_SVars,Final_Min,Final_Sol,Final_Min,Final_Sol) :- - !. - - - -%% -%% -maximize_v3(Vec,CNF) :- - retractall(tmp(_)), - term_variables(CNF,CNF_Vars), - sat_init, - sat_add_clauses(CNF,[Vec,CNF_Vars],[Vec_SVars,CNF_SVars]), - sat_solve([]), - sat_get_values(Vec_SVars,Curr_Max), - sat_get_values(CNF_SVars,Curr_Sol), - maximize_v3_loop(Vec_SVars,CNF_SVars,Curr_Max,Curr_Sol,Vec,CNF_Vars), - minisat_delete_solver, - !. - -maximize_v3_loop(Vec,CNF_SVars,Last_Max,_Last_Sol,Final_Max,Final_Sol) :- - xs_gt_ys(Vec,Last_Max,CNF-[]), - sat_add_clauses(CNF,_,_), - sat_solve([]), - sat_get_values(Vec,Curr_Max), - sat_get_values(CNF_SVars,Curr_Sol), - !, - maximize_v3_loop(Vec,CNF_SVars,Curr_Max,Curr_Sol,Final_Max,Final_Sol). -maximize_v3_loop(_Vec,_CNF_SVars,Final_Max,Final_Sol,Final_Max,Final_Sol) :- - !. - - - - -%% -%% -eliminate_prefix([],_Bit,[]) :- !. -eliminate_prefix([V|Vs],Bit,New_Vs) :- - sat_get_values([V],[VVal]), - VVal = Bit, - ( Bit = 0 -> sat_add_clauses([[-V]],_,_) ; sat_add_clauses([[V]],_,_) ), - !, - eliminate_prefix(Vs,Bit,New_Vs). -eliminate_prefix(Vs,Vs). - - - -%% -%% -% B == (Xs = Ys) -xs_eq_ys([X],[Y],B,Cnf1-Cnf2) :- - !, - eq(X,Y,B,Cnf1-Cnf2). -xs_eq_ys([X|Xs],[Y|Ys],B,Cnf1-Cnf4) :- - eq(X,Y,B1,Cnf1-Cnf2), - xs_eq_ys(Xs,Ys,B2,Cnf2-Cnf3), - and(B1,B2,B,Cnf3-Cnf4). - -%% -xs_gt_ys(Xs,Ys,[[B]|Cnf1]-Cnf2) :- - xs_gt_ys(Xs,Ys,B,Cnf1-Cnf2). - -%% -%% -xs_gt_ys([X],[Y],B,Cnf1-Cnf2) :- !, - gt(X,Y,B,Cnf1-Cnf2). -xs_gt_ys(Xs,Ys,B, Cnf1-Cnf6) :- - split(Xs,LoXs,HiXs), - split(Ys,LoYs,HiYs), - xs_gt_ys(HiXs,HiYs,B1,Cnf1-Cnf2), - xs_eq_ys(HiXs,HiYs,B2,Cnf2-Cnf3), - xs_gt_ys(LoXs,LoYs,B3,Cnf3-Cnf4), - and(B2,B3,Tmp, Cnf4-Cnf5), - or(B1,Tmp,B,Cnf5-Cnf6). - -% Z == X > Y (equivalently Z == X * -Y) -gt(X,Y,Z,[[Z,-X,Y],[-Z,X],[-Z,-Y]|Cnf]-Cnf). - -% Z == (X == Y) -eq(X,Y,Z, [[-Z,-X,Y],[-Z,X,-Y], - [Z,X,Y],[Z,-X,-Y] | Cnf]-Cnf). - -% Z == X or Y -or(X,Y,Z, [[Z,-X],[Z,-Y],[-Z,X,Y] | Cnf]-Cnf). - -% Z == X and Y -and(X,Y,Z, [[Z,X,Y],[-Z,X],[-Z,Y] | Cnf]-Cnf). - -% -split(Xs,As,Bs) :- - length(Xs,N), M is N // 2, - length(As,M), append(As,Bs,Xs). From 71fc7238ff607b0cdddb5f153ffa09b110f59c13 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 22 Apr 2019 12:18:22 +0100 Subject: [PATCH 4/6] exec --- .gitignore | 1 + C/exec.c | 8 ++++---- CMakeLists.txt | 7 +------ H/Yapproto.h | 4 ++-- H/fields.h | 4 ++-- H/locals.h | 2 +- pl/boot.yap | 2 +- 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index faccf25e8..dbae7786b 100644 --- a/.gitignore +++ b/.gitignore @@ -215,3 +215,4 @@ cmake/docs/Doxyfile *.stackdump *.gz +.Rproj.user diff --git a/C/exec.c b/C/exec.c index 27a873971..f7098440f 100755 --- a/C/exec.c +++ b/C/exec.c @@ -1628,10 +1628,10 @@ 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, YAP_dogoalinfo *gip USES_REGS) { /* create an initial pseudo environment so that when garbage - collection is going up in the environment chain it doesn't get + collection is going up in the environment chain it doesn't ge t confused */ Yap_ResetException(worker_id); // sl = Yap_InitSlot(t); @@ -1652,7 +1652,7 @@ void Yap_PrepGoal(arity_t arity, CELL *pt, YAP_dogoalinfo *gip USES_REGS) { /* keep a place where you can inform you had an exception */ if (pt) { int i; - for (i = 0; i < arity; i++) { + for (i = 0; i < 3; i++) { XREGS[i + 1] = *pt++; } } @@ -1678,7 +1678,7 @@ void Yap_PrepGoal(arity_t arity, CELL *pt, YAP_dogoalinfo *gip USES_REGS) { static bool do_goal(yamop *CodeAdr, int arity, CELL *pt, YAP_dogoalinfo *gi, bool top USES_REGS) { bool out; - Yap_PrepGoal(arity, pt, gi PASS_REGS); + Yap_PrepGoal(arity, pt, gi PASS_REGS); // CACHE_A1(); P = (yamop *)CodeAdr; // S = CellPtr(RepPredProp( diff --git a/CMakeLists.txt b/CMakeLists.txt index e0600e0fd..7cb812396 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,3 @@ - # value of 3.4.0 or lower. cmake_minimum_required(VERSION 3.4) @@ -905,11 +904,7 @@ add_subDIRECTORY(packages/ProbLog) endif() -if (WITH_MINISAT) - -add_subDIRECTORY(packages/swi-minisat2) - -endif() +add_subDIRECTORY(packages/bee) if (WITH_CLPQR) diff --git a/H/Yapproto.h b/H/Yapproto.h index 5e1999050..5ddce5ee5 100755 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -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, bool); +extern Term Yap_RunTopGoal(Term, YAP_dogoalinfo *gip,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 void Yap_PrepGoal(arity_t arity, CELL *pt, YAP_dogoalinfo *gip 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); diff --git a/H/fields.h b/H/fields.h index bc486302e..d60ec86c5 100644 --- a/H/fields.h +++ b/H/fields.h @@ -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 "heap.h" +#include "YapHeap.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 "heap.h" +#include "YapHeap.h" #undef LOC #undef LOCL diff --git a/H/locals.h b/H/locals.h index 7380c1c5d..e42e9dcd2 100644 --- a/H/locals.h +++ b/H/locals.h @@ -3,7 +3,7 @@ // Macro support #ifndef LOCAL #include "Yap.h" -#include "heap.h" +#include "YapHeap.h" #define LOCAL(A, B) A B #define LOCAL_INIT(A, B, C) \ A B; \ diff --git a/pl/boot.yap b/pl/boot.yap index 941e1c8c7..377e5db00 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -267,7 +267,7 @@ initialize_prolog :- :- c_compile( 'protect.yap' ). :- ['absf.yap']. -%:- stop_low_level_trace. +%:- ..............................lp------------------------------------------------------------------. :- use_module('error.yap'). :- [ From a87654b0b0c627b6e9cc22642ef251050ca95273 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 24 Apr 2019 10:31:05 +0100 Subject: [PATCH 5/6] exec --- C/utilpreds.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/C/utilpreds.c b/C/utilpreds.c index 2247f9344..487e921c0 100644 --- a/C/utilpreds.c +++ b/C/utilpreds.c @@ -151,8 +151,9 @@ clean_complex_tr(tr_fr_ptr TR0 USES_REGS) { } #define expand_stack(S0,SP,SF,TYPE) \ - { size_t sz = SF-S0, used = SP-S0; \ - S0 = Realloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \ + { size_t sz = SF-S0, used = SP-S0;\ +sz = 1024+sz; \ + S0 = Realloc(S0, sz*sizeof(TYPE) PASS_REGS); \ SP = S0+used; SF = S0+sz; } #define MIN_ARENA_SIZE (1048L) From b97338f84d0fd3b59f71a3ca8d87e4c68fd463c2 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 24 Apr 2019 12:10:06 +0100 Subject: [PATCH 6/6] reset excess change --- .gitignore | 1 - C/absmi.c | 57 ++++++--------- C/absmi_insts.h | 9 +-- C/c_interface.c | 146 ++++++++++++++++++------------------- C/control_absmi_insts.h | 2 +- C/exec.c | 157 ++++++++++++++++++---------------------- C/lu_absmi_insts.h | 1 + C/prim_absmi_insts.h | 138 +++++++++++++++++------------------ C/utilpreds.c | 5 +- CMakeLists.txt | 7 +- CXX/yapi.cpp | 152 +++++++++++++++++++------------------- H/YapHandles.h | 31 -------- H/Yapproto.h | 4 +- H/fields.h | 4 +- H/locals.h | 2 +- include/YapDefs.h | 4 +- pl/boot.yap | 2 +- 17 files changed, 337 insertions(+), 385 deletions(-) diff --git a/.gitignore b/.gitignore index dbae7786b..faccf25e8 100644 --- a/.gitignore +++ b/.gitignore @@ -215,4 +215,3 @@ cmake/docs/Doxyfile *.stackdump *.gz -.Rproj.user diff --git a/C/absmi.c b/C/absmi.c index 0f07a5186..fcd31e639 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -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); diff --git a/C/absmi_insts.h b/C/absmi_insts.h index 6aeaff66f..5499274c2 100644 --- a/C/absmi_insts.h +++ b/C/absmi_insts.h @@ -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); diff --git a/C/c_interface.c b/C/c_interface.c index 6113a0b29..a6e9d223a 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -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, @@ -2208,8 +2206,8 @@ X_API Term YAP_ReadFromStream(int sno) { sigjmp_buf signew; if (sigsetjmp(signew, 0)) { Yap_syntax_error(LOCAL_toktide, sno, "ReadFromStream"); - RECOVER_MACHINE_REGS(); - return 0; + RECOVER_MACHINE_REGS(); + return 0; } else { o = Yap_read_term(sno, TermNil, false); } diff --git a/C/control_absmi_insts.h b/C/control_absmi_insts.h index 483609e1b..59469248e 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/exec.c b/C/exec.c index f7098440f..f332fd307 100755 --- a/C/exec.c +++ b/C/exec.c @@ -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 diff --git a/C/lu_absmi_insts.h b/C/lu_absmi_insts.h index 3d57b09e4..bc67bebdf 100644 --- a/C/lu_absmi_insts.h +++ b/C/lu_absmi_insts.h @@ -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); diff --git a/C/prim_absmi_insts.h b/C/prim_absmi_insts.h index 679e9df4f..fc10ba1a4 100644 --- a/C/prim_absmi_insts.h +++ b/C/prim_absmi_insts.h @@ -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); diff --git a/C/utilpreds.c b/C/utilpreds.c index 487e921c0..2247f9344 100644 --- a/C/utilpreds.c +++ b/C/utilpreds.c @@ -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) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cb812396..e0600e0fd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 92e12894b..fe3a3789c 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -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 YAPPairTerm::listToArray() { return o; } -std::vector 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 o = *new std::vector(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(); } diff --git a/H/YapHandles.h b/H/YapHandles.h index bfc212dfc..f7a6be6d3 100755 --- a/H/YapHandles.h +++ b/H/YapHandles.h @@ -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 diff --git a/H/Yapproto.h b/H/Yapproto.h index 5ddce5ee5..5e1999050 100755 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -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); diff --git a/H/fields.h b/H/fields.h index d60ec86c5..bc486302e 100644 --- a/H/fields.h +++ b/H/fields.h @@ -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 diff --git a/H/locals.h b/H/locals.h index e42e9dcd2..7380c1c5d 100644 --- a/H/locals.h +++ b/H/locals.h @@ -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; \ diff --git a/include/YapDefs.h b/include/YapDefs.h index 840814886..f1c27bcd0 100755 --- a/include/YapDefs.h +++ b/include/YapDefs.h @@ -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 diff --git a/pl/boot.yap b/pl/boot.yap index 377e5db00..941e1c8c7 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -267,7 +267,7 @@ initialize_prolog :- :- c_compile( 'protect.yap' ). :- ['absf.yap']. -%:- ..............................lp------------------------------------------------------------------. +%:- stop_low_level_trace. :- use_module('error.yap'). :- [