refactor: make lambda expression types immutable

- Change Abstraction, Application, and Variable to use private fields with getter methods
- Return value types instead of pointers from constructors
- Update all type switches to match value types instead of pointer types
- Remove pointer equality optimizations (not applicable with immutable values)
- Return empty set instead of nil from GetFreeVariables default case
This commit is contained in:
2026-01-17 16:29:24 -05:00
parent c2aa77cb92
commit 7318c0dac4
21 changed files with 191 additions and 255 deletions

View File

@@ -3,17 +3,17 @@ package plugins
import (
"log/slog"
"git.maximhutz.com/max/lambda/pkg/reducer"
"git.maximhutz.com/max/lambda/pkg/interpreter"
)
type Logs struct {
logger *slog.Logger
reducer reducer.Reducer
reducer interpreter.Interpreter
}
func NewLogs(logger *slog.Logger, r reducer.Reducer) *Logs {
func NewLogs(logger *slog.Logger, r interpreter.Interpreter) *Logs {
plugin := &Logs{logger, r}
r.On(reducer.StepEvent, plugin.Step)
r.On(interpreter.StepEvent, plugin.Step)
return plugin
}

View File

@@ -5,19 +5,19 @@ package plugins
import (
"fmt"
"git.maximhutz.com/max/lambda/pkg/reducer"
"git.maximhutz.com/max/lambda/pkg/interpreter"
)
// Track the reductions made by a reduction process.
type Explanation struct {
reducer reducer.Reducer
reducer interpreter.Interpreter
}
// Attaches a new explanation tracker to a reducer.
func NewExplanation(r reducer.Reducer) *Explanation {
func NewExplanation(r interpreter.Interpreter) *Explanation {
plugin := &Explanation{reducer: r}
r.On(reducer.StartEvent, plugin.Start)
r.On(reducer.StepEvent, plugin.Step)
r.On(interpreter.StartEvent, plugin.Start)
r.On(interpreter.StepEvent, plugin.Step)
return plugin
}

View File

@@ -7,7 +7,7 @@ import (
"path/filepath"
"runtime/pprof"
"git.maximhutz.com/max/lambda/pkg/reducer"
"git.maximhutz.com/max/lambda/pkg/interpreter"
)
// Observes a reduction process, and publishes a CPU performance profile on
@@ -19,10 +19,10 @@ type Performance struct {
}
// Create a performance tracker that outputs a profile to "file".
func NewPerformance(file string, process reducer.Reducer) *Performance {
func NewPerformance(file string, process interpreter.Interpreter) *Performance {
plugin := &Performance{File: file}
process.On(reducer.StartEvent, plugin.Start)
process.On(reducer.StopEvent, plugin.Stop)
process.On(interpreter.StartEvent, plugin.Start)
process.On(interpreter.StopEvent, plugin.Stop)
return plugin
}

View File

@@ -6,7 +6,7 @@ import (
"time"
"git.maximhutz.com/max/lambda/internal/statistics"
"git.maximhutz.com/max/lambda/pkg/reducer"
"git.maximhutz.com/max/lambda/pkg/interpreter"
)
// An observer, to track reduction performance.
@@ -16,11 +16,11 @@ type Statistics struct {
}
// Create a new reduction performance Statistics.
func NewStatistics(r reducer.Reducer) *Statistics {
func NewStatistics(r interpreter.Interpreter) *Statistics {
plugin := &Statistics{}
r.On(reducer.StartEvent, plugin.Start)
r.On(reducer.StepEvent, plugin.Step)
r.On(reducer.StopEvent, plugin.Stop)
r.On(interpreter.StartEvent, plugin.Start)
r.On(interpreter.StepEvent, plugin.Step)
r.On(interpreter.StopEvent, plugin.Stop)
return plugin
}