make sure we separate betwen async exceptions and synchroneous.

This commit is contained in:
Vítor Santos Costa 2010-12-04 19:05:13 +00:00
parent c6f41e2970
commit 8db05c883b
7 changed files with 36 additions and 4 deletions

View File

@ -1861,7 +1861,6 @@ Yap_absmi(int inp)
#else
B = B->cp_b;
#endif /* YAPOR */
goto fail;
ENDBOp();
#ifdef YAPOR

View File

@ -480,6 +480,7 @@ X_API int STD_PROTO(YAP_RecoverSlots,(int));
X_API Int STD_PROTO(YAP_ArgsToSlots,(int));
X_API void STD_PROTO(YAP_SlotsToArgs,(int, Int));
X_API void STD_PROTO(YAP_Throw,(Term));
X_API void STD_PROTO(YAP_AsyncThrow,(Term));
X_API void STD_PROTO(YAP_Halt,(int));
X_API Term *STD_PROTO(YAP_TopOfLocalStack,(void));
X_API void *STD_PROTO(YAP_Predicate,(Atom,UInt,Term));
@ -2833,6 +2834,16 @@ YAP_Throw(Term t)
RECOVER_MACHINE_REGS();
}
X_API void
YAP_AsyncThrow(Term t)
{
BACKUP_MACHINE_REGS();
Yap_PrologMode |= AsyncIntMode;
Yap_JumpToEnv(t);
Yap_PrologMode &= ~AsyncIntMode;
RECOVER_MACHINE_REGS();
}
X_API void
YAP_Halt(int i)
{

View File

@ -455,7 +455,9 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
where = TermNil;
Yap_PrologMode &= ~AbortMode;
Yap_PrologMode |= InErrorMode;
Yap_signal(YAP_FAIL_SIGNAL);
/* make sure failure will be seen at next port */
if (Yap_PrologMode & AsyncIntMode)
Yap_signal(YAP_FAIL_SIGNAL);
P = FAILCODE;
} else {
if (IsVarTerm(where)) {

View File

@ -1511,7 +1511,10 @@ JumpToEnv(Term t) {
EX = BallTerm;
BallTerm = NULL;
P = (yamop *)FAILCODE;
Yap_signal(YAP_FAIL_SIGNAL);
/* make sure failure will be seen at next port */
if (Yap_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
HB = B->cp_h;
return TRUE;
}
@ -1553,7 +1556,9 @@ JumpToEnv(Term t) {
/* B->cp_h = H; */
/* I could backtrack here, but it is easier to leave the unwinding
to the emulator */
Yap_signal(YAP_FAIL_SIGNAL);
if (Yap_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
P = (yamop *)FAILCODE;
HB = B->cp_h;
/* try to recover space */

View File

@ -1545,6 +1545,7 @@ void (*handler)(int);
static int
InteractSIGINT(int ch) {
Yap_PrologMode |= AsyncIntMode;
switch (ch) {
case 'a':
/* abort computation */
@ -1554,40 +1555,49 @@ InteractSIGINT(int ch) {
Yap_Error(PURE_ABORT, TermNil, "abort from console");
/* in case someone mangles the P register */
}
Yap_PrologMode &= ~AsyncIntMode;
return -1;
case 'b':
/* continue */
Yap_signal (YAP_BREAK_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
return 1;
case 'c':
/* continue */
return 1;
case 'd':
Yap_signal (YAP_DEBUG_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
/* enter debug mode */
return 1;
case 'e':
/* exit */
Yap_PrologMode &= ~AsyncIntMode;
Yap_exit(0);
return -1;
case 'g':
/* exit */
Yap_signal (YAP_STACK_DUMP_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
return -1;
case 't':
/* start tracing */
Yap_signal (YAP_TRACE_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
return 1;
#ifdef LOW_LEVEL_TRACER
case 'T':
toggle_low_level_trace();
Yap_PrologMode &= ~AsyncIntMode;
return 1;
#endif
case 's':
/* show some statistics */
Yap_signal (YAP_STATISTICS_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
return 1;
case EOF:
Yap_PrologMode &= ~AsyncIntMode;
return(0);
break;
case 'h':
@ -1598,6 +1608,7 @@ InteractSIGINT(int ch) {
fprintf(Yap_stderr, " a for abort\n c for continue\n d for debug\n");
fprintf(Yap_stderr, " e for exit\n g for stack dump\n s for statistics\n t for trace\n");
fprintf(Yap_stderr, " b for break\n");
Yap_PrologMode &= ~AsyncIntMode;
return(0);
}
}

View File

@ -1187,6 +1187,7 @@ typedef enum
UserCCallMode = 0x4000, /* In User C-call Code */
MallocMode = 0x8000, /* Doing malloc, realloc, free */
SystemMode = 0x10000, /* in system mode */
AsyncIntMode = 0x20000 /* YAP has just been interrupted from the outside */
} prolog_exec_mode;
extern Int Yap_PrologMode;

View File

@ -435,6 +435,9 @@ extern X_API void PROTO(YAP_SlotsToArgs,(int, YAP_Int));
/* void YAP_Throw() */
extern X_API void PROTO(YAP_Throw,(YAP_Term));
/* void YAP_AsyncThrow() */
extern X_API void PROTO(YAP_AsyncThrow,(YAP_Term));
/* int YAP_LookupModule() */
#define YAP_LookupModule(T) (T)