glox/callable.go

24 lines
387 B
Go
Raw Normal View History

2024-10-09 19:57:52 +03:00
package main
type Callable struct {
arity int
call func(*Interpreter, ...any) any
}
2024-10-09 23:36:18 +03:00
func newCallable(f *FunStmt) *Callable {
return &Callable{
arity: len(f.args),
call: func(i *Interpreter, args ...any) any {
env := newEnvironment(i.globals)
for idx, arg := range f.args {
env.set(arg.lexeme, args[idx])
}
i.executeBlock(f.body, env)
return nil
},
}
}