Make the code that expands host macros more flexible

This helps reduce code in other places so you don't have to find the host object each time you want to expand macros.