fix interrupt handling, especially for ! and ;

avoid using S.
This commit is contained in:
Vítor Santos Costa 2014-05-25 20:43:52 +01:00
parent 279a057d80
commit a719c19d03
2 changed files with 367 additions and 240 deletions

253
C/absmi.c
View File

@ -525,14 +525,23 @@ push_live_regs(yamop *pco)
CELL *lab = (CELL *)(pco->u.l.l);
CELL max = lab[0];
CELL curr = lab[1];
Term tp = MkIntegerTerm((Int)pco);
Term tcp = MkIntegerTerm((Int)CP);
Term tenv = MkIntegerTerm((Int)(LCL0-ENV));
Term tyenv = MkIntegerTerm((Int)(LCL0-YENV));
CELL *start = HR;
Int tot = 0;
if (max) {
CELL i;
HR++;
*HR++ = tp;
*HR++ = tcp;
*HR++ = tenv;
*HR++ = tyenv;
tot += 4;
{
CELL i;
lab += 2;
HR++;
for (i=0; i <= max; i++) {
if (i == 8*CellSize) {
curr = lab[0];
@ -570,8 +579,6 @@ push_live_regs(yamop *pco)
}
start[0] = (CELL)Yap_MkFunctor(AtomTrue, tot);
return(AbsAppl(start));
} else {
return(TermNil);
}
}
#endif
@ -615,11 +622,12 @@ check_alarm_fail_int(int CONT USES_REGS)
}
static int
stack_overflow( CELL *env, yamop *cp USES_REGS )
stack_overflow( PredEntry *pe, CELL *env, yamop *cp USES_REGS )
{
if ((Int)(Unsigned(YREG) - Unsigned(HR)) < StackGap( PASS_REGS1 ) ||
Yap_undo_signal( YAP_STOVF_SIGNAL )) {
if (!Yap_locked_gc(((PredEntry *)(S))->ArityOfPE, env, cp)) {
S = (CELL *)pe;
if (!Yap_locked_gc(pe->ArityOfPE, env, cp)) {
Yap_NilError(OUT_OF_STACK_ERROR,LOCAL_ErrorMessage);
return 0;
}
@ -632,7 +640,7 @@ static int
code_overflow( CELL *yenv USES_REGS )
{
if (Yap_undo_signal( YAP_CDOVF_SIGNAL )) {
CELL cut_b = LCL0-(CELL *)(S[E_CB]);
CELL cut_b = LCL0-(CELL *)(yenv[E_CB]);
/* do a garbage collection first to check if we can recover memory */
if (!Yap_locked_growheap(FALSE, 0, NULL)) {
@ -640,8 +648,8 @@ code_overflow( CELL *yenv USES_REGS )
return 0;
}
CACHE_A1();
if (S == ASP) {
S[E_CB] = (CELL)(LCL0-cut_b);
if (yenv == ASP) {
yenv[E_CB] = (CELL)(LCL0-cut_b);
}
return 1;
}
@ -649,9 +657,8 @@ code_overflow( CELL *yenv USES_REGS )
}
static int
interrupt_handler( USES_REGS1 )
interrupt_handler( PredEntry *pe USES_REGS )
{
PredEntry *pe = (PredEntry *)S;
// printf("D %lx %p\n", LOCAL_ActiveSignals, P);
/* tell whether we can creep or not, this is hard because we will
@ -727,8 +734,103 @@ interrupt_handler( USES_REGS1 )
return TRUE;
}
// interrupt handling code that sets up the case when we do not have
// a guaranteed environment.
static int
interrupt_handlerc( USES_REGS1 )
safe_interrupt_handler( PredEntry *pe USES_REGS )
{
CELL *npt = HR;
// printf("D %lx %p\n", LOCAL_ActiveSignals, P);
/* tell whether we can creep or not, this is hard because we will
lose the info RSN
*/
BEGD(d0);
S = (CELL *)pe;
d0 = pe->ArityOfPE;
if (d0 == 0) {
HR[1] = MkAtomTerm((Atom) pe->FunctorOfPred);
}
else {
HR[d0 + 2] = AbsAppl(HR);
HR += d0+1+2;
*npt++ = (CELL) pe->FunctorOfPred;
BEGP(pt1);
pt1 = XREGS + 1;
for (; d0 > 0; --d0) {
BEGD(d1);
d1 = *pt1;
loop:
if (!IsVarTerm(d1)) {
/* just copy it to the heap */
pt1++;
*npt++ = d1;
} else {
if (VarOfTerm(d1) < H0 || VarOfTerm(d1) > HR) {
d1 = Deref(d1);
if (VarOfTerm(d1) < H0 || VarOfTerm(d1) > HR) {
Term v = MkVarTerm();
Bind( VarOfTerm(d1),v );
} else {
goto loop;
}
} else {
*npt++ = d1;
}
}
ENDD(d1);
}
ENDP(pt1);
}
ENDD(d0);
npt[0] = Yap_Module_Name(pe);
ARG1 = AbsPair(npt);
HR += 2;
#ifdef COROUTINING
if (Yap_undo_signal( YAP_WAKEUP_SIGNAL )) {
CalculateStackGap( PASS_REGS1 );
ARG2 = Yap_ListOfWokenGoals();
pe = WakeUpCode;
/* no more goals to wake up */
Yap_UpdateTimedVar(LOCAL_WokenGoals,TermNil);
} else
#endif
{
CalculateStackGap( PASS_REGS1 );
pe = CreepCode;
}
UNLOCK(LOCAL_SignalLock);
// allocate an fill out an environment
YENV = ASP;
CACHE_Y_AS_ENV(YREG);
ENV_YREG[E_CP] = (CELL) CP;
ENV_YREG[E_E] = (CELL) ENV;
#ifdef DEPTH_LIMIT
ENV_YREG[E_DEPTH] = DEPTH;
#endif /* DEPTH_LIMIT */
ENV = ENV_YREG;
ENV_YREG = (CELL *)((CELL)ENV_YREG + ENV_Size(CP));
WRITEBACK_Y_AS_ENV();
ENDCACHE_Y_AS_ENV();
CP = P;
P = pe->CodeOfPred;
#ifdef DEPTH_LIMIT
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is primitives */
if (pe->ModuleOfPred) {
if (DEPTH == MkIntTerm(0))
return FALSE;
else DEPTH = RESET_DEPTH();
}
} else if (pe->ModuleOfPred) {
DEPTH -= MkIntConstant(2);
}
#endif /* DEPTH_LIMIT */
return TRUE;
}
static int
interrupt_handlerc( PredEntry *pe USES_REGS )
{
/* do creep in call */
ENV = YENV;
@ -753,18 +855,20 @@ interrupt_handlerc( USES_REGS1 )
#endif /* FROZEN_STACKS */
/* setup GB */
YENV[E_CB] = (CELL) B;
return interrupt_handler( PASS_REGS1 );
return interrupt_handler( pe PASS_REGS );
}
static int
interrupt_handler_either( USES_REGS1 )
interrupt_handler_either( Term t_cut, PredEntry *pe USES_REGS )
{
ENV = YENV;
CP = NEXTOP(P, Osbpp);
YENV = (CELL *) (((char *) YENV) + P->u.Osbpp.s);
int rc;
ARG1 = push_live_regs(NEXTOP(P, Osbpp));
#ifdef FROZEN_STACKS
{
choiceptr top_b = PROTECT_FROZEN_B(B);
// protect registers before we mess about.
// recompute YENV and get ASP
#ifdef YAPOR_SBA
if (YENV > (CELL *) top_b || YENV < HR) YENV = (CELL *) top_b;
#else
@ -776,17 +880,18 @@ interrupt_handler_either( USES_REGS1 )
if (YENV > (CELL *) B)
YENV = (CELL *) B;
#endif /* FROZEN_STACKS */
/* setup GB */
ARG1 = push_live_regs(CP);
/* ARG0 has an extra argument for suspended cuts */
ARG2 = XREGS[0];
YENV[E_CB] = (CELL) B;
SET_ASP(YENV, E_CB*sizeof(CELL));
return interrupt_handler( PASS_REGS1 );
P = NEXTOP(P, Osbpp);
// should we cut? If t_cut == INT(0) no
ARG2 = t_cut;
// ASP
SET_ASP(YENV, E_CB*sizeof(CELL));
// do the work.
rc = safe_interrupt_handler( pe PASS_REGS );
return rc;
}
/* totrace interrupt calls */
//#define DEBUG_INTERRUPTS 1
/* to trace interrupt calls */
// #define DEBUG_INTERRUPTS 1
#ifdef DEBUG_INTERRUPTS
static int trace_interrupts = TRUE;
@ -810,11 +915,10 @@ interrupt_fail( USES_REGS1 )
UNLOCK(LOCAL_SignalLock);
return FALSE;
}
S = (CELL *)RepPredProp(Yap_GetPredPropByAtom(AtomFail,0));
/* make sure we have the correct environment for continuation */
ENV = B->cp_env;
YENV = (CELL *)B;
return interrupt_handler( PASS_REGS1 );
return interrupt_handler( RepPredProp(Yap_GetPredPropByAtom(AtomFail,0)) PASS_REGS );
}
static int
@ -836,17 +940,16 @@ interrupt_execute( USES_REGS1 )
UNLOCK(LOCAL_SignalLock);
return 2;
}
S = (CELL *) P->u.pp.p;
SET_ASP(YENV, E_CB*sizeof(CELL));
if ((v = code_overflow(YENV PASS_REGS)) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
if ((v = stack_overflow(ENV, CP PASS_REGS )) >= 0) {
if ((v = stack_overflow(P->u.pp.p, ENV, CP PASS_REGS )) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
return interrupt_handler( PASS_REGS1 );
return interrupt_handler( P->u.pp.p PASS_REGS );
}
static int
@ -869,17 +972,16 @@ interrupt_call( USES_REGS1 )
UNLOCK(LOCAL_SignalLock);
return 2;
}
S = (CELL *) P->u.Osbpp.p;
SET_ASP(YENV, P->u.Osbpp.s);
if ((v = code_overflow(YENV PASS_REGS)) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
if ((v = stack_overflow(YENV, NEXTOP(P, Osbpp) PASS_REGS )) >= 0) {
if ((v = stack_overflow( P->u.Osbpp.p, YENV, NEXTOP(P, Osbpp) PASS_REGS )) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
return interrupt_handlerc( PASS_REGS1 );
return interrupt_handlerc( P->u.Osbpp.p PASS_REGS );
}
static int
@ -901,7 +1003,6 @@ interrupt_pexecute( PredEntry *pen USES_REGS )
UNLOCK(LOCAL_SignalLock);
return 2; /* keep on creeping */
}
S = (CELL *) pen;
SET_ASP(YENV, E_CB*sizeof(CELL));
/* setup GB */
YENV[E_CB] = (CELL) B;
@ -909,12 +1010,12 @@ interrupt_pexecute( PredEntry *pen USES_REGS )
UNLOCK(LOCAL_SignalLock);
return v;
}
if ((v = stack_overflow(ENV, NEXTOP(P, Osbmp) PASS_REGS )) >= 0) {
if ((v = stack_overflow( pen, ENV, NEXTOP(P, Osbmp) PASS_REGS )) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
CP = NEXTOP(P, Osbmp);
return interrupt_handler( PASS_REGS1 );
return interrupt_handler( pen PASS_REGS );
}
/* don't forget I cannot creep at deallocate (where to?) */
@ -956,14 +1057,16 @@ interrupt_deallocate( USES_REGS1 )
return v;
}
if (Yap_has_a_signal()) {
PredEntry *pe;
if (Yap_op_from_opcode(P->opc) == _cut_e) {
/* followed by a cut */
ARG1 = MkIntegerTerm(LCL0-(CELL *)S[E_CB]);
S = (CELL *)RepPredProp(Yap_GetPredPropByFunc(FunctorCutBy,1));
/* followed by a cut */
ARG1 = MkIntegerTerm(LCL0-(CELL *)S[E_CB]);
pe = RepPredProp(Yap_GetPredPropByFunc(FunctorCutBy,1));
} else {
S = (CELL *)RepPredProp(Yap_GetPredPropByAtom(AtomTrue,0));
pe = RepPredProp(Yap_GetPredPropByAtom(AtomTrue,0));
}
return interrupt_handler( PASS_REGS1 );
return interrupt_handler( pe PASS_REGS );
}
if (!Yap_locked_gc(0, ENV, CP)) {
Yap_NilError(OUT_OF_STACK_ERROR,LOCAL_ErrorMessage);
@ -978,6 +1081,7 @@ interrupt_deallocate( USES_REGS1 )
static int
interrupt_cut( USES_REGS1 )
{
Term t_cut = MkIntegerTerm(LCL0-(CELL *)YENV[E_CB]);
int v;
#ifdef DEBUG_INTERRUPTS
if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s:%d (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \
@ -993,15 +1097,14 @@ interrupt_cut( USES_REGS1 )
return 2;
}
/* find something to fool S */
S = (CELL *)PredRestoreRegs;
XREGS[0] = MkIntegerTerm(LCL0-(CELL *)YENV[E_CB]);
P = NEXTOP(P,s);
return interrupt_handler_either( PASS_REGS1 );
return interrupt_handler_either( t_cut, PredRestoreRegs PASS_REGS );
}
static int
interrupt_cut_t( USES_REGS1 )
{
Term t_cut = MkIntegerTerm(LCL0-(CELL *)YENV[E_CB]);
int v;
#ifdef DEBUG_INTERRUPTS
if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s:%d: (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \
@ -1018,17 +1121,41 @@ interrupt_cut_t( USES_REGS1 )
return 2;
}
/* find something to fool S */
XREGS[0] = MkIntegerTerm(LCL0-(CELL *)S[E_CB]);
S = (CELL *)PredRestoreRegs;
P = NEXTOP(P,s);
return interrupt_handler_either( PASS_REGS1 );
return interrupt_handler_either( t_cut, PredRestoreRegs PASS_REGS );
}
static int
interrupt_cut_e( USES_REGS1 )
{
Term t_cut = MkIntegerTerm(LCL0-(CELL *)S[E_CB]);
int v;
#ifdef DEBUG_INTERRUPTS
if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s:%d: (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \
__FUNCTION__, __LINE__,YENV,ENV,ASP);
#endif
LOCK(LOCAL_SignalLock);
if ((v = check_alarm_fail_int( 2 PASS_REGS )) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
if (!Yap_has_a_signal()
|| Yap_only_has_signals(YAP_CDOVF_SIGNAL , YAP_CREEP_SIGNAL )) {
UNLOCK(LOCAL_SignalLock);
return 2;
}
/* find something to fool S */
P = NEXTOP(P,s);
return interrupt_handler_either( t_cut, PredRestoreRegs PASS_REGS );
}
static int
interrupt_commit_y( USES_REGS1 )
{
int v;
#ifdef DEBUG_INTERRUPTS
Term t_cut = YENV[P->u.yps.y];
#ifdef DEBUG_INTERRUPTS
if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s:%d: (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \
__FUNCTION__, __LINE__,YENV,ENV,ASP);
#endif
@ -1043,17 +1170,17 @@ interrupt_commit_y( USES_REGS1 )
return 2;
}
/* find something to fool S */
S = (CELL *)PredRestoreRegs;
XREGS[0] = YENV[P->u.yps.y];
P = NEXTOP(P,yps);
return interrupt_handler_either( PASS_REGS1 );
return interrupt_handler_either( t_cut, PredRestoreRegs PASS_REGS );
}
static int
interrupt_commit_x( USES_REGS1 )
{
int v;
#ifdef DEBUG_INTERRUPTS
Term t_cut = XREG(P->u.xps.x);
#ifdef DEBUG_INTERRUPTS
if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s:%d (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \
__FUNCTION__, __LINE__,YENV,ENV,ASP);
#endif
@ -1069,7 +1196,6 @@ interrupt_commit_x( USES_REGS1 )
}
PP = P->u.xps.p0;
/* find something to fool S */
S = (CELL *)PredRestoreRegs;
if (P->opc == Yap_opcode(_fcall)) {
/* fill it up */
CACHE_Y_AS_ENV(YREG);
@ -1080,9 +1206,8 @@ interrupt_commit_x( USES_REGS1 )
#endif /* DEPTH_LIMIT */
ENDCACHE_Y_AS_ENV();
}
XREGS[0] = XREG(P->u.xps.x);
P = NEXTOP(P,xps);
return interrupt_handler_either( PASS_REGS1 );
return interrupt_handler_either( t_cut, PredRestoreRegs PASS_REGS );
}
static int
@ -1105,7 +1230,6 @@ interrupt_either( USES_REGS1 )
}
PP = P->u.Osblp.p0;
/* find something to fool S */
S = (CELL *)RepPredProp(Yap_GetPredPropByFunc(FunctorRestoreRegs1,0));
SET_ASP(YENV, P->u.Osbpp.s);
if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)PROTECT_FROZEN_B(B);
@ -1113,23 +1237,25 @@ interrupt_either( USES_REGS1 )
UNLOCK(LOCAL_SignalLock);
return v;
}
if ((v = stack_overflow(YENV, NEXTOP(P, Osbpp) PASS_REGS )) >= 0) {
if ((v = stack_overflow(RepPredProp(Yap_GetPredPropByFunc(FunctorRestoreRegs1,0)), YENV, NEXTOP(P, Osbpp) PASS_REGS )) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
return interrupt_handler_either( PASS_REGS1 );
return interrupt_handler_either( MkIntTerm(0), RepPredProp(Yap_GetPredPropByFunc(FunctorRestoreRegs1,0)) PASS_REGS );
}
static int
interrupt_dexecute( USES_REGS1 )
{
int v;
PredEntry *pe;
#ifdef DEBUG_INTERRUPTS
if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s/%d (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \
__FUNCTION__, __LINE__,YENV,ENV,ASP);
#endif
PP = P->u.pp.p0;
pe = P->u.pp.p;
LOCK(LOCAL_SignalLock);
if (Yap_has_signal(YAP_CREEP_SIGNAL) &&
(PP->ExtraPredFlags & (NoDebugPredFlag|HiddenPredFlag))) {
@ -1137,7 +1263,6 @@ interrupt_dexecute( USES_REGS1 )
return 2;
}
/* set S for next instructions */
S = (CELL *) P->u.pp.p;
ASP = YENV+E_CB;
if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)PROTECT_FROZEN_B(B);
@ -1145,7 +1270,7 @@ interrupt_dexecute( USES_REGS1 )
UNLOCK(LOCAL_SignalLock);
return v;
}
if ((v = stack_overflow((CELL *)YENV[E_E], (yamop *)YENV[E_CP] PASS_REGS )) >= 0) {
if ((v = stack_overflow( P->u.pp.p, (CELL *)YENV[E_E], (yamop *)YENV[E_CP] PASS_REGS )) >= 0) {
UNLOCK(LOCAL_SignalLock);
return v;
}
@ -1177,7 +1302,7 @@ interrupt_dexecute( USES_REGS1 )
YENV[E_CB] = (CELL) B;
/* and now CREEP */
return interrupt_handler( PASS_REGS1 );
return interrupt_handler( pe PASS_REGS );
}
Int
@ -3223,7 +3348,7 @@ Yap_absmi(int inp)
#ifdef COROUTINING
NoStackCutE:
PROCESS_INT(interrupt_cut_t, do_cut_e);
PROCESS_INT(interrupt_cut_e, do_cut_e);
#endif
ENDOp();

View File

@ -30,7 +30,6 @@ static Int EnterCreepMode(Term, Term CACHE_TYPE);
static Int p_save_cp( USES_REGS1 );
static Int p_execute( USES_REGS1 );
static Int p_execute0( USES_REGS1 );
static int execute_pred(PredEntry *ppe, CELL *pt USES_REGS);
static Term
cp_as_integer(choiceptr cp USES_REGS)
@ -676,7 +675,7 @@ p_do_goal_expansion( USES_REGS1 )
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, cmod) ) ) &&
pe->OpcodeOfPred != FAIL_OPCODE &&
pe->OpcodeOfPred != UNDEF_OPCODE &&
execute_pred(pe, NULL PASS_REGS) ) {
Yap_execute_pred(pe, NULL PASS_REGS) ) {
out = TRUE;
ARG3 = ARG2;
goto complete;
@ -685,7 +684,7 @@ p_do_goal_expansion( USES_REGS1 )
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE ) ) ) &&
pe->OpcodeOfPred != FAIL_OPCODE &&
pe->OpcodeOfPred != UNDEF_OPCODE &&
execute_pred(pe, NULL PASS_REGS) ) {
Yap_execute_pred(pe, NULL PASS_REGS) ) {
out = TRUE;
ARG3 = ARG2;
goto complete;
@ -696,7 +695,7 @@ p_do_goal_expansion( USES_REGS1 )
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE ) ) ) &&
pe->OpcodeOfPred != FAIL_OPCODE &&
pe->OpcodeOfPred != UNDEF_OPCODE &&
execute_pred(pe, NULL PASS_REGS) ) {
Yap_execute_pred(pe, NULL PASS_REGS) ) {
out = TRUE;
goto complete;
}
@ -706,7 +705,7 @@ p_do_goal_expansion( USES_REGS1 )
(pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE ) ) ) &&
pe->OpcodeOfPred != FAIL_OPCODE &&
pe->OpcodeOfPred != UNDEF_OPCODE &&
execute_pred(pe, NULL PASS_REGS) ) {
Yap_execute_pred(pe, NULL PASS_REGS) ) {
ARG3 = ARG2;
out = TRUE;
}
@ -738,7 +737,7 @@ p_do_term_expansion( USES_REGS1 )
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, cmod) ) ) &&
pe->OpcodeOfPred != FAIL_OPCODE &&
pe->OpcodeOfPred != UNDEF_OPCODE &&
execute_pred(pe, NULL PASS_REGS) ) {
Yap_execute_pred(pe, NULL PASS_REGS) ) {
out = TRUE;
goto complete;
}
@ -746,7 +745,7 @@ p_do_term_expansion( USES_REGS1 )
if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE ) ) ) &&
pe->OpcodeOfPred != FAIL_OPCODE &&
pe->OpcodeOfPred != UNDEF_OPCODE &&
execute_pred(pe, NULL PASS_REGS) ) {
Yap_execute_pred(pe, NULL PASS_REGS) ) {
out = TRUE;
goto complete;
}
@ -755,7 +754,7 @@ p_do_term_expansion( USES_REGS1 )
(pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE ) ) ) &&
pe->OpcodeOfPred != FAIL_OPCODE &&
pe->OpcodeOfPred != UNDEF_OPCODE &&
execute_pred(pe, NULL PASS_REGS) ) {
Yap_execute_pred(pe, NULL PASS_REGS) ) {
out = TRUE;
}
complete:
@ -1215,8 +1214,8 @@ Yap_exec_absmi(int top)
}
static int
execute_pred(PredEntry *ppe, CELL *pt USES_REGS)
int
Yap_execute_pred(PredEntry *ppe, CELL *pt USES_REGS)
{
yamop *saved_p, *saved_cp;
yamop *CodeAdr;
@ -1226,15 +1225,9 @@ execute_pred(PredEntry *ppe, CELL *pt USES_REGS)
saved_cp = CP;
PELOCK(81,ppe);
if (ppe->ArityOfPE == 0) {
CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock);
out = do_goal(CodeAdr, 0, pt, FALSE PASS_REGS);
} else {
CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock);
out = do_goal(CodeAdr, ppe->ArityOfPE, pt, FALSE PASS_REGS);
}
CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock);
out = do_goal(CodeAdr, ppe->ArityOfPE, pt, FALSE PASS_REGS);
if (out == 1) {
choiceptr cut_B;
@ -1335,7 +1328,7 @@ Yap_execute_goal(Term t, int nargs, Term mod)
if (pe == NIL) {
return CallMetaCall(t, mod PASS_REGS);
}
return execute_pred(ppe, pt PASS_REGS);
return Yap_execute_pred(ppe, pt PASS_REGS);
}
@ -1430,13 +1423,17 @@ Yap_RunTopGoal(Term t)
}
static void
restore_regs(Term t USES_REGS)
restore_regs(Term t, int restore_all USES_REGS)
{
if (IsApplTerm(t)) {
Int i;
Int max = ArityOfFunctor(FunctorOfTerm(t));
CELL *ptr = RepAppl(t)+1;
Int max = ArityOfFunctor(FunctorOfTerm(t))-4;
CELL *ptr = RepAppl(t)+5;
P = (yamop *)IntegerOfTerm(ptr[-4]);
CP = (yamop *)IntegerOfTerm(ptr[-3]);
ENV = (CELL *)(LCL0-IntegerOfTerm(ptr[-2]));
YENV = (CELL *)(LCL0-IntegerOfTerm(ptr[-1]));
for (i = 0; i < max; i += 2) {
Int j = IntOfTerm(ptr[0]);
XREGS[j] = ptr[1];
@ -1455,7 +1452,7 @@ p_restore_regs( USES_REGS1 )
return(FALSE);
}
if (IsAtomTerm(t)) return(TRUE);
restore_regs(t PASS_REGS);
restore_regs(t, FALSE PASS_REGS);
return(TRUE);
}
@ -1466,13 +1463,15 @@ p_restore_regs2( USES_REGS1 )
Term t = Deref(ARG1), d0;
choiceptr pt0;
Int d;
if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR,t,"support for coroutining");
return(FALSE);
}
d0 = Deref(ARG2);
if (!IsAtomTerm(t)) {
restore_regs(t PASS_REGS);
restore_regs(t, TRUE PASS_REGS);
}
if (IsVarTerm(d0)) {
Yap_Error(INSTANTIATION_ERROR,d0,"support for coroutining");
@ -1481,13 +1480,16 @@ p_restore_regs2( USES_REGS1 )
if (!IsIntegerTerm(d0)) {
return(FALSE);
}
d = IntegerOfTerm(d0);
if (!d)
return TRUE;
#if YAPOR_SBA
pt0 = (choiceptr)IntegerOfTerm(d0);
pt0 = (choiceptr)d;
#else
pt0 = (choiceptr)(LCL0-IntOfTerm(d0));
pt0 = (choiceptr)(LCL0-d);
#endif
/* find where to cut to */
if (pt0 > B) {
if ((CELL *)pt0 != LCL0 && pt0 > B) {
/* Wow, we're gonna cut!!! */
while (B->cp_b < pt0) {
while (POP_CHOICE_POINT(B->cp_b))