interpreter

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2018 License: MIT Imports: 6 Imported by: 8

Documentation

Overview

Package interpreter provides the implementation of the Flux interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoFunctionCall

func DoFunctionCall(f func(args Arguments) (values.Value, error), argsObj values.Object) (values.Value, 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)

	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)
	GetRequiredObject(name string) (values.Object, 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 Interpreter

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

Interpreter used to interpret a Flux program

func NewInterpreter

func NewInterpreter(options, builtins map[string]values.Value, types *TypeScope) *Interpreter

NewInterpreter instantiates a new Flux Interpreter whose builtin values are not mutable. Options are always mutable.

func NewMutableInterpreter

func NewMutableInterpreter(options, builtins map[string]values.Value, types *TypeScope) *Interpreter

NewMutableInterpreter instantiates a new Flux Interpreter whose builtin values are mutable. Options are always mutable.

func (*Interpreter) Eval

func (itrp *Interpreter) Eval(program semantic.Node) error

Eval evaluates the expressions composing a Flux program.

func (*Interpreter) GlobalScope

func (itrp *Interpreter) GlobalScope() *Scope

GlobalScope returns a pointer to the global scope of the program. That is the scope nested directly below the options scope.

func (*Interpreter) Option

func (itrp *Interpreter) Option(name string) values.Value

Option returns a Flux option by name

func (*Interpreter) Return

func (itrp *Interpreter) Return() values.Value

Return gives the return value from the block

func (*Interpreter) SetOption

func (itrp *Interpreter) SetOption(name string, val values.Value)

SetOption sets a new option binding

func (*Interpreter) SetVar

func (itrp *Interpreter) SetVar(name string, val values.Value)

SetVar adds a variable binding to the global scope

func (*Interpreter) SideEffects

func (itrp *Interpreter) SideEffects() []values.Value

SideEffects returns the evaluated expressions of a Flux program

func (*Interpreter) TypeScope

func (itrp *Interpreter) TypeScope() *TypeScope

TypeScope returns the type scope of the interpreter

type Resolver

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

Resolver represents a value that can resolve itself

type Scope

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

TODO(Josh): Scope methods should be private

func NewScope

func NewScope() *Scope

func NewScopeWithValues

func NewScopeWithValues(vals map[string]values.Value) *Scope

NewScopeWithValues creates a new scope with the initial set of values. The vals map will be mutated.

func (*Scope) Copy

func (s *Scope) Copy() *Scope

Copy returns a copy of the scope and its parents.

func (*Scope) Get

func (s *Scope) Get(name string) values.Value

func (*Scope) Len

func (s *Scope) Len() int

func (*Scope) Lookup

func (s *Scope) Lookup(name string) (values.Value, bool)

func (*Scope) Names

func (s *Scope) Names() []string

func (*Scope) Nest

func (s *Scope) Nest() *Scope

Nest returns a new nested scope.

func (*Scope) NestWithValues

func (s *Scope) NestWithValues(values map[string]values.Value) *Scope

func (*Scope) Range

func (s *Scope) Range(f func(k string, v values.Value))

func (*Scope) Return

func (s *Scope) Return() values.Value

Return reports the return value for this scope. If no return value has been set a value with type semantic.TInvalid is returned.

func (*Scope) Set

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

func (*Scope) SetReturn

func (s *Scope) SetReturn(value values.Value)

SetReturn sets the return value of this scope.

func (*Scope) SetValues

func (s *Scope) SetValues(vals map[string]values.Value)

func (*Scope) Values

func (s *Scope) Values() map[string]values.Value

type TypeScope

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

func NewTypeScope

func NewTypeScope() *TypeScope

func (*TypeScope) LookupPolyType

func (s *TypeScope) LookupPolyType(node semantic.Node) (semantic.PolyType, bool)

func (*TypeScope) LookupType

func (s *TypeScope) LookupType(node semantic.Node) (semantic.Type, bool)

func (*TypeScope) Nest

func (s *TypeScope) Nest() *TypeScope

func (*TypeScope) SetPolyType

func (s *TypeScope) SetPolyType(node semantic.Node, typ semantic.PolyType)

func (*TypeScope) SetType

func (s *TypeScope) SetType(node semantic.Node, typ semantic.Type)

type Value

type Value interface {
	// Type reports the type of value
	Type() semantic.Type
	// 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.

Jump to

Keyboard shortcuts

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