fix reinit and improve performance for cut predicates.
This commit is contained in:
parent
b95b332f2b
commit
1a7561c609
@ -1640,16 +1640,22 @@ YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Int
|
Int
|
||||||
YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code)
|
YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
choiceptr oB = B;
|
||||||
|
/* find out where we belong */
|
||||||
|
while (B->cp_b < (choiceptr)top)
|
||||||
|
B = B->cp_b;
|
||||||
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) {
|
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) {
|
||||||
Int val;
|
Int val;
|
||||||
CPredicateV codev = (CPredicateV)exec_code;
|
CPredicateV codev = (CPredicateV)exec_code;
|
||||||
struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1));
|
struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1));
|
||||||
struct open_query_struct *oexec = execution;
|
struct open_query_struct *oexec = execution;
|
||||||
extern void PL_close_foreign_frame(struct open_query_struct *);
|
extern void PL_close_foreign_frame(struct open_query_struct *);
|
||||||
|
CELL *args = B->cp_args;
|
||||||
|
|
||||||
|
B = oB;
|
||||||
PP = pe;
|
PP = pe;
|
||||||
ctx->control = FRG_CUTTED;
|
ctx->control = FRG_CUTTED;
|
||||||
ctx->engine = NULL; //(PL_local_data *)Yap_regp;
|
ctx->engine = NULL; //(PL_local_data *)Yap_regp;
|
||||||
@ -1657,13 +1663,15 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code)
|
|||||||
if (pe->PredFlags & CArgsPredFlag) {
|
if (pe->PredFlags & CArgsPredFlag) {
|
||||||
val = execute_cargs_back(pe, exec_code, ctx PASS_REGS);
|
val = execute_cargs_back(pe, exec_code, ctx PASS_REGS);
|
||||||
} else {
|
} else {
|
||||||
val = ((codev)((&ARG1)-LCL0,0,ctx));
|
fprintf(stderr,"ctx=%p\n",ctx);
|
||||||
|
val = ((codev)(args-LCL0,0,ctx));
|
||||||
}
|
}
|
||||||
/* make sure we clean up the frames left by the user */
|
/* make sure we clean up the frames left by the user */
|
||||||
while (execution != oexec)
|
while (execution != oexec)
|
||||||
PL_close_foreign_frame(execution);
|
PL_close_foreign_frame(execution);
|
||||||
|
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
|
// B = LCL0-(CELL*)oB;
|
||||||
if (val == 0) {
|
if (val == 0) {
|
||||||
Term t;
|
Term t;
|
||||||
|
|
||||||
@ -1679,7 +1687,9 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Int ret = (exec_code)( PASS_REGS1 );
|
Int ret;
|
||||||
|
B = oB;
|
||||||
|
ret = (exec_code)( PASS_REGS1 );
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
Term t;
|
Term t;
|
||||||
|
|
||||||
|
2
C/init.c
2
C/init.c
@ -794,6 +794,7 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
code = (yamop *)(pe->cs.p_code.FirstClause);
|
code = (yamop *)(pe->cs.p_code.FirstClause);
|
||||||
|
code->u.OtapFs.p = pe;
|
||||||
if (pe->PredFlags & UserCPredFlag)
|
if (pe->PredFlags & UserCPredFlag)
|
||||||
code->opc = Yap_opcode(_try_userc);
|
code->opc = Yap_opcode(_try_userc);
|
||||||
else
|
else
|
||||||
@ -819,6 +820,7 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont)
|
|||||||
code->opc = Yap_opcode(_cut_c);
|
code->opc = Yap_opcode(_cut_c);
|
||||||
else
|
else
|
||||||
code->opc = Yap_opcode(_cut_userc);
|
code->opc = Yap_opcode(_cut_userc);
|
||||||
|
code->u.OtapFs.p = pe;
|
||||||
code->u.OtapFs.f = Cut;
|
code->u.OtapFs.f = Cut;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ void STD_PROTO(Yap_InitBigNums, (void));
|
|||||||
Int STD_PROTO(YAP_Execute,(struct pred_entry *, CPredicate));
|
Int STD_PROTO(YAP_Execute,(struct pred_entry *, CPredicate));
|
||||||
Int STD_PROTO(YAP_ExecuteFirst,(struct pred_entry *, CPredicate));
|
Int STD_PROTO(YAP_ExecuteFirst,(struct pred_entry *, CPredicate));
|
||||||
Int STD_PROTO(YAP_ExecuteNext,(struct pred_entry *, CPredicate));
|
Int STD_PROTO(YAP_ExecuteNext,(struct pred_entry *, CPredicate));
|
||||||
Int STD_PROTO(YAP_ExecuteOnCut,(struct pred_entry *, CPredicate));
|
Int STD_PROTO(YAP_ExecuteOnCut,(struct pred_entry *, CPredicate, struct cut_c_str *));
|
||||||
|
|
||||||
/* cdmgr.c */
|
/* cdmgr.c */
|
||||||
Term STD_PROTO(Yap_all_calls,(void));
|
Term STD_PROTO(Yap_all_calls,(void));
|
||||||
|
@ -40,7 +40,7 @@ struct cut_c_str{
|
|||||||
CPredicate func = (CPredicate)((yamop *)TOP->try_userc_cut_yamop)->u.OtapFs.f; \
|
CPredicate func = (CPredicate)((yamop *)TOP->try_userc_cut_yamop)->u.OtapFs.f; \
|
||||||
PredEntry *pred = (PredEntry *)((yamop *)TOP->try_userc_cut_yamop)->u.OtapFs.p; \
|
PredEntry *pred = (PredEntry *)((yamop *)TOP->try_userc_cut_yamop)->u.OtapFs.p; \
|
||||||
Yap_StartSlots( PASS_REGS1 ); \
|
Yap_StartSlots( PASS_REGS1 ); \
|
||||||
YAP_ExecuteOnCut(pred,func); \
|
YAP_ExecuteOnCut(pred, func, TOP); \
|
||||||
Yap_CloseSlots( PASS_REGS1 ); \
|
Yap_CloseSlots( PASS_REGS1 ); \
|
||||||
cut_c_pop();
|
cut_c_pop();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user