- Rename pkg/interpreter to pkg/runtime - Move ReduceOnce to new pkg/normalorder package - Convert standalone functions (Substitute, Rename, GetFree, IsFree) to receiver methods on concrete expression types - Change Set from pointer receivers to value receivers - Update all references from interpreter to runtime terminology Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
45 lines
821 B
Go
45 lines
821 B
Go
package plugins
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"git.maximhutz.com/max/lambda/internal/statistics"
|
|
"git.maximhutz.com/max/lambda/pkg/runtime"
|
|
)
|
|
|
|
// An observer, to track reduction performance.
|
|
type Statistics struct {
|
|
start time.Time
|
|
steps uint64
|
|
}
|
|
|
|
// Create a new reduction performance Statistics.
|
|
func NewStatistics(r runtime.Runtime) *Statistics {
|
|
plugin := &Statistics{}
|
|
r.On(runtime.StartEvent, plugin.Start)
|
|
r.On(runtime.StepEvent, plugin.Step)
|
|
r.On(runtime.StopEvent, plugin.Stop)
|
|
|
|
return plugin
|
|
}
|
|
|
|
func (t *Statistics) Start() {
|
|
t.start = time.Now()
|
|
t.steps = 0
|
|
}
|
|
|
|
func (t *Statistics) Step() {
|
|
t.steps++
|
|
}
|
|
|
|
func (t *Statistics) Stop() {
|
|
results := statistics.Results{
|
|
StepsTaken: t.steps,
|
|
TimeElapsed: uint64(time.Since(t.start).Milliseconds()),
|
|
}
|
|
|
|
fmt.Fprint(os.Stderr, results.String())
|
|
}
|