Documentation ¶
Overview ¶
Package types contains the Elk type checker.
Index ¶
- func Inspect(typ Type) string
- func IsAny(t Type) bool
- func IsNever(t Type) bool
- func IsNilable(typ Type, env *GlobalEnvironment) bool
- func IsVoid(t Type) bool
- func MakeFullConstantName(containerName, constName string) string
- type Any
- type BigFloatLiteral
- type CharLiteral
- type Class
- type ConstantContainer
- type ConstantMap
- func (c *ConstantMap) Constant(name value.Symbol) Type
- func (c *ConstantMap) ConstantString(name string) Type
- func (c *ConstantMap) Constants() map[value.Symbol]Type
- func (c *ConstantMap) DefineClass(name string, parent ConstantContainer, consts map[value.Symbol]Type, ...) *Class
- func (c *ConstantMap) DefineConstant(name string, val Type)
- func (c *ConstantMap) DefineMixin(name string, parent *MixinProxy, consts map[value.Symbol]Type, ...) *Mixin
- func (c *ConstantMap) DefineModule(name string, consts map[value.Symbol]Type, subtypes map[value.Symbol]Type, ...) *Module
- func (c *ConstantMap) DefineSubtype(name string, val Type)
- func (c *ConstantMap) Method(name value.Symbol) *Method
- func (c *ConstantMap) MethodString(name string) *Method
- func (c *ConstantMap) Methods() MethodMap
- func (c *ConstantMap) Name() string
- func (c *ConstantMap) SetMethod(name string, method *Method)
- func (c *ConstantMap) Subtype(name value.Symbol) Type
- func (c *ConstantMap) SubtypeString(name string) Type
- func (c *ConstantMap) Subtypes() map[value.Symbol]Type
- type Float32Literal
- type Float64Literal
- type FloatLiteral
- type GlobalEnvironment
- func (g *GlobalEnvironment) Std() *Module
- func (g *GlobalEnvironment) StdConst(name value.Symbol) Type
- func (g *GlobalEnvironment) StdConstString(name string) Type
- func (g *GlobalEnvironment) StdSubtype(name value.Symbol) Type
- func (g *GlobalEnvironment) StdSubtypeClass(name value.Symbol) *Class
- func (g *GlobalEnvironment) StdSubtypeString(name string) Type
- type Int16Literal
- type Int32Literal
- type Int64Literal
- type Int8Literal
- type IntLiteral
- type Intersection
- type Method
- func (m *Method) ExpectedParamCountString() string
- func (m *Method) HasPositionalRestParam() bool
- func (m *Method) InspectSignature() string
- func (m *Method) NamedRestParam() *Parameter
- func (m *Method) PositionalRestParam() *Parameter
- func (m *Method) PositionalRestParamIndex() int
- func (m *Method) RequiredParamCount() int
- func (m *Method) ToNonLiteral(env *GlobalEnvironment) Type
- type MethodMap
- type Mixin
- func (m *Mixin) CreateProxy() (head, tail *MixinProxy)
- func (m *Mixin) DefineMethod(name string, params []*Parameter, returnType, throwType Type) *Method
- func (m *Mixin) Parent() ConstantContainer
- func (m *Mixin) SetParent(parent *MixinProxy)
- func (m *Mixin) ToNonLiteral(env *GlobalEnvironment) Type
- type MixinProxy
- type Module
- type Never
- type Nilable
- type Parameter
- type ParameterKind
- type SingletonClass
- type StringLiteral
- type SymbolLiteral
- type Type
- type UInt16Literal
- type UInt32Literal
- type UInt64Literal
- type UInt8Literal
- type Union
- type Void
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNilable ¶
func IsNilable(typ Type, env *GlobalEnvironment) bool
func MakeFullConstantName ¶
Types ¶
type Any ¶
type Any struct{}
All types are subtypes of any. Any is not a subtype of anything other than itself. It is the top type.
func (Any) ToNonLiteral ¶
func (n Any) ToNonLiteral(env *GlobalEnvironment) Type
type BigFloatLiteral ¶
type BigFloatLiteral struct {
Value string
}
func NewBigFloatLiteral ¶
func NewBigFloatLiteral(value string) *BigFloatLiteral
func (*BigFloatLiteral) ToNonLiteral ¶
func (*BigFloatLiteral) ToNonLiteral(env *GlobalEnvironment) Type
type CharLiteral ¶
type CharLiteral struct {
Value rune
}
func NewCharLiteral ¶
func NewCharLiteral(value rune) *CharLiteral
func (*CharLiteral) ToNonLiteral ¶
func (*CharLiteral) ToNonLiteral(env *GlobalEnvironment) Type
type Class ¶
type Class struct { ConstantMap // contains filtered or unexported fields }
func (*Class) DefineMethod ¶
func (*Class) Parent ¶
func (c *Class) Parent() ConstantContainer
func (*Class) SetParent ¶
func (c *Class) SetParent(parent ConstantContainer)
func (*Class) ToNonLiteral ¶
func (c *Class) ToNonLiteral(env *GlobalEnvironment) Type
type ConstantContainer ¶
type ConstantContainer interface { Type Name() string Parent() ConstantContainer Constants() map[value.Symbol]Type Constant(name value.Symbol) Type ConstantString(name string) Type DefineConstant(name string, val Type) Subtypes() map[value.Symbol]Type Subtype(name value.Symbol) Type SubtypeString(name string) Type DefineSubtype(name string, val Type) Methods() MethodMap Method(name value.Symbol) *Method MethodString(name string) *Method DefineMethod(name string, params []*Parameter, returnType, throwType Type) *Method SetMethod(name string, method *Method) DefineClass(name string, parent ConstantContainer, consts map[value.Symbol]Type, methods MethodMap) *Class DefineModule(name string, consts map[value.Symbol]Type, subtypes map[value.Symbol]Type, methods MethodMap) *Module DefineMixin(name string, parent *MixinProxy, consts map[value.Symbol]Type, subtypes map[value.Symbol]Type, methods MethodMap) *Mixin }
type ConstantMap ¶
type ConstantMap struct {
// contains filtered or unexported fields
}
func (*ConstantMap) Constant ¶
func (c *ConstantMap) Constant(name value.Symbol) Type
Get the constant with the given name.
func (*ConstantMap) ConstantString ¶
func (c *ConstantMap) ConstantString(name string) Type
Get the constant with the given name.
func (*ConstantMap) DefineClass ¶
func (c *ConstantMap) DefineClass(name string, parent ConstantContainer, consts map[value.Symbol]Type, methods MethodMap) *Class
Define a new class.
func (*ConstantMap) DefineConstant ¶
func (c *ConstantMap) DefineConstant(name string, val Type)
func (*ConstantMap) DefineMixin ¶
func (c *ConstantMap) DefineMixin(name string, parent *MixinProxy, consts map[value.Symbol]Type, subtypes map[value.Symbol]Type, methods MethodMap) *Mixin
Define a new mixin.
func (*ConstantMap) DefineModule ¶
func (c *ConstantMap) DefineModule(name string, consts map[value.Symbol]Type, subtypes map[value.Symbol]Type, methods MethodMap) *Module
Define a new module.
func (*ConstantMap) DefineSubtype ¶
func (c *ConstantMap) DefineSubtype(name string, val Type)
func (*ConstantMap) Method ¶
func (c *ConstantMap) Method(name value.Symbol) *Method
Get the method with the given name.
func (*ConstantMap) MethodString ¶
func (c *ConstantMap) MethodString(name string) *Method
Get the method with the given name.
func (*ConstantMap) Methods ¶
func (c *ConstantMap) Methods() MethodMap
func (*ConstantMap) Name ¶
func (c *ConstantMap) Name() string
func (*ConstantMap) SetMethod ¶
func (c *ConstantMap) SetMethod(name string, method *Method)
func (*ConstantMap) Subtype ¶
func (c *ConstantMap) Subtype(name value.Symbol) Type
Get the subtype with the given name.
func (*ConstantMap) SubtypeString ¶
func (c *ConstantMap) SubtypeString(name string) Type
Get the subtype with the given name.
type Float32Literal ¶
type Float32Literal struct {
Value string
}
func NewFloat32Literal ¶
func NewFloat32Literal(value string) *Float32Literal
func (*Float32Literal) ToNonLiteral ¶
func (*Float32Literal) ToNonLiteral(env *GlobalEnvironment) Type
type Float64Literal ¶
type Float64Literal struct {
Value string
}
func NewFloat64Literal ¶
func NewFloat64Literal(value string) *Float64Literal
func (*Float64Literal) ToNonLiteral ¶
func (*Float64Literal) ToNonLiteral(env *GlobalEnvironment) Type
type FloatLiteral ¶
type FloatLiteral struct {
Value string
}
func NewFloatLiteral ¶
func NewFloatLiteral(value string) *FloatLiteral
func (*FloatLiteral) ToNonLiteral ¶
func (*FloatLiteral) ToNonLiteral(env *GlobalEnvironment) Type
type GlobalEnvironment ¶
type GlobalEnvironment struct {
Root *Module
}
func NewGlobalEnvironment ¶
func NewGlobalEnvironment() *GlobalEnvironment
Create a new global environment for type checking.
func (*GlobalEnvironment) Std ¶
func (g *GlobalEnvironment) Std() *Module
func (*GlobalEnvironment) StdConstString ¶
func (g *GlobalEnvironment) StdConstString(name string) Type
func (*GlobalEnvironment) StdSubtype ¶
func (g *GlobalEnvironment) StdSubtype(name value.Symbol) Type
func (*GlobalEnvironment) StdSubtypeClass ¶
func (g *GlobalEnvironment) StdSubtypeClass(name value.Symbol) *Class
func (*GlobalEnvironment) StdSubtypeString ¶
func (g *GlobalEnvironment) StdSubtypeString(name string) Type
type Int16Literal ¶
type Int16Literal struct {
Value string
}
func NewInt16Literal ¶
func NewInt16Literal(value string) *Int16Literal
func (*Int16Literal) ToNonLiteral ¶
func (i *Int16Literal) ToNonLiteral(env *GlobalEnvironment) Type
type Int32Literal ¶
type Int32Literal struct {
Value string
}
func NewInt32Literal ¶
func NewInt32Literal(value string) *Int32Literal
func (*Int32Literal) ToNonLiteral ¶
func (i *Int32Literal) ToNonLiteral(env *GlobalEnvironment) Type
type Int64Literal ¶
type Int64Literal struct {
Value string
}
func NewInt64Literal ¶
func NewInt64Literal(value string) *Int64Literal
func (*Int64Literal) ToNonLiteral ¶
func (i *Int64Literal) ToNonLiteral(env *GlobalEnvironment) Type
type Int8Literal ¶
type Int8Literal struct {
Value string
}
func NewInt8Literal ¶
func NewInt8Literal(value string) *Int8Literal
func (*Int8Literal) ToNonLiteral ¶
func (i *Int8Literal) ToNonLiteral(env *GlobalEnvironment) Type
type IntLiteral ¶
type IntLiteral struct {
Value string
}
func NewIntLiteral ¶
func NewIntLiteral(value string) *IntLiteral
func (*IntLiteral) ToNonLiteral ¶
func (i *IntLiteral) ToNonLiteral(env *GlobalEnvironment) Type
type Intersection ¶
type Intersection struct {
Elements []Type
}
Intersection type represents a list of types. A value has to satisfy all of the types.
func NewIntersection ¶
func NewIntersection(elements ...Type) *Intersection
func (*Intersection) ToNonLiteral ¶
func (u *Intersection) ToNonLiteral(env *GlobalEnvironment) Type
type Method ¶
type Method struct { Name string Params []*Parameter OptionalParamCount int PostParamCount int HasNamedRestParam bool ReturnType Type ThrowType Type DefinedUnder ConstantContainer }
func (*Method) ExpectedParamCountString ¶
func (*Method) HasPositionalRestParam ¶
func (*Method) InspectSignature ¶
func (*Method) NamedRestParam ¶
func (*Method) PositionalRestParam ¶
func (*Method) PositionalRestParamIndex ¶
func (*Method) RequiredParamCount ¶
func (*Method) ToNonLiteral ¶
func (m *Method) ToNonLiteral(env *GlobalEnvironment) Type
type Mixin ¶
type Mixin struct { ConstantMap // contains filtered or unexported fields }
func (*Mixin) CreateProxy ¶
func (m *Mixin) CreateProxy() (head, tail *MixinProxy)
Create a proxy that has a pointer to this mixin.
Returns two values, the head and tail proxies. This is because of the fact that it's possible to include one mixin in another, so there is an entire inheritance chain.
func (*Mixin) DefineMethod ¶
func (*Mixin) Parent ¶
func (m *Mixin) Parent() ConstantContainer
func (*Mixin) SetParent ¶
func (m *Mixin) SetParent(parent *MixinProxy)
func (*Mixin) ToNonLiteral ¶
func (m *Mixin) ToNonLiteral(env *GlobalEnvironment) Type
type MixinProxy ¶
type MixinProxy struct { *Mixin // contains filtered or unexported fields }
func NewMixinProxy ¶
func NewMixinProxy(mixin *Mixin, parent ConstantContainer) *MixinProxy
func (*MixinProxy) Parent ¶
func (m *MixinProxy) Parent() ConstantContainer
func (*MixinProxy) SetParent ¶
func (m *MixinProxy) SetParent(parent ConstantContainer)
func (*MixinProxy) ToNonLiteral ¶
func (m *MixinProxy) ToNonLiteral(env *GlobalEnvironment) Type
type Module ¶
type Module struct {
ConstantMap
}
func (*Module) DefineMethod ¶
func (*Module) Parent ¶
func (m *Module) Parent() ConstantContainer
func (*Module) ToNonLiteral ¶
func (m *Module) ToNonLiteral(env *GlobalEnvironment) Type
type Never ¶
type Never struct{}
Never represents no value. It is the bottom type. For example a function that never returns might use the type `never`. It is a subtype of all other types.
func (Never) ToNonLiteral ¶
func (n Never) ToNonLiteral(env *GlobalEnvironment) Type
type Nilable ¶
type Nilable struct {
Type Type
}
func NewNilable ¶
func (*Nilable) ToNonLiteral ¶
func (n *Nilable) ToNonLiteral(env *GlobalEnvironment) Type
type Parameter ¶
type Parameter struct { Name value.Symbol Type Type Kind ParameterKind InstanceVariable bool }
func NewParameter ¶
func (*Parameter) HasDefaultValue ¶
func (*Parameter) IsNamedRest ¶
func (*Parameter) IsOptional ¶
func (*Parameter) IsPositionalRest ¶
func (*Parameter) NameWithKind ¶
type ParameterKind ¶
type ParameterKind uint8
const ( NormalParameterKind ParameterKind = iota DefaultValueParameterKind PositionalRestParameterKind NamedRestParameterKind )
type SingletonClass ¶
type SingletonClass struct {
AttachedObject ConstantContainer
}
Type that represents the singleton class of a mixin, class etc.
func NewSingletonClass ¶
func NewSingletonClass(attached ConstantContainer) *SingletonClass
func (*SingletonClass) IsSubtypeOf ¶
func (s *SingletonClass) IsSubtypeOf(other Type, env *GlobalEnvironment) bool
func (*SingletonClass) ToNonLiteral ¶
func (s *SingletonClass) ToNonLiteral(env *GlobalEnvironment) Type
type StringLiteral ¶
type StringLiteral struct {
Value string
}
func NewStringLiteral ¶
func NewStringLiteral(value string) *StringLiteral
func (*StringLiteral) IsSubtypeOf ¶
func (s *StringLiteral) IsSubtypeOf(other Type, env *GlobalEnvironment) bool
func (*StringLiteral) ToNonLiteral ¶
func (s *StringLiteral) ToNonLiteral(env *GlobalEnvironment) Type
type SymbolLiteral ¶
type SymbolLiteral struct {
Value string
}
func NewSymbolLiteral ¶
func NewSymbolLiteral(value string) *SymbolLiteral
func (*SymbolLiteral) ToNonLiteral ¶
func (s *SymbolLiteral) ToNonLiteral(env *GlobalEnvironment) Type
type Type ¶
type Type interface { ToNonLiteral(*GlobalEnvironment) Type // contains filtered or unexported methods }
func ToNilable ¶
func ToNilable(typ Type, env *GlobalEnvironment) Type
func ToNonNilable ¶
func ToNonNilable(typ Type, env *GlobalEnvironment) Type
type UInt16Literal ¶
type UInt16Literal struct {
Value string
}
func NewUInt16Literal ¶
func NewUInt16Literal(value string) *UInt16Literal
func (*UInt16Literal) ToNonLiteral ¶
func (i *UInt16Literal) ToNonLiteral(env *GlobalEnvironment) Type
type UInt32Literal ¶
type UInt32Literal struct {
Value string
}
func NewUInt32Literal ¶
func NewUInt32Literal(value string) *UInt32Literal
func (*UInt32Literal) ToNonLiteral ¶
func (i *UInt32Literal) ToNonLiteral(env *GlobalEnvironment) Type
type UInt64Literal ¶
type UInt64Literal struct {
Value string
}
func NewUInt64Literal ¶
func NewUInt64Literal(value string) *UInt64Literal
func (*UInt64Literal) ToNonLiteral ¶
func (i *UInt64Literal) ToNonLiteral(env *GlobalEnvironment) Type
type UInt8Literal ¶
type UInt8Literal struct {
Value string
}
func NewUInt8Literal ¶
func NewUInt8Literal(value string) *UInt8Literal
func (*UInt8Literal) ToNonLiteral ¶
func (i *UInt8Literal) ToNonLiteral(env *GlobalEnvironment) Type
type Union ¶
type Union struct {
Elements []Type
}
Union type represents a list of types. A value has to satisfy at least one of the types.
func (*Union) ToNonLiteral ¶
func (u *Union) ToNonLiteral(env *GlobalEnvironment) Type
type Void ¶
type Void struct{}
Void is the type that is incompatible with any other type.
func (Void) ToNonLiteral ¶
func (v Void) ToNonLiteral(env *GlobalEnvironment) Type