pulumi/pkg/compiler/symbols.go

42 lines
1.1 KiB
Go
Raw Normal View History

// Copyright 2016 Marapongo, Inc. All rights reserved.
package compiler
import (
"github.com/marapongo/mu/pkg/ast"
)
// Symbol is a named entity that can be referenced and bound to.
type Symbol struct {
Kind SymbolKind // the kind of symbol.
Name ast.Name // the symbol's unique name.
Node *ast.Node // the Node part of the payload data structure.
Real interface{} // the real part of the payload (i.e., the whole structure).
}
// SymbolKind indicates the kind of symbol being registered (e.g., Stack, Service, etc).
type SymbolKind int
const (
SymKindService SymbolKind = iota
SymKindStack
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 23:49:47 +01:00
SymKindUninstStack
SymKindSchema
)
func NewServiceSymbol(nm ast.Name, svc *ast.Service) *Symbol {
return &Symbol{SymKindService, nm, &svc.Node, svc}
}
func NewStackSymbol(nm ast.Name, stack *ast.Stack) *Symbol {
return &Symbol{SymKindStack, nm, &stack.Node, stack}
}
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 23:49:47 +01:00
func NewUninstStackSymbol(nm ast.Name, ref *ast.UninstStack) *Symbol {
return &Symbol{SymKindUninstStack, nm, &ref.Node, ref}
}
func NewSchemaSymbol(nm ast.Name, schema *ast.Schema) *Symbol {
return &Symbol{SymKindSchema, nm, &schema.Node, schema}
}