fix exception

This commit is contained in:
Vítor Santos Costa 2018-04-16 22:51:34 +01:00
parent abb328abf0
commit 7bfe8aedbe
6 changed files with 19 additions and 16 deletions

View File

@ -551,7 +551,6 @@ static char tmpbuf[YAP_BUF_SIZE];
#include "YapErrors.h" #include "YapErrors.h"
bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) { bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) {
yap_error_number err = LOCAL_ActiveError->errorNo;
memset(new_error, 0, sizeof(yap_error_descriptor_t)); memset(new_error, 0, sizeof(yap_error_descriptor_t));
new_error->top_error = LOCAL_ActiveError; new_error->top_error = LOCAL_ActiveError;
LOCAL_ActiveError = new_error; LOCAL_ActiveError = new_error;
@ -1029,7 +1028,10 @@ static Int get_exception(USES_REGS1) {
} else { } else {
t = mkerrort(i->errorNo, TermNil, MkSysError(i)); t = mkerrort(i->errorNo, TermNil, MkSysError(i));
} }
return Yap_unify(t, ARG1); while (B && B->cp_b && ! Yap_unify(t, B->cp_a2)) {
Yap_JumpToEnv();
}
return true;
} }
return false; return false;
} }

View File

@ -148,8 +148,8 @@ static Term Eval(Term t USES_REGS) {
} }
t2 = Eval(ArgOfTerm(2, t) PASS_REGS); t2 = Eval(ArgOfTerm(2, t) PASS_REGS);
*RepAppl(t) = (CELL)fun; *RepAppl(t) = (CELL)fun;
LOCAL_ctx = ctx.p; LOCAL_ctx = ctx.p;
return Yap_eval_binary(p->FOfEE, t1, t2); return Yap_eval_binary(p->FOfEE, t1, t2);
} }
} /* else if (IsPairTerm(t)) */ } /* else if (IsPairTerm(t)) */
{ {
@ -208,8 +208,8 @@ static Int p_is(USES_REGS1) { /* X is Y */
} }
do { do {
go = false; go = false;
out = Yap_InnerEval(Deref(ARG2)); out = Yap_Eval(t PASS_REGS);
Yap_CheckArithError(); go = Yap_CheckArithError();
} while (go); } while (go);
return Yap_unify_constant(ARG1, out); return Yap_unify_constant(ARG1, out);
} }

View File

@ -632,7 +632,7 @@ __Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS) {
} }
inline static Term add_int(Int i, Int j USES_REGS) { inline static Term add_int(Int i, Int j USES_REGS) {
#if defined(__clang__) #if defined(__clang__) || defined(__GNUC__)
Int w; Int w;
if (!__builtin_add_overflow(i, j, &w)) if (!__builtin_add_overflow(i, j, &w))
RINT(w); RINT(w);

View File

@ -24,11 +24,13 @@ inline static int sub_overflow(Int x, Int i, Int j) {
} }
inline static Term sub_int(Int i, Int j USES_REGS) { inline static Term sub_int(Int i, Int j USES_REGS) {
#if defined(__clang__) #if defined(__clang__ ) || defined(__GNUC__)
Int w; Int k;
if (!__builtin_sub_overflow(i,j,&w)) if (__builtin_sub_overflow(i,j,&k)) {
RINT(w); return Yap_gmp_add_ints(i, j);
return Yap_gmp_add_ints(i, j); }
printf("%ld %ld %ld\n", i, j , k);
RINT(k);
#elif defined(__GNUC__) #elif defined(__GNUC__)
Int w; Int w;
if (!__builtin_sub_overflow_p(i,j,w)) if (!__builtin_sub_overflow_p(i,j,w))

View File

@ -332,6 +332,7 @@ once(G) :-
'$meta_call'(C, M), '$meta_call'(C, M),
!. !.
(:- G) :- '$execute'(G), !. (:- G) :- '$execute'(G), !.
(?- G) :- '$execute'(G). (?- G) :- '$execute'(G).

View File

@ -965,10 +965,8 @@ catch(G, C, A) :-
). ).
'$catch'(_,C,A) :- '$catch'(_,C,A) :-
'$get_exception'(C), '$get_exception'(C),
!, %( C = C0 -> '$execute'(A) ; throw(A0) ).
'$run_catch'(A, C). '$run_catch'(C,A).
'$catch'(_,_C,A) :-
throw(A).
% variable throws are user-handled. % variable throws are user-handled.
'$run_catch'(G,E) :- '$run_catch'(G,E) :-