interpreter

package
v0.99.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package interpreter provides the implementation of the Flux interpreter.

Index

Constants

View Source
const (
	PackageMain = "main"
	NowPkg      = "universe"
	NowOption   = "now"
)

Variables

This section is empty.

Functions

func DoFunctionCall

func DoFunctionCall(f func(args Arguments) (values.Value, error), argsObj values.Object) (values.Value, error)

DoFunctionCall will call DoFunctionCallContext with a background context.

func DoFunctionCallContext

func DoFunctionCallContext(f func(ctx context.Context, args Arguments) (values.Value, error), ctx context.Context, argsObj values.Object) (values.Value, error)

DoFunctionCallContext will treat the argsObj as the arguments to a function. It will then invoke that function with the Arguments and return the value from the function.

This function verifies that all of the arguments have been consumed by the function call.

func ResolveIdsInFunction

func ResolveIdsInFunction(scope values.Scope, origFn *semantic.FunctionExpression, n semantic.Node, localIdentifiers *[]string) (semantic.Node, error)

func ToFloatArray

func ToFloatArray(a values.Array) ([]float64, error)

func ToStringArray

func ToStringArray(a values.Array) ([]string, error)

Types

type Arguments

type Arguments interface {
	GetAll() []string
	Get(name string) (values.Value, bool)
	GetRequired(name string) (values.Value, error)

	GetString(name string) (string, bool, error)
	GetInt(name string) (int64, bool, error)
	GetFloat(name string) (float64, bool, error)
	GetBool(name string) (bool, bool, error)
	GetFunction(name string) (values.Function, bool, error)
	GetArray(name string, t semantic.Nature) (values.Array, bool, error)
	GetObject(name string) (values.Object, bool, error)
	GetDictionary(name string) (values.Dictionary, bool, error)

	GetRequiredString(name string) (string, error)
	GetRequiredInt(name string) (int64, error)
	GetRequiredFloat(name string) (float64, error)
	GetRequiredBool(name string) (bool, error)
	GetRequiredFunction(name string) (values.Function, error)
	GetRequiredArray(name string, t semantic.Nature) (values.Array, error)
	GetRequiredArrayAllowEmpty(name string, t semantic.Nature) (values.Array, error)
	GetRequiredObject(name string) (values.Object, error)
	GetRequiredDictionary(name string) (values.Dictionary, error)
	// contains filtered or unexported methods
}

Arguments provides access to the keyword arguments passed to a function. semantic.The Get{Type} methods return three values: the typed value of the arg, whether the argument was specified and any errors about the argument type. semantic.The GetRequired{Type} methods return only two values, the typed value of the arg and any errors, a missing argument is considered an error in this case.

func NewArguments

func NewArguments(obj values.Object) Arguments

type ExecOptsConfig

type ExecOptsConfig interface {
	ConfigureProfiler(ctx context.Context, profilerNames []string)
	ConfigureNow(ctx context.Context, now time.Time)
}

This interface is used by the interpreter to set options that are relevant to the execution engine. For most cases it would be sufficient to pull options out after the interpreter is run, however it is possible for the interpreter to invoke the execution engine via tableFind and chain functions. These options need to get immediately installed in the execution dependencies when they are interpreted. We cannot access them directly here due to circular dependencies, so we use an interface, with an implementation defined by the caller.

type Importer

type Importer interface {
	ImportPackageObject(path string) (*Package, error)
}

Importer produces a package given an import path

type Interpreter

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

func NewInterpreter

func NewInterpreter(pkg *Package, eoc ExecOptsConfig) *Interpreter

func (*Interpreter) Eval

func (itrp *Interpreter) Eval(ctx context.Context, node semantic.Node, scope values.Scope, importer Importer) ([]SideEffect, error)

Eval evaluates the expressions composing a Flux package and returns any side effects that occurred during this evaluation.

func (*Interpreter) PackageName

func (itrp *Interpreter) PackageName() string

type Package

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

Package is an importable package that can be used from another section of code. The package itself cannot have its attributes modified after creation, but the options may be changed.

func NewPackage

func NewPackage(name string) *Package

func NewPackageWithValues

func NewPackageWithValues(name, path string, obj values.Object) *Package

func (*Package) Array

func (p *Package) Array() values.Array

func (*Package) Bool

func (p *Package) Bool() bool

func (*Package) Bytes

func (p *Package) Bytes() []byte

func (*Package) Copy

func (p *Package) Copy() *Package

func (*Package) Dict

func (p *Package) Dict() values.Dictionary

func (*Package) Duration

func (p *Package) Duration() values.Duration

func (*Package) Equal

func (p *Package) Equal(rhs values.Value) bool

func (*Package) Float

func (p *Package) Float() float64

func (*Package) Function

func (p *Package) Function() values.Function

func (*Package) Get

func (p *Package) Get(name string) (values.Value, bool)

func (*Package) Int

func (p *Package) Int() int64

func (*Package) IsNull

func (p *Package) IsNull() bool

func (*Package) Len

func (p *Package) Len() int

func (*Package) Name

func (p *Package) Name() string

Name returns the package name.

func (*Package) Object

func (p *Package) Object() values.Object

func (*Package) Path

func (p *Package) Path() string

Path returns the canonical import path for this package.

func (*Package) Range

func (p *Package) Range(f func(name string, v values.Value))

func (*Package) Regexp

func (p *Package) Regexp() *regexp.Regexp

func (*Package) Set

func (p *Package) Set(name string, v values.Value)

func (*Package) SideEffects

func (p *Package) SideEffects() []SideEffect

func (*Package) Str

func (p *Package) Str() string

func (*Package) String

func (p *Package) String() string

func (*Package) Time

func (p *Package) Time() values.Time

func (*Package) Type

func (p *Package) Type() semantic.MonoType

func (*Package) UInt

func (p *Package) UInt() uint64

type ResolvedFunction

type ResolvedFunction struct {
	Fn    *semantic.FunctionExpression `json:"fn"`
	Scope values.Scope                 `json:"-"`
}

ResolvedFunction represents a function that can be passed down to the compiler. Both the function expression and scope are captured. The scope cannot be serialized, which is no longer a problem in the current design with the exception of the REPL which will not be able to correctly pass through the scope.

func ResolveFunction

func ResolveFunction(f values.Function) (ResolvedFunction, error)

ResolveFunction produces a function that can execute externally.

func (ResolvedFunction) Copy

type Resolver

type Resolver interface {
	Resolve() (semantic.Node, error)
	Scope() values.Scope
}

Resolver represents a value that can resolve itself. Resolving is the action of capturing the scope at function declaration and replacing any identifiers with static values from the scope where possible. TODO(nathanielc): Improve implementations of scope to only preserve values in the scope that are referrenced.

type SideEffect

type SideEffect struct {
	Node  semantic.Node
	Value values.Value
}

SideEffect contains its value, and the semantic node that generated it.

type StackEntry

type StackEntry struct {
	FunctionName string
	Location     ast.SourceLocation
}

StackEntry describes a single entry in the call stack.

func Stack

func Stack(ctx context.Context) []StackEntry

Stack retrieves the call stack for a given context.

type Value

type Value interface {
	// Type reports the type of value
	Type() semantic.MonoType
	// Value returns the actual value represented.
	Value() interface{}
	// Property returns a new value which is a property of this value.
	Property(name string) (values.Value, error)
}

Value represents any value that can be the result of evaluating any expression.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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