refactor: rename interpreter to runtime and use receiver methods
- 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>
This commit is contained in:
46
pkg/normalorder/runtime.go
Normal file
46
pkg/normalorder/runtime.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package normalorder
|
||||
|
||||
import (
|
||||
"git.maximhutz.com/max/lambda/pkg/emitter"
|
||||
"git.maximhutz.com/max/lambda/pkg/expr"
|
||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
"git.maximhutz.com/max/lambda/pkg/runtime"
|
||||
)
|
||||
|
||||
// NormalOrderReducer implements normal order (leftmost-outermost) reduction
|
||||
// for lambda calculus expressions.
|
||||
type Runtime struct {
|
||||
emitter.BaseEmitter[runtime.Event]
|
||||
expression lambda.Expression
|
||||
}
|
||||
|
||||
// NewNormalOrderReducer creates a new normal order reducer.
|
||||
func NewRuntime(expression lambda.Expression) *Runtime {
|
||||
return &Runtime{
|
||||
BaseEmitter: *emitter.New[runtime.Event](),
|
||||
expression: expression,
|
||||
}
|
||||
}
|
||||
|
||||
// Expression returns the current expression state.
|
||||
func (r *Runtime) Expression() expr.Expression {
|
||||
return r.expression
|
||||
}
|
||||
|
||||
func (r *Runtime) Step() bool {
|
||||
result, done := ReduceOnce(r.expression)
|
||||
r.expression = result
|
||||
return !done
|
||||
}
|
||||
|
||||
// Reduce performs normal order reduction on a lambda expression.
|
||||
// The expression must be a lambda.Expression; other types are returned unchanged.
|
||||
func (r *Runtime) Run() {
|
||||
r.Emit(runtime.StartEvent)
|
||||
|
||||
for !r.Step() {
|
||||
r.Emit(runtime.StepEvent)
|
||||
}
|
||||
|
||||
r.Emit(runtime.StopEvent)
|
||||
}
|
||||
Reference in New Issue
Block a user