-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
54 lines (47 loc) · 882 Bytes
/
utils.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
package main
import (
"fmt"
"os"
"strconv"
)
var FreeInts []int
const (
T_UNKNOWN int8 = -1
T_LITTERAL int8 = 0
T_POINTER int8 = 1
T_LABEL int8 = 2
T_VARIABLE int8 = 3
T_TEXT int8 = 4
)
func GetSharedIntPointer(a int) *int {
for k, _ := range FreeInts {
if FreeInts[k] == a {
return &FreeInts[k]
}
}
FreeInts = append(FreeInts, a)
return &FreeInts[len(FreeInts)-1]
}
func DebugPrint(formatter string, args ...interface{}) {
fmt.Printf(formatter+"\n", args...)
}
func CloseMessage(code int, formatter string, args ...interface{}) {
fmt.Printf(formatter+"\n", args...)
os.Exit(code)
}
func GetWordType(Word string) int8 {
switch Word[0] {
case ':':
return T_LABEL
case '*':
return T_POINTER
case '_':
return T_VARIABLE
default:
if _, err := strconv.Atoi(Word); err != nil {
return T_TEXT
} else {
return T_LITTERAL
}
}
}