More State constructors

This commit is contained in:
Ian Gulliver
2021-11-16 15:36:34 -10:00
parent 69e69acc6f
commit f2d552e076
2 changed files with 11 additions and 5 deletions

View File

@@ -19,8 +19,14 @@ type State struct {
stack []*StackFrame
}
func NewState(byteCodes [][]byte) (*State, error) {
state := &State{}
func NewState(functions [][]*Instruction) (*State, error) {
return &State{
functions: functions,
}, nil
}
func NewStateFromByteCode(byteCodes [][]byte) (*State, error) {
functions := [][]*Instruction{}
for i, byteCode := range byteCodes {
instrs, err := NewInstructionsFromByteCode(byteCode)
@@ -28,10 +34,10 @@ func NewState(byteCodes [][]byte) (*State, error) {
return nil, errors.Wrapf(err, "At function index %d", i)
}
state.functions = append(state.functions, instrs)
functions = append(functions, instrs)
}
return state, nil
return NewState(functions)
}
func (state *State) Execute() {