pulumi/pkg/ast/stable.go
joeduffy 713fe29fef Custom types, round 1
This change overhauls the core of how types are used by the entire
compiler.  In particular, we now have an ast.Type, and have begun
using its use where appropriate.  An ast.Type is a union representing
precisely one of the possible sources of types in the system:

* Primitive type: any, bool, number, string, or service.

* Stack type: a resolved reference to an actual concrete stack.

* Schema type: a resolved reference to an actual concrete schema.

* Unresolved reference: a textual reference that hasn't yet been
  resolved to a concrete artifact.

* Uninstantiated reference: a reference that has been resolved to
  an uninstantiated stack, but hasn't been bound to a concrete
  result yet.  Right now, this can point to a stack, however
  eventually we would imagine this supporting inter-stack schema
  references also.

* Decorated type: either an array or a map; in the array case, there
  is a single inner element type; in the map case, there are two,
  the keys and values; in all cases, the type recurses to any of the
  possibilities listed here.

All of the relevant AST nodes have been overhauled accordingly.

In addition to this, we now have an ast.Schema type.  It is loosely
modeled on JSON Schema in its capabilities (http://json-schema.org/).
Although we parse and perform some visitation and binding of these,
there are mostly placeholders left in the code for the interesting
aspects, such as registering symbols, resolving dependencies, and
typechecking usage of schema types.

This is part of the ongoing work behind marapongo/mu#9.
2016-12-06 14:49:47 -08:00

126 lines
2.2 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 StableDependencyRefs(refs DependencyRefs) []Ref {
sorted := make(Refs, 0, len(refs))
for ref := range refs {
sorted = append(sorted, ref)
}
sort.Sort(sorted)
return sorted
}
func StableKeys(ps PropertyBag) []string {
sorted := make([]string, 0, len(ps))
for p := range ps {
sorted = append(sorted, p)
}
sort.Strings(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 StablePropertyBag(ps PropertyBag) []string {
sorted := make([]string, 0, len(ps))
for p := range ps {
sorted = append(sorted, p)
}
sort.Strings(sorted)
return sorted
}
func StableSchemas(ss SchemaMap) []Name {
sorted := make(Names, 0, len(ss))
for s := range ss {
sorted = append(sorted, s)
}
sort.Sort(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 StableStringStringMap(ssm map[string]string) []string {
sorted := make([]string, 0, len(ssm))
for s := range ssm {
sorted = append(sorted, s)
}
sort.Strings(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]
}