values

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 16 Imported by: 30

Documentation

Overview

Package values declares the flux data types and implements them.

Index

Constants

This section is empty.

Variables

View Source
var (
	// InvalidValue is a non nil value who's type is semantic.Invalid
	InvalidValue = value{/* contains filtered or unexported fields */}

	// Null is an untyped nil value.
	Null = value{/* contains filtered or unexported fields */}
)

Functions

func AssignableTo added in v0.33.0

func AssignableTo(V, T semantic.Type) bool

AssignableTo returns true if type V is assignable to type T.

func BuildExternAssignments added in v0.40.0

func BuildExternAssignments(node semantic.Node, scope Scope) semantic.Node

BuildExternAssignments constructs nested semantic.ExternAssignment nodes mirroring the nested structure of the scope.

func CheckKind

func CheckKind(got, exp semantic.Nature)

CheckKind panics if got != exp.

func FormattedScope added in v0.40.0

func FormattedScope(scope Scope) fmt.Formatter

FormattedScope produces a fmt.Formatter for pretty printing a scope.

func NewFunction

func NewFunction(name string, typ semantic.PolyType, call func(ctx context.Context, args Object) (Value, error), sideEffect bool) *function

NewFunction returns a new function value

func NewObject

func NewObject() *object

func NewObjectWithBacking added in v0.14.0

func NewObjectWithBacking(size int) *object

func NewObjectWithValues

func NewObjectWithValues(vals map[string]Value) *object

func UnexpectedKind

func UnexpectedKind(got, exp semantic.Nature) error

Types

type Array

type Array interface {
	Value
	Get(i int) Value
	Set(i int, v Value)
	Append(v Value)
	Len() int
	Range(func(i int, v Value))
	Sort(func(i, j Value) bool)
}

Array represents an sequence of elements All elements must be the same type

func NewArray

func NewArray(elementType semantic.Type) Array

func NewArrayWithBacking

func NewArrayWithBacking(elementType semantic.Type, elements []Value) Array

type BinaryFuncSignature

type BinaryFuncSignature struct {
	Operator    ast.OperatorKind
	Left, Right semantic.Nature
}

type BinaryFunction

type BinaryFunction func(l, r Value) (Value, error)

func LookupBinaryFunction

func LookupBinaryFunction(sig BinaryFuncSignature) (BinaryFunction, error)

LookupBinaryFunction returns an appropriate binary function that evaluates two values and returns another value. If the two types are not compatible with the given operation, this returns an error.

type Duration

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

Duration is a vector representing the duration unit components.

func ConvertDuration added in v0.51.0

func ConvertDuration(v time.Duration) Duration

ConvertDuration takes a time.Duration and converts it into a Duration.

func DurationFromAST added in v0.51.0

func DurationFromAST(dur *ast.DurationLiteral) (d Duration, err error)

DurationFromAST creates a duration value from the AST DurationLiteral.

func ParseDuration

func ParseDuration(s string) (Duration, error)

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration will return the nanosecond equivalent of this duration. It will assume that months are the equivalent of 30 days.

It is recommended not to use this method unless it is absolutely needed. This method will lose any precision that is present in the Duration and it should only be used for interfacing with outside code that is not month-aware.

func (Duration) Equal added in v0.51.0

func (d Duration) Equal(other Duration) bool

Equal returns true if the two durations are equal.

func (Duration) IsPositive added in v0.51.0

func (d Duration) IsPositive() bool

IsPositive returns true if this is a positive number. It returns false if the number is zero.

func (Duration) IsZero added in v0.51.0

func (d Duration) IsZero() bool

IsZero returns true if this is a zero duration.

func (Duration) MarshalText added in v0.51.0

func (d Duration) MarshalText() ([]byte, error)

func (Duration) Mul added in v0.51.0

func (d Duration) Mul(scale int) Duration

Mul will multiply the Duration by a scalar. This multiplies each component of the vector.

func (Duration) Normalize added in v0.51.0

func (d Duration) Normalize(interval Duration) Duration

Normalize will normalize the duration within the interval. It will ensure that the output duration is the smallest positive duration that is the equivalent of the current duration.

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalText added in v0.51.0

func (d *Duration) UnmarshalText(data []byte) error

type Function

type Function interface {
	Value
	HasSideEffect() bool
	Call(ctx context.Context, args Object) (Value, error)
}

Function represents a callable type

type Object

type Object interface {
	Value
	Get(name string) (Value, bool)
	Set(name string, v Value)
	Len() int
	Range(func(name string, v Value))
}

type Package added in v0.41.0

type Package interface {
	Object
	SetOption(name string, v Value)
}

type Scope added in v0.40.0

type Scope interface {
	// Lookup a name in the scope.
	Lookup(name string) (Value, bool)

	// LocalLookup a name in current scope only.
	LocalLookup(name string) (Value, bool)

	// Set binds a variable in the current scope.
	Set(name string, v Value)
	// SetOption binds a variable in the package option scope.
	// Setting an option must occur on the specific package value.
	// If the package cannot be found no option is set, in which case the boolean return is false.
	// An error is reported if the specified package is not a package value.
	SetOption(pkg, name string, v Value) (bool, error)

	// Nest creates a new scope by nesting the current scope.
	// If the passed in object is not nil, its values will be added to the new nested scope.
	Nest(Object) Scope

	// Pop returns the parent of the current scope.
	Pop() Scope

	// Size is the number of visible names in scope.
	Size() int

	// Range iterates over all variable bindings in scope applying f.
	Range(f func(k string, v Value))

	// LocalRange iterates over all variable bindings only in the current scope.
	LocalRange(f func(k string, v Value))

	// SetReturn binds the return value of the scope.
	SetReturn(Value)

	// Return reports the bound return value of the scope.
	Return() Value

	// Copy creates a deep copy of the scope, values are not copied.
	// Copy preserves the nesting structure.
	Copy() Scope
}

func NewNestedScope added in v0.40.0

func NewNestedScope(parent Scope, obj Object) Scope

NewNestedScope creates a new scope with bindings from obj and a parent.

func NewScope added in v0.40.0

func NewScope() Scope

NewScope creates a new empty scope with no parent.

type Time

type Time int64

func ConvertTime

func ConvertTime(t time.Time) Time

func ParseTime

func ParseTime(s string) (Time, error)

func (Time) Add

func (t Time) Add(d Duration) Time

func (Time) Remainder added in v0.19.0

func (t Time) Remainder(d Duration) (r Duration)

Remainder divides t by d and returns the remainder.

func (Time) Round

func (t Time) Round(d Duration) Time

func (Time) String

func (t Time) String() string

func (Time) Sub added in v0.51.0

func (t Time) Sub(other Time) Duration

Sub takes another time and returns a duration giving the duration between the two times. A positive duration indicates that the receiver occurs after the other time.

func (Time) Time

func (t Time) Time() time.Time

func (Time) Truncate

func (t Time) Truncate(d Duration) Time

type Typer

type Typer interface {
	Type() semantic.Type
	PolyType() semantic.PolyType
}

type Value

type Value interface {
	Typer
	IsNull() bool
	Str() string
	Bytes() []byte
	Int() int64
	UInt() uint64
	Float() float64
	Bool() bool
	Time() Time
	Duration() Duration
	Regexp() *regexp.Regexp
	Array() Array
	Object() Object
	Function() Function
	Equal(Value) bool
}

func New

func New(v interface{}) Value

New constructs a new Value by inferring the type from the interface. If the interface does not translate to a valid Value type, then InvalidValue is returned.

func NewBool

func NewBool(v bool) Value

func NewBytes added in v0.40.0

func NewBytes(v []byte) Value

func NewDuration

func NewDuration(v Duration) Value

func NewFloat

func NewFloat(v float64) Value

func NewFromString added in v0.23.0

func NewFromString(t semantic.Type, s string) (Value, error)

func NewInt

func NewInt(v int64) Value

func NewNull added in v0.14.0

func NewNull(t semantic.Type) Value

func NewRegexp

func NewRegexp(v *regexp.Regexp) Value

func NewString

func NewString(v string) Value

func NewTime

func NewTime(v Time) Value

func NewUInt

func NewUInt(v uint64) Value

type ValueStringer added in v0.23.0

type ValueStringer interface {
	String() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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