feat: statistics flag, commented some more
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"git.maximhutz.com/max/lambda/internal/cli"
|
||||
"git.maximhutz.com/max/lambda/internal/config"
|
||||
"git.maximhutz.com/max/lambda/internal/executer"
|
||||
"git.maximhutz.com/max/lambda/internal/engine"
|
||||
"git.maximhutz.com/max/lambda/internal/explanation"
|
||||
"git.maximhutz.com/max/lambda/internal/performance"
|
||||
"git.maximhutz.com/max/lambda/internal/statistics"
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"git.maximhutz.com/max/lambda/pkg/saccharine"
|
||||
)
|
||||
|
||||
// Run main application.
|
||||
func main() {
|
||||
// Parse CLI arguments.
|
||||
options, err := config.FromArgs()
|
||||
cli.HandleError(err)
|
||||
|
||||
@@ -24,7 +24,8 @@ func main() {
|
||||
logger.Info("using program arguments", "args", os.Args)
|
||||
logger.Info("parsed CLI options", "options", options)
|
||||
|
||||
input, err := options.Source.Pull()
|
||||
// Get input.
|
||||
input, err := options.Source.Extract()
|
||||
cli.HandleError(err)
|
||||
|
||||
// Parse tokens.
|
||||
@@ -35,33 +36,46 @@ func main() {
|
||||
// Turn tokens into syntax tree.
|
||||
expression, err := saccharine.Parse(tokens)
|
||||
cli.HandleError(err)
|
||||
if options.Verbose {
|
||||
logger.Info("parsed syntax tree", "tree", saccharine.Stringify(expression))
|
||||
}
|
||||
logger.Info("parsed syntax tree", "tree", saccharine.Stringify(expression))
|
||||
|
||||
// Compile expression to lambda calculus.
|
||||
compiled := convert.SaccharineToLambda(expression)
|
||||
if options.Verbose {
|
||||
logger.Info("compiled lambda expression", "tree", lambda.Stringify(compiled))
|
||||
}
|
||||
logger.Info("compiled lambda expression", "tree", lambda.Stringify(compiled))
|
||||
|
||||
process := executer.New(options, &compiled)
|
||||
// Create reduction engine.
|
||||
process := engine.New(options, &compiled)
|
||||
|
||||
// If the user selected to track CPU performance, attach a profiler to the
|
||||
// process.
|
||||
if options.Profile != "" {
|
||||
profiler := performance.Track(options.Profile)
|
||||
process.On("start", profiler.Start)
|
||||
process.On("end", profiler.End)
|
||||
}
|
||||
|
||||
// If the user selected to produce a step-by-step explanation, attach an
|
||||
// observer here.
|
||||
if options.Explanation {
|
||||
explanation.Track(process)
|
||||
}
|
||||
|
||||
statistics := statistics.Track()
|
||||
process.On("start", statistics.Start)
|
||||
process.On("step", statistics.Step)
|
||||
process.On("end", statistics.End)
|
||||
// If the user opted to track statistics, attach a tracker here, too.
|
||||
if options.Statistics {
|
||||
statistics := statistics.Track()
|
||||
process.On("start", statistics.Start)
|
||||
process.On("step", statistics.Step)
|
||||
process.On("end", statistics.End)
|
||||
}
|
||||
|
||||
// If the user selected for verbose debug logs, attach a reduction tracker.
|
||||
if options.Verbose {
|
||||
process.On("step", func() {
|
||||
logger.Info("reduction", "tree", lambda.Stringify(compiled))
|
||||
})
|
||||
}
|
||||
|
||||
process.Run()
|
||||
|
||||
// Return the final reduced result.
|
||||
fmt.Println(lambda.Stringify(compiled))
|
||||
fmt.Fprint(os.Stderr, statistics.Results.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user