From 7bfe8aedbee2d69cb08f8b40e53a2cba6337e122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 16 Apr 2018 22:51:34 +0100 Subject: [PATCH] fix exception --- C/errors.c | 6 ++++-- C/eval.c | 8 ++++---- H/YapEval.h | 2 +- H/arith2.h | 12 +++++++----- pl/builtins.yap | 1 + pl/top.yap | 6 ++---- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/C/errors.c b/C/errors.c index 105a38358..c4491fe4f 100755 --- a/C/errors.c +++ b/C/errors.c @@ -551,7 +551,6 @@ static char tmpbuf[YAP_BUF_SIZE]; #include "YapErrors.h" 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)); new_error->top_error = LOCAL_ActiveError; LOCAL_ActiveError = new_error; @@ -1029,7 +1028,10 @@ static Int get_exception(USES_REGS1) { } else { 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; } diff --git a/C/eval.c b/C/eval.c index e9d6ef43d..9760112e8 100644 --- a/C/eval.c +++ b/C/eval.c @@ -148,8 +148,8 @@ static Term Eval(Term t USES_REGS) { } t2 = Eval(ArgOfTerm(2, t) PASS_REGS); *RepAppl(t) = (CELL)fun; - LOCAL_ctx = ctx.p; - return Yap_eval_binary(p->FOfEE, t1, t2); + LOCAL_ctx = ctx.p; + return Yap_eval_binary(p->FOfEE, t1, t2); } } /* else if (IsPairTerm(t)) */ { @@ -208,8 +208,8 @@ static Int p_is(USES_REGS1) { /* X is Y */ } do { go = false; - out = Yap_InnerEval(Deref(ARG2)); - Yap_CheckArithError(); + out = Yap_Eval(t PASS_REGS); + go = Yap_CheckArithError(); } while (go); return Yap_unify_constant(ARG1, out); } diff --git a/H/YapEval.h b/H/YapEval.h index e799a2288..82a578738 100644 --- a/H/YapEval.h +++ b/H/YapEval.h @@ -632,7 +632,7 @@ __Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS) { } inline static Term add_int(Int i, Int j USES_REGS) { -#if defined(__clang__) +#if defined(__clang__) || defined(__GNUC__) Int w; if (!__builtin_add_overflow(i, j, &w)) RINT(w); diff --git a/H/arith2.h b/H/arith2.h index e58eb0b20..51358f470 100755 --- a/H/arith2.h +++ b/H/arith2.h @@ -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) { -#if defined(__clang__) - Int w; - if (!__builtin_sub_overflow(i,j,&w)) - RINT(w); - return Yap_gmp_add_ints(i, j); +#if defined(__clang__ ) || defined(__GNUC__) + Int k; + if (__builtin_sub_overflow(i,j,&k)) { + return Yap_gmp_add_ints(i, j); + } + printf("%ld %ld %ld\n", i, j , k); + RINT(k); #elif defined(__GNUC__) Int w; if (!__builtin_sub_overflow_p(i,j,w)) diff --git a/pl/builtins.yap b/pl/builtins.yap index fb72a19a6..39e695cfa 100644 --- a/pl/builtins.yap +++ b/pl/builtins.yap @@ -332,6 +332,7 @@ once(G) :- '$meta_call'(C, M), !. + (:- G) :- '$execute'(G), !. (?- G) :- '$execute'(G). diff --git a/pl/top.yap b/pl/top.yap index 97dd34c0d..21333bf8f 100644 --- a/pl/top.yap +++ b/pl/top.yap @@ -965,10 +965,8 @@ catch(G, C, A) :- ). '$catch'(_,C,A) :- '$get_exception'(C), - !, - '$run_catch'(A, C). -'$catch'(_,_C,A) :- - throw(A). + %( C = C0 -> '$execute'(A) ; throw(A0) ). + '$run_catch'(C,A). % variable throws are user-handled. '$run_catch'(G,E) :-