-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.go
34 lines (26 loc) · 888 Bytes
/
app.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
package ir
import (
"github.com/cloe-lang/cloe/src/lib/core"
"github.com/cloe-lang/cloe/src/lib/debug"
)
// App represents an application of a function to arguments.
type App struct {
function interface{}
args Arguments
info *debug.Info
}
// NewApp creates an App from a function and arguments of expressions in IR.
func NewApp(f interface{}, args Arguments, info *debug.Info) App {
return App{f, args, info}
}
func (app App) interpret(args []core.Value) core.Value {
ps := make([]core.PositionalArgument, 0, len(app.args.positionals))
for _, p := range app.args.positionals {
ps = append(ps, p.interpret(args))
}
ks := make([]core.KeywordArgument, 0, len(app.args.keywords))
for _, k := range app.args.keywords {
ks = append(ks, k.interpret(args))
}
return core.AppWithInfo(interpretExpression(args, app.function), core.NewArguments(ps, ks), app.info)
}