engine.go (770B)
1 package engine 2 3 import ( 4 "context" 5 "fmt" 6 "io" 7 ) 8 9 var ( 10 ErrCodeRemaining = fmt.Errorf("bytecode remaining") 11 ) 12 13 // EngineIsh defines the interface for execution engines that handle vm initialization and execution, and rendering outputs. 14 type Engine interface { 15 // Init sets the engine up for vm execution. It must be called before Exec. 16 //Init(ctx context.Context) (bool, error) 17 // Exec executes the pending bytecode. 18 Exec(ctx context.Context, input []byte) (bool, error) 19 // Flush renders output according to the state of VM execution 20 // to the given io.Writer, and prepares the engine for another 21 // VM execution. 22 Flush(ctx context.Context, w io.Writer) (int, error) 23 // Finish must be called after the last call to Exec. 24 Finish(ctx context.Context) error 25 }