Switch to debruijn indices, genericize sub/lub/glb

More refactoring in support of HRTB. There should be no change in functionality from these changes.

r? @pnkfelix 
Bruijn