This commit is contained in:
Vítor Santos Costa 2018-04-10 00:54:34 +01:00
parent fb5564f9d1
commit 470323da5c
5 changed files with 28 additions and 42 deletions

View File

@ -647,11 +647,14 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function,
yap_error_number err; yap_error_number err;
/* disallow recursive error handling */ /* disallow recursive error handling */
if (LOCAL_PrologMode & InErrorMode && (err = LOCAL_ActiveError->errorNo)) { if (LOCAL_PrologMode & InErrorMode &&
fprintf(stderr, "%% ERROR %s %s WITHIN ERROR %s %s\n", ((err = LOCAL_ActiveError->errorNo) ||
( LOCAL_CommittedError->errorNo &&
(err = LOCAL_CommittedError->errorNo)))) {
fprintf(stderr, "%% ERROR %s %s WITHIN ERROR %s %s\n",
Yap_errorClassName(Yap_errorClass(type)), Yap_errorName(type), Yap_errorClassName(Yap_errorClass(type)), Yap_errorName(type),
Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err)); Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
Yap_RestartYap(1); return P;
} }
if (LOCAL_DoingUndefp && type == EVALUATION_ERROR_UNDEFINED) { if (LOCAL_DoingUndefp && type == EVALUATION_ERROR_UNDEFINED) {
P = FAILCODE; P = FAILCODE;
@ -1002,6 +1005,7 @@ static Int get_exception(USES_REGS1) {
Term t; Term t;
i = LOCAL_CommittedError; i = LOCAL_CommittedError;
LOCAL_CommittedError = NULL;
if (i && i->errorNo != YAP_NO_ERROR) { if (i && i->errorNo != YAP_NO_ERROR) {
if (i->errorNo == THROW_EVENT) if (i->errorNo == THROW_EVENT)
t = i->errorRawTerm; t = i->errorRawTerm;
@ -1012,12 +1016,8 @@ static Int get_exception(USES_REGS1) {
t = mkerrort(i->errorNo, TermNil, MkSysError(i)); t = mkerrort(i->errorNo, TermNil, MkSysError(i));
} }
Yap_ResetException(LOCAL_ActiveError); Yap_ResetException(LOCAL_ActiveError);
LOCAL_CommittedError = NULL; return Yap_unify(t, ARG1);
Int rc = Yap_unify(t, ARG1); }
return rc;
}
LOCAL_CommittedError = NULL;
return false; return false;
} }
@ -1091,8 +1091,8 @@ yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i) {
Term hdtl = TailOfTerm(hd); Term hdtl = TailOfTerm(hd);
if (hdhd == Termg) { if (hdhd == Termg) {
Term n = ArgOfTerm(1,hdtl); Term n = ArgOfTerm(1,hdtl);
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(n, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f); LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(n, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
} }
} }

View File

@ -948,7 +948,7 @@ static Int tag_cleanup(USES_REGS1) {
static Int cleanup_on_exit(USES_REGS1) { static Int cleanup_on_exit(USES_REGS1) {
choiceptr B0 = (choiceptr)(LCL0 - IntegerOfTerm(Deref(ARG1))); choiceptr B0 = (choiceptr)(LCL0 - IntegerOfTerm(Deref(ARG1))), bp;
Term task = Deref(ARG2); Term task = Deref(ARG2);
bool box = ArgOfTerm(1, task) == TermTrue; bool box = ArgOfTerm(1, task) == TermTrue;
Term cleanup = ArgOfTerm(3, task); Term cleanup = ArgOfTerm(3, task);
@ -956,6 +956,7 @@ static Int cleanup_on_exit(USES_REGS1) {
while (B->cp_ap->opc == FAIL_OPCODE) while (B->cp_ap->opc == FAIL_OPCODE)
B = B->cp_b; B = B->cp_b;
if (complete) { if (complete) {
return true; return true;
} }
@ -973,6 +974,14 @@ static Int cleanup_on_exit(USES_REGS1) {
complete_pt[0] = TermExit; complete_pt[0] = TermExit;
} }
Yap_ignore(cleanup, false); Yap_ignore(cleanup, false);
bp = B;
while (bp && bp != B0) {
if (bp->cp_ap == NOCODE &&
bp->cp_b) {
bp->cp_ap = TRUSTFAILCODE;
}
bp = bp->cp_b;
}
if (Yap_RaiseException()) { if (Yap_RaiseException()) {
return false; return false;
} }
@ -2028,12 +2037,11 @@ static Int JumpToEnv(USES_REGS1) {
// DBTerm *dbt = Yap_RefToException(); // DBTerm *dbt = Yap_RefToException();
while (handler while (handler
&& Yap_PredForChoicePt(handler, NULL) != PredDollarCatch && Yap_PredForChoicePt(handler, NULL) != PredDollarCatch
&& LOCAL_CBorder < LCL0 - (CELL *)handler //&& LOCAL_CBorder < LCL0 - (CELL *)handler
&& handler->cp_ap != NOCODE //&& handler->cp_ap != NOCODE
&& handler->cp_b != NULL && handler->cp_b != NULL
) { ) {
//if (handler->cp_ap != NOCODE) handler->cp_ap = TRUSTFAILCODE;
// handler->cp_ap = TRUSTFAILCODE;
handler = handler->cp_b; handler = handler->cp_b;
} }
pop_text_stack(1); pop_text_stack(1);

View File

@ -302,7 +302,7 @@ addinfo( Desc) -->
'$query_exception'(errorGoal, Desc, Call) '$query_exception'(errorGoal, Desc, Call)
} }
; ;
[[h|p(M,Na,Ar,File,FilePos)g)](_)]] [h|p(M,Na,Ar,File,FilePos)]
-> ->
[] []
). ).
@ -805,7 +805,7 @@ print_lines( S, Prefixes, Key) -->
!, !,
{ nl(S), { nl(S),
Prefixes = [PrefixS - Cmds|More], Prefixes = [PrefixS - Cmds|More],
format(S, PrefixS, []Cmds) format(S, PrefixS, Cmds)
}, },
{ {
More == [] More == []

View File

@ -308,6 +308,5 @@ read_sig.
:- '$set_no_trace'('$Error'(_), prolog). :- '$set_no_trace'('$Error'(_), prolog).
:- '$set_no_trace'('$LoopError'(_,_), prolog). :- '$set_no_trace'('$LoopError'(_,_), prolog).
:- '$set_no_trace'('$TraceError'(_,_,_,_,_), prolog). :- '$set_no_trace'('$TraceError'(_,_,_,_,_), prolog).
:- '$set_no_trace'('$run_catch'(_,_), prolog).
%%! @} %%! @}

View File

@ -965,30 +965,9 @@ catch(G, C, A) :-
). ).
'$catch'(_,C,A) :- '$catch'(_,C,A) :-
'$get_exception'(C), '$get_exception'(C),
'$run_catch'(A, C). '$execute'(A),
'$true'.
% variable throws are user-handled.
'$run_catch'(G,E) :-
E = '$VAR'(_),
!,
call(G ).
'$run_catch'(abort,_) :-
abort.
'$run_catch'('$Error'(E),E) :-
!,
'$LoopError'(E, top ).
'$run_catch'('$LoopError'(E, Where),E) :-
!,
'$LoopError'(E, Where).
'$run_catch'('$TraceError'(E, GoalNumber, G, Module, CalledFromDebugger),E) :-
!,
'$TraceError'(E, GoalNumber, G, Module, CalledFromDebugger).
'$run_catch'(_Signal,E) :-
functor( E, N, _),
'$hidden_atom'(N), !,
throw(E).
'$run_catch'( Signal, _E) :-
call( Signal ).
% %
% throw has to be *exactly* after system catch! % throw has to be *exactly* after system catch!