interpreter

package
v0.0.0-...-46d7da7 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package interpreter implements an interpreter based runtime for the Mixer IL. Typically a user creates a program, in IL form, and creates an Interpreter, by calling interpeter.New, which takes a program, and its external, native bindings as input.

Once an interpreter with a program is created, it can be used for multiple evaluation sessions. The evaluation is invoked by calling Interpreter.Eval or Interpreter.EvalFnID, which takes the name, or the id of the string of the name, as well as an attribute bag as input.

The return type is a result, which is optimized for returning values directly from the Interpreter's internal data model.

To help with debugging, the user can use the Stepper, which performs the same operations as Interpreter.Run, but stops and captures the full state of execution between instruction executions and allow the user to introspec them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extern

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

Extern represents an external, native function that is callable from within the interpreter, during program execution.

func ExternFromFn

func ExternFromFn(name string, fn interface{}) Extern

ExternFromFn creates a new, reflection based Extern, based on the given function. It panics if the function signature is incompatible to be an extern.

A function can be extern under the following conditions: - Input parameter types are one of the supported types: string, bool, int64, float64, map[string]string. - The return types can be:

  • none (i.e. func (...) {...})
  • a supported type (i.e. func (...) string {...})
  • error (i.e. func (...) error {...})
  • suported type and error (i.e. func (...) string, error {...})

type Interpreter

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

Interpreter is an interpreted execution engine for the Mixer IL.

func New

func New(p *il.Program, es map[string]Extern) *Interpreter

New returns a new Interpreter instance, that can execute the supplied program. The interpreter will only execute functions within the supplied program. Any function extern references will be resolved from the supplied externs map.

func (*Interpreter) Eval

func (i *Interpreter) Eval(fnName string, bag attribute.Bag) (Result, error)

Eval finds the function identified by the fnName parameter in the program, and evaluates it against the given bag.

func (*Interpreter) EvalFnID

func (i *Interpreter) EvalFnID(fnID uint32, bag attribute.Bag) (Result, error)

EvalFnID finds the function identified by the fnID parameter in the program, and evaluates it against the given bag.

type Result

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

Result contains the result of an evaluation performed by the interpreter.

func (Result) AsBool

func (r Result) AsBool() bool

AsBool returns the value contained in the result as a bool. If the underlying result is not bool, it panics.

func (Result) AsDouble

func (r Result) AsDouble() float64

AsDouble returns the value contained in the result as a double. If the underlying result is not double, it panics.

func (Result) AsDuration

func (r Result) AsDuration() time.Duration

AsDuration returns the value contained in the result as time.Duration. If the underlying result is not a duration, it panics.

func (Result) AsInteger

func (r Result) AsInteger() int64

AsInteger returns the value contained in the result as an integer. If the underlying result is not integer, it panics.

func (Result) AsInterface

func (r Result) AsInterface() interface{}

AsInterface returns the value contained in the result as an interface{}.

func (Result) AsString

func (r Result) AsString() string

AsString returns the value contained in the result as a string. Unlike other methods, it does not panic if the underlying value is not string and returns the string version of the data.

func (Result) Type

func (r Result) Type() il.Type

Type returns the underlying type of the value in the Result.

type Stepper

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

Stepper executes a program using single steps. It is useeful for debugging through an executing program. The stepper will capture the state of the interpreter after every execution step and stop execution, allowing the developers to inspect the state of the interpreter.

func NewStepper

func NewStepper(p *il.Program, es map[string]Extern) *Stepper

NewStepper returns a new stepper instance that executes the given program and externs.

func (*Stepper) Begin

func (s *Stepper) Begin(fnName string, bag attribute.Bag) error

Begin starts stepping into the evaluation of the function, identified by fnName.

func (*Stepper) Done

func (s *Stepper) Done() bool

Done indicates that the stepper is done, and execution is completed.

func (*Stepper) Error

func (s *Stepper) Error() error

Error returns any error that was accumulated as the outcome of execution.

func (*Stepper) Result

func (s *Stepper) Result() Result

Result returns the accumulated result of execution.

func (*Stepper) Step

func (s *Stepper) Step() bool

Step executes the next available instruction. Returns true if the program can still execute.

func (*Stepper) String

func (s *Stepper) String() string

String dumps the current state of the interpreter in a human-readable form.

Jump to

Keyboard shortcuts

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