This commit is contained in:
Vítor Santos Costa 2019-04-11 22:17:00 +01:00
parent fda10395b8
commit 8da14e339a
7 changed files with 46 additions and 39 deletions

View File

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

View File

@ -1769,7 +1769,7 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
dgi->CurSlot = LOCAL_CurSlot; dgi->CurSlot = LOCAL_CurSlot;
// ensure our current ENV receives current P. // ensure our current ENV receives current P.
Yap_PrepGoal(pe->ArityOfPE, nullptr, B PASS_REGS); Yap_PrepGoal(pe->ArityOfPE, nullptr, dgi PASS_REGS);
P = pe->CodeOfPred; P = pe->CodeOfPred;
// __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %ld %x %x args=%x,%x // __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), // slot=%ld", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
@ -1822,7 +1822,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
out = Yap_exec_absmi(true, true ); out = Yap_exec_absmi(true, true );
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
dgi->b = myB; dgi->b = LCL0-CellPtr(myB);
} else { } else {
LOCAL_CurSlot = LOCAL_CurSlot =
dgi->CurSlot; // ignore any slots created within the called goal dgi->CurSlot; // ignore any slots created within the called goal
@ -1870,7 +1870,7 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
ASP = LCL0-dgi->a; ASP = LCL0-dgi->a;
B = (choiceptr)(LCL0-dgi->b) B = (choiceptr)(LCL0-dgi->b)
RECOVER_MACHINE_REGS(); 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, 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); CP, LOCAL_CurSlot);
return TRUE; return TRUE;
} }

View File

@ -1598,7 +1598,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
ASP = (CELL *)PROTECT_FROZEN_B(B); ASP = (CELL *)PROTECT_FROZEN_B(B);
if (B == NULL || B->cp_b == NULL || 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_RestartEnv = sighold;
LOCAL_CBorder = OldBorder; LOCAL_CBorder = OldBorder;
pop_text_stack(i + 1); pop_text_stack(i + 1);
@ -1609,8 +1609,8 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
} }
YENV = ASP; YENV = ASP;
YENV[E_CB] = Unsigned(B); YENV[E_CB] = Unsigned(B);
pop_text_stack(i + 1);
out = Yap_absmi(0); out = Yap_absmi(0);
/* make sure we don't leave a FAIL signal hanging around */ /* make sure we don't leave a FAIL signal hanging around */
Yap_get_signal(YAP_FAIL_SIGNAL); Yap_get_signal(YAP_FAIL_SIGNAL);
if (!Yap_has_a_signal()) if (!Yap_has_a_signal())
@ -1621,7 +1621,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
return out; return out;
} }
void Yap_PrepGoal(arity_t arity, CELL *pt, choiceptr saved_b USES_REGS) { void Yap_PrepGoal(arity_t arity, CELL *pt, YAP_dogoalinfo *gip USES_REGS) {
/* create an initial pseudo environment so that when garbage /* 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 get
confused */ confused */
@ -1655,20 +1655,18 @@ void Yap_PrepGoal(arity_t arity, CELL *pt, choiceptr saved_b USES_REGS) {
B->cp_cp = CP; B->cp_cp = CP;
B->cp_ap = NOCODE; B->cp_ap = NOCODE;
B->cp_env = ENV; B->cp_env = ENV;
B->cp_b = saved_b;
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
B->cp_depth = DEPTH; B->cp_depth = DEPTH;
#endif /* DEPTH_LIMIT */ #endif /* DEPTH_LIMIT */
YENV = ASP = (CELL *)B; YENV = ASP = (CELL *)B;
YENV[E_CB] = (CELL)B; YENV[E_CB] = (CELL)B;
HB = HR; HB = HR;
CP = YESCODE; gip->b = LCL0-CellPtr(B);
} }
static bool do_goal(yamop *CodeAdr, int arity, CELL *pt, bool top USES_REGS) { static bool do_goal(yamop *CodeAdr, int arity, CELL *pt, YAP_dogoalinfo *gi, bool top USES_REGS) {
choiceptr saved_b = B;
bool out; bool out;
Yap_PrepGoal(arity, pt, saved_b PASS_REGS); Yap_PrepGoal(arity, pt, gi PASS_REGS);
// CACHE_A1(); // CACHE_A1();
P = (yamop *)CodeAdr; P = (yamop *)CodeAdr;
// S = CellPtr(RepPredProp( // S = CellPtr(RepPredProp(
@ -1740,18 +1738,21 @@ void Yap_fail_all(choiceptr bb USES_REGS) {
} }
bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) { bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
yamop *saved_p, *saved_cp;
yamop *CodeAdr; yamop *CodeAdr;
bool out; bool out;
YAP_dogoalinfo gi;
saved_p = P; gi.p = P;
saved_cp = CP; gi.cp = CP;
gi.b0 = LCL0-CellPtr(B);
gi.CurSlot = Yap_CurrentHandle();
gi.a = LCL0-ASP;
gi.e = LCL0-ENV;
LOCAL_PrologMode |= TopGoalMode; LOCAL_PrologMode |= TopGoalMode;
PELOCK(81, ppe); PELOCK(81, ppe);
CodeAdr = ppe->CodeOfPred; CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock); UNLOCK(ppe->PELock);
out = do_goal(CodeAdr, ppe->ArityOfPE, pt, false PASS_REGS); out = do_goal(CodeAdr, ppe->ArityOfPE, pt, &gi, false PASS_REGS);
if (out) { if (out) {
choiceptr cut_B; choiceptr cut_B;
@ -1772,14 +1773,14 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
#endif #endif
} }
#endif /* TABLING */ #endif /* TABLING */
B = cut_B; B = (choiceptr)(LCL0-gi.b0);
CP = saved_cp; CP = gi.cp;
P = saved_p; P = gi.p;
ASP = ENV; ASP = LCL0-gi.a;
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH]; DEPTH = ENV[E_DEPTH];
#endif #endif
ENV = (CELL *)(ENV[E_E]); ENV = LCL0-gi.e;
/* we have failed, and usually we would backtrack to this B, /* we have failed, and usually we would backtrack to this B,
trouble is, we may also have a delayed cut to do */ trouble is, we may also have a delayed cut to do */
if (B != NULL) if (B != NULL)
@ -1798,18 +1799,18 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
} }
return true; return true;
} else if (out == 0) { } else if (out == 0) {
P = saved_p; P = gi.p;
CP = saved_cp; CP = gi.cp;
HR = B->cp_h; HR = B->cp_h;
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
DEPTH = B->cp_depth; DEPTH = B->cp_depth;
#endif #endif
/* ASP should be set to the top of the local stack when we /* ASP should be set to the top of the local stack when we
did the call */ did the call */
ASP = B->cp_env; ASP = LCL0-gi.a;
/* YENV should be set to the current environment */ /* YENV should be set to the current environment */
YENV = ENV = (CELL *)((B->cp_env)[E_E]); YENV = ENV = LCL0-gi.e;
B = B->cp_b; B =(choiceptr)(LCL0-gi.b);
SET_BB(B); SET_BB(B);
HB = PROTECT_FROZEN_H(B); HB = PROTECT_FROZEN_H(B);
// should we catch the exception or pass it through? // should we catch the exception or pass it through?
@ -1893,7 +1894,14 @@ Term Yap_RunTopGoal(Term t, bool handle_errors) {
UInt arity; UInt arity;
Term tmod = CurrentModule; Term tmod = CurrentModule;
Term goal_out = 0; Term goal_out = 0;
LOCAL_PrologMode |= TopGoalMode; YAP_dogoalinfo gi;
gi.p = P;
gi.cp = CP;
gi.b0 = gi.b = LCL0-CellPtr(B);
gi.CurSlot = Yap_CurrentHandle();
gi.a = LCL0-ASP;
gi.e = LCL0-ENV;
LOCAL_PrologMode |= TopGoalMode;
t = Yap_YapStripModule(t, &tmod); t = Yap_YapStripModule(t, &tmod);
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
@ -1963,7 +1971,7 @@ Term Yap_RunTopGoal(Term t, bool handle_errors) {
"unable to boot because of too little Trail space"); "unable to boot because of too little Trail space");
} }
#endif #endif
goal_out = do_goal(CodeAdr, arity, pt, handle_errors PASS_REGS); goal_out = do_goal(CodeAdr, arity, pt, &gi, handle_errors PASS_REGS);
return goal_out; return goal_out;
} }
@ -2227,6 +2235,7 @@ static Int generate_pred_info(USES_REGS1) {
void Yap_InitYaamRegs(int myworker_id, bool full_reset) { void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
Term h0var; Term h0var;
YAP_dogoalinfo gi;
// getchar(); // getchar();
#if PUSH_REGS #if PUSH_REGS
/* Guarantee that after a longjmp we go back to the original abstract /* Guarantee that after a longjmp we go back to the original abstract
@ -2298,7 +2307,7 @@ void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
PREG_ADDR = NULL; PREG_ADDR = NULL;
#endif #endif
cut_c_initialize(myworker_id); cut_c_initialize(myworker_id);
Yap_PrepGoal(0, NULL, NULL PASS_REGS); Yap_PrepGoal(0, NULL, &gi PASS_REGS);
#ifdef FROZEN_STACKS #ifdef FROZEN_STACKS
H_FZ = HR; H_FZ = HR;
#ifdef YAPOR_SBA #ifdef YAPOR_SBA

View File

@ -2048,7 +2048,7 @@ restart:
static Int p_nb_heap_del(USES_REGS1) { static Int p_nb_heap_del(USES_REGS1) {
CELL *qd = GetHeap(ARG1, "deheap"); CELL *qd = GetHeap(ARG1, "deheap");
UInt old_sz, qsz; UInt qsz;
Term arena; Term arena;
Term tk, tv; Term tk, tv;
@ -2060,8 +2060,7 @@ static Int p_nb_heap_del(USES_REGS1) {
arena = qd[HEAP_ARENA]; arena = qd[HEAP_ARENA];
if (arena == 0L) if (arena == 0L)
return FALSE; return FALSE;
old_sz = ArenaSz(arena); /* garbage collection ? */
/* garbage collection ? */
qd[HEAP_SIZE] =MkIntTerm(qsz - 1); qd[HEAP_SIZE] =MkIntTerm(qsz - 1);
tk = qd[HEAP_START]; tk = qd[HEAP_START];
tv = qd[HEAP_START + 1]; tv = qd[HEAP_START + 1];

View File

@ -1,4 +1,3 @@
/************************************************************************* /*************************************************************************
* * * *
* Yap Prolog * * Yap Prolog *

View File

@ -208,7 +208,7 @@ extern bool Yap_execute_goal(Term, int, Term, bool);
extern bool Yap_exec_absmi(bool, yap_reset_t); extern bool Yap_exec_absmi(bool, yap_reset_t);
extern void Yap_trust_last(void); extern void Yap_trust_last(void);
extern void Yap_PrepGoal(UInt, CELL *, choiceptr USES_REGS); extern void Yap_PrepGoal(UInt, CELL *, struct goal_info * USES_REGS);
extern bool Yap_execute_pred(struct pred_entry *ppe, CELL *pt, extern bool Yap_execute_pred(struct pred_entry *ppe, CELL *pt,
bool pass_exception USES_REGS); bool pass_exception USES_REGS);
extern int Yap_dogc(int extra_args, Term *tp USES_REGS); extern int Yap_dogc(int extra_args, Term *tp USES_REGS);

View File

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