Metaprogramming: Defining new methods to existing function

I want to create a macro that adds methods to a function for particular types and creates some global variables (I know not the best practice but this is what I am trying).

It is not difficult for me to do this if the macro is used in global scope as esc suffices for that.

However if the macro is used in some local scope like a function how can I add to the global scope? Is that even possible?

The behavior I want is for the compiler to see the macro inside the function when it is compiling it. Say wait a second I need to add some things to global scope before compiling this function. And then proceed with compiling the function. As opposed to the more basic expressions expansion that occurs with macros.