builtin

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: 14 Imported by: 0

Documentation

Overview

Package builtin defines interfaces and helper methods to provide builtin functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(bld *builder.Builder, impl *impl.Stdlib, pkgBuilder PackageBuilder) (builder.Package, error)

Build a package from its description.

func IRFuncBuiltin

func IRFuncBuiltin[T builtinFuncImpl](name string, fnBuiltin interp.FuncBuiltin, pkg *ir.Package) *ir.FuncBuiltin

IRFuncBuiltin returns an *ir.FuncBuiltin for a function with the given name, implementation (contained in type T), interpreter slot, and package. Satisfies FuncBuilder.BuildFuncIR.

The type of the function is computed at compile time from the call to the function.

Types

type Builder

type Builder interface {
	// Name of the builder (for debugging purpose only).
	Name() string
	// Build the given package.
	Build(*builder.Builder, *impl.Stdlib, *builder.FilePackage) error
}

Builder a builtin package.

func BuildConst

func BuildConst(f ConstBuilder) Builder

BuildConst builds a function in a package.

func BuildFunc

func BuildFunc(f FuncBuilder) Builder

BuildFunc builds a function in a package.

func BuildMethod

func BuildMethod(name string, f MethodBuilder) Builder

BuildMethod builds a method for a named type in a package.

func BuildType

func BuildType(f TypeBuilder) Builder

BuildType builds a function in a package.

func ImplementBuiltin

func ImplementBuiltin(name string, fn interp.FuncBuiltin) Builder

ImplementBuiltin provides the implementation of a builtin function.

func ImplementGraphFunc

func ImplementGraphFunc(name string, slotFn interp.FuncBuiltin) Builder

ImplementGraphFunc sets the implementation in a function declaration. The function declared type does not change.

func ImplementStubFunc

func ImplementStubFunc(name string, slotFn func(impl *impl.Stdlib) interp.FuncBuiltin) Builder

ImplementStubFunc replaces a function declaration with a stdlib-provided implementation, while keeping the function's declared type.

func ParseSource

func ParseSource(fs *embed.FS, names ...string) Builder

ParseSource builds a package by parsing source files. If names is empty, all files at the top-level will parsed.

func RegisterMacro

func RegisterMacro(name string, impl cpevelements.MacroImpl) Builder

RegisterMacro registers the implementation of a meta function.

type ConstBuilder

type ConstBuilder func(*ir.Package) (string, ir.AssignableExpr, ir.Type, error)

ConstBuilder builds a type for a package.

type Func

type Func struct {
	Func *ir.FuncBuiltin
	Impl interp.FuncBuiltin
}

Func is a standard library builtin function.

func (Func) Implementation

func (f Func) Implementation() any

Implementation of the builtin function.

func (Func) Name

func (f Func) Name() string

Name of the builtin function.

type FuncBuilder

type FuncBuilder interface {
	BuildFuncIR(*impl.Stdlib, *ir.Package) (*ir.FuncBuiltin, error)
}

FuncBuilder builds a function for a package.

type MethodBuilder

type MethodBuilder interface {
	BuildMethodIR(*impl.Stdlib, builder.Package, *ir.NamedType) (*ir.FuncBuiltin, error)
}

MethodBuilder builds a method for a package given its named type.

type PackageBuilder

type PackageBuilder struct {
	// FullPath is the full path to the package, including its path and its name.
	FullPath string
	// Builders are the steps required to build the package.
	Builders []Builder
}

PackageBuilder builds a builtin package, that is a package composed of GX and Go code.

type TypeBuilder

type TypeBuilder interface {
	BuildNamedType(*impl.Stdlib, *ir.Package) (*ir.NamedType, error)
}

TypeBuilder builds a type for a package.

Jump to

Keyboard shortcuts

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