cut_c simplifications

This commit is contained in:
Vitor Santos Costa 2015-02-14 11:35:45 +00:00
parent ada2ad44de
commit 63416fdc48
3 changed files with 36 additions and 45 deletions

View File

@ -1603,18 +1603,20 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
{
CACHE_REGS
choiceptr oB = B;
Int val;
/* for slots to work */
yhandle_t CurSlot = Yap_StartSlots();
/* find out where we belong */
while (B->cp_b < (choiceptr)top)
B = B->cp_b;
PP = pe;
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) {
Int val;
// SWI Emulation
CPredicateV codev = (CPredicateV)exec_code;
struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1));
CELL *args = B->cp_args;
B = oB;
PP = pe;
ctx->control = FRG_CUTTED;
ctx->engine = NULL; //(PL_local_data *)Yap_regp;
if (pe->PredFlags & CArgsPredFlag) {
@ -1622,42 +1624,28 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
} else {
val = codev(Yap_InitSlots(pe->ArityOfPE, args),0,ctx);
}
Yap_CloseSlots(CurSlot);
PP = NULL;
// B = LCL0-(CELL*)oB;
if (val == 0) {
Term t;
LOCAL_BallTerm = EX;
EX = NULL;
if ((t = Yap_GetException())) {
cut_c_pop();
Yap_JumpToEnv(t);
return FALSE;
}
return FALSE;
} else { /* TRUE */
return TRUE;
}
} else {
Int ret, CurSlot;
// YAP Native
val = exec_code( PASS_REGS1 );
B = oB;
/* for slots to work */
CurSlot = Yap_StartSlots( );
ret = (exec_code)( PASS_REGS1 );
Yap_CloseSlots(CurSlot);
if (!ret) {
Term t;
}
Yap_CloseSlots(CurSlot);
LOCAL_BallTerm = EX;
EX = NULL;
if ((t = Yap_GetException())) {
Yap_JumpToEnv(t);
return FALSE;
}
PP = NULL;
// B = LCL0-(CELL*)oB;
if (val == 0) {
Term t;
LOCAL_BallTerm = EX;
EX = NULL;
if ((t = Yap_GetException())) {
cut_c_pop();
Yap_JumpToEnv(t);
return FALSE;
}
return ret;
return FALSE;
} else { /* TRUE */
return TRUE;
}
}

View File

@ -105,7 +105,7 @@ typedef struct regstore_t
yamop *CP_; /* 28 continuation program counter */
CELL *ENV_; /* 1 current environment */
struct cut_c_str *CUT_C_TOP;
#if defined MYDDAS_ODBC || defined MYDDAS_MYSQL || defined MYDDAS_SQLITE3
#if defined USE_MYDDAS
struct myddas_global *MYDDAS_GLOBAL_POINTER;
#endif
yamop *P_; /* 7 prolog machine program counter */

View File

@ -17,8 +17,11 @@ struct cut_c_str{
#define CUT_C_STR_SIZE ((sizeof(struct cut_c_str))/(sizeof(CELL)))
#define EXTRA_CBACK_CUT_ARG(Type,Offset) \
((Type) (*(Type *)(((CELL *)Yap_REGS.CUT_C_TOP) - (((yamop *)Yap_REGS.CUT_C_TOP->try_userc_cut_yamop)->y_u.OtapFs.extra)) + (Offset-1)))
#define EXTRA_CBACK_CUT_ARG(Type,Offset) \
EXTRA_CBACK_ARG( PP->ArityOfPE, Offset )
#define CBACK_CUT_ARG(Offset) \
B->cp_args[ (Offset) - 1 ]
#define CUT_C_PUSH(YAMOP,S_YREG) \
{ \
@ -36,11 +39,11 @@ struct cut_c_str{
#define POP_EXECUTE() \
cut_c_str_ptr TOP = Yap_REGS.CUT_C_TOP; \
CPredicate func = (CPredicate)((yamop *)TOP->try_userc_cut_yamop)->y_u.OtapFs.f; \
PredEntry *pred = (PredEntry *)((yamop *)TOP->try_userc_cut_yamop)->y_u.OtapFs.p; \
YAP_ExecuteOnCut(pred, func, TOP); \
cut_c_pop();
cut_c_str_ptr TOP = Yap_REGS.CUT_C_TOP; \
CPredicate func = (CPredicate)((yamop *)TOP->try_userc_cut_yamop)->y_u.OtapFs.f; \
PredEntry *pred = (PredEntry *)((yamop *)TOP->try_userc_cut_yamop)->y_u.OtapFs.p; \
YAP_ExecuteOnCut(pred, func, TOP); \
cut_c_pop();
/*Initializes CUT_C_TOP*/