Refactors the event emitter system from string-based messages to a type-safe generic implementation using typed events. Consolidates separate tracker packages into a unified plugins architecture. Changes: - Replace Emitter with BaseEmitter[E comparable] using generics - Add Event type with StartEvent, StepEvent, and StopEvent constants - Create Listener[E] interface with BaseListener implementation - Consolidate explanation, performance, and statistics trackers into internal/plugins package - Simplify main CLI by using plugin constructors instead of manual event subscription - Add Items() iterator method to Set for idiomatic range loops
33 lines
769 B
Go
33 lines
769 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}
|
|
}
|
|
|
|
// Begin the reduction process.
|
|
func (e Engine) Run() {
|
|
e.Emit(StartEvent)
|
|
|
|
lambda.ReduceAll(e.Expression, func() {
|
|
e.Emit(StepEvent)
|
|
})
|
|
|
|
e.Emit(StopEvent)
|
|
}
|