diff --git a/state.go b/state.go index 808ef9b..9c024e2 100644 --- a/state.go +++ b/state.go @@ -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() { diff --git a/state_test.go b/state_test.go index f4acbf6..9ff064a 100644 --- a/state_test.go +++ b/state_test.go @@ -30,7 +30,7 @@ func TestFirst(t *testing.T) { functionByteCode = append(functionByteCode, byteCode) } - state, err := NewState(functionByteCode) + state, err := NewStateFromByteCode(functionByteCode) if err != nil { t.Fatal(err) }