Documentation ¶
Overview ¶
Package interpreter provides the implementation of the Flux interpreter.
Index ¶
- func DoFunctionCall(f func(args Arguments) (values.Value, error), argsObj values.Object) (values.Value, error)
- func ResolveFunction(f values.Function) (*semantic.FunctionExpression, error)
- func ToFloatArray(a values.Array) ([]float64, error)
- func ToStringArray(a values.Array) ([]string, error)
- type Arguments
- type Interpreter
- func (itrp *Interpreter) Eval(program semantic.Node) error
- func (itrp *Interpreter) GlobalScope() *Scope
- func (itrp *Interpreter) Option(name string) values.Value
- func (itrp *Interpreter) Return() values.Value
- func (itrp *Interpreter) SetOption(name string, val values.Value)
- func (itrp *Interpreter) SetVar(name string, val values.Value)
- func (itrp *Interpreter) SideEffects() []values.Value
- func (itrp *Interpreter) TypeScope() *TypeScope
- type Resolver
- type Scope
- func (s *Scope) Copy() *Scope
- func (s *Scope) Get(name string) values.Value
- func (s *Scope) Len() int
- func (s *Scope) Lookup(name string) (values.Value, bool)
- func (s *Scope) Names() []string
- func (s *Scope) Nest() *Scope
- func (s *Scope) NestWithValues(values map[string]values.Value) *Scope
- func (s *Scope) Range(f func(k string, v values.Value))
- func (s *Scope) Return() values.Value
- func (s *Scope) Set(name string, value values.Value)
- func (s *Scope) SetReturn(value values.Value)
- func (s *Scope) SetValues(vals map[string]values.Value)
- func (s *Scope) Values() map[string]values.Value
- type TypeScope
- func (s *TypeScope) LookupPolyType(node semantic.Node) (semantic.PolyType, bool)
- func (s *TypeScope) LookupType(node semantic.Node) (semantic.Type, bool)
- func (s *TypeScope) Nest() *TypeScope
- func (s *TypeScope) SetPolyType(node semantic.Node, typ semantic.PolyType)
- func (s *TypeScope) SetType(node semantic.Node, typ semantic.Type)
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoFunctionCall ¶
func ResolveFunction ¶
func ResolveFunction(f values.Function) (*semantic.FunctionExpression, 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 ¶
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 Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
TODO(Josh): Scope methods should be private
func NewScopeWithValues ¶
NewScopeWithValues creates a new scope with the initial set of values. The vals map will be mutated.
func (*Scope) NestWithValues ¶
func (*Scope) Return ¶
Return reports the return value for this scope. If no return value has been set a value with type semantic.TInvalid is returned.
type TypeScope ¶
type TypeScope struct {
// contains filtered or unexported fields
}
func NewTypeScope ¶
func NewTypeScope() *TypeScope
func (*TypeScope) LookupPolyType ¶
func (*TypeScope) LookupType ¶
func (*TypeScope) SetPolyType ¶
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.