Reflection in Rewriting Logic: Metalogical Foundations and Metaprogramming Applications