diff --git a/vm/compiler/compiler.go b/vm/compiler/compiler.go index 23bcd8f..87bf3a9 100644 --- a/vm/compiler/compiler.go +++ b/vm/compiler/compiler.go @@ -2,10 +2,9 @@ package compiler import ( "bytes" + "embed" "fmt" - "path" "path/filepath" - "runtime" "text/template" "github.com/Masterminds/sprig" @@ -21,9 +20,11 @@ type Compiler struct { RowSync bool } +//go:embed templates/amd64-386/* templates/wasm/* +var templateFS embed.FS + // New returns a new compiler using the default .asm templates func New(os string, arch string, output16Bit bool, rowsync bool) (*Compiler, error) { - _, myname, _, _ := runtime.Caller(0) var subdir string if arch == "386" || arch == "amd64" { subdir = "amd64-386" @@ -32,9 +33,11 @@ func New(os string, arch string, output16Bit bool, rowsync bool) (*Compiler, err } 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) - compiler, err := NewFromTemplates(os, arch, output16Bit, rowsync, templateDir) - return compiler, err + tmpl, err := template.New("base").Funcs(sprig.TxtFuncMap()).ParseFS(templateFS, "templates/"+subdir+"/*.*") + if err != nil { + return nil, fmt.Errorf(`could not create templates: %v`, err) + } + return &Compiler{Template: tmpl, OS: os, Arch: arch, RowSync: rowsync, Output16Bit: output16Bit}, nil } func NewFromTemplates(os string, arch string, output16Bit bool, rowsync bool, templateDirectory string) (*Compiler, error) { diff --git a/templates/amd64-386/arithmetic.asm b/vm/compiler/templates/amd64-386/arithmetic.asm similarity index 100% rename from templates/amd64-386/arithmetic.asm rename to vm/compiler/templates/amd64-386/arithmetic.asm diff --git a/templates/amd64-386/effects.asm b/vm/compiler/templates/amd64-386/effects.asm similarity index 100% rename from templates/amd64-386/effects.asm rename to vm/compiler/templates/amd64-386/effects.asm diff --git a/templates/amd64-386/flowcontrol.asm b/vm/compiler/templates/amd64-386/flowcontrol.asm similarity index 100% rename from templates/amd64-386/flowcontrol.asm rename to vm/compiler/templates/amd64-386/flowcontrol.asm diff --git a/templates/amd64-386/gmdls.asm b/vm/compiler/templates/amd64-386/gmdls.asm similarity index 100% rename from templates/amd64-386/gmdls.asm rename to vm/compiler/templates/amd64-386/gmdls.asm diff --git a/templates/amd64-386/library.asm b/vm/compiler/templates/amd64-386/library.asm similarity index 100% rename from templates/amd64-386/library.asm rename to vm/compiler/templates/amd64-386/library.asm diff --git a/templates/amd64-386/library.h b/vm/compiler/templates/amd64-386/library.h similarity index 100% rename from templates/amd64-386/library.h rename to vm/compiler/templates/amd64-386/library.h diff --git a/templates/amd64-386/output_sound.asm b/vm/compiler/templates/amd64-386/output_sound.asm similarity index 100% rename from templates/amd64-386/output_sound.asm rename to vm/compiler/templates/amd64-386/output_sound.asm diff --git a/templates/amd64-386/patch.asm b/vm/compiler/templates/amd64-386/patch.asm similarity index 100% rename from templates/amd64-386/patch.asm rename to vm/compiler/templates/amd64-386/patch.asm diff --git a/templates/amd64-386/player.asm b/vm/compiler/templates/amd64-386/player.asm similarity index 100% rename from templates/amd64-386/player.asm rename to vm/compiler/templates/amd64-386/player.asm diff --git a/templates/amd64-386/player.h b/vm/compiler/templates/amd64-386/player.h similarity index 100% rename from templates/amd64-386/player.h rename to vm/compiler/templates/amd64-386/player.h diff --git a/templates/amd64-386/sinks.asm b/vm/compiler/templates/amd64-386/sinks.asm similarity index 100% rename from templates/amd64-386/sinks.asm rename to vm/compiler/templates/amd64-386/sinks.asm diff --git a/templates/amd64-386/sources.asm b/vm/compiler/templates/amd64-386/sources.asm similarity index 100% rename from templates/amd64-386/sources.asm rename to vm/compiler/templates/amd64-386/sources.asm diff --git a/templates/amd64-386/structs.asm b/vm/compiler/templates/amd64-386/structs.asm similarity index 100% rename from templates/amd64-386/structs.asm rename to vm/compiler/templates/amd64-386/structs.asm diff --git a/templates/wasm/arithmetic.wat b/vm/compiler/templates/wasm/arithmetic.wat similarity index 100% rename from templates/wasm/arithmetic.wat rename to vm/compiler/templates/wasm/arithmetic.wat diff --git a/templates/wasm/effects.wat b/vm/compiler/templates/wasm/effects.wat similarity index 100% rename from templates/wasm/effects.wat rename to vm/compiler/templates/wasm/effects.wat diff --git a/templates/wasm/output_sound.wat b/vm/compiler/templates/wasm/output_sound.wat similarity index 100% rename from templates/wasm/output_sound.wat rename to vm/compiler/templates/wasm/output_sound.wat diff --git a/templates/wasm/patch.wat b/vm/compiler/templates/wasm/patch.wat similarity index 100% rename from templates/wasm/patch.wat rename to vm/compiler/templates/wasm/patch.wat diff --git a/templates/wasm/player.wat b/vm/compiler/templates/wasm/player.wat similarity index 100% rename from templates/wasm/player.wat rename to vm/compiler/templates/wasm/player.wat diff --git a/templates/wasm/sinks.wat b/vm/compiler/templates/wasm/sinks.wat similarity index 100% rename from templates/wasm/sinks.wat rename to vm/compiler/templates/wasm/sinks.wat diff --git a/templates/wasm/sources.wat b/vm/compiler/templates/wasm/sources.wat similarity index 100% rename from templates/wasm/sources.wat rename to vm/compiler/templates/wasm/sources.wat