Remove broken loader

This commit is contained in:
Ian Gulliver
2021-11-20 10:20:29 -10:00
parent c67028520c
commit 3ced099a47
2 changed files with 0 additions and 66 deletions

View File

@@ -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
}

View File

@@ -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)
}
}