diff --git a/C/c_interface.c b/C/c_interface.c index 115294d49..1949bd290 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -1474,14 +1474,37 @@ YAP_Execute(PredEntry *pe, CPredicate exec_code) struct foreign_context ctx; UInt i; Int sl = 0; + Int ret; + ctx.engine = NULL; for (i=pe->ArityOfPE; i > 0; i--) { sl = Yap_InitSlot(XREGS[i]); } - return ((codev)(sl,0,&ctx)); + ret = ((codev)(sl,0,&ctx)); + if (!ret) { + Term t; + + BallTerm = EX; + EX = NULL; + if ((t = Yap_GetException())) { + Yap_JumpToEnv(t); + return FALSE; + } + } + return ret; } if (pe->PredFlags & CArgsPredFlag) { Int out = execute_cargs(pe, exec_code); + if (!out) { + Term t; + + BallTerm = EX; + EX = NULL; + if ((t = Yap_GetException())) { + Yap_JumpToEnv(t); + return FALSE; + } + } return out; } else { return((exec_code)()); @@ -1510,6 +1533,14 @@ YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) val = ((codev)((&ARG1)-LCL0,0,ctx)); } if (val == 0) { + Term t; + + BallTerm = EX; + EX = NULL; + if ((t = Yap_GetException())) { + Yap_JumpToEnv(t); + return FALSE; + } cut_fail(); } else if (val == 1) { /* TRUE */ cut_succeed(); @@ -1541,7 +1572,16 @@ YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) val = ((codev)((&ARG1)-LCL0,0,ctx)); } if (val == 0) { - cut_fail(); + Term t; + + BallTerm = EX; + EX = NULL; + if ((t = Yap_GetException())) { + Yap_JumpToEnv(t); + return FALSE; + } else { + cut_fail(); + } } else if (val == 1) { /* TRUE */ cut_succeed(); } else { diff --git a/C/exec.c b/C/exec.c index 7850e88f5..82b2c85e5 100644 --- a/C/exec.c +++ b/C/exec.c @@ -1710,8 +1710,8 @@ p_debug_on(void) return TRUE; } -static Term -GetException(void) +Term +Yap_GetException(void) { Term t = 0L; if (BallTerm) { @@ -1743,7 +1743,7 @@ p_reset_exception(void) { Term t; EX = NULL; - t = GetException(); + t = Yap_GetException(); if (!t) return FALSE; return Yap_unify(t, ARG1); @@ -1759,7 +1759,7 @@ Yap_ResetExceptionTerm(void) static Int p_get_exception(void) { - Term t = GetException(); + Term t = Yap_GetException(); if (!t) return FALSE; return Yap_unify(t, ARG1); diff --git a/H/Yapproto.h b/H/Yapproto.h index 6ac8085c9..72c91392c 100755 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -180,6 +180,7 @@ void STD_PROTO(Yap_ResetExceptionTerm,(void)); Int STD_PROTO(Yap_execute_goal,(Term, int, Term)); int STD_PROTO(Yap_exec_absmi,(int)); void STD_PROTO(Yap_trust_last,(void)); +Term STD_PROTO(Yap_GetException,(void)); /* gprof.c */ void STD_PROTO(Yap_InitLowProf,(void)); diff --git a/library/dialect/swi/fli/swi.c b/library/dialect/swi/fli/swi.c index d912e93ef..fef89146b 100755 --- a/library/dialect/swi/fli/swi.c +++ b/library/dialect/swi/fli/swi.c @@ -1271,7 +1271,7 @@ X_API int PL_put_variable(term_t t) X_API int PL_raise_exception(term_t exception) { - YAP_Throw(Yap_GetFromSlot(exception)); + EX = Yap_StoreTermInDB(Yap_GetFromSlot(exception),0); return 0; } @@ -2763,13 +2763,6 @@ PL_free(void *obj) free(obj); } -static int -PL_error(const char *pred, int arity, const char *msg, int id, ...) -{ - fprintf(stderr,"Internal PL_error Not implemented\n"); - return 0; -} - X_API int PL_eval_expression_to_int64_ex(term_t t, int64_t *val) {