Complex multiple interacting trampolines removal.

This commit is contained in:
Cas Cremers 2018-11-05 14:43:00 +01:00
parent cdda26f21f
commit c256afc7ca
5 changed files with 119 additions and 82 deletions

View File

@ -1,10 +1,8 @@
2 iterateTermOther arachne.c +1053 ; system.c +1155
1 subtermUnify arachne.c +961 1 subtermUnify arachne.c +961
3 unify mgu.c +233 ; mgu.c +247 ; mgu.c +281 3 unify mgu.c +233 ; mgu.c +247 ; mgu.c +281
dependencies: dependencies:
iterateTermOther is called using makeDepend and addOther
subtermUnify is called using unifiesWithKeys subtermUnify is called using unifiesWithKeys
unify is called using unify_combine_enc and unify_combined_tup, and a callback using the keys list? (which propagates back to subtermunify data) unify is called using unify_combine_enc and unify_combined_tup, and a callback using the keys list? (which propagates back to subtermunify data)

View File

@ -935,6 +935,66 @@ createDecryptionChain (const Binding b, const int run, const int index,
} }
} }
struct md_state
{
int neworders;
int allgood;
Term tvar;
Termlist sl;
};
//! makeDepend for next function
/** the idea is, that a substitution in run x with
* something containing should be wrapped; this
* occurs for all subterms of other runs.
*/
int
makeDepend (Term tsmall, struct md_state *state)
{
Term tsubst;
tsubst = deVar (tsmall);
if (!realTermVariable (tsubst))
{
// Only for non-variables (i.e. local constants)
int r1, e1;
r1 = TermRunid (tsubst);
e1 = firstOccurrence (sys, r1, tsubst, SEND);
if (e1 >= 0)
{
int r2, e2;
r2 = TermRunid (state->tvar);
e2 = firstOccurrence (sys, r2, tsubst, RECV);
if (e2 >= 0)
{
if (dependPushEvent (r1, e1, r2, e2))
{
state->neworders++;
return true;
}
else
{
state->allgood = false;
if (switches.output == PROOF)
{
indentPrint ();
eprintf ("Substitution for ");
termSubstPrint (state->sl->term);
eprintf (" (subterm ");
termPrint (tsmall);
eprintf (") could not be safely bound.\n");
}
return false;
}
}
}
}
return true;
}
//! Try to bind a specific existing run to a goal. //! Try to bind a specific existing run to a goal.
/** /**
@ -994,70 +1054,23 @@ bind_existing_to_goal (const Binding b, const int run, const int index,
} }
else else
{ {
int neworders; struct md_state State;
int allgood;
Term tvar;
// the idea is, that a substitution in run x with
// something containing should be wrapped; this
// occurs for all subterms of other runs.
int makeDepend (Term tsmall)
{
Term tsubst;
tsubst = deVar (tsmall); // TODO CONTEXT for makeDepend in State
if (!realTermVariable (tsubst))
{
// Only for non-variables (i.e. local constants)
int r1, e1;
r1 = TermRunid (tsubst); State.neworders = 0;
e1 = firstOccurrence (sys, r1, tsubst, SEND); State.sl = sl;
if (e1 >= 0) State.tvar = sl->term;
{ State.allgood = true;
int r2, e2; iterateTermOther (run, State.tvar, makeDepend, &State);
if (State.allgood)
r2 = TermRunid (tvar);
e2 = firstOccurrence (sys, r2, tsubst, RECV);
if (e2 >= 0)
{
if (dependPushEvent (r1, e1, r2, e2))
{
neworders++;
return true;
}
else
{
allgood = false;
if (switches.output == PROOF)
{
indentPrint ();
eprintf ("Substitution for ");
termSubstPrint (sl->term);
eprintf (" (subterm ");
termPrint (tsmall);
eprintf (") could not be safely bound.\n");
}
return false;
}
}
}
}
return true;
}
neworders = 0;
allgood = true;
tvar = sl->term;
iterateTermOther (run, tvar, makeDepend);
if (allgood)
{ {
wrapSubst (sl->next); wrapSubst (sl->next);
} }
while (neworders > 0) while (State.neworders > 0)
{ {
neworders--; State.neworders--;
dependPopEvent (); dependPopEvent ();
} }
} }

View File

@ -1128,6 +1128,19 @@ iterateEventsType (const System sys, const int run, const int evtype,
return true; return true;
} }
struct ao_state
{
Termlist tlo;
};
//! Helper for next
int
addOther (Term t, struct ao_state *state)
{
state->tlo = termlistAddNew (state->tlo, t);
return true;
}
// Iterate over all 'others': local variables of a run that are instantiated and contain some term of another run. // Iterate over all 'others': local variables of a run that are instantiated and contain some term of another run.
/** /**
* Now incorporates "checkterm" required argument of myrun to the callback: * Now incorporates "checkterm" required argument of myrun to the callback:
@ -1140,15 +1153,10 @@ iterateLocalToOther (const System sys, const int myrun,
{ {
Termlist tlo, tls; Termlist tlo, tls;
int flag; int flag;
struct ao_state State;
int addOther (Term t)
{
tlo = termlistAddNew (tlo, t);
return true;
}
flag = true; flag = true;
tlo = NULL; State.tlo = NULL;
// construct all others occuring in the recvs // construct all others occuring in the recvs
for (tls = sys->runs[myrun].sigma; tls != NULL; tls = tls->next) for (tls = sys->runs[myrun].sigma; tls != NULL; tls = tls->next)
{ {
@ -1157,11 +1165,11 @@ iterateLocalToOther (const System sys, const int myrun,
tt = tls->term; tt = tls->term;
if (realTermVariable (tt) && tt->subst != NULL); if (realTermVariable (tt) && tt->subst != NULL);
{ {
iterateTermOther (myrun, tt->subst, addOther); iterateTermOther (myrun, tt->subst, addOther, &State);
} }
} }
// now iterate over all of them // now iterate over all of them
for (tls = tlo; flag && (tls != NULL); tls = tls->next) for (tls = State.tlo; flag && (tls != NULL); tls = tls->next)
{ {
if (!callback (sys, tls->term, myrun)) if (!callback (sys, tls->term, myrun))
{ {
@ -1170,7 +1178,7 @@ iterateLocalToOther (const System sys, const int myrun,
} }
// clean up // clean up
termlistDelete (tlo); termlistDelete (State.tlo);
return flag; return flag;
} }

View File

@ -1560,21 +1560,39 @@ termSubstPrint (Term t)
} }
} }
typedef int (*CallBack) ();
struct ito_contain
{
int myrun;
CallBack callback;
void *ito_state;
};
int
testOther (Term t, struct ito_contain *state)
{
int run;
run = TermRunid (t);
if (run >= 0 && run != state->myrun)
{
return state->callback (t, state->ito_state);
}
return true;
}
// Iterate over subterm constants of other runs in a term // Iterate over subterm constants of other runs in a term
// Callback should return true to progress. This is reported in the final thing. // Callback should return true to progress. This is reported in the final thing.
int int
iterateTermOther (const int myrun, Term t, int (*callback) (Term t)) iterateTermOther (const int myrun, Term t, int (*callback) (),
void *ito_state)
{ {
int testOther (Term t, int *state) struct ito_contain State;
{
int run;
run = TermRunid (t); State.myrun = myrun;
if (run >= 0 && run != myrun) State.callback = callback;
{ State.ito_state = ito_state;
return callback (t);
} return term_iterate_state_deVar (t, testOther, NULL, NULL, NULL, &State);
return true;
}
return term_iterate_state_deVar (t, testOther, NULL, NULL, NULL, NULL);
} }

View File

@ -213,7 +213,7 @@ Term getTermFunction (Term t);
unsigned int termHidelevel (const Term tsmall, Term tbig); unsigned int termHidelevel (const Term tsmall, Term tbig);
void termSubstPrint (Term t); void termSubstPrint (Term t);
int iterateTermOther (const int myrun, Term t, int (*callback) (Term t)); int iterateTermOther (const int myrun, Term t, int (*callback) (), void *s);
extern char *RUNSEP; // by default, set to "#" extern char *RUNSEP; // by default, set to "#"