36 lines
715 B
Go
36 lines
715 B
Go
package build
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// Build describes a compiler build.
|
|
type Build struct {
|
|
Files []string
|
|
}
|
|
|
|
// New creates a new build.
|
|
func New(files ...string) *Build {
|
|
return &Build{
|
|
Files: files,
|
|
}
|
|
}
|
|
|
|
// Run parses the input files and generates an executable file.
|
|
func (build *Build) Run() (map[string]*Function, error) {
|
|
functions, errors := Scan(build.Files)
|
|
return Compile(functions, errors)
|
|
}
|
|
|
|
// Executable returns the path to the executable.
|
|
func (build *Build) Executable() string {
|
|
directory, _ := filepath.Abs(build.Files[0])
|
|
|
|
if strings.HasSuffix(directory, ".q") {
|
|
directory = filepath.Dir(directory)
|
|
}
|
|
|
|
return filepath.Join(directory, filepath.Base(directory))
|
|
}
|