40 lines
706 B
Go
40 lines
706 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
|
|
}
|
|
|
|
func New(config *config.Config) *Executor {
|
|
return &Executor{Config: config}
|
|
}
|
|
|
|
func (e Executor) Run(expr *lambda.Expression) {
|
|
e.Emit("start")
|
|
|
|
if e.Config.Explanation {
|
|
fmt.Println(lambda.Stringify(*expr))
|
|
}
|
|
|
|
for lambda.ReduceOnce(expr) {
|
|
e.Emit("step")
|
|
if e.Config.Verbose {
|
|
slog.Info("reduction", "tree", lambda.Stringify(*expr))
|
|
}
|
|
if e.Config.Explanation {
|
|
fmt.Println(" =", lambda.Stringify(*expr))
|
|
}
|
|
}
|
|
|
|
e.Emit("end")
|
|
}
|