From d594b04d15ea2f0fba1e5aefa7a3e3d3c0d77548 Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Mon, 24 Dec 2018 13:43:10 +0100 Subject: [PATCH] Code cleanup. --- src/mgu.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/mgu.c b/src/mgu.c index 4c52b72..fc2585f 100644 --- a/src/mgu.c +++ b/src/mgu.c @@ -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 { void *oldstate; @@ -129,6 +135,15 @@ struct state_mgu_tmp 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 /** * 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.unifyt2 = TermOp (t2); - int unify_combined_enc (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); - } - - return unify (TermKey (t1), TermKey (t2), tl, unify_combined_enc, + return unify (TermKey (t1), TermKey (t2), tl, unify_callback_wrapper, &tmpstate); }