Improved tokenizer
This commit is contained in:
40
src/compiler/Compile.go
Normal file
40
src/compiler/Compile.go
Normal file
@ -0,0 +1,40 @@
|
||||
package compiler
|
||||
|
||||
import "sync"
|
||||
|
||||
// Compile compiles all the functions.
|
||||
func Compile(directory string) (map[string]*Function, error) {
|
||||
functions, errors := Scan(directory)
|
||||
wg := sync.WaitGroup{}
|
||||
allFunctions := map[string]*Function{}
|
||||
|
||||
for functions != nil || errors != nil {
|
||||
select {
|
||||
case err, ok := <-errors:
|
||||
if !ok {
|
||||
errors = nil
|
||||
continue
|
||||
}
|
||||
|
||||
return nil, err
|
||||
|
||||
case function, ok := <-functions:
|
||||
if !ok {
|
||||
functions = nil
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
function.Compile()
|
||||
}()
|
||||
|
||||
allFunctions[function.Name] = function
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return allFunctions, nil
|
||||
}
|
Reference in New Issue
Block a user