I am writing a macro in Module A that will replace calls in an expression
with calls to something you could call trampoline functions. Let's say you
have some code in Module B like this:
A.@replace x = foo(y)
which the macro will transform to:
x = A.foo_trampoline(y)
The macro also creates this foo_trampoline function something like this:
function foo_trampoline(y)
analyze_the_foo_function
if some_property_holds
call some_other_function
else
call foo
end
end
The problem arises in that to analyze foo within the trampoline or to call
it, you need a Function and not just the Symbol that you can get from
args[1] of the call AST node. If you just have the Symbol, it seems you
need some way to do name resolution that has to start with Module B but I
don't know how or if you have access to calling Module information within
the macro implementation.
There is a work-around like the following where you pass in the original
function to the trampoline. Is there a more elegant way to do this that
doesn't require passing in the original function?
x = A.foo_trampoline(foo, y)
function foo_trampoline(orig_func, y)
analyze_orig_func
if some_property_holds
call some_other_function
else
call orig_func
end
end