Add goroutines

This commit is contained in:
Elara 2021-04-05 11:28:47 -07:00
parent e5b8521ba4
commit 836149ffc2
2 changed files with 31 additions and 19 deletions

12
ast.go
View File

@ -268,6 +268,12 @@ func executeCmd(cmd *Command) error {
return fmt.Errorf("%s: %s", Call.Pos, err) return fmt.Errorf("%s: %s", Call.Pos, err)
} }
} }
} else if cmd.Goroutines != nil {
// For each function call
for _, goroutine := range cmd.Goroutines {
// Attempt to call function
go CallFunction(goroutine.Call)
}
} else if cmd.Ifs != nil { } else if cmd.Ifs != nil {
// For each if statement // For each if statement
for _, If := range cmd.Ifs { for _, If := range cmd.Ifs {
@ -316,6 +322,7 @@ type Command struct {
RptLoops []*RptLoop `| @@` RptLoops []*RptLoop `| @@`
WhlLoops []*WhlLoop `| @@` WhlLoops []*WhlLoop `| @@`
Defs []*FuncDef `| @@` Defs []*FuncDef `| @@`
Goroutines []*Goroutine `| @@`
Calls []*FuncCall `| @@ )` Calls []*FuncCall `| @@ )`
} }
@ -352,6 +359,11 @@ type FuncCall struct {
Args []*Arg `@@*` Args []*Arg `@@*`
} }
type Goroutine struct {
Pos lexer.Position
Call *FuncCall `"go" @@`
}
// Arg stores arguments for function calls // Arg stores arguments for function calls
type Arg struct { type Arg struct {
Pos lexer.Position Pos lexer.Position