interp

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package interp is the dev interpreter (REQ-DEV-02, REQ-DEV-05). It runs the Go code that the compiler generates for a .gx file, with reflection, against a table of the symbols that the running app was built with. The compiled path and the interpreted path then run the same statements and call the same functions, so the two render the same bytes.

The interpreter covers a measured part of Go (DR-03): what the code generator writes, and the common expressions of a template. Compile refuses a file that uses more, and the dev server then rebuilds the app.

Only a build with the gxdev tag links this package (SI-08).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) constant.Value

func Float

func Float(lit string) constant.Value

Float makes a float constant from a literal or from an exact fraction "a/b". A constant such as 1.0 / 3 has no exact decimal form, and Go keeps it exact until a use gives it a type.

func Int

func Int(lit string) constant.Value

Int, Float, String and Bool make the untyped constants of a generated symbol table from their Go text.

func Rune

func Rune(lit string) constant.Value

Rune makes an untyped rune constant from its literal, for example "'/'". Its default type is rune, not int.

func String

func String(s string) constant.Value

Types

type File

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

File is one compiled source file: its functions by name.

func Compile

func Compile(table *Table, pkgPath, filename string, src []byte) (file *File, err error)

Compile parses the Go source of one file of the package with the import path pkgPath and prepares its functions. It resolves each name against the table and returns an *Unsupported error for code that the interpreter does not cover.

func (*File) Func

func (f *File) Func(name string) *Func

Func returns the function with the name, or nil.

func (*File) Names

func (f *File) Names() []string

Names returns the names of the functions of the file.

type Func

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

Func is one interpreted function.

func (*Func) Call

func (f *Func) Call(args []reflect.Value) []reflect.Value

Call runs the function. The arguments must have the parameter types. A panic of the code is a panic of Call, as it is in compiled code.

func (*Func) CallAny

func (f *Func) CallAny(args ...any) any

CallAny runs the function with plain values and returns its first result. A nil argument is the zero value of its parameter type, so a nil interface value passes.

func (*Func) Type

func (f *Func) Type() reflect.Type

Type returns the type of the function.

type Package

type Package struct {
	// Path is the import path and Name is the package name.
	Path string
	Name string
	// Values holds the functions, the variables and the typed constants.
	// A variable is an addressable value, so the interpreter reads its
	// current value and can assign to it.
	Values map[string]reflect.Value
	// Consts holds the untyped constants.
	Consts map[string]constant.Value
	// Types holds the named types.
	Types map[string]reflect.Type
	// Methods holds a function for each method that reflection cannot
	// call: an unexported method. The key is "Type.method", or
	// "*Type.method" for a pointer receiver. The function takes the
	// receiver as its first argument.
	Methods map[string]reflect.Value
}

Package is the symbols of one Go package, as the generated symbol table of an app lists them (REQ-DEV-04).

type RuneConst

type RuneConst struct{ constant.Value }

RuneConst marks a constant of a table as an untyped rune constant.

type Table

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

Table is the symbol table of an app: its packages by import path.

func NewTable

func NewTable(pkgs ...*Package) *Table

NewTable returns a table of the packages.

func (*Table) Package

func (t *Table) Package(path string) *Package

Package returns the package with the import path, or nil.

type Unsupported

type Unsupported struct {
	Pos token.Position
	Msg string
}

Unsupported is the error of Compile for code outside the part of Go that the interpreter covers, or for a name that the table does not hold. The dev server takes the rebuild path for it.

func (*Unsupported) Error

func (e *Unsupported) Error() string

Directories

Path Synopsis
Package interptest holds Go functions that the interpreter tests run two times: as compiled code and as interpreted code.
Package interptest holds Go functions that the interpreter tests run two times: as compiled code and as interpreted code.

Jump to

Keyboard shortcuts

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