-
Notifications
You must be signed in to change notification settings - Fork 6
/
concurrentcall.go
51 lines (40 loc) · 1.01 KB
/
concurrentcall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ast
import (
"errors"
"fmt"
"strings"
"github.com/NicoNex/tau/internal/code"
"github.com/NicoNex/tau/internal/compiler"
"github.com/NicoNex/tau/internal/obj"
)
type ConcurrentCall struct {
fn Node
args []Node
}
func NewConcurrentCall(fn Node, args []Node) Node {
return ConcurrentCall{fn, args}
}
func (c ConcurrentCall) Eval() (obj.Object, error) {
return obj.NullObj, errors.New("ast.ConcurrentCall: not a constant expression")
}
func (c ConcurrentCall) String() string {
var args = make([]string, len(c.args))
for i, a := range c.args {
args[i] = a.String()
}
return fmt.Sprintf("tau %v(%s)", c.fn, strings.Join(args, ", "))
}
func (c ConcurrentCall) Compile(comp *compiler.Compiler) (position int, err error) {
if position, err = c.fn.Compile(comp); err != nil {
return
}
for _, a := range c.args {
if position, err = a.Compile(comp); err != nil {
return
}
}
return comp.Emit(code.OpConcurrentCall, len(c.args)), nil
}
func (ConcurrentCall) IsConstExpression() bool {
return false
}