Documentation ¶
Overview ¶
Package engine orchestrates client input with vm execution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Loop ¶
Loop starts an engine execution loop with the given symbol as the starting node.
The root reads inputs from the provided reader, one line at a time.
It will execute until running out of bytecode in the buffer.
Any error not handled by the engine will terminate the oop and return an error.
Rendered output is written to the provided writer.
func RunPersisted ¶
func RunPersisted(cfg Config, rs resource.Resource, pr persist.Persister, input []byte, w io.Writer, ctx context.Context) error
RunPersisted performs a single vm execution from client input using a persisted state.
State is first loaded from storage. The vm is initialized with the state and executed. The new state is then saved to storage.
The resulting output of the execution will be written to the provided writer.
The state is identified by the SessionId member of the Config. Before first execution, the caller must ensure that an initialized state actually is available for the identifier, otherwise the method will fail.
It will also fail if execution by the underlying Engine fails.
Types ¶
type Config ¶
type Config struct { OutputSize uint32 // Maximum size of output from a single rendered page SessionId string Root string FlagCount uint32 CacheSize uint32 }
Config globally defines behavior of all components driven by the engine.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is an execution engine that handles top-level errors when running client inputs against code in the bytecode buffer.
func NewDefaultEngine ¶
NewDefaultEngine is a convenience function to instantiate a filesystem-backed engine with no output constraints.
func NewEngine ¶
func NewEngine(cfg Config, st *state.State, rs resource.Resource, ca cache.Memory, ctx context.Context) Engine
NewEngine creates a new Engine
func NewSizedEngine ¶
NewSizedEngine is a convenience function to instantiate a filesystem-backed engine with a specified output constraint.
func (*Engine) Exec ¶
Exec processes user input against the current state of the virtual machine environment.
If successfully executed, output of the last execution is available using the WriteResult call.
A bool return valus of false indicates that execution should be terminated. Calling Exec again has undefined effects.
Fails if: - input is formally invalid (too long etc) - no current bytecode is available - input processing against bytcode failed
func (*Engine) Init ¶
Init must be explicitly called before using the Engine instance.
It loads and executes code for the start node.
func (*Engine) WriteResult ¶
WriteResult writes the output of the last vm execution to the given writer.
Fails if - required data inputs to the template are not available. - the template for the given node point is note available for retrieval using the resource.Resource implementer. - the supplied writer fails to process the writes.