refactor: extract Reducer interface and update engine to use abstractions
Introduce reducer.Reducer interface and update the engine to use abstract expr.Expression and reducer.Reducer types, enabling pluggable reduction strategies. - Add pkg/reducer/reducer.go with Reducer interface. - Add pkg/lambda/reducer.go with NormalOrderReducer implementation. - Update engine to accept expr.Expression and reducer.Reducer. - Update plugins to use expr.Expression directly (no pointer dereference). - Update main and tests to pass reducer to engine. Closes #30
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"git.maximhutz.com/max/lambda/internal/engine"
|
||||
"git.maximhutz.com/max/lambda/internal/plugins"
|
||||
"git.maximhutz.com/max/lambda/pkg/convert"
|
||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
"git.maximhutz.com/max/lambda/pkg/saccharine"
|
||||
)
|
||||
|
||||
@@ -33,8 +34,9 @@ func main() {
|
||||
compiled := convert.SaccharineToLambda(ast)
|
||||
logger.Info("compiled λ expression", "tree", compiled.String())
|
||||
|
||||
// Create reduction engine.
|
||||
process := engine.New(options, &compiled)
|
||||
// Create reduction engine with normal order reducer.
|
||||
reducer := lambda.NewNormalOrderReducer()
|
||||
process := engine.New(options, compiled, reducer)
|
||||
|
||||
// If the user selected to track CPU performance, attach a profiler to the
|
||||
// process.
|
||||
@@ -61,7 +63,7 @@ func main() {
|
||||
process.Run()
|
||||
|
||||
// Return the final reduced result.
|
||||
result := (*process.Expression).String()
|
||||
result := process.Expression.String()
|
||||
err = options.Destination.Write(result)
|
||||
cli.HandleError(err)
|
||||
}
|
||||
|
||||
@@ -41,11 +41,12 @@ func runSample(samplePath string) (string, error) {
|
||||
Verbose: false,
|
||||
}
|
||||
|
||||
// Create and run the engine.
|
||||
process := engine.New(cfg, &compiled)
|
||||
// Create and run the engine with normal order reducer.
|
||||
reducer := lambda.NewNormalOrderReducer()
|
||||
process := engine.New(cfg, compiled, reducer)
|
||||
process.Run()
|
||||
|
||||
return lambda.Stringify(compiled) + "\n", nil
|
||||
return process.Expression.String() + "\n", nil
|
||||
}
|
||||
|
||||
// Test that all samples produce expected output.
|
||||
|
||||
Reference in New Issue
Block a user