builder

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 35 Imported by: 4

Documentation

Overview

Package builder builds a GX intermediate representation (IR). First, the GX source code is parsed to build a go/ast tree.

This package then builds an internal tree from the go/ast tree to resolve types and references. The root of the internal tree is a package. Each node in the tree refers to an external IR node that will be the output of the compilation.

The output IR tree is build from multiple passes of the internal tree:

  1. internal nodes and their matching external GIR node are created
  2. all types are resolved.
  3. the external IR tree is filled.

Errors are accumulated during these phases to report to the user. The output tree is available even if some errors occurred.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder represents a build session from text to the intermediate representation.

func New

func New(loader Loader) *Builder

New returns a new build session.

func (*Builder) Build

func (b *Builder) Build(path string) (Package, error)

Build a package given its path.

func (*Builder) BuildFiles

func (b *Builder) BuildFiles(packagePath, packageName string, fs fs.FS, filenames []string) (Package, error)

BuildFiles builds a package from a list of files. Note that the package is not registered by the builder.

func (*Builder) Import

func (b *Builder) Import(path string) (*ir.Package, error)

Import a package from its path using the builder.

func (*Builder) Loader

func (b *Builder) Loader() Loader

Loader returns the package loader of the builder.

func (*Builder) NewIncrementalPackage

func (b *Builder) NewIncrementalPackage(fullname string) *IncrementalPackage

NewIncrementalPackage creates a new incremental package.

func (*Builder) NewPackage

func (b *Builder) NewPackage(path, name string) (*FilePackage, error)

NewPackage returns a new builder package given the path of the package and its name.

type FilePackage

type FilePackage struct {
	// contains filtered or unexported fields
}

FilePackage builds GX package from GX source files or programmatically build IR.

func (*FilePackage) BuildFiles

func (pkg *FilePackage) BuildFiles(fs fs.FS, filenames []string) (err error)

BuildFiles complete the package definitions from a list of source files.

func (*FilePackage) IR

func (pkg *FilePackage) IR() *ir.Package

IR returns the package GX intermediate representation.

func (*FilePackage) ImportIR

func (pkg *FilePackage) ImportIR(decls *ir.Declarations) error

ImportIR imports package definitions from a GX intermediate representation.

type IncrementalPackage

type IncrementalPackage struct {
	// contains filtered or unexported fields
}

IncrementalPackage builds GX package from an AST. It uses a single file in which everything is defined. Any name in the package can be reassigned without triggering an error. The main use case is for GX in a notebook.

func (*IncrementalPackage) Build

func (pkg *IncrementalPackage) Build(src string) error

Build a AST source file. Definitions are added to the package or replace existing definitions.

func (*IncrementalPackage) BuildExpr

func (pkg *IncrementalPackage) BuildExpr(src string) (ir.Expr, error)

BuildExpr builds an expression.

func (*IncrementalPackage) IR

func (pkg *IncrementalPackage) IR() *ir.Package

IR returns the package GX intermediate representation.

type Loader

type Loader interface {
	Load(bld *Builder, path string) (Package, error)
}

Loader loads packages given their import path.

type Package

type Package interface {
	// IR returns the current package intermediate representation.
	IR() *ir.Package
}

Package used by the builder to build a corresponding IR package.

Directories

Path Synopsis
Package builtins provides builtins for the compiler.
Package builtins provides builtins for the compiler.
Package irb keeps track of IRs being built and how to add them to the package declarations.
Package irb keeps track of IRs being built and how to add them to the package declarations.
Package testbuild provides helper functions to test the build step in GX.
Package testbuild provides helper functions to test the build step in GX.

Jump to

Keyboard shortcuts

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