Another trampoline bites the dust.

This commit is contained in:
Cas Cremers 2018-10-22 04:25:34 +02:00
parent a373667c23
commit 368009e84f

View File

@ -214,36 +214,44 @@ newkeylevel (const int level)
return 1; return 1;
} }
//! count local constants struct state_tcc
float
term_constcount (const System sys, Term t)
{ {
int n, total; int leaves;
float ratio; int nonvariables;
};
int countMe (Term t) //! Simple helper for below
int
countMe (Term t, struct state_tcc *stcc)
{ {
if (TermRunid (t) >= 0) if (TermRunid (t) >= 0)
{ {
total++; (stcc->leaves)++;
if (!isTermVariable (t)) if (!isTermVariable (t))
{ {
n++; (stcc->nonvariables)++;
} }
} }
return 1; return 1;
} }
n = 0; //! count local constants
total = 0; float
term_iterate_deVar (t, countMe, NULL, NULL, NULL); term_constcount (const System sys, Term t)
if (total == 0) {
float ratio;
struct state_tcc Stcc;
Stcc.nonvariables = 0;
Stcc.leaves = 0;
term_iterate_state_deVar (t, countMe, NULL, NULL, NULL, &Stcc);
if (Stcc.leaves == 0)
{ {
ratio = 1; ratio = 1;
} }
else else
{ {
ratio = ((total - n) / total); ratio = ((Stcc.leaves - Stcc.nonvariables) / Stcc.leaves);
} }
return ratio; return ratio;
} }