fix slots: have slots ready at init, even if we don't have a Prolog top-level;

don't get lost after pruning.
This commit is contained in:
ubu32 2011-07-11 22:12:32 -07:00
parent 2a51403518
commit 11a74236dc
3 changed files with 19 additions and 1 deletions

View File

@ -1134,6 +1134,7 @@ YAP_cut_up(void)
pointer back to where cut_up called it. Slots depend on it. */
if (ENV > B->cp_env) {
ASP = B->cp_env;
Yap_PopSlots( PASS_REGS1 );
}
#ifdef YAPOR
{
@ -2166,6 +2167,7 @@ run_emulator(YAP_dogoalinfo *dgi)
#endif /* DEPTH_LIMIT */
YENV = ENV = B->cp_env;
ASP = (CELL *)(B+1);
Yap_PopSlots( PASS_REGS1 );
B = B->cp_b;
HB = B->cp_h;
} else {
@ -2210,6 +2212,7 @@ YAP_EnterGoal(PredEntry *pe, Term *ptr, YAP_dogoalinfo *dgi)
B = myB;
HB = H;
ASP = YENV = (CELL *)B;
Yap_PopSlots( PASS_REGS1 );
YENV[E_CB] = Unsigned (B);
out = run_emulator(dgi);
RECOVER_MACHINE_REGS();
@ -2271,6 +2274,7 @@ YAP_LeaveGoal(int backtrack, YAP_dogoalinfo *dgi)
}
/* recover local stack */
ASP = (CELL *)(B+1);
Yap_PopSlots( PASS_REGS1 );
/* make sure we prune C-choicepoints */
if (POP_CHOICE_POINT(B->cp_b))
{
@ -2344,6 +2348,7 @@ YAP_RunGoalOnce(Term t)
B = cut_pt;
}
ASP = B->cp_env;
Yap_PopSlots( PASS_REGS1 );
ENV = (CELL *)ASP[E_E];
B = (choiceptr)ASP[E_CB];
#ifdef DEPTH_LIMIT
@ -2413,6 +2418,7 @@ YAP_ShutdownGoal(int backtrack)
}
/* we can always recover the stack */
ASP = cut_pt->cp_env;
Yap_PopSlots( PASS_REGS1 );
ENV = (CELL *)ASP[E_E];
B = (choiceptr)ASP[E_CB];
Yap_TrimTrail();

View File

@ -997,7 +997,6 @@ exec_absmi(int top USES_REGS)
YENV = ASP;
YENV[E_CB] = Unsigned (B);
out = Yap_absmi(0);
Yap_StartSlots( PASS_REGS1 );
/* make sure we don't leave a FAIL signal hanging around */
LOCAL_ActiveSignals &= ~YAP_FAIL_SIGNAL;
if (!LOCAL_ActiveSignals)
@ -1656,6 +1655,7 @@ Yap_InitYaamRegs(void)
/* the first real choice-point will also have AP=FAIL */
/* always have an empty slots for people to use */
CurSlot = 0;
Yap_StartSlots( PASS_REGS1 );
LOCAL_GlobalArena = TermNil;
h0var = MkVarTerm();
#if COROUTINING

12
H/Yap.h
View File

@ -1217,6 +1217,18 @@ Yap_CurrentSlot( USES_REGS1 ) {
return IntOfTerm(ASP[0]);
}
/* pop slots when pruning */
static inline void
Yap_PopSlots( USES_REGS1 ) {
while (LCL0-CurSlot < ASP) {
Int old_slots;
CELL *ptr = LCL0-CurSlot;
old_slots = IntOfTerm(ptr[0]);
ptr += (old_slots+1);
CurSlot = IntOfTerm(*ptr);
}
}
/************************/
#ifdef THREADS
typedef struct thandle {