Documentation
¶
Overview ¶
Package interp evaluates GX code given an evaluator.
All values in the interpreter are represented in elements. The GX Context evaluates GX code represented as an intermediate representation (IR) tree (see github.com/gx-org/gx/build/ir), evaluates a function given a receiver and arguments passed as interpreter elements.
Index ¶
- func FuncDeclFromElement(el ir.Element) (*ir.FuncDecl, error)
- func FuncFromElement(el ir.Element) (ir.Func, error)
- func PkgFuncFromElement(el ir.Element) (ir.PkgFunc, error)
- func ShapeFromElement(node ir.Element) (*shape.Shape, error)
- func ToSingleElement(ctx ir.Evaluator, node ir.SourceNode, els []ir.Element) (ir.Element, error)
- func Underlying(val ir.Element) ir.Element
- type ArraySlicer
- type Copier
- type Evaluator
- type FileScope
- func (fitp *FileScope) Context() *context.Context
- func (fitp *FileScope) EvalExpr(expr ir.Expr) (ir.Element, error)
- func (fitp *FileScope) EvalFunc(f ir.PkgFunc, call *ir.CallExpr, args []ir.Element) ([]ir.Element, error)
- func (fitp *FileScope) Evaluator() evaluator.Evaluator
- func (fitp *FileScope) File() *ir.File
- func (fitp *FileScope) InitScope() *ir.File
- func (fitp *FileScope) Materialiser() materialise.Materialiser
- func (fitp *FileScope) NewFunc(fn ir.PkgFunc, recv *Receiver) Func
- func (fitp *FileScope) NewFuncLitScope(eval Evaluator) *FuncLitScope
- func (fitp *FileScope) Sub(vals map[string]ir.Element) *FileScope
- type FixedShape
- type FixedSlice
- type Func
- type FuncBuiltin
- type FuncLitScope
- type Interpreter
- type NType
- type NamedType
- func (n *NamedType) Copy() Copier
- func (n *NamedType) Flatten() ([]ir.Element, error)
- func (n *NamedType) NamedType() *ir.NamedType
- func (n *NamedType) RecvCopy() *NamedType
- func (n *NamedType) Select(expr *ir.SelectorExpr) (ir.Element, error)
- func (n *NamedType) String() string
- func (n *NamedType) Type() ir.Type
- func (n *NamedType) Under() ir.Element
- func (n *NamedType) Unflatten(handles *flatten.Parser) (values.Value, error)
- type NewFunc
- type Package
- type Receiver
- type Selector
- type Slice
- func (n *Slice) Compare(x canonical.Comparable) bool
- func (n *Slice) Elements() []ir.Element
- func (n *Slice) Expr() (ir.AssignableExpr, error)
- func (n *Slice) Flatten() ([]ir.Element, error)
- func (*Slice) Kind() ir.Kind
- func (n *Slice) Len() int
- func (n *Slice) Slice(fitp *FileScope, expr *ir.IndexExpr, index evaluator.NumericalElement) (ir.Element, error)
- func (n *Slice) String() string
- func (n *Slice) Type() ir.Type
- func (n *Slice) Unflatten(handles *flatten.Parser) (values.Value, error)
- type Slicer
- type Struct
- func (n *Struct) Copy() Copier
- func (n *Struct) Flatten() ([]ir.Element, error)
- func (n *Struct) Select(expr *ir.SelectorExpr) (ir.Element, error)
- func (n *Struct) SetField(name string, value ir.Element)
- func (n *Struct) String() string
- func (n *Struct) StructType() *ir.StructType
- func (n *Struct) Type() ir.Type
- func (n *Struct) Unflatten(handles *flatten.Parser) (values.Value, error)
- type Tuple
- type WithAxes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FuncDeclFromElement ¶ added in v0.3.0
FuncDeclFromElement extracts a function declaration from an element.
func FuncFromElement ¶ added in v0.6.0
FuncFromElement extracts a function declaration from an element.
func PkgFuncFromElement ¶ added in v0.6.0
PkgFuncFromElement extracts a function declaration from an element.
func ShapeFromElement ¶ added in v0.3.0
ShapeFromElement returns the shape of a numerical element.
func ToSingleElement ¶
ToSingleElement packs multiple elements into a tuple. If the slice els contains only one element, this element is returned.
Types ¶
type ArraySlicer ¶ added in v0.3.0
type ArraySlicer interface { evaluator.NumericalElement SliceArray(fitp *FileScope, expr ir.AssignableExpr, index evaluator.NumericalElement) (evaluator.NumericalElement, error) Type() ir.Type }
ArraySlicer is a state element with an array that can be sliced.
type Copier ¶ added in v0.3.0
Copier is an interface implemented by nodes that need to be copied when passed to a function.
type Evaluator ¶ added in v0.3.0
type Evaluator interface { evaluator.Evaluator // NewFunc creates a new function given its definition and a receiver. NewFunc(*Interpreter, ir.PkgFunc, *Receiver) Func // NewFuncLit calls a function literal. NewFuncLit(fitp *FileScope, ref *ir.FuncLit) (Func, error) }
Evaluator provides core primitives for the interpreter.
type FileScope ¶ added in v0.3.0
type FileScope struct {
// contains filtered or unexported fields
}
FileScope returns an interpreter given the scope of a file from within a package.
func (*FileScope) EvalFunc ¶ added in v0.3.0
func (fitp *FileScope) EvalFunc(f ir.PkgFunc, call *ir.CallExpr, args []ir.Element) ([]ir.Element, error)
EvalFunc evaluates a function.
func (*FileScope) Evaluator ¶ added in v0.3.0
Evaluator returns the evaluator used by the interpreter
func (*FileScope) InitScope ¶ added in v0.3.0
InitScope returns the initial file scope (as opposed to the file of the current context).
func (*FileScope) Materialiser ¶ added in v0.3.0
func (fitp *FileScope) Materialiser() materialise.Materialiser
Materialiser returns the materialiser to convert elements into graph nodes.
func (*FileScope) NewFuncLitScope ¶ added in v0.3.0
func (fitp *FileScope) NewFuncLitScope(eval Evaluator) *FuncLitScope
NewFuncLitScope returns a new interpreter for a function literal.
type FixedShape ¶ added in v0.3.0
FixedShape is an (array) element from which the shape has been fully determined.
type FixedSlice ¶ added in v0.3.0
FixedSlice is a slice
type Func ¶ added in v0.3.0
type Func interface { ir.Element Func() ir.Func Recv() *Receiver Call(fitp *FileScope, call *ir.CallExpr, args []ir.Element) ([]ir.Element, error) }
Func is an element owning a callable function.
type FuncBuiltin ¶
type FuncBuiltin func(ctx evaluator.Context, call elements.CallAt, fn Func, irFunc *ir.FuncBuiltin, args []ir.Element) ([]ir.Element, error)
FuncBuiltin defines a builtin function provided by a backend.
type FuncLitScope ¶ added in v0.3.0
type FuncLitScope struct {
// contains filtered or unexported fields
}
FuncLitScope is an interpreter scope to evaluate function literals.
func (*FuncLitScope) FileScope ¶ added in v0.3.0
func (litp *FuncLitScope) FileScope() *FileScope
FileScope returns the interpreter for a file scope.
type Interpreter ¶ added in v0.3.0
type Interpreter struct {
// contains filtered or unexported fields
}
Interpreter runs GX code given an evaluator and package options.
func New ¶ added in v0.3.0
func New(eval Evaluator, options []options.PackageOption) (*Interpreter, error)
New returns a new interpreter.
func (*Interpreter) Core ¶ added in v0.3.0
func (itp *Interpreter) Core() *context.Core
Core returns the core context.
func (*Interpreter) EvalFunc ¶ added in v0.3.0
func (itp *Interpreter) EvalFunc(fn *ir.FuncDecl, in *elements.InputElements) (outs []ir.Element, err error)
EvalFunc evaluates a function.
type NamedType ¶ added in v0.3.0
type NamedType struct {
// contains filtered or unexported fields
}
NamedType references a type exported by an imported package.
func NewNamedType ¶ added in v0.3.0
NewNamedType returns a new node representing an exported type.
func (*NamedType) RecvCopy ¶ added in v0.3.0
RecvCopy copies the underlying element and returns the element encapsulated in this named type.
func (*NamedType) Select ¶ added in v0.3.0
Select returns the field given an index. Returns nil if the receiver type cannot select fields.
type Package ¶ added in v0.3.0
type Package struct {
// contains filtered or unexported fields
}
Package groups elements exported by a package.
func NewPackage ¶ added in v0.3.0
NewPackage returns a package grouping everything that a package exports.
type Slice ¶ added in v0.3.0
type Slice struct {
// contains filtered or unexported fields
}
Slice element storing a slice of elements.
func (*Slice) Compare ¶ added in v0.3.0
func (n *Slice) Compare(x canonical.Comparable) bool
Compare the slice to another canonical value.
func (*Slice) Expr ¶ added in v0.3.0
func (n *Slice) Expr() (ir.AssignableExpr, error)
Expr returns the IR expression representing the slice.
func (*Slice) Slice ¶ added in v0.3.0
func (n *Slice) Slice(fitp *FileScope, expr *ir.IndexExpr, index evaluator.NumericalElement) (ir.Element, error)
Slice of the tuple.
type Slicer ¶ added in v0.3.0
type Slicer interface {
Slice(fitp *FileScope, expr *ir.IndexExpr, index evaluator.NumericalElement) (ir.Element, error)
}
Slicer is a state element that can be sliced.
type Struct ¶ added in v0.3.0
type Struct struct {
// contains filtered or unexported fields
}
Struct is an instance of a structure.
func NewStructFromElements ¶ added in v0.3.0
func NewStructFromElements(typ *ir.StructType, vals []ir.Element) *Struct
NewStructFromElements returns a new node representing a structure instance given a slice of
func (*Struct) Flatten ¶ added in v0.3.0
Flatten returns a flat list of all the elements stored in the structure.
func (*Struct) Select ¶ added in v0.3.0
Select returns the value of a field of a structure given its index.
func (*Struct) StructType ¶ added in v0.3.0
func (n *Struct) StructType() *ir.StructType
StructType returns the type of the structure.
type Tuple ¶ added in v0.3.0
type Tuple struct {
// contains filtered or unexported fields
}
Tuple value grouping multiple values together.
func NewTuple ¶ added in v0.3.0
NewTuple returns a tuple to store the result of a function returning more than one value.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package context maintains the namespaces and stack for the interpreter.
|
Package context maintains the namespaces and stack for the interpreter. |
Package elements provides generic elements, independent of the evaluator, for the interpreter.
|
Package elements provides generic elements, independent of the evaluator, for the interpreter. |
Package evaluator defines interfaces for the interpreter to use to evaluate GX code.
|
Package evaluator defines interfaces for the interpreter to use to evaluate GX code. |
Package grapheval implements the evaluation of core GX functions.
|
Package grapheval implements the evaluation of core GX functions. |
Package materialise defines interfaces and helper functions to transform elements into graph nodes.
|
Package materialise defines interfaces and helper functions to transform elements into graph nodes. |
Package numbers implement elements representing numbers for the interpreter.
|
Package numbers implement elements representing numbers for the interpreter. |
Package proxies provides proxy for all GX values.
|
Package proxies provides proxy for all GX values. |