Merge branch 'master' of git@git.dcc.fc.up.pt:yap-6.3

This commit is contained in:
Fabrizio Riguzzi 2014-10-16 17:23:22 +02:00
commit fa24b214af
15 changed files with 25787 additions and 4393 deletions

View File

@ -154,12 +154,12 @@ eval0(Int fi) {
case op_inf: case op_inf:
{ {
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */ #ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
Yap_Error(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity"); Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity");
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
RERROR(); RERROR();
#else #else
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) {/* iso */ if (yap_flags[LANGUAGE_MODE_FLAG] == 1) {/* iso */
Yap_Error(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity"); Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity");
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
RERROR(); RERROR();
} else { } else {
@ -170,13 +170,11 @@ eval0(Int fi) {
case op_nan: case op_nan:
{ {
#ifdef _MSC_VER /* Microsoft's Visual C++ Compi<ler */ #ifdef _MSC_VER /* Microsoft's Visual C++ Compi<ler */
Yap_Error(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity"); Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity");
P = (yamop *)FAILCODE;
RERROR(); RERROR();
#else #else
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) {/* iso */ if (yap_flags[LANGUAGE_MODE_FLAG] == 1) {/* iso */
Yap_Error(TYPE_ERROR_EVALUABLE, TermNil, "evaluating not-a-number"); Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, "evaluating not-a-number");
P = (yamop *)FAILCODE;
RERROR(); RERROR();
} else { } else {
RFLOAT(NAN); RFLOAT(NAN);
@ -287,7 +285,7 @@ Yap_InitConstExps(void)
for (i = 0; i < sizeof(InitConstTab)/sizeof(InitConstEntry); ++i) { for (i = 0; i < sizeof(InitConstTab)/sizeof(InitConstEntry); ++i) {
AtomEntry *ae = RepAtom(Yap_LookupAtom(InitConstTab[i].OpName)); AtomEntry *ae = RepAtom(Yap_LookupAtom(InitConstTab[i].OpName));
if (ae == NULL) { if (ae == NULL) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"at InitConstExps"); Yap_EvalError(OUT_OF_HEAP_ERROR,TermNil,"at InitConstExps");
return; return;
} }
WRITE_LOCK(ae->ARWLock); WRITE_LOCK(ae->ARWLock);

View File

@ -951,34 +951,40 @@ static InitUnEntry InitUnTab[] = {
{"random", op_random1} {"random", op_random1}
}; };
Atom
Yap_NameOfUnaryOp(int i)
{
return Yap_LookupAtom(InitUnTab[i].OpName);
}
static Int static Int
p_unary_is( USES_REGS1 ) p_unary_is( USES_REGS1 )
{ /* X is Y */ { /* X is Y */
Term t = Deref(ARG2); Term t = Deref(ARG2);
Term top; Term top;
yap_error_number err;
LOCAL_mathn = 1;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, ARG2, "X is Y"); Yap_EvalError(INSTANTIATION_ERROR, t, "unbound unary operator");
return FALSE; return FALSE;
} }
Yap_ClearExs(); Yap_ClearExs();
top = Yap_Eval(Deref(ARG3)); top = Yap_Eval(Deref(ARG3));
if (Yap_FoundArithError()) { if ((err=Yap_FoundArithError())) {
LOCAL_mathtt[0] = top; Yap_EvalError(err,ARG3,"X is op(Y): error in Y ");
return TRUE; return FALSE;
} }
if (IsIntTerm(t)) { if (IsIntTerm(t)) {
Term tout; Term tout;
Int i; Int i;
LOCAL_mathop = i = IntegerOfTerm(t); i = IntegerOfTerm(t);
tout = eval1(i, top PASS_REGS); tout = eval1(i, top PASS_REGS);
if (Yap_FoundArithError()) { if ((err=Yap_FoundArithError())) {
LOCAL_mathtt[0] = top; Functor f = Yap_MkFunctor( Yap_NameOfUnaryOp(i), 1 );
LOCAL_mathop = i; Term t = Yap_MkApplTerm( f, 1, &top );
LOCAL_mathn = 1; Yap_EvalError(err, t ,"error in %s/1 ", RepAtom(NameOfFunctor(f))->StrOfAE);
return TRUE; return FALSE;
} }
return Yap_unify_constant(ARG1,tout); return Yap_unify_constant(ARG1,tout);
} }
@ -988,24 +994,23 @@ p_unary_is( USES_REGS1 )
Term out; Term out;
if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, 1)))) { if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, 1)))) {
Term ti[2]; Term ti[2];
/* error */ /* error */
ti[0] = t; ti[0] = t;
ti[1] = MkIntTerm(1); ti[1] = MkIntTerm(1);
t = Yap_MkApplTerm(FunctorSlash, 2, ti); t = Yap_MkApplTerm(FunctorSlash, 2, ti);
Yap_Error(TYPE_ERROR_EVALUABLE, t, Yap_EvalError(TYPE_ERROR_EVALUABLE, t,
"functor %s/%d for arithmetic expression", "functor %s/%d for arithmetic expression",
RepAtom(name)->StrOfAE,1); RepAtom(name)->StrOfAE,1);
P = FAILCODE; return FALSE;
return(FALSE);
} }
LOCAL_mathop = p->FOfEE;
out= eval1(p->FOfEE, top PASS_REGS); out= eval1(p->FOfEE, top PASS_REGS);
if (Yap_FoundArithError()) { if ((err=Yap_FoundArithError())) {
LOCAL_mathtt[0] = top; Functor f = Yap_MkFunctor( name, 1 );
LOCAL_mathop = p->FOfEE; Term t = Yap_MkApplTerm( f, 1, &top );
LOCAL_mathn = 1; Yap_EvalError(err, t ,"error in %s/1", RepAtom(name)->StrOfAE);
return FALSE; return FALSE;
} }
return Yap_unify_constant(ARG1,out); return Yap_unify_constant(ARG1,out);
@ -1019,7 +1024,7 @@ p_unary_op_as_integer( USES_REGS1 )
Term t = Deref(ARG1); Term t = Deref(ARG1);
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR,t, "X is Y"); Yap_EvalError(INSTANTIATION_ERROR,t, "X is _Y");
return(FALSE); return(FALSE);
} }
if (IsIntTerm(t)) { if (IsIntTerm(t)) {
@ -1037,12 +1042,6 @@ p_unary_op_as_integer( USES_REGS1 )
return(FALSE); return(FALSE);
} }
Atom
Yap_NameOfUnaryOp(int i)
{
return Yap_LookupAtom(InitUnTab[i].OpName);
}
void void
Yap_InitUnaryExps(void) Yap_InitUnaryExps(void)
{ {
@ -1052,7 +1051,7 @@ Yap_InitUnaryExps(void)
for (i = 0; i < sizeof(InitUnTab)/sizeof(InitUnEntry); ++i) { for (i = 0; i < sizeof(InitUnTab)/sizeof(InitUnEntry); ++i) {
AtomEntry *ae = RepAtom(Yap_LookupAtom(InitUnTab[i].OpName)); AtomEntry *ae = RepAtom(Yap_LookupAtom(InitUnTab[i].OpName));
if (ae == NULL) { if (ae == NULL) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"at InitUnaryExps"); Yap_EvalError(OUT_OF_HEAP_ERROR,TermNil,"at InitUnaryExps");
return; return;
} }
WRITE_LOCK(ae->ARWLock); WRITE_LOCK(ae->ARWLock);

View File

@ -1146,30 +1146,48 @@ p_binary_is( USES_REGS1 )
{ /* X is Y */ { /* X is Y */
Term t = Deref(ARG2); Term t = Deref(ARG2);
Term t1, t2; Term t1, t2;
yap_error_number err;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_ArithError(INSTANTIATION_ERROR,t, "X is Y"); Yap_ArithError(INSTANTIATION_ERROR,t, "VAR(X , Y)");
return(FALSE); return(FALSE);
} }
Yap_ClearExs(); Yap_ClearExs();
t1 = Yap_Eval(Deref(ARG3)); t1 = Yap_Eval(Deref(ARG3));
if (Yap_FoundArithError()) { if ((err = Yap_FoundArithError())) {
LOCAL_mathtt[0] = t1; Atom name;
if (IsIntTerm(t)) {
Int i = IntOfTerm(t);
name = Yap_NameOfBinaryOp(i);
} else {
name = AtomOfTerm(Deref(ARG2));
}
Yap_EvalError(err,ARG3,"X is ~s/2: error in first argument ", RepAtom(name)->StrOfAE);
return FALSE; return FALSE;
} }
LOCAL_mathtt[0] = t1;
t2 = Yap_Eval(Deref(ARG4)); t2 = Yap_Eval(Deref(ARG4));
if (Yap_FoundArithError()) { if ((err=Yap_FoundArithError())) {
LOCAL_mathtt[0] = t2; Atom name;
if (IsIntTerm(t)) {
Int i = IntOfTerm(t);
name = Yap_NameOfBinaryOp(i);
} else {
name = AtomOfTerm(Deref(ARG2));
}
Yap_EvalError(err,ARG3,"X is ~s/2: error in first argument ", RepAtom(name)->StrOfAE);
return FALSE; return FALSE;
} }
if (IsIntTerm(t)) { if (IsIntTerm(t)) {
Term tout = eval2(IntOfTerm(t), t1, t2 PASS_REGS); Int i = IntOfTerm(t);
Term tout = eval2(i, t1, t2 PASS_REGS);
if (Yap_FoundArithError()) { if (Yap_FoundArithError()) {
LOCAL_mathtt[0] = t1; Term ts[2], terr;
LOCAL_mathtt[1] = t2; Atom name = Yap_NameOfBinaryOp( i );
LOCAL_mathn = 2; Functor f = Yap_MkFunctor( name, 2 );
LOCAL_mathop = IntOfTerm(t); ts[0] = t1;
ts[1] = t2;
terr = Yap_MkApplTerm( f, 2, ts );
Yap_EvalError(err, terr ,"error in ~s/2 ", RepAtom(name)->StrOfAE);
return FALSE; return FALSE;
} }
return Yap_unify_constant(ARG1,tout); return Yap_unify_constant(ARG1,tout);
@ -1186,7 +1204,7 @@ p_binary_is( USES_REGS1 )
ti[0] = t; ti[0] = t;
ti[1] = MkIntTerm(1); ti[1] = MkIntTerm(1);
t = Yap_MkApplTerm(FunctorSlash, 2, ti); t = Yap_MkApplTerm(FunctorSlash, 2, ti);
Yap_Error(TYPE_ERROR_EVALUABLE, t, Yap_EvalError(TYPE_ERROR_EVALUABLE, t,
"functor %s/%d for arithmetic expression", "functor %s/%d for arithmetic expression",
RepAtom(name)->StrOfAE,2); RepAtom(name)->StrOfAE,2);
P = FAILCODE; P = FAILCODE;
@ -1194,10 +1212,12 @@ p_binary_is( USES_REGS1 )
} }
out= eval2(p->FOfEE, t1, t2 PASS_REGS); out= eval2(p->FOfEE, t1, t2 PASS_REGS);
if (Yap_FoundArithError()) { if (Yap_FoundArithError()) {
LOCAL_mathtt[0] = t1; Term ts[2], terr;
LOCAL_mathtt[1] = t2; Functor f = Yap_MkFunctor( name, 2 );
LOCAL_mathn = 2; ts[0] = t1;
LOCAL_mathop = IntOfTerm(t); ts[1] = t2;
terr = Yap_MkApplTerm( f, 2, ts );
Yap_EvalError(err, terr ,"error in ~s/2 ", RepAtom(name)->StrOfAE);
return FALSE; return FALSE;
} }
return Yap_unify_constant(ARG1,out); return Yap_unify_constant(ARG1,out);
@ -1213,10 +1233,11 @@ do_arith23(arith2_op op USES_REGS)
Term t = Deref(ARG1); Term t = Deref(ARG1);
Int out; Int out;
Term t1, t2; Term t1, t2;
yap_error_number err;
Yap_ClearExs(); Yap_ClearExs();
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_ArithError(INSTANTIATION_ERROR,t, "X is Y"); Yap_EvalError(INSTANTIATION_ERROR,t, "X is Y");
return(FALSE); return(FALSE);
} }
t1 = Yap_Eval(t); t1 = Yap_Eval(t);
@ -1226,11 +1247,13 @@ do_arith23(arith2_op op USES_REGS)
if (t2 == 0L) if (t2 == 0L)
return FALSE; return FALSE;
out= eval2(op, t1, t2 PASS_REGS); out= eval2(op, t1, t2 PASS_REGS);
if (Yap_FoundArithError()) { if ((err=Yap_FoundArithError())) {
LOCAL_mathtt[0] = t1; Term ts[2], t;
LOCAL_mathtt[1] = t2; Functor f = Yap_MkFunctor( Yap_NameOfBinaryOp(op), 2 );
LOCAL_mathn = 2; ts[0] = t1;
LOCAL_mathop = op; ts[1] = t2;
t = Yap_MkApplTerm( f, 2, ts );
Yap_EvalError(err, t ,"error in ~s(Y,Z) ",Yap_NameOfBinaryOp(op));
return FALSE; return FALSE;
} }
return Yap_unify_constant(ARG3,out); return Yap_unify_constant(ARG3,out);
@ -1290,7 +1313,7 @@ p_binary_op_as_integer( USES_REGS1 )
Term t = Deref(ARG1); Term t = Deref(ARG1);
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR,t, "X is Y"); Yap_EvalError(INSTANTIATION_ERROR,t, "X is Y");
return(FALSE); return(FALSE);
} }
if (IsIntTerm(t)) { if (IsIntTerm(t)) {
@ -1324,7 +1347,7 @@ Yap_InitBinaryExps(void)
for (i = 0; i < sizeof(InitBinTab)/sizeof(InitBinEntry); ++i) { for (i = 0; i < sizeof(InitBinTab)/sizeof(InitBinEntry); ++i) {
AtomEntry *ae = RepAtom(Yap_LookupAtom(InitBinTab[i].OpName)); AtomEntry *ae = RepAtom(Yap_LookupAtom(InitBinTab[i].OpName));
if (ae == NULL) { if (ae == NULL) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"at InitBinaryExps"); Yap_EvalError(OUT_OF_HEAP_ERROR,TermNil,"at InitBinaryExps");
return; return;
} }
WRITE_LOCK(ae->ARWLock); WRITE_LOCK(ae->ARWLock);

View File

@ -554,6 +554,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
int psize = YAP_BUF_SIZE; int psize = YAP_BUF_SIZE;
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
Yap_ClearExs();
if (where == 0L) if (where == 0L)
where = TermNil; where = TermNil;
#if DEBUG_STRICT #if DEBUG_STRICT

101
C/eval.c
View File

@ -107,8 +107,15 @@ Eval(Term t USES_REGS)
if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, 0)))) { if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, 0)))) {
/* error */ /* error */
Term ti[2];
/* error */
ti[0] = t;
ti[1] = MkIntTerm(0);
t = Yap_MkApplTerm(FunctorSlash, 2, ti);
return Yap_ArithError(TYPE_ERROR_EVALUABLE, t, return Yap_ArithError(TYPE_ERROR_EVALUABLE, t,
"atom %s for arithmetic expression", "atom %s in arithmetic expression",
RepAtom(name)->StrOfAE); RepAtom(name)->StrOfAE);
} }
return Yap_eval_atom(p->FOfEE); return Yap_eval_atom(p->FOfEE);
@ -214,27 +221,29 @@ static Int
p_is( USES_REGS1 ) p_is( USES_REGS1 )
{ /* X is Y */ { /* X is Y */
Term out = 0L; Term out = 0L;
yap_error_number err;
Term t = Deref(ARG2);
if (IsVarTerm(t)) {
Yap_EvalError(INSTANTIATION_ERROR,t, "X is Y");
return(FALSE);
}
Yap_ClearExs(); Yap_ClearExs();
while (!(out = Yap_InnerEval(Deref(ARG2)))) { do {
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { out = Yap_InnerEval(Deref(ARG2));
if ((err = Yap_FoundArithError()) == YAP_NO_ERROR)
break;
if (err == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) { if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} else { } else {
LOCAL_mathtt[0] = Deref(ARG2); Yap_EvalError(err, ARG2, "X is Exp");
LOCAL_mathop = 0;
LOCAL_mathn = 0;
return FALSE; return FALSE;
} }
Yap_Error(LOCAL_Error_TYPE, LOCAL_mathtt[0], LOCAL_ErrorMessage); } while (TRUE);
return FALSE;
}
if (Yap_FoundArithError()) {
return TRUE;
}
return Yap_unify_constant(ARG1,out); return Yap_unify_constant(ARG1,out);
} }
@ -256,20 +265,20 @@ p_isnan( USES_REGS1 )
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) { if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} else { } else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
if (IsVarTerm(out)) { if (IsVarTerm(out)) {
Yap_Error(INSTANTIATION_ERROR, out, "isnan/1"); Yap_EvalError(INSTANTIATION_ERROR, out, "isnan/1");
return FALSE; return FALSE;
} }
if (!IsFloatTerm(out)) { if (!IsFloatTerm(out)) {
Yap_Error(TYPE_ERROR_FLOAT, out, "isnan/1"); Yap_EvalError(TYPE_ERROR_FLOAT, out, "isnan/1");
return FALSE; return FALSE;
} }
return isnan(FloatOfTerm(out)); return isnan(FloatOfTerm(out));
@ -291,20 +300,20 @@ p_isinf( USES_REGS1 )
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) { if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} else { } else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
if (IsVarTerm(out)) { if (IsVarTerm(out)) {
Yap_Error(INSTANTIATION_ERROR, out, "isinf/1"); Yap_EvalError(INSTANTIATION_ERROR, out, "isinf/1");
return FALSE; return FALSE;
} }
if (!IsFloatTerm(out)) { if (!IsFloatTerm(out)) {
Yap_Error(TYPE_ERROR_FLOAT, out, "isinf/1"); Yap_EvalError(TYPE_ERROR_FLOAT, out, "isinf/1");
return FALSE; return FALSE;
} }
return isinf(FloatOfTerm(out)); return isinf(FloatOfTerm(out));
@ -345,11 +354,11 @@ p_logsum( USES_REGS1 )
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) { if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} else { } else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
@ -373,11 +382,11 @@ p_logsum( USES_REGS1 )
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) { if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} else { } else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
@ -400,6 +409,8 @@ Yap_ArithError(yap_error_number type, Term where, char *format,...)
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
if (LOCAL_ArithError)
return 0L;
LOCAL_ArithError = TRUE; LOCAL_ArithError = TRUE;
LOCAL_Error_TYPE = type; LOCAL_Error_TYPE = type;
LOCAL_Error_Term = where; LOCAL_Error_Term = where;
@ -419,6 +430,32 @@ Yap_ArithError(yap_error_number type, Term where, char *format,...)
return 0L; return 0L;
} }
yamop *
Yap_EvalError(yap_error_number type, Term where, char *format,...)
{
CACHE_REGS
va_list ap;
if (LOCAL_ArithError) {
return Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
}
if (!LOCAL_ErrorMessage)
LOCAL_ErrorMessage = LOCAL_ErrorSay;
va_start (ap, format);
if (format != NULL) {
#if HAVE_VSNPRINTF
(void) vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, format, ap);
#else
(void) vsprintf(LOCAL_ErrorMessage, format, ap);
#endif
} else {
LOCAL_ErrorMessage[0] = '\0';
}
va_end (ap);
return Yap_Error( type, where, LOCAL_ErrorMessage);
}
/** /**
@{ @{
@ -478,23 +515,23 @@ init_between( USES_REGS1 )
Term t2 = Deref(ARG2); Term t2 = Deref(ARG2);
if (IsVarTerm(t1)) { if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "between/3"); Yap_EvalError(INSTANTIATION_ERROR, t1, "between/3");
return FALSE; return FALSE;
} }
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
Yap_Error(INSTANTIATION_ERROR, t1, "between/3"); Yap_EvalError(INSTANTIATION_ERROR, t1, "between/3");
return FALSE; return FALSE;
} }
if (!IsIntegerTerm(t1) && if (!IsIntegerTerm(t1) &&
!IsBigIntTerm(t1)) { !IsBigIntTerm(t1)) {
Yap_Error(TYPE_ERROR_INTEGER, t1, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t1, "between/3");
return FALSE; return FALSE;
} }
if (!IsIntegerTerm(t2) && if (!IsIntegerTerm(t2) &&
!IsBigIntTerm(t2) && !IsBigIntTerm(t2) &&
t2 != MkAtomTerm(AtomInf) && t2 != MkAtomTerm(AtomInf) &&
t2 != MkAtomTerm(AtomInfinity)) { t2 != MkAtomTerm(AtomInfinity)) {
Yap_Error(TYPE_ERROR_INTEGER, t2, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t2, "between/3");
return FALSE; return FALSE;
} }
if (IsIntegerTerm(t1) && IsIntegerTerm(t2)) { if (IsIntegerTerm(t1) && IsIntegerTerm(t2)) {
@ -506,7 +543,7 @@ init_between( USES_REGS1 )
if (!IsVarTerm(t3)) { if (!IsVarTerm(t3)) {
if (!IsIntegerTerm(t3)) { if (!IsIntegerTerm(t3)) {
if (!IsBigIntTerm(t3)) { if (!IsBigIntTerm(t3)) {
Yap_Error(TYPE_ERROR_INTEGER, t3, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3");
return FALSE; return FALSE;
} }
cut_fail(); cut_fail();
@ -530,7 +567,7 @@ init_between( USES_REGS1 )
if (!IsVarTerm(t3)) { if (!IsVarTerm(t3)) {
if (!IsIntegerTerm(t3)) { if (!IsIntegerTerm(t3)) {
if (!IsBigIntTerm(t3)) { if (!IsBigIntTerm(t3)) {
Yap_Error(TYPE_ERROR_INTEGER, t3, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3");
return FALSE; return FALSE;
} }
cut_fail(); cut_fail();
@ -547,7 +584,7 @@ init_between( USES_REGS1 )
if (!IsVarTerm(t3)) { if (!IsVarTerm(t3)) {
if (!IsIntegerTerm(t3) && !IsBigIntTerm(t3)) { if (!IsIntegerTerm(t3) && !IsBigIntTerm(t3)) {
Yap_Error(TYPE_ERROR_INTEGER, t3, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3");
return FALSE; return FALSE;
} }
if (Yap_acmp(t3, t1 PASS_REGS) >= 0 && Yap_acmp(t2,t3 PASS_REGS) >= 0 && P != FAILCODE) if (Yap_acmp(t3, t1 PASS_REGS) >= 0 && Yap_acmp(t2,t3 PASS_REGS) >= 0 && P != FAILCODE)

View File

@ -1427,39 +1427,39 @@ Yap_MathException__( USES_REGS1 )
feclearexcept(FE_ALL_EXCEPT); feclearexcept(FE_ALL_EXCEPT);
if (raised & FE_OVERFLOW) { if (raised & FE_OVERFLOW) {
LOCAL_matherror = EVALUATION_ERROR_FLOAT_OVERFLOW; return EVALUATION_ERROR_FLOAT_OVERFLOW;
} else if (raised & (FE_INVALID|FE_INEXACT)) { } else if (raised & (FE_INVALID|FE_INEXACT)) {
LOCAL_matherror = EVALUATION_ERROR_UNDEFINED; return EVALUATION_ERROR_UNDEFINED;
} else if (raised & FE_DIVBYZERO) { } else if (raised & FE_DIVBYZERO) {
LOCAL_matherror = EVALUATION_ERROR_ZERO_DIVISOR; return EVALUATION_ERROR_ZERO_DIVISOR;
} else if (raised & FE_UNDERFLOW) { } else if (raised & FE_UNDERFLOW) {
LOCAL_matherror = EVALUATION_ERROR_FLOAT_UNDERFLOW; return EVALUATION_ERROR_FLOAT_UNDERFLOW;
} else { } else {
LOCAL_matherror = EVALUATION_ERROR_UNDEFINED; return EVALUATION_ERROR_UNDEFINED;
} }
} }
#elif (defined(__svr4__) || defined(__SVR4)) #elif (defined(__svr4__) || defined(__SVR4))
switch(sip->si_code) { switch(sip->si_code) {
case FPE_INTDIV: case FPE_INTDIV:
LOCAL_matherror = EVALUATION_ERROR_ZERO_DIVISOR; return EVALUATION_ERROR_ZERO_DIVISOR;
break; break;
case FPE_INTOVF: case FPE_INTOVF:
LOCAL_matherror = EVALUATION_ERROR_INT_OVERFLOW; return EVALUATION_ERROR_INT_OVERFLOW;
break; break;
case FPE_FLTDIV: case FPE_FLTDIV:
LOCAL_matherror = EVALUATION_ERROR_ZERO_DIVISOR; return EVALUATION_ERROR_ZERO_DIVISOR;
break; break;
case FPE_FLTOVF: case FPE_FLTOVF:
LOCAL_matherror = EVALUATION_ERROR_FLOAT_OVERFLOW; return EVALUATION_ERROR_FLOAT_OVERFLOW;
break; break;
case FPE_FLTUND: case FPE_FLTUND:
LOCAL_matherror = EVALUATION_ERROR_FLOAT_UNDERFLOW; return EVALUATION_ERROR_FLOAT_UNDERFLOW;
break; break;
case FPE_FLTRES: case FPE_FLTRES:
case FPE_FLTINV: case FPE_FLTINV:
case FPE_FLTSUB: case FPE_FLTSUB:
default: default:
LOCAL_matherror = EVALUATION_ERROR_UNDEFINED; return EVALUATION_ERROR_UNDEFINED;
} }
set_fpu_exceptions(0); set_fpu_exceptions(0);
#endif #endif
@ -1470,24 +1470,10 @@ Yap_MathException__( USES_REGS1 )
static Int static Int
p_fpe_error( USES_REGS1 ) p_fpe_error( USES_REGS1 )
{ {
if (LOCAL_mathn == 0) { Yap_Error(LOCAL_matherror, LOCAL_mathtt, LOCAL_mathstring);
Yap_Error(LOCAL_matherror, LOCAL_mathtt[0], "arithmetic");
} else if (LOCAL_mathn == 1) {
Term t;
Functor f;
f = Yap_MkFunctor( Yap_NameOfUnaryOp(LOCAL_mathop), 1);
t = Yap_MkApplTerm(f, 1, LOCAL_mathtt);
Yap_Error(LOCAL_matherror, t, "arithmetic");
} else if (LOCAL_mathn == 2) {
Term t;
Functor f;
f = Yap_MkFunctor( Yap_NameOfBinaryOp(LOCAL_mathop), 2);
t = Yap_MkApplTerm(f, 2, LOCAL_mathtt);
Yap_Error(LOCAL_matherror, t, "arithmetic");
}
LOCAL_matherror = YAP_NO_ERROR; LOCAL_matherror = YAP_NO_ERROR;
LOCAL_mathtt = TermNil;
LOCAL_mathstring = NULL;
return FALSE; return FALSE;
} }

View File

@ -308,10 +308,8 @@
#define REMOTE_matherror(wid) REMOTE(wid)->matherror_ #define REMOTE_matherror(wid) REMOTE(wid)->matherror_
#define LOCAL_mathtt LOCAL->mathtt_ #define LOCAL_mathtt LOCAL->mathtt_
#define REMOTE_mathtt(wid) REMOTE(wid)->mathtt_ #define REMOTE_mathtt(wid) REMOTE(wid)->mathtt_
#define LOCAL_mathn LOCAL->mathn_ #define LOCAL_mathstring LOCAL->mathstring_
#define REMOTE_mathn(wid) REMOTE(wid)->mathn_ #define REMOTE_mathstring(wid) REMOTE(wid)->mathstring_
#define LOCAL_mathop LOCAL->mathop_
#define REMOTE_mathop(wid) REMOTE(wid)->mathop_
#define LOCAL_CurrentError LOCAL->CurrentError_ #define LOCAL_CurrentError LOCAL->CurrentError_
#define REMOTE_CurrentError(wid) REMOTE(wid)->CurrentError_ #define REMOTE_CurrentError(wid) REMOTE(wid)->CurrentError_

View File

@ -365,6 +365,7 @@ Term Yap_eval_binary(Int,Term,Term);
Term Yap_InnerEval__(Term USES_REGS); Term Yap_InnerEval__(Term USES_REGS);
Int Yap_ArithError(yap_error_number,Term,char *msg, ...); Int Yap_ArithError(yap_error_number,Term,char *msg, ...);
yamop* Yap_EvalError(yap_error_number,Term,char *msg, ...);
#include "inline-only.h" #include "inline-only.h"
@ -390,15 +391,12 @@ Yap_ClearExs(void)
feclearexcept(FE_ALL_EXCEPT); feclearexcept(FE_ALL_EXCEPT);
} }
inline static bool inline static yap_error_number
Yap_FoundArithError__(USES_REGS1) Yap_FoundArithError__(USES_REGS1)
{ {
if (Yap_MathException() || LOCAL_Error_TYPE) { if (LOCAL_Error_TYPE != YAP_NO_ERROR)
Yap_external_signal( worker_id, YAP_FPE_SIGNAL ); return LOCAL_Error_TYPE;
regcache->P_ = FAILCODE; return Yap_MathException();
return true;
}
return false;
} }
Atom Yap_NameOfUnaryOp(int i); Atom Yap_NameOfUnaryOp(int i);

View File

@ -173,9 +173,8 @@ typedef struct worker_local {
struct db_globs* s_dbg_; struct db_globs* s_dbg_;
yap_error_number matherror_; yap_error_number matherror_;
Term mathtt_[4]; Term mathtt_;
Int mathn_; char* mathstring_;
Term mathop_;
yap_error_number CurrentError_; yap_error_number CurrentError_;
int heap_overflows_; int heap_overflows_;

View File

@ -174,8 +174,7 @@ static void InitWorker(int wid) {
REMOTE_matherror(wid) = YAP_NO_ERROR; REMOTE_matherror(wid) = YAP_NO_ERROR;
REMOTE_mathn(wid) = 0; REMOTE_mathstring(wid) = NULL;
REMOTE_mathop(wid) = YAP_NO_ERROR;
REMOTE_CurrentError(wid) = YAP_NO_ERROR; REMOTE_CurrentError(wid) = YAP_NO_ERROR;
REMOTE_heap_overflows(wid) = 0; REMOTE_heap_overflows(wid) = 0;

View File

@ -188,7 +188,6 @@ static void RestoreWorker(int wid USES_REGS) {
#ifdef LOAD_DYLD #ifdef LOAD_DYLD
#endif #endif

View File

@ -983,9 +983,6 @@
/* Define to the one symbol short name of this package. */ /* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME #undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */ /* Define to the version of this package. */
#undef PACKAGE_VERSION #undef PACKAGE_VERSION

29374
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -195,9 +195,8 @@ struct db_globs* s_dbg void
//eval.c //eval.c
yap_error_number matherror =YAP_NO_ERROR yap_error_number matherror =YAP_NO_ERROR
Term mathtt[4] void Term mathtt void
Int mathn =0 char* mathstring =NULL
int mathop =0
yap_error_number CurrentError =YAP_NO_ERROR yap_error_number CurrentError =YAP_NO_ERROR
//grow.c //grow.c

View File

@ -45,6 +45,5 @@ mkdir -p packages/cplint/approx/simplecuddLPADs
AC_CONFIG_FILES([packages/cplint/Makefile]) AC_CONFIG_FILES([packages/cplint/Makefile])
AC_CONFIG_FILES([packages/cplint/approx/simplecuddLPADs/Makefile]) AC_CONFIG_FILES([packages/cplint/approx/simplecuddLPADs/Makefile])
AC_CONFIG_FILES([packages/cplint/slipcase/Makefile])