Updated documentation
This commit is contained in:
parent
264872e638
commit
7598411c8f
@ -1,14 +1,5 @@
|
|||||||
package build
|
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.
|
// Build describes a compiler build.
|
||||||
type Build struct {
|
type Build struct {
|
||||||
Files []string
|
Files []string
|
||||||
@ -20,36 +11,3 @@ func New(files ...string) *Build {
|
|||||||
Files: files,
|
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"))
|
|
||||||
}
|
|
||||||
|
35
src/build/Executable.go
Normal file
35
src/build/Executable.go
Normal file
@ -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"))
|
||||||
|
}
|
12
src/build/Run.go
Normal file
12
src/build/Run.go
Normal file
@ -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)
|
||||||
|
}
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CreateLabel creates a label that is tied to this function by using a suffix.
|
// 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 := strings.Builder{}
|
||||||
tmp.WriteString(prefix)
|
tmp.WriteString(prefix)
|
||||||
tmp.WriteString(" ")
|
tmp.WriteString(" ")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package core
|
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.
|
// count stores how often a certain statement appeared so we can generate a unique label from it.
|
||||||
type count struct {
|
type count struct {
|
||||||
|
@ -26,3 +26,12 @@
|
|||||||
- [token](token) - Converts a file to tokens with the `Tokenize` function
|
- [token](token) - Converts a file to tokens with the `Tokenize` function
|
||||||
- [types](types) - Type system
|
- [types](types) - Type system
|
||||||
- [x86](x86) - x86-64 implementation
|
- [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)
|
Loading…
x
Reference in New Issue
Block a user