diff --git a/load/load.go b/load/load.go deleted file mode 100644 index d6e6aac..0000000 --- a/load/load.go +++ /dev/null @@ -1,54 +0,0 @@ -package load - -import "bytes" - -import "github.com/firestuff/subcoding/vm" -import "github.com/lunixbochs/struc" -import "github.com/pkg/errors" - -const instructionBytes = 32 - -func Load(byteCodes [][]byte) ([][]*vm.Instruction, error) { - fncs := [][]*vm.Instruction{} - - for i, byteCode := range byteCodes { - instrs, err := loadFunction(byteCode) - if err != nil { - return nil, errors.Wrapf(err, "At function index %d", i) - } - - fncs = append(fncs, instrs) - } - - return fncs, nil -} - -func loadFunction(byteCode []byte) ([]*vm.Instruction, error) { - instrs := []*vm.Instruction{} - - for start := 0; start < len(byteCode); start += instructionBytes { - chunk := byteCode[start : start+instructionBytes] - - instr, err := loadInstruction(chunk) - if err != nil { - return nil, errors.Wrapf(err, "At byte offset %d", start) - } - - instrs = append(instrs, instr) - } - - return instrs, nil -} - -func loadInstruction(byteCode []byte) (*vm.Instruction, error) { - instr := &vm.Instruction{} - - reader := bytes.NewReader(byteCode) - - err := struc.Unpack(reader, instr) - if err != nil { - return nil, errors.Wrap(err, "Error decoding instruction") - } - - return instr, nil -} diff --git a/test/load_test.go b/test/load_test.go deleted file mode 100644 index 9007a2c..0000000 --- a/test/load_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package test - -import "testing" - -import "github.com/firestuff/subcoding/load" - -func TestLoad(t *testing.T) { - _, err := load.Load(nil) - if err != nil { - t.Fatal(err) - } -}