diff --git a/src/scanner/Scan.go b/src/scanner/Scan.go index 2a8fe26..ab9a606 100644 --- a/src/scanner/Scan.go +++ b/src/scanner/Scan.go @@ -13,14 +13,8 @@ import ( // Scan scans all the files included in the build. func Scan(build *config.Build) (*core.Environment, error) { s := scanner{ - constants: make(chan *core.Constant, 128), - enums: make(chan *types.Enum, 128), - functions: make(chan *core.Function, 128), - files: make(chan *fs.File, 128), - structs: make(chan *types.Struct, 128), - globals: make(chan *core.Global, 128), - errors: make(chan error), - build: build, + items: make(chan any, 512), + build: build, } go func() { @@ -28,74 +22,27 @@ func Scan(build *config.Build) (*core.Environment, error) { s.queueDirectory(filepath.Join(global.Library, "strings"), "strings") s.queue(build.Files...) s.group.Wait() - close(s.constants) - close(s.enums) - close(s.functions) - close(s.files) - close(s.structs) - close(s.globals) - close(s.errors) + close(s.items) }() env := core.NewEnvironment(build) - for s.functions != nil || s.files != nil || s.structs != nil || s.constants != nil || s.enums != nil || s.globals != nil || s.errors != nil { - select { - case f, ok := <-s.functions: - if !ok { - s.functions = nil - continue - } - - env.ReceiveFunction(f) - - case file, ok := <-s.files: - if !ok { - s.files = nil - continue - } - - env.ReceiveFile(file) - - case structure, ok := <-s.structs: - if !ok { - s.structs = nil - continue - } - - env.ReceiveStruct(structure) - - case constant, ok := <-s.constants: - if !ok { - s.constants = nil - continue - } - - env.ReceiveConstant(constant) - - case enum, ok := <-s.enums: - if !ok { - s.enums = nil - continue - } - - env.ReceiveEnum(enum) - - case global, ok := <-s.globals: - if !ok { - s.globals = nil - continue - } - - env.ReceiveGlobal(global) - - case err, ok := <-s.errors: - if !ok { - s.errors = nil - continue - } - - return env, err + for item := range s.items { + switch v := item.(type) { + case *core.Function: + env.ReceiveFunction(v) + case *fs.File: + env.ReceiveFile(v) + case *types.Struct: + env.ReceiveStruct(v) + case *core.Constant: + env.ReceiveConstant(v) + case *types.Enum: + env.ReceiveEnum(v) + case *core.Global: + env.ReceiveGlobal(v) + case error: + return env, v } } diff --git a/src/scanner/queue.go b/src/scanner/queue.go index 63a28ac..9e6e8b5 100644 --- a/src/scanner/queue.go +++ b/src/scanner/queue.go @@ -8,7 +8,7 @@ func (s *scanner) queue(files ...string) { stat, err := os.Stat(file) if err != nil { - s.errors <- err + s.items <- err return } diff --git a/src/scanner/queueDirectory.go b/src/scanner/queueDirectory.go index 8f7eea9..eabda03 100644 --- a/src/scanner/queueDirectory.go +++ b/src/scanner/queueDirectory.go @@ -62,6 +62,6 @@ func (s *scanner) queueDirectory(directory string, pkg string) { }) if err != nil { - s.errors <- err + s.items <- err } } \ No newline at end of file diff --git a/src/scanner/queueFile.go b/src/scanner/queueFile.go index 03e1744..9c53510 100644 --- a/src/scanner/queueFile.go +++ b/src/scanner/queueFile.go @@ -6,7 +6,7 @@ func (s *scanner) queueFile(file string, pkg string) { err := s.scanFile(file, pkg) if err != nil { - s.errors <- err + s.items <- err } }) } \ No newline at end of file diff --git a/src/scanner/scanConst.go b/src/scanner/scanConst.go index fe77feb..271bc76 100644 --- a/src/scanner/scanConst.go +++ b/src/scanner/scanConst.go @@ -58,7 +58,7 @@ func (s *scanner) scanConst(file *fs.File, tokens token.List, i int) (int, error return i, errors.New(InvalidExpression, file, valueTokens) } - s.constants <- &core.Constant{ + s.items <- &core.Constant{ Name: name, File: file, Value: value, diff --git a/src/scanner/scanEnum.go b/src/scanner/scanEnum.go index d05c29d..5491731 100644 --- a/src/scanner/scanEnum.go +++ b/src/scanner/scanEnum.go @@ -64,7 +64,7 @@ func (s *scanner) scanEnum(file *fs.File, tokens token.List, i int) (int, error) } if tokens[i].Kind == token.BlockEnd { - s.enums <- enum + s.items <- enum return i, nil } diff --git a/src/scanner/scanExtern.go b/src/scanner/scanExtern.go index 3201caf..a9a52df 100644 --- a/src/scanner/scanExtern.go +++ b/src/scanner/scanExtern.go @@ -55,7 +55,7 @@ func (s *scanner) scanExternLibrary(file *fs.File, tokens token.List, i int) (in } i = j - s.functions <- function + s.items <- function case token.BlockEnd: return i, nil diff --git a/src/scanner/scanFile.go b/src/scanner/scanFile.go index 0362603..1df0c4e 100644 --- a/src/scanner/scanFile.go +++ b/src/scanner/scanFile.go @@ -15,7 +15,7 @@ func (s *scanner) scanFile(path string, pkg string) error { } file := fs.NewFile(path, pkg, contents) - s.files <- file + s.items <- file tokens := file.Tokens for i := 0; i < len(tokens); i++ { diff --git a/src/scanner/scanFunction.go b/src/scanner/scanFunction.go index 70914d6..203dd0b 100644 --- a/src/scanner/scanFunction.go +++ b/src/scanner/scanFunction.go @@ -20,6 +20,6 @@ func (s *scanner) scanFunction(file *fs.File, tokens token.List, i int) (int, er } function.SetBody(bodyStart, i) - s.functions <- function + s.items <- function return i, nil } \ No newline at end of file diff --git a/src/scanner/scanGlobal.go b/src/scanner/scanGlobal.go index ff739de..49bc5b7 100644 --- a/src/scanner/scanGlobal.go +++ b/src/scanner/scanGlobal.go @@ -35,7 +35,7 @@ func (s *scanner) scanGlobal(file *fs.File, tokens token.List, i int) (int, erro ThreadLocal: threadLocal, } - s.globals <- global + s.items <- global } if tokens[i].Kind == token.BlockEnd { diff --git a/src/scanner/scanStruct.go b/src/scanner/scanStruct.go index e70a971..8c21954 100644 --- a/src/scanner/scanStruct.go +++ b/src/scanner/scanStruct.go @@ -38,7 +38,7 @@ func (s *scanner) scanStruct(file *fs.File, tokens token.List, i int) (int, erro } if tokens[i].Kind == token.BlockEnd { - s.structs <- structure + s.items <- structure return i, nil } diff --git a/src/scanner/scanner.go b/src/scanner/scanner.go index a6a1379..82bd21a 100644 --- a/src/scanner/scanner.go +++ b/src/scanner/scanner.go @@ -4,21 +4,12 @@ import ( "sync" "git.urbach.dev/cli/q/src/config" - "git.urbach.dev/cli/q/src/core" - "git.urbach.dev/cli/q/src/fs" - "git.urbach.dev/cli/q/src/types" ) // scanner is used to scan files before the actual compilation step. type scanner struct { - constants chan *core.Constant - enums chan *types.Enum - functions chan *core.Function - files chan *fs.File - structs chan *types.Struct - globals chan *core.Global - errors chan error - build *config.Build - queued sync.Map - group sync.WaitGroup + items chan any + build *config.Build + queued sync.Map + group sync.WaitGroup } \ No newline at end of file