compiler

package
v0.0.0-...-acc6289 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

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 New

func New(l *lexer.Lexer) *Compiler

New is our constructor

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.

func (*Compiler) Output

func (p *Compiler) Output() []byte

Output returns the bytecodes of the compiled program.

func (*Compiler) Write

func (p *Compiler) Write(output string)

Write outputs our generated bytecode to the named file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL