-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
66 lines (60 loc) · 1.2 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
package main
import (
"fmt"
"gokula/vm"
"os"
)
type startupInfo struct {
method string
path string
}
func main() {
startupInfo, err := readArgs()
if err != nil {
info()
} else {
var err error
vm.CompiledFileInstance, err = vm.Load(startupInfo.path)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
if startupInfo.method == "show" {
fmt.Println(vm.CompiledFileInstance)
} else if startupInfo.method == "run" {
err = vm.CompiledFileInstance.Run()
if err != nil {
fmt.Println("error: ", err)
}
}
}
}
func readArgs() (startupInfo, error) {
si := startupInfo{}
err := fmt.Errorf("illegal args")
if len(os.Args) < 2 {
return si, err
}
for index, str := range os.Args {
if index == 0 {
continue
} else if index == 1 {
if str == "-r" || str == "--run" {
si.method = "run"
} else if str == "-s" || str == "--show" {
si.method = "show"
} else {
return si, err
}
} else if index == 2 {
si.path = str
}
}
return si, nil
}
func info() {
str := `Usage: gokula <command> <*.kulac> [<args>]
-r, --run Run a kula-compiled-file in release mode
-s, --show Output a kula-compiled-file in bytecode format`
fmt.Println(str)
}