Snapshot before more surgery
First pass at new mode infrastructure plumbing

This brings the Mercury mode system all the way out through the planner,
though it does not actually really avail itself of any of the improved
functionality.  It compiles and passes all selftests, but that, too, is
hardly saying anything.