Improve error handling routine, trying to make it more robust.

Improve hole handling in stack expansion
Clause interrpeter was supposed to prune _trust_me
Wrong messages for acos and atanh


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1249 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2005-02-24 21:46:40 +00:00
parent bdff56d3b0
commit 9807a22069
7 changed files with 57 additions and 33 deletions

View File

@ -797,7 +797,7 @@ p_asin(Term t E_ARGS)
out = asin(dbl); out = asin(dbl);
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(out)) { if (isnan(out)) {
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t, "acos(%f)", dbl); Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t, "asin(%f)", dbl);
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
RERROR(); RERROR();
} }
@ -1061,7 +1061,7 @@ p_atanh(Term t E_ARGS)
out = atanh(dbl); out = atanh(dbl);
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(out)) { if (isnan(out)) {
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t, "acosh(%f)", dbl); Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t, "atanh(%f)", dbl);
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
RERROR(); RERROR();
} }

View File

@ -5118,4 +5118,3 @@ Yap_InitBackDB(void)
Yap_InitCPredBack("$current_immediate_key", 2, 4, init_current_key, cont_current_key, Yap_InitCPredBack("$current_immediate_key", 2, 4, init_current_key, cont_current_key,
SyncPredFlag|HiddenPredFlag); SyncPredFlag|HiddenPredFlag);
} }

View File

@ -267,6 +267,12 @@ dump_stack(void)
char tp[256]; char tp[256];
yamop *ipc = CP; yamop *ipc = CP;
#if DEBUG
fprintf(stderr,"%% YAP regs: P=%p, CP=%p, ASP=%p, H=%p, TR=%p, HeapTop=%p\n",P,CP,ASP,H,TR,HeapTop);
fprintf(stderr,"%% YAP mode: %x\n",Yap_PrologMode);
if (Yap_ErrorMessage)
fprintf(stderr,"%% YAP_ErrorMessage: %s\n",Yap_ErrorMessage);
#endif
if (H > ASP || H > LCL0) { if (H > ASP || H > LCL0) {
fprintf(stderr,"%% YAP ERROR: Global Collided against Local (%p--%p)\n",H,ASP); fprintf(stderr,"%% YAP ERROR: Global Collided against Local (%p--%p)\n",H,ASP);
} else if (HeapTop > (ADDR)Yap_GlobalBase) { } else if (HeapTop > (ADDR)Yap_GlobalBase) {
@ -293,7 +299,10 @@ dump_stack(void)
} }
} }
#endif #endif
fprintf (stderr,"Goal Stack Dump (* is backtrack point)\n"); detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, (char *)H, 256);
fprintf (stderr,"Running code at %s\n",(char *)H);
detect_bug_location(CP, FIND_PRED_FROM_ANYWHERE, (char *)H, 256);
fprintf (stderr,"Continuation is at %s\n",(char *)H);
while (b_ptr != NULL) { while (b_ptr != NULL) {
while (env_ptr && env_ptr <= (CELL *)b_ptr) { while (env_ptr && env_ptr <= (CELL *)b_ptr) {
detect_bug_location(ipc, FIND_PRED_FROM_ENV, tp, 256); detect_bug_location(ipc, FIND_PRED_FROM_ENV, tp, 256);
@ -362,7 +371,9 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
char *tp = tmpbuf; char *tp = tmpbuf;
int psize = YAP_BUF_SIZE; int psize = YAP_BUF_SIZE;
#if DEBUG
fprintf(stderr,"***** Processing Error %d (%x,%x) ***\n", type, ActiveSignals,Yap_PrologMode);
#endif
if (type == INTERRUPT_ERROR) { if (type == INTERRUPT_ERROR) {
fprintf(stderr,"%% YAP exiting: cannot handle signal %d\n", fprintf(stderr,"%% YAP exiting: cannot handle signal %d\n",
(int)IntOfTerm(where)); (int)IntOfTerm(where));
@ -421,8 +432,6 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
Yap_PrologMode &= ~AbortMode; Yap_PrologMode &= ~AbortMode;
Yap_PrologMode |= InErrorMode; Yap_PrologMode |= InErrorMode;
} else { } else {
if (type != SYNTAX_ERROR)
where = Yap_CopyTerm(Deref(where));
if (IsVarTerm(where)) { if (IsVarTerm(where)) {
/* we must be careful someone gave us a copy to a local variable */ /* we must be careful someone gave us a copy to a local variable */
Term t = MkVarTerm(); Term t = MkVarTerm();
@ -432,7 +441,9 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
/* Exit Abort Mode, if we were there */ /* Exit Abort Mode, if we were there */
Yap_PrologMode &= ~AbortMode; Yap_PrologMode &= ~AbortMode;
Yap_PrologMode |= InErrorMode; Yap_PrologMode |= InErrorMode;
where = Yap_CopyTerm(where); if (!(where = Yap_CopyTerm(where))) {
where = TermNil;
}
} }
va_start (ap, format); va_start (ap, format);
/* now build the error string */ /* now build the error string */
@ -1653,6 +1664,9 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
nt[1] = MkPairTerm(MkAtomTerm(Yap_LookupAtom(tmpbuf)), Yap_all_calls()); nt[1] = MkPairTerm(MkAtomTerm(Yap_LookupAtom(tmpbuf)), Yap_all_calls());
} }
if (serious) { if (serious) {
/* disable active signals at this point */
ActiveSignals = 0;
CreepFlag = CalculateStackGap();
if (type == PURE_ABORT) if (type == PURE_ABORT)
Yap_JumpToEnv(MkAtomTerm(Yap_LookupAtom("$abort"))); Yap_JumpToEnv(MkAtomTerm(Yap_LookupAtom("$abort")));
else else
@ -1660,6 +1674,6 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
} }
Yap_PrologMode &= ~InErrorMode; Yap_PrologMode &= ~InErrorMode;
return(P); return P;
} }

View File

@ -228,10 +228,10 @@ MoveLocalAndTrail(void)
static void static void
MoveGlobal(void) MoveGlobal(void)
{ {
/* /*
* cpcellsd(To,From,NOfCells) - copy the cells downwards - in * cpcellsd(To,From,NOfCells) - copy the cells downwards - in
* absmi.asm * absmi.asm
*/ */
#if HAVE_MEMMOVE #if HAVE_MEMMOVE
cpcellsd((CELL *)Yap_GlobalBase, (CELL *)OldGlobalBase, OldH - (CELL *)OldGlobalBase); cpcellsd((CELL *)Yap_GlobalBase, (CELL *)OldGlobalBase, OldH - (CELL *)OldGlobalBase);
#else #else
@ -1067,7 +1067,7 @@ execute_growstack(long size0, int from_trail, int in_parser, tr_fr_ptr *old_trp,
return FALSE; return FALSE;
} }
YAPEnterCriticalSection(); YAPEnterCriticalSection();
GDiff = DelayDiff = size; GDiff = DelayDiff = size-size0;
} else { } else {
YAPEnterCriticalSection(); YAPEnterCriticalSection();
if (Yap_GlobalBase != old_Yap_GlobalBase) { if (Yap_GlobalBase != old_Yap_GlobalBase) {

View File

@ -3400,7 +3400,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
*--ASP = (CELL)current_env; *--ASP = (CELL)current_env;
if (!Yap_growheap(FALSE, MinHeapGap, NULL)) { if (!Yap_growheap(FALSE, MinHeapGap, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE); return FALSE;
} }
current_env = (CELL *)*ASP; current_env = (CELL *)*ASP;
ASP++; ASP++;
@ -3566,7 +3566,7 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
if (gc_margin < gc_lim) if (gc_margin < gc_lim)
gc_margin = gc_lim; gc_margin = gc_lim;
GcCalls++; GcCalls++;
if (gc_on) { if (gc_on && !(Yap_PrologMode & InErrorMode)) {
effectiveness = do_gc(predarity, current_env, nextop); effectiveness = do_gc(predarity, current_env, nextop);
if (effectiveness > 90) { if (effectiveness > 90) {
while (gc_margin < H-H0) while (gc_margin < H-H0)

View File

@ -11,8 +11,12 @@
* File: index.c * * File: index.c *
* comments: Indexing a Prolog predicate * * comments: Indexing a Prolog predicate *
* * * *
* Last rev: $Date: 2005-02-21 16:50:00 $,$Author: vsc $ * * Last rev: $Date: 2005-02-24 21:46:39 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.115 2005/02/21 16:50:00 vsc
* amd64 fixes
* library fixes
*
* Revision 1.114 2005/01/28 23:14:36 vsc * Revision 1.114 2005/01/28 23:14:36 vsc
* move to Yap-4.5.7 * move to Yap-4.5.7
* Fix clause size * Fix clause size
@ -7607,6 +7611,14 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
case _trust_me2: case _trust_me2:
case _trust_me3: case _trust_me3:
case _trust_me4: case _trust_me4:
#ifdef YAPOR
CUT_prune_to(B->cp_b);
#else
B = B->cp_b;
#endif /* YAPOR */
#ifdef TABLING
abolish_incomplete_subgoals(B);
#endif /* TABLING */
b0 = B; b0 = B;
ipc = NEXTOP(ipc,ld); ipc = NEXTOP(ipc,ld);
break; break;

View File

@ -296,7 +296,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, CELL *ptf, CELL *H
} }
static Term static Term
CopyTerm(Term inp) { CopyTerm(Term inp, UInt arity) {
Term t = Deref(inp); Term t = Deref(inp);
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
@ -310,21 +310,21 @@ CopyTerm(Term inp) {
Hi = H+1; Hi = H+1;
H += 2; H += 2;
if ((res = copy_complex_term(Hi-2, Hi-1, Hi, Hi)) < 0) { if ((res = copy_complex_term(Hi-2, Hi-1, Hi, Hi)) < 0) {
ARG3 = t; XREGS[arity+1] = t;
H = Hi-1; H = Hi-1;
if (res == -1) { /* handle overflow */ if (res == -1) { /* handle overflow */
if (!Yap_gc(3, ENV, P)) { if (!Yap_gc(arity+1, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
return FALSE; return FALSE;
} }
t = Deref(ARG3); t = Deref(XREGS[arity+1]);
goto restart_attached; goto restart_attached;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
return FALSE; return FALSE;
} }
t = Deref(ARG3); t = Deref(XREGS[arity+1]);
goto restart_attached; goto restart_attached;
} }
} }
@ -348,20 +348,20 @@ CopyTerm(Term inp) {
int res; int res;
if ((res = copy_complex_term(ap-1, ap+1, Hi, Hi)) < 0) { if ((res = copy_complex_term(ap-1, ap+1, Hi, Hi)) < 0) {
H = Hi; H = Hi;
ARG3 = t; XREGS[arity+1] = t;
if (res == -1) { /* handle overflow */ if (res == -1) { /* handle overflow */
if (!Yap_gc(3, ENV, P)) { if (!Yap_gc(arity+1, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
return FALSE; return FALSE;
} }
t = Deref(ARG3); t = Deref(XREGS[arity+1]);
goto restart_list; goto restart_list;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
return FALSE; return FALSE;
} }
t = Deref(ARG3); t = Deref(XREGS[arity+1]);
goto restart_list; goto restart_list;
} }
} }
@ -385,20 +385,20 @@ CopyTerm(Term inp) {
if ((res = copy_complex_term(ap, ap+ArityOfFunctor(f), HB0+1, HB0)) < 0) { if ((res = copy_complex_term(ap, ap+ArityOfFunctor(f), HB0+1, HB0)) < 0) {
H = HB0; H = HB0;
ARG3 = t; XREGS[arity+1] = t;
if (res == -1) { if (res == -1) {
if (!Yap_gc(3, ENV, P)) { if (!Yap_gc(arity+1, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
return FALSE; return FALSE;
} }
t = Deref(ARG3); t = Deref(XREGS[arity+1]);
goto restart_appl; goto restart_appl;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
return FALSE; return FALSE;
} }
t = Deref(ARG3); t = Deref(XREGS[arity+1]);
goto restart_appl; goto restart_appl;
} }
} }
@ -409,13 +409,13 @@ CopyTerm(Term inp) {
Term Term
Yap_CopyTerm(Term inp) { Yap_CopyTerm(Term inp) {
return CopyTerm(inp); return CopyTerm(inp, 0);
} }
static Int static Int
p_copy_term(void) /* copy term t to a new instance */ p_copy_term(void) /* copy term t to a new instance */
{ {
Term t = CopyTerm(ARG1); Term t = CopyTerm(ARG1, 2);
if (t == 0L) if (t == 0L)
return FALSE; return FALSE;
/* be careful, there may be a stack shift here */ /* be careful, there may be a stack shift here */
@ -688,7 +688,6 @@ p_copy_term_no_delays(void) /* copy term t to a new instance */
{ {
Term t = CopyTermNoDelays(ARG1); Term t = CopyTermNoDelays(ARG1);
if (t == 0L) { if (t == 0L) {
printf("Error\n");
return FALSE; return FALSE;
} }
/* be careful, there may be a stack shift here */ /* be careful, there may be a stack shift here */