istio: istio.io/istio/mixer/pkg/il/interpreter Index | Files

package interpreter

import "istio.io/istio/mixer/pkg/il/interpreter"

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 interpreter.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

Package Files

extern.go interpreter.go interpreterRun.gen.go result.go stackFrame.go stepper.go

type Extern Uses

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 Uses

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 Uses

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

Interpreter is an interpreted execution engine for the Mixer IL.

func New Uses

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 Uses

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 Uses

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 Uses

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

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

func (Result) AsBool Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (r Result) AsInterface() interface{}

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

func (Result) AsString Uses

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 Uses

func (r Result) Type() il.Type

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

type Stepper Uses

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 Uses

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 Uses

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 Uses

func (s *Stepper) Done() bool

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

func (*Stepper) Error Uses

func (s *Stepper) Error() error

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

func (*Stepper) Result Uses

func (s *Stepper) Result() Result

Result returns the accumulated result of execution.

func (*Stepper) Step Uses

func (s *Stepper) Step() bool

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

func (*Stepper) String Uses

func (s *Stepper) String() string

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

Package interpreter imports 11 packages (graph) and is imported by 4 packages. Updated 2019-06-12. Refresh now. Tools for package owners.