diff --git a/src/build/Build.go b/src/build/Build.go index 64e1190..9d969ba 100644 --- a/src/build/Build.go +++ b/src/build/Build.go @@ -1,14 +1,5 @@ package build -import ( - "path/filepath" - "strings" - - "git.akyoto.dev/cli/q/src/compiler" - "git.akyoto.dev/cli/q/src/config" - "git.akyoto.dev/cli/q/src/scanner" -) - // Build describes a compiler build. type Build struct { Files []string @@ -20,36 +11,3 @@ func New(files ...string) *Build { Files: files, } } - -// Run compiles the input files. -func (build *Build) Run() (compiler.Result, error) { - constants, files, functions, structs, errors := scanner.Scan(build.Files) - return compiler.Compile(constants, files, functions, structs, errors) -} - -// Executable returns the path to the executable. -func (build *Build) Executable() string { - path, _ := filepath.Abs(build.Files[0]) - - if strings.HasSuffix(path, ".q") { - path = fromFileName(path) - } else { - path = fromDirectoryName(path) - } - - if config.TargetOS == config.Windows { - path += ".exe" - } - - return path -} - -// fromDirectoryName returns the executable path based on the directory name. -func fromDirectoryName(path string) string { - return filepath.Join(path, filepath.Base(path)) -} - -// fromFileName returns the executable path based on the file name. -func fromFileName(path string) string { - return filepath.Join(filepath.Dir(path), strings.TrimSuffix(filepath.Base(path), ".q")) -} diff --git a/src/build/Executable.go b/src/build/Executable.go new file mode 100644 index 0000000..4eff03e --- /dev/null +++ b/src/build/Executable.go @@ -0,0 +1,35 @@ +package build + +import ( + "path/filepath" + "strings" + + "git.akyoto.dev/cli/q/src/config" +) + +// Executable returns the path to the executable. +func (build *Build) Executable() string { + path, _ := filepath.Abs(build.Files[0]) + + if strings.HasSuffix(path, ".q") { + path = fromFileName(path) + } else { + path = fromDirectoryName(path) + } + + if config.TargetOS == config.Windows { + path += ".exe" + } + + return path +} + +// fromDirectoryName returns the executable path based on the directory name. +func fromDirectoryName(path string) string { + return filepath.Join(path, filepath.Base(path)) +} + +// fromFileName returns the executable path based on the file name. +func fromFileName(path string) string { + return filepath.Join(filepath.Dir(path), strings.TrimSuffix(filepath.Base(path), ".q")) +} diff --git a/src/build/Run.go b/src/build/Run.go new file mode 100644 index 0000000..bbc06d8 --- /dev/null +++ b/src/build/Run.go @@ -0,0 +1,12 @@ +package build + +import ( + "git.akyoto.dev/cli/q/src/compiler" + "git.akyoto.dev/cli/q/src/scanner" +) + +// Run compiles the input files. +func (build *Build) Run() (compiler.Result, error) { + constants, files, functions, structs, errors := scanner.Scan(build.Files) + return compiler.Compile(constants, files, functions, structs, errors) +} diff --git a/src/core/CreateLabel.go b/src/core/CreateLabel.go index 2e874ac..5342638 100644 --- a/src/core/CreateLabel.go +++ b/src/core/CreateLabel.go @@ -6,7 +6,7 @@ import ( ) // CreateLabel creates a label that is tied to this function by using a suffix. -func (f *Function) CreateLabel(prefix string, count uint16) string { +func (f *Function) CreateLabel(prefix string, count counter) string { tmp := strings.Builder{} tmp.WriteString(prefix) tmp.WriteString(" ") diff --git a/src/core/count.go b/src/core/count.go index f200d7e..5d793fc 100644 --- a/src/core/count.go +++ b/src/core/count.go @@ -1,6 +1,6 @@ package core -type counter = uint16 +type counter = uint8 // count stores how often a certain statement appeared so we can generate a unique label from it. type count struct { diff --git a/src/readme.md b/src/readme.md index 1716ab7..3dc207b 100644 --- a/src/readme.md +++ b/src/readme.md @@ -26,3 +26,12 @@ - [token](token) - Converts a file to tokens with the `Tokenize` function - [types](types) - Type system - [x86](x86) - x86-64 implementation + +## Typical flow + +1. [main](../main.go) +1. [cli.Main](cli/Main.go) +1. [build.Run](build/Run.go) +1. [scanner.Scan](scanner/Scan.go) +1. [compiler.Compile](compiler/Compile.go) +1. [compiler.WriteFile](compiler/WriteFile.go) \ No newline at end of file