Documentation
¶
Overview ¶
Package checker implements the Elk type checker
Package checker implements the Elk type checker ¶
Package checker implements the Elk type checker
Index ¶
- Constants
- Variables
- func CheckAST(sourceName string, ast *ast.ProgramNode, globalEnv *types.GlobalEnvironment, ...) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
- func CheckASTNative(sourceName string, ast *ast.ProgramNode, globalEnv *types.GlobalEnvironment, ...) (*compiler.GoCompiler, diagnostic.DiagnosticList)
- func CheckFile(fileName string, globalEnv *types.GlobalEnvironment, flags bitfield.BitField16, ...) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
- func CheckFileNative(fileName string, globalEnv *types.GlobalEnvironment, output io.Writer, ...) (*compiler.GoCompiler, diagnostic.DiagnosticList)
- func CheckSource(sourceName string, source string, globalEnv *types.GlobalEnvironment, ...) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
- func CheckSourceNative(sourceName string, source string, globalEnv *types.GlobalEnvironment, ...) (*compiler.GoCompiler, diagnostic.DiagnosticList)
- func I(typ types.Type) string
- type CheckExpressionFunc
- type Checker
- func (c *Checker) CanBeFalsy(typ types.Type) bool
- func (c *Checker) CanBeTruthy(typ types.Type) bool
- func (c *Checker) CheckSource(sourceName string, source string) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
- func (c *Checker) ClearErrors()
- func (c *Checker) DefinedMacros() bool
- func (c *Checker) Env() *types.GlobalEnvironment
- func (c *Checker) GetIteratorElementType(typ types.Type) (types.Type, types.Type)
- func (c *Checker) GetIteratorType(typ types.Type) types.Type
- func (c *Checker) IsClosure(typ types.Namespace) bool
- func (c *Checker) IsFalse(typ types.Type) bool
- func (c *Checker) IsFalsy(typ types.Type) bool
- func (c *Checker) IsHeader() bool
- func (c *Checker) IsIncremental() bool
- func (c *Checker) IsNil(typ types.Type) bool
- func (c *Checker) IsNilable(typ types.Type) bool
- func (c *Checker) IsNotNilable(typ types.Type) bool
- func (c *Checker) IsSubtype(a, b types.Type) bool
- func (c *Checker) IsTheSameNamespace(a, b types.Namespace) bool
- func (c *Checker) IsTheSameType(a, b types.Type) bool
- func (c *Checker) IsTrue(typ types.Type) bool
- func (c *Checker) IsTruthy(typ types.Type) bool
- func (c *Checker) MacroTypeOf(node ast.Node) types.Type
- func (c *Checker) NewNormalisedIntersection(elements ...types.Type) types.Type
- func (c *Checker) NewNormalisedUnion(elements ...types.Type) types.Type
- func (c *Checker) NormaliseType(typ types.Type) types.Type
- func (c *Checker) SelfType() types.Type
- func (c *Checker) SetHeader(val bool)
- func (c *Checker) SetIncremental(val bool)
- func (c *Checker) Std(name value.Symbol) types.Type
- func (c *Checker) StdAST() *types.Module
- func (c *Checker) StdAnyInt() types.Type
- func (c *Checker) StdArrayList() *types.Class
- func (c *Checker) StdArrayTuple() *types.Class
- func (c *Checker) StdBigFloat() *types.Class
- func (c *Checker) StdBool() *types.Class
- func (c *Checker) StdClass() *types.Class
- func (c *Checker) StdConstantNode() *types.Mixin
- func (c *Checker) StdConstantNodeConvertible() *types.Interface
- func (c *Checker) StdElk() *types.Module
- func (c *Checker) StdExpressionNode() *types.Mixin
- func (c *Checker) StdExpressionNodeConvertible() *types.Interface
- func (c *Checker) StdFalse() *types.Class
- func (c *Checker) StdFloat() *types.Class
- func (c *Checker) StdHashMap() *types.Class
- func (c *Checker) StdHashRecord() *types.Class
- func (c *Checker) StdHashSet() *types.Class
- func (c *Checker) StdIdentifierNode() *types.Mixin
- func (c *Checker) StdIdentifierNodeConvertible() *types.Interface
- func (c *Checker) StdInspectable() types.Type
- func (c *Checker) StdInstanceVariableNode() *types.Mixin
- func (c *Checker) StdInstanceVariableNodeConvertible() *types.Interface
- func (c *Checker) StdInt() *types.Class
- func (c *Checker) StdList() *types.Mixin
- func (c *Checker) StdLiteralPatternNode() *types.Mixin
- func (c *Checker) StdLiteralPatternNodeConvertible() *types.Interface
- func (c *Checker) StdMap() *types.Mixin
- func (c *Checker) StdNil() *types.Class
- func (c *Checker) StdNode() *types.Mixin
- func (c *Checker) StdNodeConvertible() *types.Interface
- func (c *Checker) StdPatternNode() *types.Mixin
- func (c *Checker) StdPatternNodeConvertible() *types.Interface
- func (c *Checker) StdPrimitiveIterable() *types.Interface
- func (c *Checker) StdRange() *types.Mixin
- func (c *Checker) StdRecord() *types.Mixin
- func (c *Checker) StdSet() *types.Mixin
- func (c *Checker) StdString() *types.Class
- func (c *Checker) StdStringConvertible() types.Type
- func (c *Checker) StdTrue() *types.Class
- func (c *Checker) StdTuple() *types.Mixin
- func (c *Checker) StdTypeNode() *types.Mixin
- func (c *Checker) StdTypeNodeConvertible() *types.Interface
- func (c *Checker) StdValue() *types.Class
- func (c *Checker) ToNilable(typ types.Type) types.Type
- func (c *Checker) ToNonFalsy(typ types.Type) types.Type
- func (c *Checker) ToNonLiteral(typ types.Type, widenSingletonTypes bool) types.Type
- func (c *Checker) ToNonNilable(typ types.Type) types.Type
- func (c *Checker) ToNonTruthy(typ types.Type) types.Type
- func (c *Checker) TypeOf(node ast.Node) types.Type
- func (c *Checker) TypesIntersect(a, b types.Type) bool
Constants ¶
const ( HeaderFlag bitfield.BitFlag16 = 1 << iota // whether the currently checked file is an Elk header file `.elh` GoCompilerFlag )
const ( NEW_CONST constState = iota CHECKING_CONST CHECKED_CONST )
const ( NEW_TYPEDEF typedefState = iota CHECKING_MACRO_TYPEDEF CHECKED_MACRO_TYPEDEF CHECKING_TYPEDEF CHECKED_TYPEDEF ERROR_TYPEDEF )
Variables ¶
var MethodCheckConcurrencyLimit = 100
Functions ¶
func CheckAST ¶
func CheckAST(sourceName string, ast *ast.ProgramNode, globalEnv *types.GlobalEnvironment, flags bitfield.BitField16, threadPool *vm.ThreadPool) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
Check the types of an Elk AST and generate bytecode
func CheckASTNative ¶
func CheckASTNative(sourceName string, ast *ast.ProgramNode, globalEnv *types.GlobalEnvironment, output io.Writer, threadPool *vm.ThreadPool) (*compiler.GoCompiler, diagnostic.DiagnosticList)
Check the types of an Elk AST and generate Go source
func CheckFile ¶
func CheckFile(fileName string, globalEnv *types.GlobalEnvironment, flags bitfield.BitField16, threadPool *vm.ThreadPool) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
Check the types of an Elk file and generate bytecode
func CheckFileNative ¶
func CheckFileNative(fileName string, globalEnv *types.GlobalEnvironment, output io.Writer, threadPool *vm.ThreadPool) (*compiler.GoCompiler, diagnostic.DiagnosticList)
Check the types of an Elk file and generate Go source
func CheckSource ¶
func CheckSource(sourceName string, source string, globalEnv *types.GlobalEnvironment, flags bitfield.BitField16, threadPool *vm.ThreadPool) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
Check the types of Elk source code ang generate bytecode
func CheckSourceNative ¶
func CheckSourceNative(sourceName string, source string, globalEnv *types.GlobalEnvironment, output io.Writer, threadPool *vm.ThreadPool) (*compiler.GoCompiler, diagnostic.DiagnosticList)
Check the types of Elk source code and generate Go source
Types ¶
type CheckExpressionFunc ¶
type CheckExpressionFunc func(ast.ExpressionNode) ast.ExpressionNode
type Checker ¶
type Checker struct {
Filename string // name of the current source file
Errors *diagnostic.SyncDiagnosticList // list of typechecking errors
ASTCache *concurrent.Map[string, *ast.ProgramNode] // stores the ASTs of parsed source code files
// contains filtered or unexported fields
}
Holds the state of the type checking process
func NewWithEnv ¶
func NewWithEnv(env *types.GlobalEnvironment) *Checker
Instantiate a new Checker instance.
func (*Checker) CheckSource ¶
func (c *Checker) CheckSource(sourceName string, source string) (*vm.BytecodeFunction, diagnostic.DiagnosticList)
Used in the REPL to typecheck and compile the input
func (*Checker) ClearErrors ¶
func (c *Checker) ClearErrors()
func (*Checker) DefinedMacros ¶
func (*Checker) Env ¶
func (c *Checker) Env() *types.GlobalEnvironment
func (*Checker) GetIteratorElementType ¶
func (*Checker) IsIncremental ¶
func (*Checker) IsNotNilable ¶
Type cannot be `nil`
func (*Checker) IsTheSameNamespace ¶
Check whether the two given types represent the same type. Return true if they do, otherwise false.
func (*Checker) MacroTypeOf ¶
Returns the type of the AST node, for use in macros