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