-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
113 lines (95 loc) · 2.07 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"github.com/DQNEO/minigo/stdlib/fmt"
"github.com/DQNEO/minigo/stdlib/strings"
"os"
)
var GENERATION int = 1
var debugMode = false // execute debugf() or not
var debugToken = false
var debugAst = false
var debugParser = false
var tokenizeOnly = false
var parseOnly = false
var resolveOnly = false
var emitPosition = false
var _printVersion = false
func printVersion() {
fmt.Println("minigo 0.3.0")
fmt.Println("Copyright (C) 2019 @DQNEO")
_printVersion = true
}
func parseOpts(args []string) []string {
var r []string
for _, opt := range args {
if opt == "--version" {
printVersion()
return nil
}
if opt == "-t" {
debugToken = true
}
if opt == "-a" {
debugAst = true
}
if opt == "-p" {
debugParser = true
}
if opt == "--position" {
emitPosition = true
}
if opt == "-d" {
debugMode = true
}
if opt == "--tokenize-only" {
tokenizeOnly = true
}
if opt == "--parse-only" {
parseOnly = true
}
if opt == "--resolve-only" {
resolveOnly = true
}
if strings.HasSuffix(opt, ".go") {
r = append(r, opt)
} else if opt == "-" {
return []string{"/dev/stdin"}
}
}
return r
}
func main() {
// parsing arguments
var sourceFiles []string
assert(len(os.Args) > 0, nil, "os.Args should not be empty")
if len(os.Args) > 1 {
sourceFiles = parseOpts(os.Args[1:])
}
if len(sourceFiles) == 0 {
if _printVersion {
return
}
fmt.Println("No input files.")
return
}
if tokenizeOnly {
dumpTokenForFiles(sourceFiles)
return
}
// setup the universe scope
universe := newUniverse()
pkgUniverse := compileUniverse(universe)
// compiler unsafe package
symbolTable = &SymbolTable{}
symbolTable.allScopes = map[normalizedPackagePath]*Scope{}
pkgUnsafe := compileUnsafe(universe)
pkgIRuntime := compileRuntime(universe)
directDependencies := parseImports(sourceFiles)
libs := compilePackages(universe, directDependencies)
pkgMain := compileMainFiles(universe, sourceFiles)
if pkgMain == nil {
return
}
program := build(pkgUniverse, pkgUnsafe, pkgIRuntime, libs, pkgMain)
program.emit()
}