Code cleanup.

This commit is contained in:
Cas Cremers 2018-12-24 13:43:10 +01:00
parent 102a3ff3b7
commit d594b04d15

View File

@ -121,6 +121,12 @@ termlistSubstReset (Termlist tl)
} }
} }
/**
* Helper structure and function for unify
*
* These help to allow recursive calls within unify while still passing through the "outer" callback and state pointers.
*/
struct state_mgu_tmp struct state_mgu_tmp
{ {
void *oldstate; void *oldstate;
@ -129,6 +135,15 @@ struct state_mgu_tmp
Term unifyt2; Term unifyt2;
}; };
int
unify_callback_wrapper (Termlist tl, struct state_mgu_tmp *ptr_tmpstate)
{
// now the keys are unified (subst in this tl)
// and we try the inner terms
return unify (ptr_tmpstate->unifyt1, ptr_tmpstate->unifyt2, tl,
ptr_tmpstate->oldcallback, ptr_tmpstate->oldstate);
}
//! Most general unifier iteration //! Most general unifier iteration
/** /**
* Try to determine the most general unifier of two terms, if so calls function. * Try to determine the most general unifier of two terms, if so calls function.
@ -247,15 +262,7 @@ unify (Term t1, Term t2, Termlist tl, int (*callback) (), void *state)
tmpstate.unifyt1 = TermOp (t1); tmpstate.unifyt1 = TermOp (t1);
tmpstate.unifyt2 = TermOp (t2); tmpstate.unifyt2 = TermOp (t2);
int unify_combined_enc (Termlist tl, struct state_mgu_tmp *ptr_tmpstate) return unify (TermKey (t1), TermKey (t2), tl, unify_callback_wrapper,
{
// now the keys are unified (subst in this tl)
// and we try the inner terms
return unify (ptr_tmpstate->unifyt1, ptr_tmpstate->unifyt2, tl,
ptr_tmpstate->oldcallback, ptr_tmpstate->oldstate);
}
return unify (TermKey (t1), TermKey (t2), tl, unify_combined_enc,
&tmpstate); &tmpstate);
} }