e02921dc35
This change completes the implementation of dependency and type binding. The top-level change here is that, during the first semantic analysis AST walk, we gather up all unknown dependencies. Then the compiler resolves them, caching the lookups to ensure that we don't load the same stack twice. Finally, during the second and final semantic analysis AST walk, we populate the bound nodes by looking up what the compiler resolved for us.
90 lines
1.5 KiB
Go
90 lines
1.5 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package ast
|
|
|
|
import (
|
|
"sort"
|
|
)
|
|
|
|
func StableClusters(cs Clusters) []string {
|
|
sorted := make([]string, 0, len(cs))
|
|
for c := range cs {
|
|
sorted = append(sorted, c)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableDependencies(ds Dependencies) []Ref {
|
|
sorted := make(Refs, 0, len(ds))
|
|
for d := range ds {
|
|
sorted = append(sorted, d)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableBoundDependencies(ds BoundDependencies) []Ref {
|
|
sorted := make(Refs, 0, len(ds))
|
|
for d := range ds {
|
|
sorted = append(sorted, d)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableProperties(ps Properties) []string {
|
|
sorted := make([]string, 0, len(ps))
|
|
for p := range ps {
|
|
sorted = append(sorted, p)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableServices(ss ServiceMap) []Name {
|
|
sorted := make(Names, 0, len(ss))
|
|
for s := range ss {
|
|
sorted = append(sorted, s)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableUntypedServices(ss UntypedServiceMap) []Name {
|
|
sorted := make(Names, 0, len(ss))
|
|
for s := range ss {
|
|
sorted = append(sorted, s)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
type Names []Name
|
|
|
|
func (s Names) Len() int {
|
|
return len(s)
|
|
}
|
|
|
|
func (s Names) Swap(i, j int) {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
|
|
func (s Names) Less(i, j int) bool {
|
|
return s[i] < s[j]
|
|
}
|
|
|
|
type Refs []Ref
|
|
|
|
func (s Refs) Len() int {
|
|
return len(s)
|
|
}
|
|
|
|
func (s Refs) Swap(i, j int) {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
|
|
func (s Refs) Less(i, j int) bool {
|
|
return s[i] < s[j]
|
|
}
|