From e86a995dd20652fda5f4f77caf1da5540b654a39 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 11 Jan 2010 10:35:36 +0000 Subject: [PATCH] fix bad test faster interface to eval (obs from Jose Santos) --- C/eval.c | 81 +++++++++++++++++++++++------------------------------- C/tracer.c | 2 ++ H/eval.h | 2 +- 3 files changed, 38 insertions(+), 47 deletions(-) diff --git a/C/eval.c b/C/eval.c index bcc7721eb..260c79460 100644 --- a/C/eval.c +++ b/C/eval.c @@ -42,6 +42,8 @@ Eval(Term t) if (IsVarTerm(t)) { ArithError = TRUE; return Yap_ArithError(INSTANTIATION_ERROR,t,"in arithmetic"); + } else if (IsNumTerm(t)) { + return t; } else if (IsAtomTerm(t)) { ExpEntry *p; Atom name = AtomOfTerm(t); @@ -59,56 +61,43 @@ Eval(Term t) RepAtom(name)->StrOfAE); } return Yap_eval_atom(p->FOfEE); - } else if (IsIntTerm(t)) { - return t; } else if (IsApplTerm(t)) { Functor fun = FunctorOfTerm(t); - switch ((CELL)fun) { - case (CELL)FunctorLongInt: - case (CELL)FunctorDouble: -#ifdef USE_GMP - case (CELL)FunctorBigInt: -#endif - return t; - default: - { - if ((Atom)fun == AtomFoundVar) { - return Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, - "cyclic term in arithmetic expression"); - } else { - Int n = ArityOfFunctor(fun); - Atom name = NameOfFunctor(fun); - ExpEntry *p; - Term t1, t2; + if ((Atom)fun == AtomFoundVar) { + return Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, + "cyclic term in arithmetic expression"); + } else { + Int n = ArityOfFunctor(fun); + Atom name = NameOfFunctor(fun); + ExpEntry *p; + Term t1, t2; + + if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, n)))) { + Term ti[2]; - if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, n)))) { - Term ti[2]; - - /* error */ - ti[0] = t; - ti[1] = MkIntegerTerm(n); - t = Yap_MkApplTerm(FunctorSlash, 2, ti); - return Yap_ArithError(TYPE_ERROR_EVALUABLE, t, - "functor %s/%d for arithmetic expression", - RepAtom(name)->StrOfAE,n); - } - *RepAppl(t) = (CELL)AtomFoundVar; - t1 = Eval(ArgOfTerm(1,t)); - if (t1 == 0L) { - *RepAppl(t) = (CELL)fun; - return FALSE; - } - if (n == 1) { - *RepAppl(t) = (CELL)fun; - return Yap_eval_unary(p->FOfEE, t1); - } - t2 = Eval(ArgOfTerm(2,t)); - *RepAppl(t) = (CELL)fun; - if (t2 == 0L) - return FALSE; - return Yap_eval_binary(p->FOfEE,t1,t2); - } + /* error */ + ti[0] = t; + ti[1] = MkIntegerTerm(n); + t = Yap_MkApplTerm(FunctorSlash, 2, ti); + return Yap_ArithError(TYPE_ERROR_EVALUABLE, t, + "functor %s/%d for arithmetic expression", + RepAtom(name)->StrOfAE,n); } + *RepAppl(t) = (CELL)AtomFoundVar; + t1 = Eval(ArgOfTerm(1,t)); + if (t1 == 0L) { + *RepAppl(t) = (CELL)fun; + return FALSE; + } + if (n == 1) { + *RepAppl(t) = (CELL)fun; + return Yap_eval_unary(p->FOfEE, t1); + } + t2 = Eval(ArgOfTerm(2,t)); + *RepAppl(t) = (CELL)fun; + if (t2 == 0L) + return FALSE; + return Yap_eval_binary(p->FOfEE,t1,t2); } } /* else if (IsPairTerm(t)) */ { if (TailOfTerm(t) != TermNil) { diff --git a/C/tracer.c b/C/tracer.c index 54e333105..b7a04c112 100644 --- a/C/tracer.c +++ b/C/tracer.c @@ -172,6 +172,8 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args) LOCK(Yap_heap_regs->low_level_trace_lock); sc = Yap_heap_regs; vsc_count++; + if (vsc_count < 77000) + return; #ifdef THREADS Yap_heap_regs->thread_handle[worker_id].thread_inst_count++; #endif diff --git a/H/eval.h b/H/eval.h index 621047438..e1cb2916b 100644 --- a/H/eval.h +++ b/H/eval.h @@ -175,7 +175,7 @@ Int STD_PROTO(Yap_ArithError,(yap_error_number,Term,char *msg, ...)); inline EXTERN Term Yap_Eval(Term t) { - if (t == 0L || !IsVarTerm(t) || IsNumTerm(t)) + if (t == 0L || ( !IsVarTerm(t) && IsNumTerm(t) )) return t; return Yap_InnerEval(t); }