More State constructors
This commit is contained in:
14
state.go
14
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() {
|
||||
|
||||
Reference in New Issue
Block a user