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
|
||||
YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code)
|
||||
YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
|
||||
{
|
||||
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)) {
|
||||
Int val;
|
||||
CPredicateV codev = (CPredicateV)exec_code;
|
||||
struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1));
|
||||
struct open_query_struct *oexec = execution;
|
||||
extern void PL_close_foreign_frame(struct open_query_struct *);
|
||||
CELL *args = B->cp_args;
|
||||
|
||||
B = oB;
|
||||
PP = pe;
|
||||
ctx->control = FRG_CUTTED;
|
||||
ctx->engine = NULL; //(PL_local_data *)Yap_regp;
|
||||
@ -1657,13 +1663,15 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code)
|
||||
if (pe->PredFlags & CArgsPredFlag) {
|
||||
val = execute_cargs_back(pe, exec_code, ctx PASS_REGS);
|
||||
} 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 */
|
||||
while (execution != oexec)
|
||||
PL_close_foreign_frame(execution);
|
||||
|
||||
PP = NULL;
|
||||
// B = LCL0-(CELL*)oB;
|
||||
if (val == 0) {
|
||||
Term t;
|
||||
|
||||
@ -1679,7 +1687,9 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code)
|
||||
return TRUE;
|
||||
}
|
||||
} else {
|
||||
Int ret = (exec_code)( PASS_REGS1 );
|
||||
Int ret;
|
||||
B = oB;
|
||||
ret = (exec_code)( PASS_REGS1 );
|
||||
if (!ret) {
|
||||
Term t;
|
||||
|
||||
|
2
C/init.c
2
C/init.c
@ -794,6 +794,7 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont)
|
||||
return;
|
||||
}
|
||||
code = (yamop *)(pe->cs.p_code.FirstClause);
|
||||
code->u.OtapFs.p = pe;
|
||||
if (pe->PredFlags & UserCPredFlag)
|
||||
code->opc = Yap_opcode(_try_userc);
|
||||
else
|
||||
@ -819,6 +820,7 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont)
|
||||
code->opc = Yap_opcode(_cut_c);
|
||||
else
|
||||
code->opc = Yap_opcode(_cut_userc);
|
||||
code->u.OtapFs.p = pe;
|
||||
code->u.OtapFs.f = Cut;
|
||||
#endif
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ void STD_PROTO(Yap_InitBigNums, (void));
|
||||
Int STD_PROTO(YAP_Execute,(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_ExecuteOnCut,(struct pred_entry *, CPredicate));
|
||||
Int STD_PROTO(YAP_ExecuteOnCut,(struct pred_entry *, CPredicate, struct cut_c_str *));
|
||||
|
||||
/* cdmgr.c */
|
||||
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; \
|
||||
PredEntry *pred = (PredEntry *)((yamop *)TOP->try_userc_cut_yamop)->u.OtapFs.p; \
|
||||
Yap_StartSlots( PASS_REGS1 ); \
|
||||
YAP_ExecuteOnCut(pred,func); \
|
||||
YAP_ExecuteOnCut(pred, func, TOP); \
|
||||
Yap_CloseSlots( PASS_REGS1 ); \
|
||||
cut_c_pop();
|
||||
|
||||
|
Reference in New Issue
Block a user