feat: new engine format

This commit is contained in:
2026-02-07 00:12:50 -05:00
parent 8b80cea32b
commit 1d94fa70ff
11 changed files with 45 additions and 100 deletions

View File

@@ -7,7 +7,7 @@ import (
)
type Engine interface {
Load() Process
Load(Repr) (Process, error)
Name() string
InType() string
}
@@ -22,8 +22,18 @@ func (e convertedEngine[T]) InType() string { return e.inType }
func (e convertedEngine[T]) Name() string { return e.name }
func (e convertedEngine[T]) Load() Process {
return convertedProcess[T]{e.engine.Load(), e.inType}
func (e convertedEngine[T]) Load(r Repr) (Process, error) {
t, ok := r.Data().(T)
if !ok {
return nil, fmt.Errorf("'ncorrent format '%s' for engine '%s'", r.ID(), e.inType)
}
process, err := e.engine(t)
if err != nil {
return nil, err
}
return convertedProcess[T]{process, e.inType}, nil
}
func RegisterEngine[T any](registry *Registry, e engine.Engine[T], name, inType string) error {

View File

@@ -1,8 +1,6 @@
package registry
import (
"fmt"
"git.maximhutz.com/max/lambda/pkg/engine"
)
@@ -28,14 +26,6 @@ func (b convertedProcess[T]) Get() (Repr, error) {
return NewRepr(b.inType, s), nil
}
func (b convertedProcess[T]) Set(r Repr) error {
if t, ok := r.Data().(T); ok {
return b.process.Set(t)
}
return fmt.Errorf("Incorrent format '%s' for engine '%s'.", r.ID(), b.inType)
}
func (b convertedProcess[T]) Step(i int) bool {
return b.process.Step(i)
}

View File

@@ -1,11 +1,14 @@
package registry
// A Repr is a lambda calculus expression. It can have any type of
// representation, so long as that class is known to the registry it is handled
// by.
type Repr interface {
// Id returns to name of the objects underlying representation. If is
// assumed that if two Repr objects have the same Id(), they share the same
// representation.
// ID returns the name of the underlying representation. It is assumed that
// if two expressions have the same Id(), they have the same representation.
ID() string
// The base expression data.
Data() any
}