error handling (Miguel Areias)
This commit is contained in:
parent
6741d961b3
commit
4180fd9737
@ -328,7 +328,7 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno,
|
||||
} else {
|
||||
Yap_Error__(file, function, lineno, type, where);
|
||||
}
|
||||
siglongjmp(*LOCAL_RestartEnv, 4);
|
||||
siglongjmp(*LOCAL_RestartEnv, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
4
C/eval.c
4
C/eval.c
@ -369,7 +369,7 @@ static Int p_logsum(USES_REGS1) { /* X is Y */
|
||||
}
|
||||
}
|
||||
|
||||
yamop *Yap_EvalError__(const char *file, const char *function, int lineno,
|
||||
void Yap_EvalError__(const char *file, const char *function, int lineno,
|
||||
yap_error_number type, Term where, ...) {
|
||||
CACHE_REGS
|
||||
va_list ap;
|
||||
@ -387,7 +387,7 @@ yamop *Yap_EvalError__(const char *file, const char *function, int lineno,
|
||||
buf[0] = '\0';
|
||||
}
|
||||
va_end(ap);
|
||||
return Yap_Error__(file, function, lineno, type, where, buf);
|
||||
Yap_ThrowError__(file, function, lineno, type, where, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
21
C/exec.c
21
C/exec.c
@ -1461,15 +1461,28 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
||||
LOCAL_RestartEnv = sighold;
|
||||
return false;
|
||||
}
|
||||
case 4: {
|
||||
case 4:
|
||||
/* abort */
|
||||
/* can be called from anywgerre, must reset registers,
|
||||
/* can be called from anywhere, must reset registers,
|
||||
*/
|
||||
LOCAL_RestartEnv = sighold;
|
||||
Yap_JumpToEnv(TermDAbort);
|
||||
P = (yamop *)FAILCODE;
|
||||
if (OldBorder == 0)
|
||||
break;
|
||||
LOCAL_CBorder = OldBorder;
|
||||
LOCAL_PrologMode = UserMode;
|
||||
} break;
|
||||
LOCAL_RestartEnv = sighold;
|
||||
return false;
|
||||
case 5:
|
||||
// going up, unless there is no up to go to. or someone
|
||||
// but we should inform the caller on what happened.
|
||||
if (B && B->cp_b && B->cp_b <= (choiceptr)(LCL0-LOCAL_CBorder)) {
|
||||
break;
|
||||
}
|
||||
LOCAL_RestartEnv = sighold;
|
||||
LOCAL_PrologMode = UserMode;
|
||||
LOCAL_CBorder = OldBorder;
|
||||
return false;
|
||||
default:
|
||||
/* do nothing */
|
||||
LOCAL_PrologMode = UserMode;
|
||||
|
@ -1025,7 +1025,9 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc,
|
||||
|
||||
Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
|
||||
CACHE_REGS
|
||||
Volatile Term t;
|
||||
// ensure that if we throw an exception
|
||||
// t will be 0.
|
||||
Volatile Term t = 0;
|
||||
JMPBUFF FailBuff;
|
||||
yhandle_t sls = Yap_StartSlots();
|
||||
LOCAL_toktide = LOCAL_tokptr;
|
||||
|
@ -403,7 +403,7 @@ Term Yap_InnerEval__(Term USES_REGS);
|
||||
|
||||
#define Yap_EvalError(id, t, ...) \
|
||||
Yap_EvalError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
|
||||
yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number, Term,
|
||||
void Yap_EvalError__(const char *, const char *, int, yap_error_number, Term,
|
||||
...);
|
||||
|
||||
#define Yap_ArithError(id, t, ...) \
|
||||
@ -412,8 +412,7 @@ yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number, Term,
|
||||
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "")
|
||||
#define Yap_AbsmiError(id) \
|
||||
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "")
|
||||
extern Int Yap_ArithError__(const char *, const char *, int, yap_error_number,
|
||||
Term, ...);
|
||||
|
||||
|
||||
#include "inline-only.h"
|
||||
|
||||
@ -470,7 +469,6 @@ Atom Yap_NameOfBinaryOp(int i);
|
||||
#define RBIG(v) return (Yap_MkBigIntTerm(v))
|
||||
#define RERROR() \
|
||||
{ \
|
||||
Yap_BinError(LOCAL_Error_TYPE); \
|
||||
return (0L); \
|
||||
}
|
||||
|
||||
|
@ -843,48 +843,37 @@ static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
|
||||
PyObject *lhs, *rhs;
|
||||
term_t tleft = PL_new_term_ref(), tright = PL_new_term_ref();
|
||||
|
||||
while (true) {
|
||||
functor_t fun;
|
||||
|
||||
AOK (PL_get_functor(targ, &fun), false);
|
||||
if (fun == FUNCTOR_comma2) {
|
||||
if (!PL_get_arg(1, targ, taux)) {
|
||||
return false;
|
||||
}
|
||||
AOK( PL_get_arg(1, taux, tleft), false);
|
||||
lhs = term_to_python(tleft, eval, NULL);
|
||||
AOK ( PL_get_arg(2, taux, tright), false);
|
||||
rhs = term_to_python(tright, eval, NULL);
|
||||
if (PyDict_SetItem(dict, lhs, rhs) < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
|
||||
// Py_DECREF(lhs);
|
||||
// Py_DECREF(rhs);
|
||||
|
||||
AOK(PL_get_arg(1, targ, targ), false);
|
||||
AOK(PL_get_arg(1, targ, tleft), false);
|
||||
lhs = atom_to_python_string(tleft);
|
||||
if (lhs == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
AOK(PL_get_arg(2, targ, tright), false);
|
||||
rhs = term_to_python(tright, eval, NULL);
|
||||
if (rhs == NULL) {
|
||||
PyErr_Print();
|
||||
return FALSE;
|
||||
}
|
||||
if (PyDict_SetItem(dict, lhs, rhs) < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
|
||||
// Py_DECREF(lhs);
|
||||
// Py_DECREF(rhs);
|
||||
break;
|
||||
while (fun == FUNCTOR_comma2) {
|
||||
AOK( PL_get_arg(1, targ, tleft), false);
|
||||
if (! copy_to_dictionary(dict, tleft, taux, eval) )
|
||||
return false;
|
||||
AOK ( PL_get_arg(2, targ, targ), false);
|
||||
return copy_to_dictionary(dict, tright, taux, eval);
|
||||
}
|
||||
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
|
||||
// Py_DECREF(lhs);
|
||||
// Py_DECREF(rhs);
|
||||
|
||||
AOK(PL_get_arg(1, targ, tleft), false);
|
||||
lhs = atom_to_python_string(tleft);
|
||||
if (lhs == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
AOK(PL_get_arg(2, targ, tright), false);
|
||||
rhs = term_to_python(tright, eval, NULL);
|
||||
if (rhs == NULL) {
|
||||
PyErr_Print();
|
||||
return false;
|
||||
}
|
||||
return PyDict_SetItem(dict, lhs, rhs) >= 0;
|
||||
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
|
||||
// Py_DECREF(lhs);
|
||||
// Py_DECREF(rhs);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
|
||||
atom_t name;
|
||||
|
@ -272,6 +272,7 @@ be lost.
|
||||
current_prolog_flag(debug, false), !,
|
||||
'$execute_nonstop'(G,Mod).
|
||||
'$spy'([Mod|G]) :-
|
||||
'$stop_creeping'(_),
|
||||
CP is '$last_choice_pt',
|
||||
'$debugger_input',
|
||||
'$do_spy'(G, Mod, CP, spy).
|
||||
|
@ -107,39 +107,42 @@ system_error(Type,Goal,Culprit) :-
|
||||
fail.
|
||||
'$LoopError'(_, _) :-
|
||||
flush_output,
|
||||
'$close_error',
|
||||
'$close_error',
|
||||
fail.
|
||||
|
||||
'$process_error'('$forward'(Msg), _) :-
|
||||
!,
|
||||
throw( '$forward'(Msg) ).
|
||||
!,
|
||||
throw( '$forward'(Msg) ).
|
||||
'$process_error'(abort, Level) :-
|
||||
!,
|
||||
(
|
||||
Level \== top
|
||||
->
|
||||
throw( abort )
|
||||
;
|
||||
current_prolog_flag(break_level, 0)
|
||||
->
|
||||
print_message(informational,abort(user)),
|
||||
fail
|
||||
;
|
||||
current_prolog_flag(break_level, I0),
|
||||
I is I0-1,
|
||||
current_prolog_flag(break_level, I),
|
||||
throw(abort)
|
||||
).
|
||||
'$process_error'(error(thread_cancel(_Id), _G),top) :- !.
|
||||
'$process_error'(error(thread_cancel(Id), G), _) :- !,
|
||||
throw(error(thread_cancel(Id), G)).
|
||||
!,
|
||||
(
|
||||
Level \== top
|
||||
->
|
||||
throw( abort )
|
||||
;
|
||||
current_prolog_flag(break_level, 0)
|
||||
->
|
||||
print_message(informational,abort(user)),
|
||||
fail
|
||||
;
|
||||
current_prolog_flag(break_level, I0),
|
||||
I is I0-1,
|
||||
current_prolog_flag(break_level, I),
|
||||
throw(abort)
|
||||
).
|
||||
'$process_error'(error(thread_cancel(_Id), _G),top) :-
|
||||
!.
|
||||
'$process_error'(error(thread_cancel(Id), G), _) :-
|
||||
!,
|
||||
throw(error(thread_cancel(Id), G)).
|
||||
'$process_error'(error(permission_error(module,redefined,A),B), Level) :-
|
||||
Level \= top, !,
|
||||
throw(error(permission_error(module,redefined,A),B)).
|
||||
'$process_error'(error(Msg, Where), _) :-
|
||||
print_message(error,error(Msg, Where)), !.
|
||||
'$process_error'(error(Msg, Where), _) :-
|
||||
print_message(error,error(Msg, [g|Where])), !.
|
||||
Level \= top, !,
|
||||
throw(error(permission_error(module,redefined,A),B)).
|
||||
'$process_error'(Error, _Level) :-
|
||||
functor(Error, Severity, _),
|
||||
print_message(Severity, Error), !.
|
||||
%'$process_error'(error(Msg, Where), _) :-
|
||||
% print_message(error,error(Msg, [g|Where])), !.
|
||||
'$process_error'(Throw, _) :-
|
||||
print_message(error,error(unhandled_exception,Throw)).
|
||||
|
||||
|
@ -352,7 +352,8 @@ read_sig.
|
||||
% make thes predicates non-traceable.
|
||||
|
||||
:- '$set_no_trace'(current_choicepoint(_DCP), yap_hacks).
|
||||
:- '$set_no_trace'(current_choice_point(_DCP), yap_hacks).
|
||||
:- '$set_no_trace'('$current_choice_point'(_DCP), prolog).
|
||||
:- '$set_no_trace'('$$cut_by'(_DCP), prolog).
|
||||
:- '$set_no_trace'(true, yap_hacks).
|
||||
:- '$set_no_trace'(true, prolog).
|
||||
:- '$set_no_trace'('$call'(_,_,_,_), prolog).
|
||||
|
Reference in New Issue
Block a user