Split files

This commit is contained in:
Ian Gulliver
2021-11-15 20:44:26 -10:00
parent be6b726851
commit 6b1da92a3a
6 changed files with 254 additions and 291 deletions

30
instruction.go Normal file
View File

@@ -0,0 +1,30 @@
package vm
import "bytes"
import "github.com/lunixbochs/struc"
import "github.com/pkg/errors"
const InstructionBytes = 32
type Instruction struct {
OpCode OpCodeType
Reserved [4]byte
Operand1 Operand
Operand2 Operand
opHandler OpHandler `struc:"skip"`
}
func NewInstruction(byteCode []byte) (*Instruction, error) {
instr := &Instruction{}
reader := bytes.NewReader(byteCode)
err := struc.Unpack(reader, instr)
if err != nil {
return nil, errors.Wrap(err, "Error decoding instruction")
}
return instr, nil
}