Another double trampoline removed.

This commit is contained in:
Cas Cremers 2018-10-19 15:43:08 -04:00
parent 38bb02aa61
commit 6ee81d304d

View File

@ -930,6 +930,32 @@ termOccursInRun (Term t, int run)
return false; return false;
} }
//! Iterate over preceding bindings and check if term occurs there.
int
occurs_in_previous_binding (const System sys, const int run, const int ev,
const Term t)
{
List bl;
for (bl = sys->bindings; bl != NULL; bl = bl->next)
{
Binding b;
b = (Binding) bl->data;
if (isDependEvent (b->run_to, b->ev_to, run, ev))
{
if (isTermEqual (b->term, t))
{
return true;
}
}
}
return false;
}
//! Draw a class choice //! Draw a class choice
/** /**
* \rho classes are already dealt with in the headers, so we should ignore them. * \rho classes are already dealt with in the headers, so we should ignore them.
@ -939,12 +965,6 @@ drawClass (const System sys, Binding b)
{ {
Term varterm; Term varterm;
// now check in previous things whether we saw that term already
int notSameTerm (Binding b2)
{
return (!isTermEqual (varterm, b2->term));
}
varterm = deVar (b->term); varterm = deVar (b->term);
// Variable? // Variable?
@ -968,15 +988,12 @@ drawClass (const System sys, Binding b)
} }
// Seen before? // Seen before?
if (!iterate_preceding_bindings (b->run_to, b->ev_to, notSameTerm)) if (occurs_in_previous_binding (sys, b->run_to, b->ev_to, varterm))
{ {
// We saw the same term before. Exit. // We saw the same term before. Exit.
return; return;
} }
// not seen before: choose class // not seen before: choose class
eprintf ("\t"); eprintf ("\t");
chooseTermNode (varterm); chooseTermNode (varterm);
@ -1092,15 +1109,9 @@ drawBinding (const System sys, Binding b)
*/ */
if (1 == 1 || sys->runs[b->run_from].role == I_M) if (1 == 1 || sys->runs[b->run_from].role == I_M)
{ {
// now check in previous things whether we saw that term already // now check in previous things whether we saw that term already, if so exit
int notSameTerm (Binding b2) if (occurs_in_previous_binding (sys, b->run_to, b->ev_to, b->term))
{ {
return (!isTermEqual (b->term, b2->term));
}
if (!iterate_preceding_bindings (b->run_to, b->ev_to, notSameTerm))
{
// We saw the same term before. Exit.
return; return;
} }
} }