Improved tokenizer
This commit is contained in:
parent
8549aedc60
commit
8de28852cd
10 changed files with 57 additions and 53 deletions
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue