diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7c12bc5..ff62aa6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -67,4 +67,4 @@ jobs: env: CGO_LDFLAGS: ${{ matrix.config.cgo_ldflags }} run: | - go test ./bridge ./compiler ./oto + go test ./vm ./vm/compiler/bridge ./vm/compiler ./oto diff --git a/cmd/sointu-compile/main.go b/cmd/sointu-compile/main.go index 666f2ad..817de48 100644 --- a/cmd/sointu-compile/main.go +++ b/cmd/sointu-compile/main.go @@ -14,7 +14,7 @@ import ( "gopkg.in/yaml.v3" "github.com/vsariola/sointu" - "github.com/vsariola/sointu/compiler" + "github.com/vsariola/sointu/vm/compiler" ) func filterExtensions(input map[string]string, extensions []string) map[string]string { diff --git a/cmd/sointu-play/main.go b/cmd/sointu-play/main.go index 6d29877..a37620c 100644 --- a/cmd/sointu-play/main.go +++ b/cmd/sointu-play/main.go @@ -15,8 +15,8 @@ import ( "gopkg.in/yaml.v3" "github.com/vsariola/sointu" - "github.com/vsariola/sointu/bridge" "github.com/vsariola/sointu/oto" + "github.com/vsariola/sointu/vm/compiler/bridge" ) func main() { diff --git a/cmd/sointu-track/main.go b/cmd/sointu-track/main.go index 0c7607c..9920acd 100644 --- a/cmd/sointu-track/main.go +++ b/cmd/sointu-track/main.go @@ -4,9 +4,9 @@ import ( "fmt" "os" - "github.com/vsariola/sointu/bridge" "github.com/vsariola/sointu/oto" "github.com/vsariola/sointu/tracker/gioui" + "github.com/vsariola/sointu/vm/compiler/bridge" ) func main() { diff --git a/tracker/gmdlsentry.go b/tracker/gmdlsentry.go index 1bd4659..309aacf 100644 --- a/tracker/gmdlsentry.go +++ b/tracker/gmdlsentry.go @@ -1,6 +1,6 @@ package tracker -import "github.com/vsariola/sointu/compiler" +import "github.com/vsariola/sointu/vm" type GmDlsEntry struct { Start int @@ -10,11 +10,11 @@ type GmDlsEntry struct { Name string } -var GmDlsEntryMap = make(map[compiler.SampleOffset]int) +var GmDlsEntryMap = make(map[vm.SampleOffset]int) func init() { for i, e := range GmDlsEntries { - key := compiler.SampleOffset{Start: uint32(e.Start), LoopStart: uint16(e.LoopStart), LoopLength: uint16(e.LoopLength)} + key := vm.SampleOffset{Start: uint32(e.Start), LoopStart: uint16(e.LoopStart), LoopLength: uint16(e.LoopLength)} GmDlsEntryMap[key] = i } } diff --git a/tracker/model.go b/tracker/model.go index ccb462e..a8ff4bc 100644 --- a/tracker/model.go +++ b/tracker/model.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/vsariola/sointu" - "github.com/vsariola/sointu/compiler" + "github.com/vsariola/sointu/vm" ) // Model implements the mutable state for the tracker program GUI. @@ -812,7 +812,7 @@ func (m *Model) Param(index int) (Parameter, error) { return Parameter{Type: typ, Min: min, Max: max, Name: name, Hint: text, Value: val}, nil } if unit.Type == "oscillator" && index == 0 { - key := compiler.SampleOffset{Start: uint32(unit.Parameters["samplestart"]), LoopStart: uint16(unit.Parameters["loopstart"]), LoopLength: uint16(unit.Parameters["looplength"])} + key := vm.SampleOffset{Start: uint32(unit.Parameters["samplestart"]), LoopStart: uint16(unit.Parameters["loopstart"]), LoopLength: uint16(unit.Parameters["looplength"])} val := 0 hint := "0 / custom" if v, ok := GmDlsEntryMap[key]; ok { diff --git a/compiler/encoded_patch.go b/vm/bytepatch.go similarity index 97% rename from compiler/encoded_patch.go rename to vm/bytepatch.go index 67fc343..3ccd8b6 100644 --- a/compiler/encoded_patch.go +++ b/vm/bytepatch.go @@ -1,4 +1,4 @@ -package compiler +package vm import ( "errors" @@ -7,7 +7,7 @@ import ( "github.com/vsariola/sointu" ) -type EncodedPatch struct { +type BytePatch struct { Commands []byte Values []byte DelayTimes []uint16 @@ -22,8 +22,8 @@ type SampleOffset struct { LoopLength uint16 } -func Encode(patch sointu.Patch, featureSet FeatureSet) (*EncodedPatch, error) { - var c EncodedPatch +func Encode(patch sointu.Patch, featureSet FeatureSet) (*BytePatch, error) { + var c BytePatch sampleOffsetMap := map[SampleOffset]int{} globalAddrs := map[int]uint16{} globalFixups := map[int]([]int){} diff --git a/bridge/bridge.go b/vm/compiler/bridge/bridge.go similarity index 95% rename from bridge/bridge.go rename to vm/compiler/bridge/bridge.go index 9865c78..71da140 100644 --- a/bridge/bridge.go +++ b/vm/compiler/bridge/bridge.go @@ -1,7 +1,7 @@ package bridge -// #cgo CFLAGS: -I"${SRCDIR}/../build/" -// #cgo LDFLAGS: "${SRCDIR}/../build/libsointu.a" +// #cgo CFLAGS: -I"${SRCDIR}/../../../build/" +// #cgo LDFLAGS: "${SRCDIR}/../../../build/libsointu.a" // #include import "C" import ( @@ -10,7 +10,7 @@ import ( "strings" "github.com/vsariola/sointu" - "github.com/vsariola/sointu/compiler" + "github.com/vsariola/sointu/vm" ) type BridgeService struct { @@ -23,7 +23,7 @@ func (s BridgeService) Compile(patch sointu.Patch) (sointu.Synth, error) { func Synth(patch sointu.Patch) (*C.Synth, error) { s := new(C.Synth) - comPatch, err := compiler.Encode(patch, compiler.AllFeatures{}) + comPatch, err := vm.Encode(patch, vm.AllFeatures{}) if err != nil { return nil, fmt.Errorf("error compiling patch: %v", err) } @@ -102,7 +102,7 @@ func (s *C.Synth) Release(voice int) { // Update func (s *C.Synth) Update(patch sointu.Patch) error { - comPatch, err := compiler.Encode(patch, compiler.AllFeatures{}) + comPatch, err := vm.Encode(patch, vm.AllFeatures{}) if err != nil { return fmt.Errorf("error compiling patch: %v", err) } diff --git a/bridge/bridge_test.go b/vm/compiler/bridge/bridge_test.go similarity index 98% rename from bridge/bridge_test.go rename to vm/compiler/bridge/bridge_test.go index 0bb8808..c4627b1 100644 --- a/bridge/bridge_test.go +++ b/vm/compiler/bridge/bridge_test.go @@ -14,7 +14,7 @@ import ( "testing" "github.com/vsariola/sointu" - "github.com/vsariola/sointu/bridge" + "github.com/vsariola/sointu/vm/compiler/bridge" "gopkg.in/yaml.v2" // TODO: test the song using a mocks instead ) @@ -78,7 +78,7 @@ func TestRenderSamples(t *testing.T) { func TestAllRegressionTests(t *testing.T) { _, myname, _, _ := runtime.Caller(0) - files, err := filepath.Glob(path.Join(path.Dir(myname), "..", "tests", "*.yml")) + files, err := filepath.Glob(path.Join(path.Dir(myname), "..", "..", "..", "tests", "*.yml")) if err != nil { t.Fatalf("cannot glob files in the test directory: %v", err) } @@ -217,7 +217,7 @@ func TestDivideByZero(t *testing.T) { func compareToRawFloat32(t *testing.T, buffer []float32, rawname string) { _, filename, _, _ := runtime.Caller(0) - expectedb, err := ioutil.ReadFile(path.Join(path.Dir(filename), "..", "tests", "expected_output", rawname)) + expectedb, err := ioutil.ReadFile(path.Join(path.Dir(filename), "..", "..", "..", "tests", "expected_output", rawname)) if err != nil { t.Fatalf("cannot read expected: %v", err) } diff --git a/bridge/init_windows.go b/vm/compiler/bridge/init_windows.go similarity index 100% rename from bridge/init_windows.go rename to vm/compiler/bridge/init_windows.go diff --git a/compiler/compiler.go b/vm/compiler/compiler.go similarity index 93% rename from compiler/compiler.go rename to vm/compiler/compiler.go index 42d4b31..f102061 100644 --- a/compiler/compiler.go +++ b/vm/compiler/compiler.go @@ -10,6 +10,7 @@ import ( "github.com/Masterminds/sprig" "github.com/vsariola/sointu" + "github.com/vsariola/sointu/vm" ) type Compiler struct { @@ -30,7 +31,7 @@ func New(os string, arch string, output16Bit bool) (*Compiler, error) { } else { return nil, fmt.Errorf("compiler.New failed, because only amd64, 386 and wasm archs are supported (targeted architecture was %v)", arch) } - templateDir := filepath.Join(path.Dir(myname), "..", "templates", subdir) + templateDir := filepath.Join(path.Dir(myname), "..", "..", "templates", subdir) compiler, err := NewFromTemplates(os, arch, output16Bit, templateDir) return compiler, err } @@ -49,7 +50,7 @@ func (com *Compiler) Library() (map[string]string, error) { return nil, fmt.Errorf(`compiling as a library is supported only on 386 and amd64 architectures (targeted architecture was %v)`, com.Arch) } templates := []string{"library.asm", "library.h"} - features := AllFeatures{} + features := vm.AllFeatures{} retmap := map[string]string{} for _, templateName := range templates { compilerMacros := *NewCompilerMacros(*com) @@ -80,13 +81,13 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) { } else if com.Arch == "wasm" { templates = []string{"player.wat"} } - features := NecessaryFeaturesFor(song.Patch) + features := vm.NecessaryFeaturesFor(song.Patch) retmap := map[string]string{} - encodedPatch, err := Encode(song.Patch, features) + encodedPatch, err := vm.Encode(song.Patch, features) if err != nil { return nil, fmt.Errorf(`could not encode patch: %v`, err) } - patterns, sequences, err := ConstructPatterns(song) + patterns, sequences, err := vm.ConstructPatterns(song) if err != nil { return nil, fmt.Errorf(`could not encode song: %v`, err) } @@ -103,7 +104,7 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) { FeatureSetMacros X86Macros SongMacros - *EncodedPatch + *vm.BytePatch Patterns [][]byte Sequences [][]byte PatternLength int @@ -118,7 +119,7 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) { FeatureSetMacros WasmMacros SongMacros - *EncodedPatch + *vm.BytePatch Patterns [][]byte Sequences [][]byte PatternLength int diff --git a/compiler/compiler_macros.go b/vm/compiler/compiler_macros.go similarity index 100% rename from compiler/compiler_macros.go rename to vm/compiler/compiler_macros.go diff --git a/compiler/featureset_macros.go b/vm/compiler/featureset_macros.go similarity index 91% rename from compiler/featureset_macros.go rename to vm/compiler/featureset_macros.go index c1f460c..a018372 100644 --- a/compiler/featureset_macros.go +++ b/vm/compiler/featureset_macros.go @@ -1,7 +1,9 @@ package compiler +import "github.com/vsariola/sointu/vm" + type FeatureSetMacros struct { - FeatureSet + vm.FeatureSet } func (p *FeatureSetMacros) HasOp(instruction string) bool { diff --git a/compiler/song_macros.go b/vm/compiler/song_macros.go similarity index 100% rename from compiler/song_macros.go rename to vm/compiler/song_macros.go diff --git a/compiler/wasm_macros.go b/vm/compiler/wasm_macros.go similarity index 100% rename from compiler/wasm_macros.go rename to vm/compiler/wasm_macros.go diff --git a/compiler/x86_macros.go b/vm/compiler/x86_macros.go similarity index 98% rename from compiler/x86_macros.go rename to vm/compiler/x86_macros.go index 32acc8d..88f0656 100644 --- a/compiler/x86_macros.go +++ b/vm/compiler/x86_macros.go @@ -4,6 +4,8 @@ import ( "fmt" "math" "strings" + + "github.com/vsariola/sointu/vm" ) type X86Macros struct { @@ -17,10 +19,10 @@ type X86Macros struct { intConsts []int calls map[string]bool stackframes map[string][]string - features FeatureSet + features vm.FeatureSet } -func NewX86Macros(os string, Amd64 bool, features FeatureSet, DisableSections bool) *X86Macros { +func NewX86Macros(os string, Amd64 bool, features vm.FeatureSet, DisableSections bool) *X86Macros { return &X86Macros{ calls: map[string]bool{}, usesFloatConst: map[float32]bool{}, diff --git a/compiler/featureset.go b/vm/featureset.go similarity index 99% rename from compiler/featureset.go rename to vm/featureset.go index b9425b9..8b38817 100644 --- a/compiler/featureset.go +++ b/vm/featureset.go @@ -1,4 +1,4 @@ -package compiler +package vm import ( "sort" diff --git a/compiler/patterns.go b/vm/patterns.go similarity index 99% rename from compiler/patterns.go rename to vm/patterns.go index 68a0447..cf400c8 100644 --- a/compiler/patterns.go +++ b/vm/patterns.go @@ -1,4 +1,4 @@ -package compiler +package vm import ( "errors" diff --git a/compiler/patterns_test.go b/vm/patterns_test.go similarity index 91% rename from compiler/patterns_test.go rename to vm/patterns_test.go index f808c69..6b1c321 100644 --- a/compiler/patterns_test.go +++ b/vm/patterns_test.go @@ -1,11 +1,11 @@ -package compiler_test +package vm_test import ( "reflect" "testing" "github.com/vsariola/sointu" - "github.com/vsariola/sointu/compiler" + "github.com/vsariola/sointu/vm" ) func TestPatternReusing(t *testing.T) { @@ -21,7 +21,7 @@ func TestPatternReusing(t *testing.T) { }}, }, } - patterns, sequences, err := compiler.ConstructPatterns(&song) + patterns, sequences, err := vm.ConstructPatterns(&song) if err != nil { t.Fatalf("erorr constructing patterns: %v", err) } @@ -47,7 +47,7 @@ func TestUnnecessaryHolds(t *testing.T) { Order: []int{0, 1}, }}}, } - patterns, sequences, err := compiler.ConstructPatterns(&song) + patterns, sequences, err := vm.ConstructPatterns(&song) if err != nil { t.Fatalf("erorr constructing patterns: %v", err) } @@ -75,7 +75,7 @@ func TestDontCares(t *testing.T) { }}, }, } - patterns, sequences, err := compiler.ConstructPatterns(&song) + patterns, sequences, err := vm.ConstructPatterns(&song) if err != nil { t.Fatalf("erorr constructing patterns: %v", err) }