ir

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: 16 Imported by: 2

Documentation

Overview

Package ir is the GX Intermediate Representation (IR) tree. The tree is built by the GX builder google3/third_party/gxlang/gx/build/builder/builder from GX source code.

The structure and semantic is modeled after the go/ast package.

Index

Constants

View Source
const (
	// DefineAxisGroup is the prefix used in parameters to define an axis group.
	DefineAxisGroup = "___"
	// DefineAxisLength is the prefix used in parameters to define an axis length.
	DefineAxisLength = "_"
)
View Source
const (
	InvalidKind = Kind(dtype.Invalid)

	BoolKind     = Kind(dtype.Bool)
	Int32Kind    = Kind(dtype.Int32)
	Int64Kind    = Kind(dtype.Int64)
	Uint32Kind   = Kind(dtype.Uint32)
	Uint64Kind   = Kind(dtype.Uint64)
	Bfloat16Kind = Kind(dtype.Bfloat16)
	Float32Kind  = Kind(dtype.Float32)
	Float64Kind  = Kind(dtype.Float64)

	IntIdxKind = Kind(iota + dtype.MaxDataType)
	IntLenKind

	// UnknownKind is a proxy type used while a type is being inferred by the compiler.
	UnknownKind
	// VoidKind is a type for expression returning nothing.
	VoidKind
	// InterfaceKind is an interface.
	InterfaceKind
	// NumberFloatKind is a float number with no concrete type.
	NumberFloatKind
	// NumberIntKind is an integer number with no concrete type.
	NumberIntKind

	ArrayKind
	BuiltinKind
	FuncKind
	RankKind
	SliceKind
	StringKind
	StructKind
	TupleKind
	IRKind
	PackageKind
	MetaTypeKind

	// Maximum value for a Kind constant.
	MaxKind
)

Kind of data supported by GX.

View Source
const Blank = "_"

Blank characters when an identifier is not needed.

Variables

View Source
var (
	// DefaultIntKind is the default kind for integer.
	DefaultIntKind = Int64Kind

	// DefaultIntType is the default type used for an integer.
	DefaultIntType = TypeFromKind(Int64Kind)
)
View Source
var DefaultFloatType = Float32Type()

DefaultFloatType is the default type used for a scalar.

Functions

func CanBeNumber

func CanBeNumber(typ Type) bool

CanBeNumber returns true if the value of a kind can be a number.

func IsAxisLengthType added in v0.3.0

func IsAxisLengthType(typ Type) bool

IsAxisLengthType returns true if a type is the type for an array axis length.

func IsBoolOp

func IsBoolOp(op token.Token) bool

IsBoolOp returns true if op is an operator returning a boolean.

func IsDataType

func IsDataType(typ Type) bool

IsDataType returns true if the type can be stored in an array.

func IsExported

func IsExported(name string) bool

IsExported returns true if a name is exported (the first letter is capitalized).

func IsFloat

func IsFloat(typ Type) bool

IsFloat return true if type is a float.

func IsFloatKind

func IsFloatKind(kind Kind) bool

IsFloatKind returns true if kind is a float.

func IsIndexType

func IsIndexType(typ Type) bool

IsIndexType returns true if the kind is a supported array index type.

func IsInteger

func IsInteger(typ Type) bool

IsInteger return true if kind is an integer.

func IsIntegerKind

func IsIntegerKind(kind Kind) bool

IsIntegerKind return true if kind is an integer.

func IsNumber

func IsNumber(knd Kind) bool

IsNumber returns true if the kind is a number.

func IsRangeOk

func IsRangeOk(k Kind) bool

IsRangeOk returns true if the kind can be used to iterate in a for loop with a range statement.

func IsSlicingOk

func IsSlicingOk(typ Type) bool

IsSlicingOk returns true if the type supports slicing, (that is value_of_type[i]).

func IsStatic

func IsStatic(tp Type) bool

IsStatic return true if the type is static, that is if the instance of the type can be evaluated when the graph is being constructed.

func IsValid

func IsValid(tp Type) bool

IsValid returns true if the type is valid.

func Shape

func Shape(tp Type) (ArrayRank, Type)

Shape returns the data type and axes of an array. An invalid data type is returned if the type is not a container. A slice returns a nil rank.

func SupportOperators

func SupportOperators(typ Type) bool

SupportOperators returns true if the type supports unary or binary operators.

func TypeInclude

func TypeInclude(fetcher Fetcher, set Type, typ Type) (bool, error)

TypeInclude returns if a typ is included in a type or not.

func TypeString added in v0.4.0

func TypeString(typ Type) string

TypeString returns a string representation of a type for users.

func ValidIdent

func ValidIdent(ident *ast.Ident) bool

ValidIdent returns true if the ident points to a valid identifier.

func ValidName

func ValidName(n string) bool

ValidName returns true if a name is a valid identifier.

Types

type Annotation added in v0.6.0

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

Annotation is a key pointing to some data.

func NewAnnotation added in v0.6.0

func NewAnnotation(key string, val any) *Annotation

NewAnnotation creates a new annotation. This function is mostly used for tests. Prefer Annotations.Append instead.

func (*Annotation) Key added in v0.6.0

func (ann *Annotation) Key() string

Key of the annotation.

func (*Annotation) Value added in v0.6.0

func (ann *Annotation) Value() any

Value of the annotation.

type Annotations added in v0.6.0

type Annotations struct {
	Anns []*Annotation
}

Annotations maps key to annotation value.

func (*Annotations) Append added in v0.6.0

func (anns *Annotations) Append(pkg *Package, key string, value any)

Append a new annotation to the slice of annotation.

func (*Annotations) AppendAnn added in v0.6.0

func (anns *Annotations) AppendAnn(ann *Annotation)

AppendAnn appends an annotation already constructed.

type AnonymousStorage

type AnonymousStorage struct {
	Src *ast.Ident
	Typ Type
}

AnonymousStorage stores values that have not been labelled (for example, the axis length in [_]float32).

func (*AnonymousStorage) Expr

func (s *AnonymousStorage) Expr() ast.Expr

Expr returns the expression in the AST tree.

func (*AnonymousStorage) NameDef

func (s *AnonymousStorage) NameDef() *ast.Ident

NameDef returns the identifier identifying the storage.

func (*AnonymousStorage) Same added in v0.3.0

func (s *AnonymousStorage) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*AnonymousStorage) Source

func (s *AnonymousStorage) Source() ast.Node

Source returns the node in the AST tree.

func (*AnonymousStorage) Type

func (s *AnonymousStorage) Type() Type

Type of the destination of the assignment.

type ArrayLitExpr

type ArrayLitExpr struct {
	Src  *ast.CompositeLit
	Typ  ArrayType
	Elts []AssignableExpr
}

ArrayLitExpr is an array literal.

func (*ArrayLitExpr) Expr

func (s *ArrayLitExpr) Expr() ast.Expr

Expr returns the AST expression.

func (*ArrayLitExpr) NewFromValues

func (s *ArrayLitExpr) NewFromValues(elts []AssignableExpr) *ArrayLitExpr

NewFromValues returns a new literal of the same type from a slice of values.

func (*ArrayLitExpr) Source

func (s *ArrayLitExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*ArrayLitExpr) String

func (s *ArrayLitExpr) String() string

func (*ArrayLitExpr) Type

func (s *ArrayLitExpr) Type() Type

Type returns the type returned by the function call.

func (*ArrayLitExpr) Values

func (s *ArrayLitExpr) Values() []AssignableExpr

Values returns the expressions defining the values of the array.

type ArrayRank

type ArrayRank interface {
	Expr

	// IsAtomic returns true if the rank has no axes.
	IsAtomic() bool

	// Axes returns all axis in the rank.
	Axes() []AxisLengths

	// Equal returns true if two ranks are equal.
	Equal(Fetcher, ArrayRank) (bool, error)

	// AssignableTo returns true if this rank can be assigned to the destination rank.
	AssignableTo(Fetcher, ArrayRank) (bool, error)

	// ConvertibleTo returns true if this rank can be converted to the destination rank.
	ConvertibleTo(Fetcher, ArrayRank) (bool, error)

	// SubRank returns the rank with the top-axis removed.
	SubRank() (ArrayRank, bool)

	// String representation of the rank.
	String() string
	// contains filtered or unexported methods
}

ArrayRank of an array.

type ArrayType

type ArrayType interface {
	Zeroer
	SourceNode
	SlicerType

	// ArrayType returns the source code defining the array type.
	// May be nil.
	ArrayType() ast.Expr

	// Rank returns the rank of the array,
	// that is, a list of the array's axes.
	Rank() ArrayRank

	// DataType returns the element type of the array.
	DataType() Type
	// contains filtered or unexported methods
}

ArrayType is a type with a rank.

func NewArrayType

func NewArrayType(src ast.Expr, dtype Type, rank ArrayRank) ArrayType

NewArrayType returns a new array from a data type and a rank.

func ToArrayType

func ToArrayType(typ Type) ArrayType

ToArrayType converts a type into an array type. Returns nil if the conversion is not possible

func ToArrayTypeGivenShape

func ToArrayTypeGivenShape(typ Type, sh *shape.Shape) (ArrayType, error)

ToArrayTypeGivenShape converts a type to the underlying array type. Returns an error with the array type does not match the shape.

func Uint64Type

func Uint64Type() ArrayType

Uint64Type returns the type for a uint64.

type AssignCallResult

type AssignCallResult struct {
	Storage
	Call        *CallExpr
	ResultIndex int
}

AssignCallResult assigns the result of a function call.

func (*AssignCallResult) Value

Value returns the expression stored in the storage.

type AssignCallStmt

type AssignCallStmt struct {
	Src  *ast.AssignStmt
	Call *CallExpr
	List []*AssignCallResult
}

AssignCallStmt assigns the results of a function call returning more than one value to variables.

func (*AssignCallStmt) Source

func (s *AssignCallStmt) Source() ast.Node

Source returns the node in the AST tree.

func (*AssignCallStmt) String

func (s *AssignCallStmt) String() string

type AssignExpr

type AssignExpr struct {
	Storage
	X AssignableExpr
}

AssignExpr assigns an expression to a Assignable node.

func (*AssignExpr) Value

func (a *AssignExpr) Value(Expr) AssignableExpr

Value returns the expression stored in the storage.

type AssignExprStmt

type AssignExprStmt struct {
	Src  *ast.AssignStmt
	List []*AssignExpr
}

AssignExprStmt assigns the results of expressions (possibly functions returning one value) to variables.

func (*AssignExprStmt) Source

func (s *AssignExprStmt) Source() ast.Node

Source returns the node in the AST tree.

func (*AssignExprStmt) String

func (s *AssignExprStmt) String() string

type AssignableExpr

type AssignableExpr interface {
	Expr
	// contains filtered or unexported methods
}

AssignableExpr is an expression which can be assigned to variable. This excludes package or types.

type AtomicValue

type AtomicValue interface {
	AssignableExpr
	// contains filtered or unexported methods
}

AtomicValue is implemented by all atomic values.

type AtomicValueT

type AtomicValueT[T dtype.GoDataType] struct {
	Src ast.Expr
	Val T
	Typ Type
}

AtomicValueT is a builtin constant.

func False

func False() *AtomicValueT[bool]

False returns an atomic value equal to false.

func True

func True() *AtomicValueT[bool]

True returns an atomic value equal to true.

func (*AtomicValueT[T]) Expr

func (s *AtomicValueT[T]) Expr() ast.Expr

Expr returns the AST expression.

func (*AtomicValueT[T]) Source

func (s *AtomicValueT[T]) Source() ast.Node

Source returns the node in the AST tree.

func (*AtomicValueT[T]) String

func (s *AtomicValueT[T]) String() string

String representation.

func (*AtomicValueT[T]) Type

func (s *AtomicValueT[T]) Type() Type

Type returns the type returned by the function call.

type AxLengthName added in v0.3.0

type AxLengthName struct {
	Src *ast.Ident
	Typ Type
}

AxLengthName defines a name for the length of an axis or a group of axes.

func (*AxLengthName) NameDef added in v0.3.0

func (s *AxLengthName) NameDef() *ast.Ident

NameDef returns the identifier identifying the storage.

func (*AxLengthName) Same added in v0.3.0

func (s *AxLengthName) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*AxLengthName) Source added in v0.3.0

func (s *AxLengthName) Source() ast.Node

Source returns the node in the AST tree.

func (*AxLengthName) String added in v0.3.0

func (dm *AxLengthName) String() string

String representation of the dimension.

func (*AxLengthName) Type added in v0.3.0

func (s *AxLengthName) Type() Type

Type of the destination of the assignment.

type AxisExpr

type AxisExpr struct {
	// Source of the axis expression.
	// May be different from the source of the expression, for example
	// the expression is formed from a function call.
	Src ast.Expr
	// X computes the size of the axis.
	X AssignableExpr
}

AxisExpr is an array axis specified using an expression.

func (*AxisExpr) AssignableTo

func (dm *AxisExpr) AssignableTo(fetcher Fetcher, dst AxisLengths) (bool, error)

AssignableTo returns true if a dimension can be assigned to another.

func (*AxisExpr) AxisValue

func (dm *AxisExpr) AxisValue() AssignableExpr

AxisValue returns the value assigned to the axis.

func (*AxisExpr) Equal

func (dm *AxisExpr) Equal(fetcher Fetcher, other AxisLengths) (bool, error)

Equal returns true if other has the axis length.

func (*AxisExpr) NumAxes

func (dm *AxisExpr) NumAxes() int

NumAxes returns the number of axis represented by the group.

func (*AxisExpr) Source

func (dm *AxisExpr) Source() ast.Node

Source returns the source expression specifying the dimension.

func (*AxisExpr) String

func (dm *AxisExpr) String() string

String representation of the dimension.

func (*AxisExpr) Type

func (dm *AxisExpr) Type() Type

Type of the expression.

func (*AxisExpr) Value

func (dm *AxisExpr) Value(Expr) AssignableExpr

Value of the axis.

type AxisInfer

type AxisInfer struct {
	Src *ast.Ident
	X   AxisLengths
}

AxisInfer is an array axis specified as "_" and inferred by the compiler.

func (*AxisInfer) AssignableTo

func (dm *AxisInfer) AssignableTo(fetcher Fetcher, dst AxisLengths) (bool, error)

AssignableTo returns true if a dimension can be assigned to another.

func (*AxisInfer) AxisValue

func (dm *AxisInfer) AxisValue() AssignableExpr

AxisValue returns the value assigned to the axis.

func (*AxisInfer) Equal

func (dm *AxisInfer) Equal(fetcher Fetcher, other AxisLengths) (bool, error)

Equal returns true if other has the axis length.

func (*AxisInfer) Expr

func (dm *AxisInfer) Expr() ast.Expr

Expr returns how to compute the dimension as an expression.

func (*AxisInfer) Source

func (dm *AxisInfer) Source() ast.Node

Source returns the source expression specifying the dimension.

func (*AxisInfer) String

func (dm *AxisInfer) String() string

String representation of the dimension.

func (*AxisInfer) Type

func (dm *AxisInfer) Type() Type

Type of the expression.

func (*AxisInfer) Value

func (dm *AxisInfer) Value(Expr) AssignableExpr

Value of the axis.

type AxisLengths

type AxisLengths interface {
	Expr

	// AxisValue returns the value associated with the axis.
	// Can return nil if the axis has not been resolved.
	AxisValue() AssignableExpr

	// Equal returns true if two axis lengths have been resolved and are equal.
	// Returns an error if one of the axis has not been resolved.
	Equal(Fetcher, AxisLengths) (bool, error)

	// AssignableTo returns true if this axis length can be assigned to another.
	AssignableTo(Fetcher, AxisLengths) (bool, error)

	// String representation of the axis length.
	String() string
	// contains filtered or unexported methods
}

AxisLengths specification of an array.

type BaseType

type BaseType[T ast.Expr] struct {
	Src T
}

BaseType is the base of all types.

func (BaseType[T]) NameDef

func (BaseType[T]) NameDef() *ast.Ident

NameDef of the base type always returns a nil name definition.

func (*BaseType[T]) Same added in v0.3.0

func (m *BaseType[T]) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*BaseType[T]) Source

func (m *BaseType[T]) Source() ast.Node

Source returns the source node defining the type.

func (BaseType[T]) Type

func (BaseType[T]) Type() Type

Type of a type: always return metatype.

func (BaseType[T]) Value

func (BaseType[T]) Value(Expr) AssignableExpr

Value returns nil.

type BinaryExpr

type BinaryExpr struct {
	Src  *ast.BinaryExpr
	X, Y AssignableExpr
	Typ  Type
}

BinaryExpr is an operator with two arguments.

func (*BinaryExpr) Expr

func (s *BinaryExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*BinaryExpr) Source

func (s *BinaryExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*BinaryExpr) String

func (s *BinaryExpr) String() string

String representation.

func (*BinaryExpr) Type

func (s *BinaryExpr) Type() Type

Type returned by the expression.

type BlockStmt

type BlockStmt struct {
	Src  *ast.BlockStmt
	List []Stmt
}

BlockStmt is a braced statement list.

func (*BlockStmt) Source

func (s *BlockStmt) Source() ast.Node

Source returns the node in the AST tree.

func (*BlockStmt) String

func (b *BlockStmt) String() string

type BuiltinType

type BuiltinType struct {
	BaseType[ast.Expr]

	Impl any
}

BuiltinType is an opaque type maintained by the backend. These are the only atomic types that can have a state.

func (*BuiltinType) AssignableTo

func (s *BuiltinType) AssignableTo(fetcher Fetcher, target Type) (bool, error)

AssignableTo reports if the type can be assigned to other.

func (*BuiltinType) ConvertibleTo

func (s *BuiltinType) ConvertibleTo(fetcher Fetcher, target Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting).

func (*BuiltinType) Equal

func (s *BuiltinType) Equal(_ Fetcher, other Type) (bool, error)

Equal returns true if other is the same type.

func (*BuiltinType) Kind

func (s *BuiltinType) Kind() Kind

Kind returns the scalar kind.

func (*BuiltinType) String

func (s *BuiltinType) String() string

String representation of the type.

func (*BuiltinType) Value

func (s *BuiltinType) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

type CallExpr

type CallExpr struct {
	Src    *ast.CallExpr
	Args   []AssignableExpr
	Callee *FuncValExpr
}

CallExpr is an expression calling a function.

func (*CallExpr) Expr

func (s *CallExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*CallExpr) ExprFromResult

func (s *CallExpr) ExprFromResult(i int) *CallResultExpr

ExprFromResult returns an expression pointing to the ith result of a function call.

func (*CallExpr) Source

func (s *CallExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*CallExpr) String

func (s *CallExpr) String() string

String representation.

func (*CallExpr) Type

func (s *CallExpr) Type() Type

Type returns the type returned by the function call. Use CallExpr.Func.Type to get the type of the function being called.

type CallResultExpr

type CallResultExpr struct {
	Index int
	Call  *CallExpr
}

CallResultExpr represents the ith result of a function call as an expression.

func (*CallResultExpr) Expr

func (s *CallResultExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*CallResultExpr) Source

func (s *CallResultExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*CallResultExpr) String

func (s *CallResultExpr) String() string

String representation.

func (*CallResultExpr) Type

func (s *CallResultExpr) Type() Type

Type returns the type returned by the function call. Use CallExpr.Func.Type to get the type of the function being called.

type Canonical

type Canonical interface {
	Expr() (AssignableExpr, error)
}

Canonical is a canonical value with a IR representation.

type CastExpr

type CastExpr struct {
	Src ast.Expr
	Typ Type

	X Expr
}

CastExpr casts a type to another.

func (*CastExpr) Expr

func (s *CastExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*CastExpr) Orig

func (s *CastExpr) Orig() Expr

Orig returns the expression being casted.

func (*CastExpr) Source

func (s *CastExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*CastExpr) String

func (e *CastExpr) String() string

func (*CastExpr) Type

func (s *CastExpr) Type() Type

Type returns the target type of the cast.

type ConstExpr

type ConstExpr struct {
	Decl *ConstSpec

	VName *ast.Ident
	Val   AssignableExpr
}

ConstExpr is a name,expr constant pair.

func (*ConstExpr) Deps

func (expr *ConstExpr) Deps() ([]*ValueRef, error)

Deps returns the dependencies of a constant expression.

func (*ConstExpr) NameDef

func (cst *ConstExpr) NameDef() *ast.Ident

NameDef returns the name defining the storage.

func (*ConstExpr) Same added in v0.3.0

func (cst *ConstExpr) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*ConstExpr) Source

func (cst *ConstExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*ConstExpr) String

func (e *ConstExpr) String() string

Type returns the type of an expression.

func (*ConstExpr) Type

func (cst *ConstExpr) Type() Type

Type returns the type of an expression.

func (*ConstExpr) Value

func (cst *ConstExpr) Value(Expr) AssignableExpr

Value assigned to the constant.

type ConstSpec added in v0.3.0

type ConstSpec struct {
	FFile *File
	Src   *ast.ValueSpec
	Type  *TypeValExpr
	Exprs []*ConstExpr
}

ConstSpec declares a package constant.

type Declarations

type Declarations struct {
	Package *Package

	Consts []*ConstSpec
	Funcs  []PkgFunc
	Types  []*NamedType
	Vars   []*VarSpec
}

Declarations in a package.

func (*Declarations) ConstExprs

func (decls *Declarations) ConstExprs() ([]*ConstExpr, error)

ConstExprs returns all constant expressions with respect to their dependency. That is expressions are ordered such that an expression is always after its dependencies. If a cycle exists, then the ordering between the expressions in that cycle is not defined.

func (*Declarations) TypeByName

func (decls *Declarations) TypeByName(name string) *NamedType

TypeByName returns a type defined in the package given its name. Returns nil if the type could not be found.

type EinsumExpr

type EinsumExpr struct {
	Src        ast.Expr
	X, Y       Expr
	BatchAxes  [2][]int
	ReduceAxes [2][]int
	Typ        Type
}

EinsumExpr represents an einsum expression.

func (*EinsumExpr) Expr

func (s *EinsumExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*EinsumExpr) Source

func (s *EinsumExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*EinsumExpr) String

func (s *EinsumExpr) String() string

String representation.

func (*EinsumExpr) Type

func (s *EinsumExpr) Type() Type

Type returns the type returned by the einsum.

type Element added in v0.3.0

type Element interface {
	Type() Type
}

Element is a value returned by the evaluator.

type Evaluator added in v0.3.0

type Evaluator interface {
	File() *File
	EvalExpr(Expr) (Element, error)
}

Evaluator evaluates IR expressions into canonical values.

type Expr

type Expr interface {
	SourceNode
	Type() Type
	String() string
}

Expr is an expression that returns a (typed) result.

func RankSize

func RankSize(r ArrayRank) Expr

RankSize is the total number of elements across all axes.

type ExprStmt

type ExprStmt struct {
	Src *ast.ExprStmt
	X   Expr
}

ExprStmt is a statement evaluating an expression with no return result.

func (*ExprStmt) Source

func (s *ExprStmt) Source() ast.Node

Source returns the node in the AST tree.

func (*ExprStmt) String

func (e *ExprStmt) String() string

type Fetcher

type Fetcher interface {
	Evaluator
	fmterr.ErrAppender
	BuildExpr(ast.Expr) (Expr, bool)
	IsDefined(string) bool
}

Fetcher represents a scope in the compiler.

type Field

type Field struct {
	Group *FieldGroup

	Name *ast.Ident
}

Field is a field belonging to a field group.

func (*Field) Expr

func (s *Field) Expr() ast.Expr

Expr returns

func (*Field) Source

func (s *Field) Source() ast.Node

Source returns the source defining the field.

func (*Field) Storage

func (s *Field) Storage() *FieldStorage

Storage returns a storage pointing to the field.

func (*Field) String

func (s *Field) String() string

String returns a string representation of the field.

func (*Field) Type

func (s *Field) Type() Type

Type returns the type of the field.

type FieldGroup

type FieldGroup struct {
	Src    *ast.Field
	Fields []*Field
	Type   *TypeValExpr
}

FieldGroup is a list of field matched to a type.

func (*FieldGroup) NumFields

func (s *FieldGroup) NumFields() int

NumFields returns the number of field in the group.

func (*FieldGroup) Source

func (s *FieldGroup) Source() ast.Node

Source returns the node in the AST tree.

func (*FieldGroup) String

func (g *FieldGroup) String() string

type FieldList

type FieldList struct {
	Src  *ast.FieldList
	List []*FieldGroup
}

FieldList is a list of fields, enclosed by parentheses, curly braces, or square brackets.

func (*FieldList) Fields

func (s *FieldList) Fields() []*Field

Fields returns a list of all the fields in the structure in a consistent order which can be used as a reference.

func (*FieldList) FindField

func (s *FieldList) FindField(name string) *Field

FindField returns the field matching the given name or nil if not found.

func (*FieldList) Len

func (s *FieldList) Len() int

Len returns the total number of fields in the list.

func (*FieldList) Source

func (s *FieldList) Source() ast.Node

Source returns the source defining the field.

func (*FieldList) String

func (l *FieldList) String() string

func (*FieldList) TupleType

func (s *FieldList) TupleType() *TupleType

TupleType returns the fields as a tuple, regardless of their number.

func (*FieldList) Type

func (s *FieldList) Type() Type

Type returns the fields as a type.

type FieldLit

type FieldLit struct {
	*FieldStorage
	X AssignableExpr
}

FieldLit assigns a value to a field in a structure literal.

func (*FieldLit) Same added in v0.3.0

func (lit *FieldLit) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*FieldLit) Value

func (lit *FieldLit) Value(Expr) AssignableExpr

Value returns the value stored in the field.

type FieldStorage

type FieldStorage struct {
	Field *Field
}

FieldStorage is a field to which values can be assigned to.

func (*FieldStorage) NameDef

func (s *FieldStorage) NameDef() *ast.Ident

NameDef returns the identifier identifying the storage.

func (*FieldStorage) Same added in v0.3.0

func (s *FieldStorage) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*FieldStorage) Source

func (s *FieldStorage) Source() ast.Node

Source returns the node in the AST tree.

func (*FieldStorage) Type

func (s *FieldStorage) Type() Type

Type of the destination of the assignment.

type File

type File struct {
	Package *Package
	Src     *ast.File

	Imports []*ImportDecl
}

File represents a GX source file.

func (*File) FileSet

func (f *File) FileSet() *token.FileSet

FileSet returns the package fileset.

func (*File) FindImport

func (f *File) FindImport(path string) *ImportDecl

FindImport returns an import declaration given a package full path. Returns nil if the path cannot be found.

func (*File) Name

func (f *File) Name() string

Name of the file.

type Func

type Func interface {
	Expr

	// Name of the function (without the package name).
	Name() string

	// Doc returns associated documentation or nil.
	Doc() *ast.CommentGroup

	// File owning the function.
	File() *File

	// Type of the function.
	// If the function is generic, then the type will have been inferred by the compiler from the
	// types passed as args. Note that both FuncType() and Type() must return the same underlying
	// value, though FuncType returns the concrete type.
	FuncType() *FuncType
}

Func is a callable GX function.

type FuncBuiltin

type FuncBuiltin struct {
	FFile *File
	Src   *ast.FuncDecl
	FType *FuncType
	Impl  FuncImpl
	Anns  Annotations
}

FuncBuiltin is a function provided by a backend. The implementation is opaque to GX.

func (*FuncBuiltin) Annotations added in v0.6.0

func (s *FuncBuiltin) Annotations() *Annotations

Annotations returns the annotations attached to the function.

func (*FuncBuiltin) Doc

func (s *FuncBuiltin) Doc() *ast.CommentGroup

Doc returns associated documentation or nil.

func (*FuncBuiltin) File

func (s *FuncBuiltin) File() *File

File declaring the function.

func (*FuncBuiltin) FuncType

func (s *FuncBuiltin) FuncType() *FuncType

FuncType returns the concrete type of the function.

func (*FuncBuiltin) Name

func (s *FuncBuiltin) Name() string

Name of the function. Returns an empty string if the function is anonymous.

func (*FuncBuiltin) NameDef

func (s *FuncBuiltin) NameDef() *ast.Ident

NameDef is the name definition of the function.

func (*FuncBuiltin) New added in v0.6.0

func (s *FuncBuiltin) New(src *ast.FuncDecl, file *File, fType *FuncType) PkgFunc

New returns a new function given a source, a file, and a type.

func (*FuncBuiltin) Same added in v0.3.0

func (s *FuncBuiltin) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*FuncBuiltin) Source

func (s *FuncBuiltin) Source() ast.Node

Source returns the node in the AST tree.

func (*FuncBuiltin) String

func (f *FuncBuiltin) String() string

String returns a string representation of the builtin function.

func (*FuncBuiltin) Type

func (s *FuncBuiltin) Type() Type

Type returns the type of the function.

func (*FuncBuiltin) Value

func (s *FuncBuiltin) Value(x Expr) AssignableExpr

Value returns a reference to the function.

type FuncDecl

type FuncDecl struct {
	FFile *File
	Src   *ast.FuncDecl
	FType *FuncType
	Body  *BlockStmt
	Anns  Annotations
}

FuncDecl is a GX function declared at the package level.

func (*FuncDecl) Annotations added in v0.6.0

func (s *FuncDecl) Annotations() *Annotations

Annotations returns the annotations attached to the function.

func (*FuncDecl) Doc

func (s *FuncDecl) Doc() *ast.CommentGroup

Doc returns associated documentation or nil.

func (*FuncDecl) File

func (s *FuncDecl) File() *File

File declaring the function.

func (*FuncDecl) FullyQualifiedName

func (s *FuncDecl) FullyQualifiedName() string

FullyQualifiedName returns a fully qualified function name, that is the full package path and the name of the function.

func (*FuncDecl) FuncType

func (s *FuncDecl) FuncType() *FuncType

FuncType returns the concrete type of the function.

func (*FuncDecl) Name

func (s *FuncDecl) Name() string

Name of the function. Returns an empty string if the function is anonymous.

func (*FuncDecl) NameDef

func (s *FuncDecl) NameDef() *ast.Ident

NameDef is the name definition of the function.

func (*FuncDecl) New added in v0.6.0

func (s *FuncDecl) New(src *ast.FuncDecl, file *File, fType *FuncType) PkgFunc

New returns a new function given a source, a file, and a type.

func (*FuncDecl) Same added in v0.3.0

func (s *FuncDecl) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*FuncDecl) Source

func (s *FuncDecl) Source() ast.Node

Source returns the node in the AST tree.

func (*FuncDecl) String

func (f *FuncDecl) String() string

String returns a string representation of the function.

func (*FuncDecl) Type

func (s *FuncDecl) Type() Type

Type returns the type of the function.

func (*FuncDecl) Value

func (s *FuncDecl) Value(x Expr) AssignableExpr

Value returns a reference to the function.

type FuncImpl

type FuncImpl interface {
	// BuildFuncType builds the type of a function given how it is called.
	BuildFuncType(fetcher Fetcher, call *CallExpr) (*FuncType, error)

	// Implementation of the function, provided by the backend.
	Implementation() any
}

FuncImpl is a builtin opaque function implementation provided by a backend or a host language.

For example, the function num.Concat is not implemented in GX and directly provided by the backend.

type FuncLit

type FuncLit struct {
	Src   *ast.FuncLit
	FType *FuncType
	FFile *File
	Body  *BlockStmt
}

FuncLit is a function literal.

func (*FuncLit) Doc

func (s *FuncLit) Doc() *ast.CommentGroup

Doc returns associated documentation or nil.

func (*FuncLit) Expr

func (s *FuncLit) Expr() ast.Expr

Expr returns the expression in the source code.

func (*FuncLit) File

func (s *FuncLit) File() *File

File declaring the function literal.

func (*FuncLit) FuncType

func (s *FuncLit) FuncType() *FuncType

FuncType returns the concrete type of the function.

func (*FuncLit) Name

func (s *FuncLit) Name() string

Name of the function. Returns an empty string since literals are always anonymous.

func (*FuncLit) NameDef

func (s *FuncLit) NameDef() *ast.Ident

NameDef returns nil because function literals are anonymous.

func (*FuncLit) Same added in v0.3.0

func (s *FuncLit) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*FuncLit) Source

func (s *FuncLit) Source() ast.Node

Source returns the node in the AST tree.

func (*FuncLit) Store

func (s *FuncLit) Store() Storage

Store returns the function literal as a store.

func (*FuncLit) String

func (s *FuncLit) String() string

String representation of the literal.

func (*FuncLit) Type

func (s *FuncLit) Type() Type

Type returns the type of the function.

func (*FuncLit) Value

func (s *FuncLit) Value(x Expr) AssignableExpr

Value returns the function literal as an assignable expression.

type FuncType

type FuncType struct {
	BaseType[*ast.FuncType]

	Receiver   *FieldList
	TypeParams *FieldList
	Params     *FieldList
	Results    *FieldList

	TypeParamsValues []TypeParamValue

	// CompEval is set to true if the function can be called at compilation time.
	CompEval bool
}

FuncType defines a function signature.

func MetaFuncType

func MetaFuncType() *FuncType

MetaFuncType returns the type of a meta function.

func (*FuncType) AssignableTo

func (s *FuncType) AssignableTo(fetcher Fetcher, other Type) (bool, error)

AssignableTo reports if the type can be assigned to other.

func (*FuncType) ConvertibleTo

func (s *FuncType) ConvertibleTo(fetcher Fetcher, target Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting).

func (*FuncType) Equal

func (s *FuncType) Equal(fetcher Fetcher, other Type) (bool, error)

Equal returns true if other is the same type.

func (*FuncType) Kind

func (s *FuncType) Kind() Kind

Kind returns the function kind.

func (*FuncType) NameString added in v0.4.0

func (s *FuncType) NameString(name string) string

NameString returns a string representation of a signature given a name. The name can be empty.

func (*FuncType) ReceiverField

func (s *FuncType) ReceiverField() *Field

ReceiverField returns a field representing the receiver of the function, or nil if the function has no receiver.

func (*FuncType) Source

func (s *FuncType) Source() ast.Node

Source returns the node in the AST tree.

func (*FuncType) String

func (s *FuncType) String() string

String representation of the type.

func (*FuncType) Value

func (s *FuncType) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

type FuncValExpr

type FuncValExpr struct {
	X Expr
	F Storage
	// T is the function type if the function has been specialised by the call
	// (in the context of generic functions).
	T *FuncType
}

FuncValExpr is an expression pointing to a function.

func (*FuncValExpr) Name

func (s *FuncValExpr) Name() string

Name returns the name of a function

func (*FuncValExpr) Source

func (s *FuncValExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*FuncValExpr) Store

func (s *FuncValExpr) Store() Storage

Store storing the type.

func (*FuncValExpr) String

func (s *FuncValExpr) String() string

String representation.

func (*FuncValExpr) Type

func (s *FuncValExpr) Type() Type

Type of the function being called.

type IfStmt

type IfStmt struct {
	Src  *ast.IfStmt
	Init Stmt
	Cond AssignableExpr
	Body *BlockStmt
	Else Stmt
}

IfStmt is a if Statements.

func (*IfStmt) Source

func (s *IfStmt) Source() ast.Node

Source returns the node in the AST tree.

func (*IfStmt) String

func (*IfStmt) String() string

type ImportDecl

type ImportDecl struct {
	Src  *ast.ImportSpec
	Path string
}

ImportDecl imports a package.

func (*ImportDecl) Name

func (s *ImportDecl) Name() string

Name used to reference the package.

func (*ImportDecl) NameDef

func (s *ImportDecl) NameDef() *ast.Ident

NameDef is the name definition of the function.

func (*ImportDecl) Same added in v0.3.0

func (s *ImportDecl) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*ImportDecl) Source

func (s *ImportDecl) Source() ast.Node

Source returns the node in the AST tree.

func (*ImportDecl) String

func (s *ImportDecl) String() string

func (*ImportDecl) Type

func (*ImportDecl) Type() Type

Type returns the IR package type.

func (*ImportDecl) Value

func (s *ImportDecl) Value(x Expr) AssignableExpr

Value returns a reference to the function.

type Importer added in v0.3.0

type Importer interface {
	// Import a package given its path.
	Import(pkgPath string) (*Package, error)
}

Importer imports packages given their path.

type IndexExpr

type IndexExpr struct {
	Src   *ast.IndexExpr
	X     Expr
	Index Expr
	Typ   Type
}

IndexExpr selects an index on a indexable type.

func (*IndexExpr) Expr

func (s *IndexExpr) Expr() ast.Expr

Expr returns the AST expression.

func (*IndexExpr) Source

func (s *IndexExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*IndexExpr) String

func (s *IndexExpr) String() string

String representation.

func (*IndexExpr) Type

func (s *IndexExpr) Type() Type

Type returns the type of the indexed element.

type IndexListExpr

type IndexListExpr struct {
	Src     *ast.IndexListExpr
	X       Expr
	Indices Expr
	Typ     Type
}

IndexListExpr selects an index on a indexable type.

func (*IndexListExpr) Expr

func (s *IndexListExpr) Expr() ast.Expr

Expr returns the AST expression.

func (*IndexListExpr) Source

func (s *IndexListExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*IndexListExpr) String

func (s *IndexListExpr) String() string

String representation.

func (*IndexListExpr) Type

func (s *IndexListExpr) Type() Type

Type returns the type of the indexed element.

type Int

type Int = int64

Int is the default integer for indices, for loops, etc. It needs to match DefaultIntKind above

type InterfaceType

type InterfaceType struct {
	BaseType[ast.Expr]
}

InterfaceType defines the type of an interface.

func (*InterfaceType) AssignableTo

func (s *InterfaceType) AssignableTo(Fetcher, Type) (bool, error)

AssignableTo reports whether a value of the type can be assigned to another. Always returns false.

func (*InterfaceType) ConvertibleTo

func (s *InterfaceType) ConvertibleTo(Fetcher, Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting). Always returns false.

func (*InterfaceType) Equal

func (s *InterfaceType) Equal(Fetcher, Type) (bool, error)

Equal returns true if other is the same type.

func (*InterfaceType) Kind

func (s *InterfaceType) Kind() Kind

Kind returns the interface kind.

func (*InterfaceType) String

func (s *InterfaceType) String() string

String representation of the type.

func (*InterfaceType) Value

func (s *InterfaceType) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

type Kind

type Kind uint

Kind of a type.

func KindFromString

func KindFromString(ident string) Kind

KindFromString returns a kind given an identifier. It only works for the basic types that don't take other parameters -- so it doesn't work for tensors, tuples or functions.

The "unknown" string returns an invalid kind because it is invalid to write:

var name unknown

func KindGeneric

func KindGeneric[T dtype.GoDataType]() Kind

KindGeneric returns the kind of a variable from its generic type. If the type is not supported, an invalid type is returned.

func (Kind) DType

func (k Kind) DType() dtype.DataType

DType converts a GX kind into an array data type.

func (Kind) String

func (k Kind) String() string

String returns a string representation of a kind.

type LocalVarStorage

type LocalVarStorage struct {
	Src *ast.Ident
	Typ Type
}

LocalVarStorage is a local variable to which values can be assigned to.

func (*LocalVarStorage) Expr

func (s *LocalVarStorage) Expr() ast.Expr

Expr returns the expression in the AST tree.

func (*LocalVarStorage) NameDef

func (s *LocalVarStorage) NameDef() *ast.Ident

NameDef returns the identifier identifying the storage.

func (*LocalVarStorage) Same added in v0.3.0

func (s *LocalVarStorage) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*LocalVarStorage) Source

func (s *LocalVarStorage) Source() ast.Node

Source returns the node in the AST tree.

func (*LocalVarStorage) Type

func (s *LocalVarStorage) Type() Type

Type of the destination of the assignment.

type Macro

type Macro struct {
	FFile *File
	Src   *ast.FuncDecl
	FType *FuncType

	BuildSynthetic any
}

Macro is a function that takes a set of IR nodes as an input and returns a new set of IR nodes (or a compiler error). An example of such function is math/graph.Grad. The implementation is opaque to GX.

func (*Macro) Annotations added in v0.6.0

func (s *Macro) Annotations() *Annotations

Annotations returns the annotations attached to the function.

func (*Macro) Doc

func (s *Macro) Doc() *ast.CommentGroup

Doc returns associated documentation or nil.

func (*Macro) File

func (s *Macro) File() *File

File declaring the function literal.

func (*Macro) FuncType

func (s *Macro) FuncType() *FuncType

FuncType returns the concrete type of the function.

func (*Macro) Name

func (s *Macro) Name() string

Name of the function.

func (*Macro) NameDef

func (s *Macro) NameDef() *ast.Ident

NameDef is the name definition of the function.

func (*Macro) New added in v0.6.0

func (s *Macro) New(src *ast.FuncDecl, file *File, fType *FuncType) PkgFunc

New returns a new function given a source, a file, and a type.

func (*Macro) Same added in v0.3.0

func (s *Macro) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*Macro) Source

func (s *Macro) Source() ast.Node

Source returns the node in the AST tree.

func (*Macro) String

func (s *Macro) String() string

String representation of the literal.

func (*Macro) Type

func (s *Macro) Type() Type

Type returns the type of the function.

func (*Macro) Value

func (s *Macro) Value(x Expr) AssignableExpr

Value returns a reference to the function.

type NamedType

type NamedType struct {
	BaseType[ast.Expr]

	Src        *ast.TypeSpec
	File       *File
	Underlying *TypeValExpr

	Methods []PkgFunc
}

NamedType defines a new type from an existing type.

func (*NamedType) AssignableTo

func (s *NamedType) AssignableTo(fetcher Fetcher, target Type) (bool, error)

AssignableTo reports if the type can be assigned to other.

func (*NamedType) ConvertibleTo

func (s *NamedType) ConvertibleTo(fetcher Fetcher, target Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting).

func (*NamedType) Equal

func (s *NamedType) Equal(fetcher Fetcher, other Type) (bool, error)

Equal returns true if other is the same type.

func (*NamedType) FullName

func (s *NamedType) FullName() string

FullName returns the full name of the type, that is the full package path and the type name.

func (*NamedType) Kind

func (s *NamedType) Kind() Kind

Kind of the underlying type.

func (*NamedType) MethodByName

func (s *NamedType) MethodByName(name string) PkgFunc

MethodByName returns a method given its name, or nil if not method has that name.

func (*NamedType) Name

func (s *NamedType) Name() string

Name of the type.

func (*NamedType) NameDef

func (s *NamedType) NameDef() *ast.Ident

NameDef returns the name defining the storage.

func (*NamedType) Package

func (s *NamedType) Package() *Package

Package returns the package to which the type belongs to.

func (*NamedType) Same added in v0.3.0

func (s *NamedType) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*NamedType) Source

func (s *NamedType) Source() ast.Node

Source returns the node in the AST tree.

func (*NamedType) String

func (s *NamedType) String() string

String representation of the type.

func (*NamedType) Type

func (s *NamedType) Type() Type

Type returns the type of an expression.

func (*NamedType) Value

func (s *NamedType) Value(x Expr) AssignableExpr

Value assigned to the constant.

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node in the tree.

type Number

type Number interface {
	Expr
	// contains filtered or unexported methods
}

Number is a constant defined in the source code to which no concrete type has been assigned.

type NumberCastExpr

type NumberCastExpr struct {
	X   Expr
	Typ Type
}

NumberCastExpr casts a number to a given type.

func (*NumberCastExpr) Source

func (s *NumberCastExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*NumberCastExpr) String

func (s *NumberCastExpr) String() string

String representation of the number.

func (*NumberCastExpr) Type

func (s *NumberCastExpr) Type() Type

Type returns the type returned by the function call.

type NumberFloat

type NumberFloat struct {
	Src *ast.BasicLit
	Val *big.Float
}

NumberFloat is a float number for which the type has not been inferred yet.

func (NumberFloat) DefaultType

func (s NumberFloat) DefaultType() Type

DefaultType returns the default type of the number.

func (*NumberFloat) Expr

func (s *NumberFloat) Expr() ast.Expr

Expr returns the AST expression.

func (*NumberFloat) Source

func (s *NumberFloat) Source() ast.Node

Source returns the node in the AST tree.

func (*NumberFloat) String

func (e *NumberFloat) String() string

func (*NumberFloat) Type

func (s *NumberFloat) Type() Type

Type returns the type returned by the function call.

func (*NumberFloat) Zero

func (s *NumberFloat) Zero() AssignableExpr

Zero returns a zero float number.

type NumberInt

type NumberInt struct {
	Src *ast.BasicLit
	Val *big.Int
}

NumberInt is an integer number for which the type has not been inferred yet.

func (NumberInt) DefaultType

func (s NumberInt) DefaultType() Type

DefaultType returns the default type of the number.

func (*NumberInt) Expr

func (s *NumberInt) Expr() ast.Expr

Expr returns the AST expression.

func (*NumberInt) Source

func (s *NumberInt) Source() ast.Node

Source returns the node in the AST tree.

func (*NumberInt) String

func (e *NumberInt) String() string

func (*NumberInt) Type

func (s *NumberInt) Type() Type

Type returns the type returned by the function call.

func (*NumberInt) Zero

func (s *NumberInt) Zero() AssignableExpr

Zero returns a zero float number.

type Package

type Package struct {
	FSet  *token.FileSet
	Files map[string]*File

	Name *ast.Ident
	Path string

	Decls *Declarations
}

Package is a GX package.

func (*Package) ExportedConsts

func (pkg *Package) ExportedConsts() []*ConstExpr

ExportedConsts returns the list of exported constants.

func (*Package) ExportedFuncs

func (pkg *Package) ExportedFuncs() iter.Seq[PkgFunc]

ExportedFuncs returns the list of exported functions of a package.

func (*Package) ExportedTypes

func (pkg *Package) ExportedTypes() []*NamedType

ExportedTypes returns the list of exported types of a package.

func (*Package) File

func (pkg *Package) File(name string) *File

File returns the AST tree given a file name. Return nil if the name does not match any file. If the name is empty, returns the first file (in alphabetical order).

func (*Package) FindFunc

func (pkg *Package) FindFunc(name string) PkgFunc

FindFunc returns a function given its name or nil if not found.

func (*Package) FullName

func (pkg *Package) FullName() string

FullName returns the full name of the package, including its path.

func (*Package) String

func (pkg *Package) String() string

String representation of the package.

type PackageRef

type PackageRef struct {
	X    *ValueRef
	Decl *ImportDecl
}

PackageRef is a reference to a package.

func (*PackageRef) Source

func (s *PackageRef) Source() ast.Node

Source returns the node in the AST tree.

func (*PackageRef) String

func (s *PackageRef) String() string

String representation.

func (*PackageRef) Type

func (s *PackageRef) Type() Type

Type returns the package type.

type ParenExpr

type ParenExpr struct {
	Src *ast.ParenExpr
	X   Expr
}

ParenExpr is a parenthesized expression.

func (*ParenExpr) Expr

func (s *ParenExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*ParenExpr) Source

func (s *ParenExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*ParenExpr) Store

func (s *ParenExpr) Store() Storage

Store returns the storage referenced by this expression.

func (*ParenExpr) String

func (s *ParenExpr) String() string

String representation.

func (*ParenExpr) Type

func (s *ParenExpr) Type() Type

Type returns the type returned by the expression.

type PkgFunc

type PkgFunc interface {
	New(*ast.FuncDecl, *File, *FuncType) PkgFunc
	StorageWithValue
	Func
	Annotations() *Annotations
	// contains filtered or unexported methods
}

PkgFunc is a function declared at the package level.

type RangeStmt

type RangeStmt struct {
	Src        *ast.RangeStmt
	Key, Value Storage
	X          AssignableExpr
	Body       *BlockStmt
}

RangeStmt is a range statement in for loops.

func (*RangeStmt) Source

func (s *RangeStmt) Source() ast.Node

Source returns the node in the AST tree.

func (*RangeStmt) String

func (*RangeStmt) String() string

type Rank

type Rank struct {
	Src *ast.ArrayType
	Ax  []AxisLengths
}

Rank with a known number of axes. The length of some axes may still be unknown.

func NewRank

func NewRank(axlens []int) *Rank

NewRank returns a new rank from a slice of axis lengths.

func (*Rank) AssignableTo

func (r *Rank) AssignableTo(fetcher Fetcher, dst ArrayRank) (bool, error)

AssignableTo returns true if this rank can be assigned to the destination rank.

func (*Rank) Axes

func (r *Rank) Axes() []AxisLengths

Axes returns all axis in the rank.

func (*Rank) AxisLengths

func (r *Rank) AxisLengths() []AxisLengths

AxisLengths of the rank.

func (*Rank) ConvertibleTo

func (r *Rank) ConvertibleTo(fetcher Fetcher, dst ArrayRank) (bool, error)

ConvertibleTo returns true if this rank can be converted to the destination rank.

func (*Rank) Equal

func (r *Rank) Equal(fetcher Fetcher, other ArrayRank) (bool, error)

Equal returns true if other has the same number of axes and each axis has the same length.

func (*Rank) IsAtomic

func (r *Rank) IsAtomic() bool

IsAtomic returns true if the rank is equals to zero (that is it has no axes).

func (*Rank) Source

func (r *Rank) Source() ast.Node

Source returns the source node defining the rank.

func (*Rank) String

func (r *Rank) String() string

String returns a string representation of the rank.

func (*Rank) SubRank

func (r *Rank) SubRank() (ArrayRank, bool)

SubRank returns the rank with the top-axis removed or nil if the rank is already 0.

func (*Rank) Type

func (r *Rank) Type() Type

Type returns the rank type.

type RankInfer

type RankInfer struct {
	Src *ast.ArrayType
	Rnk ArrayRank
}

RankInfer is a rank determined at compile time (specified using ___ or ...).

func (*RankInfer) AssignableTo

func (r *RankInfer) AssignableTo(fetcher Fetcher, dst ArrayRank) (bool, error)

AssignableTo returns true if this rank can be assigned to the destination rank.

func (*RankInfer) Axes

func (r *RankInfer) Axes() []AxisLengths

Axes returns all axis in the rank.

func (*RankInfer) ConvertibleTo

func (r *RankInfer) ConvertibleTo(fetcher Fetcher, dst ArrayRank) (bool, error)

ConvertibleTo returns true if this rank can be converted to the destination rank.

func (*RankInfer) Equal

func (r *RankInfer) Equal(fetcher Fetcher, other ArrayRank) (bool, error)

Equal returns true if other has the same rank and dimensions.

func (*RankInfer) IsAtomic

func (r *RankInfer) IsAtomic() bool

IsAtomic returns true if the rank has no axes.

func (*RankInfer) Source

func (r *RankInfer) Source() ast.Node

Source returns the node defining the rank.

func (*RankInfer) String

func (r *RankInfer) String() string

String returns a string representation of the rank.

func (*RankInfer) SubRank

func (r *RankInfer) SubRank() (ArrayRank, bool)

SubRank returns the rank with the top-axis removed.

func (*RankInfer) Type

func (r *RankInfer) Type() Type

Type returns the rank type.

type ReturnStmt

type ReturnStmt struct {
	Src     *ast.ReturnStmt
	Results []Expr
}

ReturnStmt is a return statement in a function.

func (*ReturnStmt) Source

func (s *ReturnStmt) Source() ast.Node

Source returns the node in the AST tree.

func (*ReturnStmt) String

func (s *ReturnStmt) String() string

func (*ReturnStmt) Type

func (s *ReturnStmt) Type() Type

Type of the result being returned.

type RuntimeValue

type RuntimeValue interface {
	Type() Type
}

RuntimeValue is a value that only exists at runtime, that is when GX code is being interpreted.

type RuntimeValueExpr

type RuntimeValueExpr interface {
	Expr
	Value(Expr) RuntimeValue
}

RuntimeValueExpr is an expression representing a runtime value. Such expression will never be present in a compiled package. This type is used by the interpreter to represent a GX value as an expression.

type RuntimeValueExprT

type RuntimeValueExprT[T RuntimeValue] struct {
	Src ast.Expr
	Typ Type
	Val T
}

RuntimeValueExprT is a runtime expression specialised for a value type. The Src field can be nil if the value was not computed from an expression in the source code (e.g. a value given as a static value programmatically).

func (*RuntimeValueExprT[T]) Expr

func (s *RuntimeValueExprT[T]) Expr() ast.Expr

Expr returns the expression in the source code.

func (*RuntimeValueExprT[T]) Source

func (s *RuntimeValueExprT[T]) Source() ast.Node

Source returns the node in the AST tree.

func (*RuntimeValueExprT[T]) String

func (s *RuntimeValueExprT[T]) String() string

String representation of the type.

func (*RuntimeValueExprT[T]) Type

func (s *RuntimeValueExprT[T]) Type() Type

Type returns the type referenced by the expression.

func (*RuntimeValueExprT[T]) Value

func (s *RuntimeValueExprT[T]) Value(Expr) RuntimeValue

Value returns the runtime value stored in the expression.

type SelectorExpr

type SelectorExpr struct {
	Src  *ast.SelectorExpr
	X    Expr
	Stor Storage
}

SelectorExpr selects a field on a structure.

func (*SelectorExpr) Expr

func (s *SelectorExpr) Expr() ast.Expr

Expr returns the AST expression.

func (*SelectorExpr) Select

func (s *SelectorExpr) Select(typ Type) (method PkgFunc, field *Field)

Select finds a method on a named type or a field in a structure.

func (*SelectorExpr) Source

func (s *SelectorExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*SelectorExpr) Store

func (s *SelectorExpr) Store() Storage

Store returns the storage referenced by this expression.

func (*SelectorExpr) String

func (s *SelectorExpr) String() string

String representation.

func (*SelectorExpr) Type

func (s *SelectorExpr) Type() Type

Type returns the type returned after the selection.

type SliceLitExpr

type SliceLitExpr struct {
	Src  ast.Expr
	Typ  Type
	Elts []AssignableExpr
}

SliceLitExpr is a slice literal.

func (*SliceLitExpr) Expr

func (s *SliceLitExpr) Expr() ast.Expr

Expr returns the AST expression.

func (*SliceLitExpr) Source

func (s *SliceLitExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*SliceLitExpr) String

func (s *SliceLitExpr) String() string

String representation.

func (*SliceLitExpr) Type

func (s *SliceLitExpr) Type() Type

Type returns the type returned by the function call.

type SliceType

type SliceType struct {
	BaseType[*ast.ArrayType]

	DType *TypeValExpr
	Rank  int
}

SliceType defines the type for a slice.

func IntIndexSliceType

func IntIndexSliceType() *SliceType

IntIndexSliceType returns a slice of axis lengths type.

func IntLenSliceType

func IntLenSliceType() *SliceType

IntLenSliceType returns a slice of axis lengths type.

func (*SliceType) AssignableTo

func (s *SliceType) AssignableTo(fetcher Fetcher, target Type) (bool, error)

AssignableTo reports if the type can be assigned to other.

func (*SliceType) ConvertibleTo

func (s *SliceType) ConvertibleTo(fetcher Fetcher, target Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting).

func (*SliceType) ElementType

func (s *SliceType) ElementType() (Type, bool)

ElementType returns the type of an element in that slice.

func (*SliceType) Equal

func (s *SliceType) Equal(fetcher Fetcher, other Type) (bool, error)

Equal returns true if other is the same type.

func (*SliceType) Kind

func (s *SliceType) Kind() Kind

Kind returns the slide kind.

func (*SliceType) Source

func (s *SliceType) Source() ast.Node

Source returns the node in the AST tree.

func (*SliceType) String

func (s *SliceType) String() string

String representation of the type.

func (*SliceType) Value

func (s *SliceType) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

type SlicerType

type SlicerType interface {
	Type
	// ElementType returns the type of an element, that is the type
	// returned by a slice at the top level. For example:
	// float32[2][3][4] returns float32[3][4]
	// If the number of axis is 0, nil is returned.
	ElementType() (Type, bool)
}

SlicerType is a type supporting slice operations: (e.g. slicerType[i])

type SourceNode

type SourceNode interface {
	Node
	Source() ast.Node
}

SourceNode is a node with a position in GX source code.

type SpecialisedFunc

type SpecialisedFunc struct {
	X Expr
	F *FuncValExpr
	T *FuncType
}

SpecialisedFunc is a storage for a function that has been specialised

func (*SpecialisedFunc) NameDef

func (s *SpecialisedFunc) NameDef() *ast.Ident

NameDef returns the identifier identifying the storage.

func (*SpecialisedFunc) Same added in v0.3.0

func (s *SpecialisedFunc) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*SpecialisedFunc) Source

func (s *SpecialisedFunc) Source() ast.Node

Source returns the node in the AST tree.

func (*SpecialisedFunc) Type

func (s *SpecialisedFunc) Type() Type

Type of the destination of the assignment.

func (*SpecialisedFunc) Value

func (s *SpecialisedFunc) Value(x Expr) AssignableExpr

Value returns the function as a value.

type Stmt

type Stmt interface {
	SourceNode

	String() string
	// contains filtered or unexported methods
}

Stmt is a statement that performs an action. No value is being returned.

type Storage

type Storage interface {
	SourceNode

	NameDef() *ast.Ident
	Same(Storage) bool
	Type() Type
	// contains filtered or unexported methods
}

Storage is a node that can store a value. (e.g. a field in a function)

type StorageWithValue

type StorageWithValue interface {
	Storage
	// Value returns the value stored given the expression pointing to the storage.
	Value(Expr) AssignableExpr
	// contains filtered or unexported methods
}

StorageWithValue is a storage to which a value has been assigned to. (e.g. a variable that has been defined)

func BuiltinStorage

func BuiltinStorage(name string, val AssignableExpr) StorageWithValue

BuiltinStorage stores a value in a builtin storage.

func FalseStorage

func FalseStorage() StorageWithValue

FalseStorage returns the storage for the value of true.

func TrueStorage

func TrueStorage() StorageWithValue

TrueStorage returns the storage for the value of true.

type StringLiteral

type StringLiteral struct {
	Src *ast.BasicLit
}

StringLiteral is a string defined by a literal.

func (*StringLiteral) Expr

func (s *StringLiteral) Expr() ast.Expr

Expr returns the AST expression.

func (*StringLiteral) Source

func (s *StringLiteral) Source() ast.Node

Source returns the node in the AST tree.

func (*StringLiteral) String

func (s *StringLiteral) String() string

String representation of the number.

func (*StringLiteral) Type

func (s *StringLiteral) Type() Type

Type returns the type returned by the function call.

type StructFieldStorage

type StructFieldStorage struct {
	Sel *SelectorExpr
}

StructFieldStorage is a field in a structure.

func (*StructFieldStorage) Expr

func (s *StructFieldStorage) Expr() ast.Expr

Expr returns the expression in the AST tree.

func (*StructFieldStorage) NameDef

func (s *StructFieldStorage) NameDef() *ast.Ident

NameDef returns the identifier identifying the storage.

func (*StructFieldStorage) Same added in v0.3.0

func (s *StructFieldStorage) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*StructFieldStorage) Source

func (s *StructFieldStorage) Source() ast.Node

Source returns the node in the AST tree.

func (*StructFieldStorage) Type

func (s *StructFieldStorage) Type() Type

Type of the destination of the assignment.

type StructLitExpr

type StructLitExpr struct {
	Src  *ast.CompositeLit
	Elts []*FieldLit
	Typ  Type
}

StructLitExpr is a structure literal.

func (*StructLitExpr) Expr

func (s *StructLitExpr) Expr() ast.Expr

Expr returns the AST expression.

func (*StructLitExpr) Source

func (s *StructLitExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*StructLitExpr) String

func (s *StructLitExpr) String() string

String representation.

func (*StructLitExpr) Type

func (s *StructLitExpr) Type() Type

Type returns the type returned by the function call.

type StructType

type StructType struct {
	BaseType[*ast.StructType]

	Fields *FieldList
}

StructType defines the type of a structure.

func (*StructType) AssignableTo

func (s *StructType) AssignableTo(fetcher Fetcher, target Type) (bool, error)

AssignableTo reports if the type can be assigned to other.

func (*StructType) ConvertibleTo

func (s *StructType) ConvertibleTo(fetcher Fetcher, target Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting).

func (*StructType) Equal

func (s *StructType) Equal(_ Fetcher, other Type) (bool, error)

Equal returns true if other is the same type.

func (*StructType) Kind

func (s *StructType) Kind() Kind

Kind returns the structure kind.

func (*StructType) NumFields

func (s *StructType) NumFields() int

NumFields returns the number of fields in a structure.

func (*StructType) Source

func (s *StructType) Source() ast.Node

Source returns the node in the AST tree.

func (*StructType) String

func (s *StructType) String() string

String representation of the type.

func (*StructType) Value

func (s *StructType) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

type Tuple

type Tuple struct {
	Exprs []Expr
}

Tuple is a group of expression.

func (*Tuple) Source

func (s *Tuple) Source() ast.Node

Source returns the node in the AST tree.

func (*Tuple) String

func (e *Tuple) String() string

String representation of the tuple.

func (*Tuple) Type

func (s *Tuple) Type() Type

Type returns the tuple type.

type TupleType

type TupleType struct {
	BaseType[ast.Expr]

	Types []Type
}

TupleType is the type of the result of a function that returns more than one value.

func (*TupleType) AssignableTo

func (s *TupleType) AssignableTo(fetcher Fetcher, target Type) (bool, error)

AssignableTo reports whether a value of the type can be assigned to another.

func (*TupleType) ConvertibleTo

func (s *TupleType) ConvertibleTo(fetcher Fetcher, target Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting). Always returns false.

func (*TupleType) Equal

func (s *TupleType) Equal(fetcher Fetcher, target Type) (bool, error)

Equal returns true if other is the same type.

func (*TupleType) Kind

func (s *TupleType) Kind() Kind

Kind returns the scalar kind.

func (*TupleType) String

func (s *TupleType) String() string

String representation of the type.

func (*TupleType) Value

func (s *TupleType) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

type Type

type Type interface {
	StorageWithValue

	// Kind of the type.
	Kind() Kind

	// Equal returns true if other is the same type.
	Equal(Fetcher, Type) (bool, error)

	// AssignableTo reports whether a value of the type can be assigned to another.
	AssignableTo(Fetcher, Type) (bool, error)

	// ConvertibleTo reports whether a value of the type can be converted to another
	// (using static type casting).
	ConvertibleTo(Fetcher, Type) (bool, error)

	// String representation of the type.
	String() string
}

Type of a value.

func AnyType

func AnyType() Type

AnyType returns the type for the keyword any.

func AtomicFromString

func AtomicFromString(ident string) Type

AtomicFromString returns a scalar type singleton from a string.

func Bfloat16Type

func Bfloat16Type() Type

Bfloat16Type returns the type for a bfloat16.

func BoolType

func BoolType() Type

BoolType returns the type for a boolean.

func DefaultNumberType

func DefaultNumberType(kind Kind) Type

DefaultNumberType returns the default GX type for a number.

func Float32Type

func Float32Type() Type

Float32Type returns the type for a float32.

func Float64Type

func Float64Type() Type

Float64Type returns the type for a float64.

func Int32Type

func Int32Type() Type

Int32Type returns the type for a int32.

func Int64Type

func Int64Type() Type

Int64Type returns the type for a int64.

func IntIndexType

func IntIndexType() Type

IntIndexType returns the type for intidx, that is the length of an axis.

func IntLenType

func IntLenType() Type

IntLenType returns the type for intlen, that is the length of an axis.

func InvalidType

func InvalidType() Type

InvalidType returns an invalid type. Often used as a placeholder when an error occurred.

func MetaType

func MetaType() Type

MetaType returns the meta type shared across all types.

func NumberFloatType

func NumberFloatType() Type

NumberFloatType returns the type for a float number.

func NumberIntType

func NumberIntType() Type

NumberIntType returns the type for an integer number.

func PackageType

func PackageType() Type

PackageType returns the package type.

func RankType

func RankType() Type

RankType returns the rank type.

func StringType

func StringType() Type

StringType returns the type for a string.

func TypeFromKind

func TypeFromKind(kind Kind) Type

TypeFromKind returns a type from a kind.

func Uint32Type

func Uint32Type() Type

Uint32Type returns the type for a uint32.

func Underlying

func Underlying(typ Type) Type

Underlying returns the underlying type of a type.

func UnknownType

func UnknownType() Type

UnknownType returns the unknown type.

func VoidType

func VoidType() Type

VoidType returns the void type.

type TypeAssertExpr

type TypeAssertExpr struct {
	Src *ast.TypeAssertExpr
	Typ Type

	X Expr
}

TypeAssertExpr casts a type to another while disabling compiler checks on array dimensions. Dimension checks are postponed from compilation time to run time.

func (*TypeAssertExpr) Expr

func (s *TypeAssertExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*TypeAssertExpr) Orig

func (s *TypeAssertExpr) Orig() Expr

Orig returns the expression being casted.

func (*TypeAssertExpr) Source

func (s *TypeAssertExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*TypeAssertExpr) String

func (e *TypeAssertExpr) String() string

func (*TypeAssertExpr) Type

func (s *TypeAssertExpr) Type() Type

Type returns the target type of the cast.

type TypeCastExpr

type TypeCastExpr interface {
	AssignableExpr
	Orig() Expr
}

TypeCastExpr is an abstract type conversion.

type TypeParam

type TypeParam struct {
	BaseType[ast.Expr]

	Field *Field
}

TypeParam is a type mapping to a field name in a function type parameters.

func (*TypeParam) AssignableTo

func (s *TypeParam) AssignableTo(fetcher Fetcher, typ Type) (bool, error)

AssignableTo reports whether a value of the type can be assigned to another.

func (*TypeParam) ConvertibleTo

func (s *TypeParam) ConvertibleTo(fetcher Fetcher, typ Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting).

func (*TypeParam) Equal

func (s *TypeParam) Equal(fetcher Fetcher, typ Type) (bool, error)

Equal returns true if other is the same type.

func (*TypeParam) Kind

func (s *TypeParam) Kind() Kind

Kind of the type.

func (*TypeParam) Same added in v0.3.0

func (s *TypeParam) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*TypeParam) Source

func (s *TypeParam) Source() ast.Node

Source defining the type.

func (*TypeParam) String

func (s *TypeParam) String() string

String representation of the type.

func (*TypeParam) Type

func (s *TypeParam) Type() Type

Type of the type.

func (*TypeParam) Value

func (s *TypeParam) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

type TypeParamValue

type TypeParamValue struct {
	Field *Field
	Typ   Type
}

TypeParamValue assigns a type to a field of a more generic type.

type TypeSet

type TypeSet struct {
	BaseType[*ast.InterfaceType]
	Typs []Type
}

TypeSet represents a set of types.

func (*TypeSet) ArrayType

func (s *TypeSet) ArrayType() ast.Expr

ArrayType returns the source code defining the type. Always returns nil.

func (*TypeSet) AssignableTo

func (s *TypeSet) AssignableTo(fetcher Fetcher, target Type) (bool, error)

AssignableTo reports whether a value of the type can be assigned to another.

func (*TypeSet) ConvertibleTo

func (s *TypeSet) ConvertibleTo(fetcher Fetcher, target Type) (bool, error)

ConvertibleTo reports whether a value of the type can be converted to another (using static type casting).

func (*TypeSet) DataType

func (s *TypeSet) DataType() Type

DataType returns the type of the element.

func (*TypeSet) ElementType

func (s *TypeSet) ElementType() (Type, bool)

ElementType returns the type of an element.

func (*TypeSet) Equal

func (s *TypeSet) Equal(fetcher Fetcher, target Type) (bool, error)

Equal returns true if other is the exact same type set.

func (*TypeSet) Kind

func (s *TypeSet) Kind() Kind

Kind returns the scalar kind.

func (*TypeSet) Rank

func (*TypeSet) Rank() ArrayRank

Rank of the array.

func (*TypeSet) Source

func (s *TypeSet) Source() ast.Node

Source returns the source code defining the type. Always returns nil.

func (*TypeSet) String

func (s *TypeSet) String() string

String representation of the type.

func (*TypeSet) Value

func (s *TypeSet) Value(x Expr) AssignableExpr

Value returns a value pointing to the receiver.

func (*TypeSet) Zero

func (s *TypeSet) Zero() AssignableExpr

Zero returns a zero expression of the same type.

type TypeValExpr

type TypeValExpr struct {
	X   Expr
	Typ Type
}

TypeValExpr is an expression pointing to a type.

func AtomTypeExpr

func AtomTypeExpr(typ Type) *TypeValExpr

AtomTypeExpr returns a type expression for an atomic type.

func (*TypeValExpr) Source

func (s *TypeValExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*TypeValExpr) Store

func (s *TypeValExpr) Store() Storage

Store storing the type.

func (*TypeValExpr) String

func (s *TypeValExpr) String() string

String representation.

func (*TypeValExpr) Type

func (s *TypeValExpr) Type() Type

Type of the function being called.

type UnaryExpr

type UnaryExpr struct {
	Src *ast.UnaryExpr
	X   AssignableExpr
}

UnaryExpr is an operator with a single argument.

func (*UnaryExpr) Expr

func (s *UnaryExpr) Expr() ast.Expr

Expr returns the expression in the source code.

func (*UnaryExpr) Source

func (s *UnaryExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*UnaryExpr) String

func (s *UnaryExpr) String() string

String representation.

func (*UnaryExpr) Type

func (s *UnaryExpr) Type() Type

Type returns the type returned by the expression.

type Value

type Value interface {
	SourceNode
	Type() Type
}

Value is a value used by the compiler. It can be any thing with a type (package, constant, ...). This is a superset of AssignableExpr.

type ValueRef

type ValueRef struct {
	Src  *ast.Ident
	Stor Storage
}

ValueRef is a reference to a value.

func Idents

func Idents(expr Expr) ([]*ValueRef, error)

Idents returns a slice of all identifiers used in an expression.

func (*ValueRef) Expr

func (s *ValueRef) Expr() ast.Expr

Expr returns the expression in the source code.

func (*ValueRef) Source

func (s *ValueRef) Source() ast.Node

Source returns the node in the AST tree.

func (*ValueRef) Store

func (s *ValueRef) Store() Storage

Store returns the storage referenced by this expression.

func (*ValueRef) String

func (s *ValueRef) String() string

String representation.

func (*ValueRef) Type

func (s *ValueRef) Type() Type

Type returns the type returned by the function call. Use CallExpr.Func.Type to get the type of the function being called.

type VarExpr

type VarExpr struct {
	Decl  *VarSpec
	VName *ast.Ident
}

VarExpr is a name,expr static variable pair.

func (*VarExpr) NameDef

func (vr *VarExpr) NameDef() *ast.Ident

NameDef returns the identifier for the static variable.

func (*VarExpr) Same added in v0.3.0

func (vr *VarExpr) Same(o Storage) bool

Same returns true if the other storage is this storage.

func (*VarExpr) Source

func (vr *VarExpr) Source() ast.Node

Source returns the node in the AST tree.

func (*VarExpr) Type

func (vr *VarExpr) Type() Type

Type returns the type of an expression.

type VarSpec added in v0.3.0

type VarSpec struct {
	FFile *File
	Src   *ast.ValueSpec
	TypeV Type
	Exprs []*VarExpr
}

VarSpec declares a static variable and, optionally, a default value.

type WithStore

type WithStore interface {
	Expr
	Store() Storage
}

WithStore is an expression which points to a storage.

type Zeroer

type Zeroer interface {
	Type
	Zero() AssignableExpr
}

Zeroer is a type able to create a zero value of the type as an expression.

Directories

Path Synopsis
Package generics provides functions to handle generics with the GX IR.
Package generics provides functions to handle generics with the GX IR.
Package irhelper provides helper functions to build IR programmatically.
Package irhelper provides helper functions to build IR programmatically.
Package irstring builds a string representation of an IR tree.
Package irstring builds a string representation of an IR tree.

Jump to

Keyboard shortcuts

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