Documentation
¶
Overview ¶
Package compiler contains the "compiler" for our simple virtual machine.
It reads the string of tokens from the lexer, and outputs the bytecode which is equivalent.
The approach to labels is the same as in the inspiring-project: Every time we come across a label we output a pair of temporary bytes in our bytecode. Later, once we've read the whole program and assume we've found all existing labels, we go back up and fix the generated addresses.
This mechanism is the reason for the `fixups` and `labels` maps in the Compiler object - the former keeps track of offsets in our generated bytecodes that need to be patched with the address/offset of a given label, and the latter lets us record the offset at which labels were seen.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler contains our compiler-state
func (*Compiler) Compile ¶
func (p *Compiler) Compile()
Compile processe the stream of tokens from the lexer and builds up the bytecode program.
func (*Compiler) Dump ¶
func (p *Compiler) Dump()
Dump processe the stream of tokens from the lexer and shows the structure of the program.