Work-in-progress intermediate code generator.

Still figuring out what the interface ought to be here, so this is just
a trial run. Pretty verbose and awkward right now so will probably
adjust some more before settling on a final codegen interface.