From 63416fdc48389c1c5571c5d4bc3771a67c868ce3 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 14 Feb 2015 11:35:45 +0000 Subject: [PATCH] cut_c simplifications --- C/c_interface.c | 62 ++++++++++++++++++++----------------------------- H/Regs.h | 2 +- H/cut_c.h | 17 ++++++++------ 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/C/c_interface.c b/C/c_interface.c index 30bbdc5be..1edf37db9 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -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,43 +1624,29 @@ 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; - B = oB; - /* for slots to work */ - CurSlot = Yap_StartSlots( ); - ret = (exec_code)( PASS_REGS1 ); - Yap_CloseSlots(CurSlot); - if (!ret) { - Term t; - - LOCAL_BallTerm = EX; - EX = NULL; - if ((t = Yap_GetException())) { - Yap_JumpToEnv(t); - return FALSE; - } - } - return ret; + // YAP Native + val = exec_code( PASS_REGS1 ); + B = oB; } + 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; + } } diff --git a/H/Regs.h b/H/Regs.h index 019b69d22..f3764283c 100755 --- a/H/Regs.h +++ b/H/Regs.h @@ -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 */ diff --git a/H/cut_c.h b/H/cut_c.h index 75b942dc9..6eb0a8acb 100644 --- a/H/cut_c.h +++ b/H/cut_c.h @@ -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*/