From 499b4f8987fe7592e7d60eda76a3a7dfe2a492d8 Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Mon, 24 Dec 2018 14:10:47 +0100 Subject: [PATCH] Removed trampoline for keycallback in subtermunify. --- src/mgu.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/mgu.c b/src/mgu.c index c28cc61..ef8ccb2 100644 --- a/src/mgu.c +++ b/src/mgu.c @@ -287,6 +287,22 @@ unify (Term t1, Term t2, Termlist tl, int (*callback) (), void *state) } +/** + * State for subterm unification call into keycallback + */ +struct su_kcb_state +{ + int (*callback) (Termlist, Termlist); + Termlist keylist; +}; + +int +keycallback (Termlist tl, struct su_kcb_state *ptr_kcb_state) +{ + assert (ptr_kcb_state != NULL); + return ptr_kcb_state->callback (tl, ptr_kcb_state->keylist); +} + //! Subterm unification /** * Try to unify (a subterm of) tbig with tsmall. @@ -307,11 +323,10 @@ subtermUnify (Term tbig, Term tsmall, Termlist tl, Termlist keylist, int (*callback) (Termlist, Termlist)) { int proceed; + struct su_kcb_state kcb_state; - int keycallback (Termlist tl) - { - return callback (tl, keylist); - } + kcb_state.callback = callback; + kcb_state.keylist = keylist; proceed = true; @@ -321,7 +336,7 @@ subtermUnify (Term tbig, Term tsmall, Termlist tl, Termlist keylist, // Three options: // 1. simple unification - proceed = proceed && unify (tbig, tsmall, tl, keycallback, NULL); + proceed = proceed && unify (tbig, tsmall, tl, keycallback, &kcb_state); // [2/3]: complex if (switches.intruder)