Add code to resolve virtual method dispatches

This uses some ugly memoization for efficiency