compiler

package
v0.28.3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

The compiler package provides a compiler and Go runtime for a subset of the Flux language. Only pure functions are supported by the compiler. A function is compiled and then may be called repeatedly with different arguments. The function must be pure meaning it has no side effects. Other language features are not supported.

This runtime is not portable by design. The runtime consists of Go types that have been constructed based on the Flux function being compiled. Those types are not serializable and cannot be transported to other systems or environments. This design is intended to limit the scope under which compilation must be supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompilationCache

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

CompilationCache caches compilation results based on the type of the function.

func NewCompilationCache

func NewCompilationCache(fn *semantic.FunctionExpression, scope Scope) *CompilationCache

func (*CompilationCache) Compile

func (c *CompilationCache) Compile(in semantic.Type) (Func, error)

Compile returns a compiled function based on the provided type. The result will be cached for subsequent calls.

type Evaluator

type Evaluator interface {
	Type() semantic.Type
	EvalString(scope Scope) (string, error)
	EvalInt(scope Scope) (int64, error)
	EvalUInt(scope Scope) (uint64, error)
	EvalFloat(scope Scope) (float64, error)
	EvalBool(scope Scope) (bool, error)
	EvalTime(scope Scope) (values.Time, error)
	EvalDuration(scope Scope) (values.Duration, error)
	EvalRegexp(scope Scope) (*regexp.Regexp, error)
	EvalArray(scope Scope) (values.Array, error)
	EvalObject(scope Scope) (values.Object, error)
	EvalFunction(scope Scope) (values.Function, error)
}

type Func

type Func interface {
	Type() semantic.Type
	Eval(input values.Object) (values.Value, error)
	EvalString(input values.Object) (string, error)
	EvalInt(input values.Object) (int64, error)
	EvalUInt(input values.Object) (uint64, error)
	EvalFloat(input values.Object) (float64, error)
	EvalBool(input values.Object) (bool, error)
	EvalTime(input values.Object) (values.Time, error)
	EvalDuration(input values.Object) (values.Duration, error)
	EvalRegexp(input values.Object) (*regexp.Regexp, error)
	EvalArray(input values.Object) (values.Array, error)
	EvalObject(input values.Object) (values.Object, error)
	EvalFunction(input values.Object) (values.Function, error)
}

func Compile

func Compile(f *semantic.FunctionExpression, in semantic.Type, builtins Scope) (Func, error)

func CompileFnParam

func CompileFnParam(fn *semantic.FunctionExpression, paramType, returnType semantic.Type) (Func, string, error)

Utility function for compiling an `fn` parameter for rename or drop/keep. In addition to the function expression, it takes two types to verify the result against: a single argument type, and a single return type.

func CompileReduceFn added in v0.23.0

func CompileReduceFn(fn *semantic.FunctionExpression, paramType semantic.Type) (Func, []string, error)

type Scope

type Scope map[string]values.Value

func (Scope) Copy

func (s Scope) Copy() Scope

func (Scope) GetArray

func (s Scope) GetArray(name string) values.Array

func (Scope) GetBool

func (s Scope) GetBool(name string) bool

func (Scope) GetDuration

func (s Scope) GetDuration(name string) values.Duration

func (Scope) GetFloat

func (s Scope) GetFloat(name string) float64

func (Scope) GetFunction

func (s Scope) GetFunction(name string) values.Function

func (Scope) GetInt

func (s Scope) GetInt(name string) int64

func (Scope) GetObject

func (s Scope) GetObject(name string) values.Object

func (Scope) GetRegexp

func (s Scope) GetRegexp(name string) *regexp.Regexp

func (Scope) GetString

func (s Scope) GetString(name string) string

func (Scope) GetTime

func (s Scope) GetTime(name string) values.Time

func (Scope) GetUInt

func (s Scope) GetUInt(name string) uint64

func (Scope) Set

func (s Scope) Set(name string, v values.Value)

func (Scope) Type

func (s Scope) Type(name string) semantic.Type

Jump to

Keyboard shortcuts

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