reorganize things into different packages

This commit is contained in:
vsariola 2021-03-02 17:19:45 +02:00
parent e46ece3648
commit a035845b81
19 changed files with 43 additions and 38 deletions

View File

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

View File

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

View File

@ -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() {

View File

@ -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() {

View File

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

View File

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

View File

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

View File

@ -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 <sointu.h>
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)
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
package compiler
package vm
import (
"sort"

View File

@ -1,4 +1,4 @@
package compiler
package vm
import (
"errors"

View File

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