Rebase of #2711 (the rest of the new bytecode emitter)

Rebase of #2711