From e28891abd5960d5960b4d030c4c5c09dea9028f7 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:38:18 +0300 Subject: [PATCH] refactor: move ConstructPatterns into compiler package ConstructPatterns was never used except during compilation, so it makes sense to have it closer where it is used. We could consider making it even private function, as the pattern table construction is quite specific to how compiler compiles and probably not that reusable elsewhere. --- vm/compiler/compiler.go | 2 +- vm/{ => compiler}/patterns.go | 2 +- vm/{ => compiler}/patterns_test.go | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) rename vm/{ => compiler}/patterns.go (99%) rename vm/{ => compiler}/patterns_test.go (92%) diff --git a/vm/compiler/compiler.go b/vm/compiler/compiler.go index 8269a39..f6a8faf 100644 --- a/vm/compiler/compiler.go +++ b/vm/compiler/compiler.go @@ -91,7 +91,7 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) { if err != nil { return nil, fmt.Errorf(`could not encode patch: %v`, err) } - patterns, sequences, err := vm.ConstructPatterns(song) + patterns, sequences, err := ConstructPatterns(song) if err != nil { return nil, fmt.Errorf(`could not encode song: %v`, err) } diff --git a/vm/patterns.go b/vm/compiler/patterns.go similarity index 99% rename from vm/patterns.go rename to vm/compiler/patterns.go index 671cbce..ad1942e 100644 --- a/vm/patterns.go +++ b/vm/compiler/patterns.go @@ -1,4 +1,4 @@ -package vm +package compiler import ( "errors" diff --git a/vm/patterns_test.go b/vm/compiler/patterns_test.go similarity index 92% rename from vm/patterns_test.go rename to vm/compiler/patterns_test.go index e59223d..d5c9c6f 100644 --- a/vm/patterns_test.go +++ b/vm/compiler/patterns_test.go @@ -1,11 +1,11 @@ -package vm_test +package compiler_test import ( "reflect" "testing" "github.com/vsariola/sointu" - "github.com/vsariola/sointu/vm" + "github.com/vsariola/sointu/vm/compiler" ) func TestPatternReusing(t *testing.T) { @@ -22,7 +22,7 @@ func TestPatternReusing(t *testing.T) { }}, }, } - patterns, sequences, err := vm.ConstructPatterns(&song) + patterns, sequences, err := compiler.ConstructPatterns(&song) if err != nil { t.Fatalf("erorr constructing patterns: %v", err) } @@ -49,7 +49,7 @@ func TestUnnecessaryHolds(t *testing.T) { Order: []int{0, 1}, }}}, } - patterns, sequences, err := vm.ConstructPatterns(&song) + patterns, sequences, err := compiler.ConstructPatterns(&song) if err != nil { t.Fatalf("erorr constructing patterns: %v", err) } @@ -77,7 +77,7 @@ func TestDontCares(t *testing.T) { }}, }, } - patterns, sequences, err := vm.ConstructPatterns(&song) + patterns, sequences, err := compiler.ConstructPatterns(&song) if err != nil { t.Fatalf("erorr constructing patterns: %v", err) }