comp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package comp implements a byte code generator targeting the vm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compiler

type Compiler struct {
	*goparser.Parser
	vm.Code            // produced code, to fill VM with
	Data    []vm.Value // produced data, will be at the bottom of VM stack
	Entry   int        // offset in Code to start execution from
	// contains filtered or unexported fields
}

Compiler represents the state of a compiler.

func NewCompiler

func NewCompiler(spec *lang.Spec) *Compiler

NewCompiler returns a new compiler state for a given scanner.

func (*Compiler) ApplyDump

func (c *Compiler) ApplyDump(d *Dump) error

ApplyDump sets previously saved dump, restoring the state of global variables.

func (*Compiler) BuildDebugInfo

func (c *Compiler) BuildDebugInfo() *vm.DebugInfo

BuildDebugInfo constructs a DebugInfo from the compiler's symbol table and source registry. The result can be passed to DumpFrame/DumpCallStack.

func (*Compiler) Compile

func (c *Compiler) Compile(name, src string) error

Compile parses src and generates code and data, or returns a non-nil error. Code and data are added incrementally in c.Code and C.Data. name identifies the source ("m:<content>" for inline, "f:<path>" for file).

func (*Compiler) Dump

func (c *Compiler) Dump() *Dump

Dump creates a snapshot of the execution state of global variables. This method is specifically implemented in the Compiler to minimize the coupling between the dump format and other components. By situating the dump logic in the Compiler, it relies solely on the program being executed and the indexing algorithm used for ordering variables (currently, this is an integer that corresponds to the order of variables in the program). This design choice allows the Virtual Machine (VM) to evolve its memory management strategies without compromising backward compatibility with dumps generated by previous versions.

func (*Compiler) MethodNames

func (c *Compiler) MethodNames() []string

MethodNames returns the reverse mapping of global method IDs to names.

func (*Compiler) PrintCode

func (c *Compiler) PrintCode()

PrintCode pretty prints the generated code.

func (*Compiler) PrintData

func (c *Compiler) PrintData()

PrintData pretty prints the generated global data symbols in compiler.

type Dump

type Dump struct {
	Values []*DumpValue
}

Dump represents the state of a data dump.

type DumpValue

type DumpValue struct {
	Index int
	Name  string
	Kind  int
	Type  string
	Value any
}

DumpValue is a value of a dump state.

Jump to

Keyboard shortcuts

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