Split out the loader from the VM
This commit is contained in:
17
vm/state.go
17
vm/state.go
@@ -2,8 +2,6 @@ package vm
|
||||
|
||||
import "fmt"
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
type State struct {
|
||||
running bool
|
||||
err error
|
||||
@@ -24,21 +22,6 @@ func NewState(functions [][]*Instruction) (*State, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewStateFromByteCode(byteCodes [][]byte) (*State, error) {
|
||||
functions := [][]*Instruction{}
|
||||
|
||||
for i, byteCode := range byteCodes {
|
||||
instrs, err := NewInstructionsFromByteCode(byteCode)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "At function index %d", i)
|
||||
}
|
||||
|
||||
functions = append(functions, instrs)
|
||||
}
|
||||
|
||||
return NewState(functions)
|
||||
}
|
||||
|
||||
func (state *State) Execute() error {
|
||||
state.setHandlers()
|
||||
state.call(0)
|
||||
|
||||
Reference in New Issue
Block a user