Split out the loader from the VM

This commit is contained in:
Ian Gulliver
2021-11-18 19:56:58 -10:00
parent 941939da83
commit 4332632c77
4 changed files with 66 additions and 52 deletions

View File

@@ -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)