elements

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: 12 Imported by: 1

Documentation

Overview

Package elements provides generic elements, independent of the evaluator, for the interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AxesFromElement

func AxesFromElement(el ir.Element) ([]int, error)

AxesFromElement returns a shape from a state element. An error is returned if a concrete shape cannot be returned.

func ConstantFromElement

func ConstantFromElement(el ir.Element) *values.HostArray

ConstantFromElement returns the host value represented by an element. The function returns (nil, nil) if the element does not host a numerical value.

func ConstantIntFromElement

func ConstantIntFromElement(el ir.Element) (val int, err error)

ConstantIntFromElement returns a scalar on a host given an element.

func ConstantScalarFromElement

func ConstantScalarFromElement[T dtype.GoDataType](el ir.Element) (val T, err error)

ConstantScalarFromElement returns a scalar on a host given an element.

func StringFromElement

func StringFromElement(el ir.Element) (string, error)

StringFromElement returns the string value stored in a element.

Types

type CallAt

type CallAt = NodeFile[*ir.CallExpr]

CallAt is a function call GX expression.

type ElementWithArrayFromContext

type ElementWithArrayFromContext interface {
	evaluator.NumericalElement

	// ArrayFromContext fetches an array from the argument.
	ArrayFromContext(*values.FuncInputs) (values.Array, error)
}

ElementWithArrayFromContext is an element able to return a concrete value from the current context. For example, a value passed as an argument to the function.

type ElementWithConstant

type ElementWithConstant interface {
	evaluator.NumericalElement

	// NumericalConstant returns the value of a constant represented by a node.
	NumericalConstant() *values.HostArray
}

ElementWithConstant is an element with a concrete value that is already known.

type ExprAt

type ExprAt = NodeFile[ir.AssignableExpr]

ExprAt is a generic GX expression.

func NewExprAt

func NewExprAt(file *ir.File, expr ir.AssignableExpr) ExprAt

NewExprAt returns a new expression at a given position.

type FieldAt

type FieldAt = NodeFile[*ir.Field]

FieldAt is a typed field at a given position.

type InputElements

type InputElements struct {
	// Values are the initial input GX values passed to the function call
	// before they were encapsulated in elements for the interpreter.
	Values values.FuncInputs

	// Receiver on which the function call was done.
	// Can be nil.
	Receiver ir.Element

	// Args returns list of arguments passed to the interpreter at call time.
	Args []ir.Element
}

InputElements is the receiver and arguments with which the function was called.

type NodeAt

type NodeAt = NodeFile[ir.Node]

NodeAt is a generic GX node.

type NodeFile

type NodeFile[T ir.Node] struct {
	// contains filtered or unexported fields
}

NodeFile is an expression with the file in which it is declared.

func NewNodeAt

func NewNodeAt[T ir.Node](file *ir.File, expr T) NodeFile[T]

NewNodeAt returns a new expression at a given position.

func (NodeFile[T]) ExprSrc

func (ea NodeFile[T]) ExprSrc() ast.Expr

ExprSrc returns the source expression.

func (NodeFile[T]) FSet

func (ea NodeFile[T]) FSet() *token.FileSet

FSet returns the fileset of the expression.

func (NodeFile[T]) File

func (ea NodeFile[T]) File() *ir.File

File returns the file in which the expression is declared.

func (NodeFile[T]) Node

func (ea NodeFile[T]) Node() T

Node returns the expression.

func (NodeFile[T]) NodeFile

func (ea NodeFile[T]) NodeFile() NodeFile[ir.Node]

NodeFile returns a general node.

func (NodeFile[T]) String

func (ea NodeFile[T]) String() string

String representation of the node in the source code.

func (NodeFile[T]) ToExprAt

func (ea NodeFile[T]) ToExprAt() ExprAt

ToExprAt converts a type position into a generic node position.

func (NodeFile[T]) ToNodeAt

func (ea NodeFile[T]) ToNodeAt() NodeAt

ToNodeAt converts a type position into a generic node position.

func (NodeFile[T]) ToValueAt

func (ea NodeFile[T]) ToValueAt() ValueAt

ToValueAt converts a type position into a generic node position.

type PackageVarSetElement

type PackageVarSetElement struct {
	// Pck is the package owning the variable.
	Pkg string
	// Index of the variable in the package definition.
	Var string
	// Value of the static variable for the compiler.
	Value ir.Element
}

PackageVarSetElement is an option to set a package variable to an element.

func (PackageVarSetElement) Package

func (p PackageVarSetElement) Package() string

Package for which the option has been built.

type SelectAt

type SelectAt = NodeFile[*ir.SelectorExpr]

SelectAt is a typed field at a given position.

type StorageAt

type StorageAt = NodeFile[ir.Storage]

StorageAt is a generic GX expression.

type String

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

String is a GX string.

func NewString

func NewString(str *ir.StringLiteral) (*String, error)

NewString returns a state element storing a string GX value.

func (*String) StringValue

func (n *String) StringValue() *values.String

StringValue returns the string value as a GX value.

func (*String) Type added in v0.3.0

func (n *String) Type() ir.Type

Type of the element.

func (*String) Unflatten

func (n *String) Unflatten(handles *flatten.Parser) (values.Value, error)

Unflatten consumes the next handles to return a GX value.

type ValueAt

type ValueAt = NodeFile[ir.Value]

ValueAt is a generic GX expression.

func NewValueAt

func NewValueAt(file *ir.File, expr ir.Value) ValueAt

NewValueAt returns a new expression at a given position.

Jump to

Keyboard shortcuts

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