Refactored code structure
This commit is contained in:
parent
9e52e2dd1c
commit
fd6e874b44
54 changed files with 583 additions and 450 deletions
|
@ -9,22 +9,21 @@ import (
|
|||
"git.akyoto.dev/cli/q/src/build/config"
|
||||
)
|
||||
|
||||
// Build builds an executable.
|
||||
// Build parses the arguments and creates a build.
|
||||
func Build(args []string) int {
|
||||
b := build.New()
|
||||
dry := false
|
||||
|
||||
for i := 0; i < len(args); i++ {
|
||||
switch args[i] {
|
||||
case "--dry":
|
||||
dry = true
|
||||
|
||||
case "--assembler", "-a":
|
||||
case "-a", "--assembler":
|
||||
config.Assembler = true
|
||||
|
||||
case "--verbose", "-v":
|
||||
config.Verbose = true
|
||||
|
||||
case "-c", "--comments":
|
||||
config.Comments = true
|
||||
case "-d", "--dry":
|
||||
config.Dry = true
|
||||
case "-v", "--verbose":
|
||||
config.Assembler = true
|
||||
config.Comments = true
|
||||
default:
|
||||
if strings.HasPrefix(args[i], "-") {
|
||||
fmt.Printf("Unknown parameter: %s\n", args[i])
|
||||
|
@ -39,6 +38,11 @@ func Build(args []string) int {
|
|||
b.Files = append(b.Files, ".")
|
||||
}
|
||||
|
||||
return run(b)
|
||||
}
|
||||
|
||||
// run starts the build by running the compiler and then writing the result to disk.
|
||||
func run(b *build.Build) int {
|
||||
result, err := b.Run()
|
||||
|
||||
if err != nil {
|
||||
|
@ -47,12 +51,10 @@ func Build(args []string) int {
|
|||
}
|
||||
|
||||
if config.Assembler {
|
||||
result.EachFunction(result.Main, map[*build.Function]bool{}, func(f *build.Function) {
|
||||
f.PrintInstructions()
|
||||
})
|
||||
result.PrintInstructions()
|
||||
}
|
||||
|
||||
if dry {
|
||||
if config.Dry {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ func Help(w io.Writer, code int) int {
|
|||
build options:
|
||||
|
||||
--assembler, -a Show assembler instructions.
|
||||
--verbose, -v Show verbose output.`)
|
||||
--comments, -c Show assembler comments.
|
||||
--verbose, -v Show everything.`)
|
||||
return code
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue