comp

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: BSD-3-Clause Imports: 16 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

	FuncRanges []vm.FuncRange // bytecode [Start, End) range for every compiled function, in source order
	// 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) 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) (err 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.

func (*Compiler) CompileFiles added in v0.4.0

func (c *Compiler) CompileFiles(sources []goparser.PackageSource) (err error)

CompileFiles compiles several in-memory source files as a single main-package unit (Phase 1 across all files, then Phase 2 code-gen), so top-level symbols declared in one file are visible to the others regardless of file or declaration order. Backs `mvm run f1.go f2.go ...`.

func (*Compiler) FillTypeSlots added in v0.4.0

func (c *Compiler) FillTypeSlots()

FillTypeSlots settles deferred type Data slots to their final rtype, now that MaterializeAll + the per-type reserve/fill attach have run. The reserve path fills each type's identity in place, so a slot's type already holds the final rtype; only slots left invalid at generate time (deferred, or an imported descriptor that could not materialize at parse) need settling here.

func (*Compiler) MaterializeAll added in v0.4.0

func (c *Compiler) MaterializeAll()

MaterializeAll builds the rtype of every *Type reachable from the compiler's symbol table and type dedup maps (recursing into fields/elem/key/params/ returns/embedded/base). After the flip goparser leaves composite/named-struct rtypes nil; this fills them with layout rtypes (reserving a method-bearing synth identity for named method types) before run, so the VM never dereferences a nil Rtype and the synth attach can fill methods into each identity in place.

func (*Compiler) MethodFuncTypes added in v0.2.0

func (c *Compiler) MethodFuncTypes() []reflect.Type

MethodFuncTypes returns a slice of bound-method func types (no receiver) indexed by global method ID. Entries are nil when no interface declaration recorded the signature (e.g. methods on native types resolved purely via reflect).

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.

Jump to

Keyboard shortcuts

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