Generating Bytecode
In this chapter, we continue with code generation, taking the intermediate code from Chapter 9, Intermediate Code Generation, and generating bytecode from it. When you translate from intermediate code into a format that will run, you are generating final code. Conventionally this happens at compile time, but it could occur later—at link time, load time, or runtime. We will generate bytecode in the usual way at compile time. This chapter and the following chapter on generating native code present you with two additional forms of final code that you can choose besides transpiling to another high-level language as described in Chapter 11.
Translation from intermediate code to bytecode is performed by walking through a list of intermediate instructions, translating each intermediate code instruction into one or more bytecode instructions. A straightforward loop is used to traverse the list, with a different chunk of code for each intermediate code instruction...