68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"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/explanation"
|
|
"git.maximhutz.com/max/lambda/internal/performance"
|
|
"git.maximhutz.com/max/lambda/internal/statistics"
|
|
"git.maximhutz.com/max/lambda/pkg/convert"
|
|
"git.maximhutz.com/max/lambda/pkg/lambda"
|
|
"git.maximhutz.com/max/lambda/pkg/saccharine"
|
|
)
|
|
|
|
// Run main application.
|
|
func main() {
|
|
options, err := config.FromArgs()
|
|
cli.HandleError(err)
|
|
|
|
logger := options.GetLogger()
|
|
logger.Info("using program arguments", "args", os.Args)
|
|
logger.Info("parsed CLI options", "options", options)
|
|
|
|
input, err := options.Source.Pull()
|
|
cli.HandleError(err)
|
|
|
|
// Parse tokens.
|
|
tokens, err := saccharine.GetTokens(input)
|
|
cli.HandleError(err)
|
|
logger.Info("parsed tokens", "tokens", tokens)
|
|
|
|
// 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))
|
|
}
|
|
|
|
compiled := convert.SaccharineToLambda(expression)
|
|
if options.Verbose {
|
|
logger.Info("compiled lambda expression", "tree", lambda.Stringify(compiled))
|
|
}
|
|
|
|
process := executer.New(options, &compiled)
|
|
if options.Profile != "" {
|
|
profiler := performance.Track(options.Profile)
|
|
process.On("start", profiler.Start)
|
|
process.On("end", profiler.End)
|
|
}
|
|
|
|
if options.Explanation {
|
|
explanation.Track(process)
|
|
}
|
|
|
|
statistics := statistics.Track()
|
|
process.On("start", statistics.Start)
|
|
process.On("step", statistics.Step)
|
|
process.On("end", statistics.End)
|
|
|
|
process.Run()
|
|
|
|
fmt.Println(lambda.Stringify(compiled))
|
|
fmt.Fprint(os.Stderr, statistics.Results.String())
|
|
}
|