blob: 8bfe60abbb8535d2b013f43d22cfb407c15f9352 (
plain)
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
|
package scope
type SymbolID struct {
symbolKind SymbolKind
scopeID ScopeID
indexInScope int
}
func (id SymbolID) SymbolKind() SymbolKind {
return id.symbolKind
}
func (id SymbolID) ScopeID() ScopeID {
return id.scopeID
}
func (id SymbolID) IndexInScope() int {
return id.indexInScope
}
type SymbolKind int
const (
// A variable symbol is bound to a local on the stack.
SymbolKindVariable SymbolKind = iota
// An env symbol is bound to a local on the stack, outside of the function's scope.
// Emitted at lookup time, so the SymbolScope has no array for them.
SymbolKindEnv SymbolKind = iota
// A global symbol is bound to a global from a dependency.
SymbolKindGlobal SymbolKind = iota
)
func (s SymbolKind) String() string {
switch s {
case SymbolKindVariable:
return "variable"
case SymbolKindEnv:
return "env"
case SymbolKindGlobal:
return "global"
default:
panic("unknown symbol kind")
}
}
type Symbol[D SymbolData] struct {
name string
data D
}
func (s Symbol[D]) Data() D {
return s.data
}
type SymbolData interface {
SymbolVariable | SymbolEnv | SymbolGlobal
}
type SymbolVariable struct {
localIndex int
}
func (sv SymbolVariable) LocalIndex() int {
return sv.localIndex
}
type SymbolEnv struct {
indexInEnv int
}
func (se SymbolEnv) IndexInEnv() int {
return se.indexInEnv
}
type SymbolGlobal struct {
id string
}
func (sg SymbolGlobal) ID() string {
return sg.id
}
|