-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
90 lines (86 loc) · 2.1 KB
/
Copy pathmain.go
File metadata and controls
90 lines (86 loc) · 2.1 KB
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
package main
import (
"cuteify/compile"
packageSys "cuteify/package"
"cuteify/parser"
"fmt"
"os"
"reflect"
"strings"
"time"
)
func main() {
startTime := time.Now()
genHTML := false
path := "./test"
args := os.Args[1:]
for i := 0; i < len(args); i++ {
if args[i] == "--ast" || args[i] == "-ast" {
genHTML = true
} else {
path = args[i]
}
}
tmp, err := packageSys.GetPackage(path, true)
if err != nil {
panic(err)
}
if genHTML {
f, err := os.Create("./ast.html")
if err != nil {
panic(err)
}
generateASTHTML(tmp.AST.(*parser.Node), f)
f.Close()
fmt.Println("\033[32mOK\033[0m:AST HTML written to ./ast.html")
fmt.Println("\n=== Text AST ===")
pr(tmp.AST.(*parser.Node), 0)
return
}
co := &compile.Compiler{}
code := co.Compile(tmp.AST.(*parser.Node))
os.WriteFile(`./_main.asm`, []byte(code), 0644)
fmt.Println("\033[32mOK\033[0m:Finish in", time.Since(startTime))
}
func pr(block *parser.Node, tabnum int) {
/*if block.Ignore {
return
}*/
fmt.Println(strings.Repeat("\t", tabnum), reflect.TypeOf(block.Value), block.Value)
/*TODO:
if sb, ok := block.Value.(*parser.StructBlock); ok {
fmt.Printf("\n=== Struct: %s ===\n", sb.Name)
fmt.Println("Fields:")
for _, f := range sb.Fields {
accessStr := "public"
if f.Access == parser.AccessReadOnly {
accessStr = "readonly"
} else if f.Access == parser.AccessWriteOnly {
accessStr = "writeonly"
} else if f.Access == parser.AccessPrivate {
accessStr = "private"
}
defaultStr := ""
if f.DefaultValue != nil {
defaultStr = fmt.Sprintf(" (default: %v)", f.DefaultValue)
}
tagStr := ""
if len(f.Tags) > 0 {
var tagParts []string
for _, t := range f.Tags {
tagParts = append(tagParts, t.Key+":"+t.Value)
}
tagStr = fmt.Sprintf(" (tags: %v)", tagParts)
}
fmt.Printf(" - %s: %v (access: %s)%s%s\n", f.Name, f.Type, accessStr, defaultStr, tagStr)
}
fmt.Println("Methods:")
for _, m := range sb.Methods {
fmt.Printf(" - %s\n", m.Name.String())
}
fmt.Println("=====================\n")
}*/
for _, k := range block.Children {
pr(k, tabnum+1)
}
}