-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbol.go
48 lines (37 loc) · 880 Bytes
/
symbol.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
package gosdlisp
var symbolTable map[string]*Symbol
func init() {
symbolTable = make(map[string]*Symbol)
// Initialization of Symbol T
symbolT := &Symbol{Name: "T"}
symbolT.Value = symbolT
symbolTable["T"] = symbolT
// Initialization of Symbol QUIT
symbolQuit := &Symbol{Name: "QUIT"}
symbolTable["QUIT"] = symbolQuit
symbolExit := &Symbol{Name: "EXIT"}
symbolTable["EXIT"] = symbolExit
// Initialization of system functions
registSystemFunctions()
}
type Symbol struct {
Name string
Value T
Function T
}
func NewSymbol(name string) *Symbol {
_, exists := symbolTable[name]
if !exists {
symbolTable[name] = &Symbol{Name: name}
}
return symbolTable[name]
}
func AddSymbolFunc(name string, f Function) {
s := NewSymbol(name)
s.Function = f
symbolTable[name] = s
}
func (s *Symbol) String() string {
return s.Name
}
func (s *Symbol) A() {}