The Engine struct embeds BaseEmitter but wasn't initializing it, causing a nil map panic when emitting events. Now properly initializes the BaseEmitter using emitter.New[Event]().
37 lines
821 B
Go
37 lines
821 B
Go
// Package "engine" provides an extensible interface for users to interfact with
|
|
// λ-calculus.
|
|
package engine
|
|
|
|
import (
|
|
"git.maximhutz.com/max/lambda/internal/config"
|
|
"git.maximhutz.com/max/lambda/pkg/emitter"
|
|
"git.maximhutz.com/max/lambda/pkg/lambda"
|
|
)
|
|
|
|
// A process for reducing one λ-expression.
|
|
type Engine struct {
|
|
Config *config.Config
|
|
Expression *lambda.Expression
|
|
emitter.BaseEmitter[Event]
|
|
}
|
|
|
|
// Create a new engine, given an unreduced λ-expression.
|
|
func New(config *config.Config, expression *lambda.Expression) *Engine {
|
|
return &Engine{
|
|
Config: config,
|
|
Expression: expression,
|
|
BaseEmitter: *emitter.New[Event](),
|
|
}
|
|
}
|
|
|
|
// Begin the reduction process.
|
|
func (e Engine) Run() {
|
|
e.Emit(StartEvent)
|
|
|
|
lambda.ReduceAll(e.Expression, func() {
|
|
e.Emit(StepEvent)
|
|
})
|
|
|
|
e.Emit(StopEvent)
|
|
}
|