-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
41 lines (34 loc) · 819 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"log"
"loxcc/internal"
"loxcc/internal/analyzer"
"loxcc/internal/codegen"
"os"
"gopkg.in/yaml.v3"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: loxcc [path]")
return
}
// define default build-config, and load from file if exists.
config := internal.BuildConfig{OutputFolder: "build"}
data, err := os.ReadFile("build-config.yaml")
if err == nil { // will not report an error if ReadFile fails.
if err := yaml.Unmarshal(data, &config); err != nil {
log.Fatalln(err.Error())
}
}
data, err = os.ReadFile(os.Args[1])
if err != nil {
log.Fatalln(err.Error())
}
program, err := analyzer.Analyze(string(data))
if err != nil {
log.Fatalln(err.Error())
}
code := codegen.Generate(program)
internal.Build(config, os.Args[1], code)
}