refactor: rewrite CLI and internal architecture #41
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user