Implemented directory walk
This commit is contained in:
parent
0fe419da86
commit
886ea27d54
13 changed files with 100 additions and 20 deletions
|
@ -5,9 +5,12 @@ import (
|
|||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.akyoto.dev/cli/q/build/elf"
|
||||
"git.akyoto.dev/cli/q/cli/log"
|
||||
"git.akyoto.dev/cli/q/directory"
|
||||
"git.akyoto.dev/cli/q/elf"
|
||||
"git.akyoto.dev/cli/q/errors"
|
||||
"git.akyoto.dev/cli/q/log"
|
||||
)
|
||||
|
||||
// Build describes a compiler build.
|
||||
|
@ -43,29 +46,25 @@ func (build *Build) Run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Executable returns the path to the executable.
|
||||
func (build *Build) Executable() string {
|
||||
return filepath.Join(build.Directory, build.Name)
|
||||
}
|
||||
|
||||
// Compile compiles all the functions.
|
||||
func (build *Build) Compile() error {
|
||||
file, err := os.Open(build.Directory)
|
||||
stat, err := os.Stat(build.Directory)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
files, err := file.Readdirnames(0)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
if !stat.IsDir() {
|
||||
return &errors.InvalidDirectory{Path: build.Directory}
|
||||
}
|
||||
|
||||
for _, name := range files {
|
||||
log.Info.Println(name)
|
||||
}
|
||||
directory.Walk(build.Directory, func(file string) {
|
||||
if !strings.HasSuffix(file, ".q") {
|
||||
return
|
||||
}
|
||||
|
||||
log.Info.Println(file)
|
||||
})
|
||||
|
||||
build.Code.Write([]byte{
|
||||
0xb8, 0x01, 0x00, 0x00, 0x00, // mov eax, 1
|
||||
|
@ -83,6 +82,11 @@ func (build *Build) Compile() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Executable returns the path to the executable.
|
||||
func (build *Build) Executable() string {
|
||||
return filepath.Join(build.Directory, build.Name)
|
||||
}
|
||||
|
||||
// writeToDisk writes the executable file to disk.
|
||||
func writeToDisk(filePath string, code []byte, data []byte) error {
|
||||
file, err := os.Create(filePath)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue