types

package
v0.0.0-...-1fe86a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package types contains the Elk type checker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inspect

func Inspect(typ Type) string

func IsAny

func IsAny(t Type) bool

func IsNever

func IsNever(t Type) bool

func IsNilable

func IsNilable(typ Type, env *GlobalEnvironment) bool

func IsVoid

func IsVoid(t Type) bool

func MakeFullConstantName

func MakeFullConstantName(containerName, constName string) string

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 NewClass

func NewClass(name string, parent ConstantContainer, consts map[value.Symbol]Type, methods MethodMap) *Class

func (*Class) DefineMethod

func (c *Class) DefineMethod(name string, params []*Parameter, returnType, throwType Type) *Method

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) Constants

func (c *ConstantMap) Constants() map[value.Symbol]Type

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.

func (*ConstantMap) Subtypes

func (c *ConstantMap) Subtypes() map[value.Symbol]Type

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) StdConst

func (g *GlobalEnvironment) StdConst(name value.Symbol) Type

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 GetMethod

func GetMethod(typ Type, name string, env *GlobalEnvironment) *Method

func NewMethod

func NewMethod(name string, params []*Parameter, returnType Type, throwType Type, definedUnder ConstantContainer) *Method

func (*Method) ExpectedParamCountString

func (m *Method) ExpectedParamCountString() string

func (*Method) HasPositionalRestParam

func (m *Method) HasPositionalRestParam() bool

func (*Method) InspectSignature

func (m *Method) InspectSignature() string

func (*Method) NamedRestParam

func (m *Method) NamedRestParam() *Parameter

func (*Method) PositionalRestParam

func (m *Method) PositionalRestParam() *Parameter

func (*Method) PositionalRestParamIndex

func (m *Method) PositionalRestParamIndex() int

func (*Method) RequiredParamCount

func (m *Method) RequiredParamCount() int

func (*Method) ToNonLiteral

func (m *Method) ToNonLiteral(env *GlobalEnvironment) Type

type MethodMap

type MethodMap map[value.Symbol]*Method

type Mixin

type Mixin struct {
	ConstantMap
	// contains filtered or unexported fields
}

func NewMixin

func NewMixin(name string, parent *MixinProxy, consts map[value.Symbol]Type, subtypes map[value.Symbol]Type, methods MethodMap) *Mixin

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 (m *Mixin) DefineMethod(name string, params []*Parameter, returnType, throwType Type) *Method

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 NewModule

func NewModule(
	name string,
	consts map[value.Symbol]Type,
	subtypes map[value.Symbol]Type,
	methods MethodMap,
) *Module

func (*Module) DefineMethod

func (m *Module) DefineMethod(name string, params []*Parameter, returnType, throwType Type) *Method

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 NewNilable(typ Type) *Nilable

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 NewParameter(name value.Symbol, typ Type, kind ParameterKind, instanceVariable bool) *Parameter

func (*Parameter) HasDefaultValue

func (p *Parameter) HasDefaultValue() bool

func (*Parameter) IsNamedRest

func (p *Parameter) IsNamedRest() bool

func (*Parameter) IsOptional

func (p *Parameter) IsOptional() bool

func (*Parameter) IsPositionalRest

func (p *Parameter) IsPositionalRest() bool

func (*Parameter) NameWithKind

func (p *Parameter) NameWithKind() string

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 NewUnion

func NewUnion(elements ...Type) *Union

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

Directories

Path Synopsis
Package ast defines typed AST nodes used by Elk
Package ast defines typed AST nodes used by Elk
Package checker implements the Elk type checker
Package checker implements the Elk type checker

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL