refactor: rewrite CLI and internal architecture #41

Merged
mvhutz merged 14 commits from feat/updated-arch into main 2026-02-07 03:25:32 +00:00
Showing only changes of commit dc872d15ae - Show all commits

View File

@@ -1,7 +1,6 @@
package main
import (
"fmt"
"os"
"git.maximhutz.com/max/lambda/internal/cli"
@@ -18,41 +17,38 @@ func main() {
logger.Info("parsed CLI options", "options", options)
r := GetRegistry()
fmt.Println(1)
// Get input.
input, err := options.Source.Extract()
cli.HandleError(err)
fmt.Println(2)
// Parse code into syntax tree.
repr, err := r.Unmarshal(input, "saccharine")
cli.HandleError(err)
logger.Info("parsed syntax tree", "tree", repr)
fmt.Println(3)
// Compile expression to lambda calculus.
compiled, err := r.ConvertTo(repr, "lambda")
cli.HandleError(err)
logger.Info("compiled λ expression", "tree", compiled)
fmt.Println(4)
// Create reducer with the compiled expression.
engine, err := r.GetDefaultEngine("lambda")
cli.HandleError(err)
fmt.Println(5)
err = engine.Set(compiled)
cli.HandleError(err)
// Run reduction.
for engine.Step(1) {
}
fmt.Println(6)
// Return the final reduced result.
result, err := engine.Get()
cli.HandleError(err)
fmt.Println(7, result)
output, err := r.Marshal(result)
cli.HandleError(err)
fmt.Println(8)
err = options.Destination.Write(output)
cli.HandleError(err)
}