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 ¶
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.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result contains the result of an evaluation performed by the interpreter.
func (Result) AsBool ¶
AsBool returns the value contained in the result as a bool. If the underlying result is not bool, it panics.
func (Result) AsDouble ¶
AsDouble returns the value contained in the result as a double. If the underlying result is not double, it panics.
func (Result) AsDuration ¶
AsDuration returns the value contained in the result as time.Duration. If the underlying result is not a duration, it panics.
func (Result) AsInteger ¶
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{}.
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 ¶
NewStepper returns a new stepper instance that executes the given program and externs.
func (*Stepper) Begin ¶
Begin starts stepping into the evaluation of the function, identified by fnName.