Files
lambda/internal/executer/executer.go

40 lines
744 B
Go

package executer
import (
"fmt"
"log/slog"
"git.maximhutz.com/max/lambda/internal/config"
"git.maximhutz.com/max/lambda/pkg/emitter"
"git.maximhutz.com/max/lambda/pkg/lambda"
)
type Executor struct {
Config *config.Config
emitter.Emitter[*lambda.Expression]
}
func New(config *config.Config) *Executor {
return &Executor{Config: config}
}
func (e Executor) Run(expr *lambda.Expression) {
e.Emit("start", expr)
if e.Config.Explanation {
fmt.Println(lambda.Stringify(*expr))
}
for lambda.ReduceOnce(expr) {
e.Emit("step", expr)
if e.Config.Verbose {
slog.Info("reduction", "tree", lambda.Stringify(*expr))
}
if e.Config.Explanation {
fmt.Println(" =", lambda.Stringify(*expr))
}
}
e.Emit("end", expr)
}