have

package
v0.0.0-...-cd658ce Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2017 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Negotiate and validate types in an AST.

Index

Constants

View Source
const (
	OBJECT_VAR = ObjectType(iota + 1)
	OBJECT_TYPE
	OBJECT_PACKAGE
	OBJECT_LABEL
	OBJECT_GENERIC
	OBJECT_GENERIC_TYPE
)
View Source
const (
	WHEN_KIND_IS = WhenPredicateKind(iota + 1)
	WHEN_KIND_IMPLEMENTS
	WHEN_KIND_DEFAULT
)
View Source
const (
	KIND_SIMPLE = Kind(iota + 1)
	KIND_ARRAY
	KIND_SLICE
	KIND_MAP
	KIND_POINTER
	KIND_CUSTOM
	KIND_STRUCT
	KIND_INTERFACE
	KIND_TUPLE
	KIND_FUNC
	KIND_CHAN
	// Type checker code doesn't have to bother with KIND_GENERIC_PARAM, all types of the generic kind
	// are substituted with actual types before they end up in type checker.
	KIND_GENERIC_PARAM
	KIND_GENERIC_INST
	KIND_UNKNOWN
)
View Source
const (
	SIMPLE_TYPE_BOOL = SimpleTypeID(iota + 1)
	SIMPLE_TYPE_BYTE
	SIMPLE_TYPE_COMPLEX128
	SIMPLE_TYPE_COMPLEX64
	SIMPLE_TYPE_ERROR
	SIMPLE_TYPE_FLOAT32
	SIMPLE_TYPE_FLOAT64
	SIMPLE_TYPE_INT
	SIMPLE_TYPE_INT16
	SIMPLE_TYPE_INT32
	SIMPLE_TYPE_INT64
	SIMPLE_TYPE_INT8
	SIMPLE_TYPE_RUNE
	SIMPLE_TYPE_STRING
	SIMPLE_TYPE_UINT
	SIMPLE_TYPE_UINT16
	SIMPLE_TYPE_UINT32
	SIMPLE_TYPE_UINT64
	SIMPLE_TYPE_UINT8
	SIMPLE_TYPE_UINTPTR
)
View Source
const (
	CHAN_DIR_BI = ChanDir(iota)
	CHAN_DIR_RECEIVE
	CHAN_DIR_SEND
)
View Source
const Blank = "_"
View Source
const BuiltinsFileName = "_builtin.hav"
View Source
const LocalPkg = "."

Variables

View Source
var ForcedIndent = &forcedIndent{}

Functions

func AreComparable

func AreComparable(tc *TypesContext, e1, e2 TypedExpr) bool

Implements the definition of comparable operands from the Go spec. Panic if e1's or e2's methods return errors - their types need to be negotiated earlier.

func AreOrdered

func AreOrdered(t1, t2 Type) bool

Implements the definition of ordered operands from the Go spec.

func CheckCondition

func CheckCondition(tc *TypesContext, expr TypedExpr) error

func CheckTypeAssert

func CheckTypeAssert(tc *TypesContext, src TypedExpr, target Type) error

Check if type assertion is sane.

func Implements

func Implements(iface, value Type) bool

Tells whether value's methods are a subset of iface's methods.

func IsAssignable

func IsAssignable(to, what Type) bool

Implements the definition of assignability from the Go spec.

func IsBlank

func IsBlank(e TypedExpr) bool

func IsBoolAssignable

func IsBoolAssignable(t Type) bool

func IsConvertable

func IsConvertable(tc *TypesContext, what TypedExpr, to Type) bool

Implements convertability definition from Go spec https://golang.ir/ref/spec#Conversions

func IsIdentincal

func IsIdentincal(to, what Type) bool

func IsInterface

func IsInterface(t Type) bool

Can be used to check if a type is an interface. Works with interfaces aliased by named types.

func IsNamed

func IsNamed(t Type) bool

Implements the definition of named types from the Go spec.

func IsPackage

func IsPackage(e TypedExpr) bool

func IsTypeBool

func IsTypeBool(t Type) bool

func IsTypeComplexType

func IsTypeComplexType(t Type) bool

func IsTypeFloatKind

func IsTypeFloatKind(t Type) bool

func IsTypeInt

func IsTypeInt(t Type) bool

func IsTypeIntKind

func IsTypeIntKind(t Type) bool

func IsTypeNumeric

func IsTypeNumeric(t Type) bool

func IsTypeSimple

func IsTypeSimple(t Type, simpleType SimpleTypeID) bool

func IsTypeString

func IsTypeString(t Type) bool

func IsUnnamed

func IsUnnamed(t Type) bool

Implements the definition of unnamed types from the Go spec.

func NegotiateExprType

func NegotiateExprType(tc *TypesContext, varType *Type, value TypedExpr) error

This will overwrite the type pointer by varType.

func NegotiateTupleUnpackAssign

func NegotiateTupleUnpackAssign(tc *TypesContext, onlyFuncCalls bool, lhsTypes []*Type, rhs TypedExpr) error

Helper function useful for situations where an expression returning more than one result is assigned to multiple variables. In some situations only func calls unpacking works. Type assertions or map inclusion testing doesn't work in non-assignment situtations, examples:

func x() int, bool:

return someMap[7] // Doesn't work (in Golang as well)

func x(int, bool):

pass

x(someMap[7]) // Doesn't work (in Golang as well)

UseonlyFuncCalls argument to control this.

Types

type ArrayExpr

type ArrayExpr struct {
	Left  Expr
	Index []Expr
	// contains filtered or unexported fields
}

implements PrimaryExpr

func (*ArrayExpr) ApplyType

func (ex *ArrayExpr) ApplyType(tc *TypesContext, typ Type) error

func (*ArrayExpr) Generate

func (ae *ArrayExpr) Generate(tc *TypesContext, current *CodeChunk)

func (*ArrayExpr) GuessType

func (ex *ArrayExpr) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*ArrayExpr) Pos

func (e *ArrayExpr) Pos() gotoken.Pos

func (*ArrayExpr) ReferedObject

func (ex *ArrayExpr) ReferedObject() Object

func (*ArrayExpr) Type

func (ex *ArrayExpr) Type(tc *TypesContext) (Type, error)

type ArrayType

type ArrayType struct {
	Size int
	Of   Type
}

func (*ArrayType) Kind

func (t *ArrayType) Kind() Kind

func (*ArrayType) Known

func (t *ArrayType) Known() bool

func (*ArrayType) MapSubtypes

func (t *ArrayType) MapSubtypes(callback func(t Type) bool)

func (*ArrayType) String

func (t *ArrayType) String() string

func (*ArrayType) ZeroValue

func (t *ArrayType) ZeroValue() string

type AssignStmt

type AssignStmt struct {
	Lhs, Rhs []Expr
	Token    *Token
	// contains filtered or unexported fields
}

implements SimpleStmt

func (*AssignStmt) Generate

func (as *AssignStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*AssignStmt) InlineGenerate

func (as *AssignStmt) InlineGenerate(tc *TypesContext, current *CodeChunk, noParenth bool)

func (*AssignStmt) Label

func (s *AssignStmt) Label() *Object

func (*AssignStmt) NegotiateTypes

func (as *AssignStmt) NegotiateTypes(tc *TypesContext) error

type BasicLit

type BasicLit struct {
	// contains filtered or unexported fields
}

implements Expr

func (*BasicLit) ApplyType

func (ex *BasicLit) ApplyType(tc *TypesContext, typ Type) error

func (*BasicLit) Generate

func (lit *BasicLit) Generate(tc *TypesContext, current *CodeChunk)

func (*BasicLit) GuessType

func (ex *BasicLit) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*BasicLit) Pos

func (e *BasicLit) Pos() gotoken.Pos

func (*BasicLit) Type

func (ex *BasicLit) Type(tc *TypesContext) (Type, error)

type BinaryOp

type BinaryOp struct {
	Left, Right Expr
	// contains filtered or unexported fields
}

implements Expr

func (*BinaryOp) ApplyType

func (ex *BinaryOp) ApplyType(tc *TypesContext, typ Type) error

func (*BinaryOp) Generate

func (op *BinaryOp) Generate(tc *TypesContext, current *CodeChunk)

func (*BinaryOp) GuessType

func (ex *BinaryOp) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*BinaryOp) Pos

func (e *BinaryOp) Pos() gotoken.Pos

func (*BinaryOp) Type

func (ex *BinaryOp) Type(tc *TypesContext) (Type, error)

type BlankExpr

type BlankExpr struct {
	// contains filtered or unexported fields
}

Blank expression, represents no expression. Sometimes useful. implements Expr

func NewBlankExpr

func NewBlankExpr() *BlankExpr

func (*BlankExpr) ApplyType

func (ex *BlankExpr) ApplyType(tc *TypesContext, typ Type) error

func (*BlankExpr) GuessType

func (ex *BlankExpr) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*BlankExpr) Pos

func (e *BlankExpr) Pos() gotoken.Pos

func (*BlankExpr) Type

func (ex *BlankExpr) Type(tc *TypesContext) (Type, error)

type BranchStmt

type BranchStmt struct {
	Token *Token
	Right *Ident

	// Is nil for breaks/continues in unnamed loops/switches.
	GotoLabel *LabelStmt
	// Is nil for goto statements. Otherwise it is the statement
	// that the continue/break refers to.
	Branchable Stmt
	// contains filtered or unexported fields
}

Break, continue, goto

func (*BranchStmt) Generate

func (bs *BranchStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*BranchStmt) Label

func (s *BranchStmt) Label() *Object

func (*BranchStmt) NegotiateTypes

func (bs *BranchStmt) NegotiateTypes(tc *TypesContext) error

type BranchStmtsMap

type BranchStmtsMap map[string][]*BranchStmt

BranchStmtsMap is used to store branch statements (break, continue, goto) that haven't been paired with their labels/statements yet. When parser finishes parsing blocks of code/branchable statments, it looks into this structure to see if there were any matches.

func (BranchStmtsMap) Add

func (b BranchStmtsMap) Add(bs *BranchStmt)

func (BranchStmtsMap) FindAll

func (b BranchStmtsMap) FindAll(label string) []*BranchStmt

func (BranchStmtsMap) MatchBranchableStmt

func (b BranchStmtsMap) MatchBranchableStmt(branchable Stmt, lblName string, allowedBranchStmts ...TokenType)

func (BranchStmtsMap) MatchGotoLabels

func (b BranchStmtsMap) MatchGotoLabels(labels map[string]*LabelStmt)

func (BranchStmtsMap) Remove

func (b BranchStmtsMap) Remove(bs *BranchStmt)

type BranchStmtsTree

type BranchStmtsTree struct {
	Members  BranchStmtsMap
	Children []*BranchStmtsTree
}

BranchStmtsTree stores a hierarchy of BranchStmtsMaps. Each nested block of code has its own BranchStmtsMap. This tree is needed to detect situations where gotos jump into blocks of code (only jumping outside/within blocks is possible).

func NewBranchStmtsTree

func NewBranchStmtsTree() *BranchStmtsTree

func (*BranchStmtsTree) CountBranchStmts

func (b *BranchStmtsTree) CountBranchStmts() int

func (*BranchStmtsTree) FindAll

func (b *BranchStmtsTree) FindAll(label string) []*BranchStmt

func (*BranchStmtsTree) MatchBranchableStmt

func (b *BranchStmtsTree) MatchBranchableStmt(branchable Stmt, lblName string, allowedBranchStmts ...TokenType)

Call MatchBranchableStmt on every BranchStmtsMap in the tree.

func (*BranchStmtsTree) MatchGotoLabels

func (b *BranchStmtsTree) MatchGotoLabels(labels map[string]*LabelStmt)

Call MatchGotoLabels on every BranchStmtsMap in the tree.

func (*BranchStmtsTree) NewChild

func (b *BranchStmtsTree) NewChild() *BranchStmtsTree

type BranchTreesStack

type BranchTreesStack []*BranchStmtsTree

type ChanDir

type ChanDir int

type ChanType

type ChanType struct {
	Of  Type
	Dir ChanDir
}

func (*ChanType) Kind

func (t *ChanType) Kind() Kind

func (*ChanType) Known

func (t *ChanType) Known() bool

func (*ChanType) MapSubtypes

func (t *ChanType) MapSubtypes(callback func(t Type) bool)

func (*ChanType) String

func (t *ChanType) String() string

func (*ChanType) ZeroValue

func (t *ChanType) ZeroValue() string

type CodeBlock

type CodeBlock struct {
	Statements []Stmt
	Labels     map[string]*LabelStmt
}

func (*CodeBlock) AddLabel

func (cb *CodeBlock) AddLabel(l *LabelStmt) error

func (*CodeBlock) CheckTypes

func (cb *CodeBlock) CheckTypes(tc *TypesContext) error

func (*CodeBlock) Generate

func (bl *CodeBlock) Generate(tc *TypesContext, current *CodeChunk)

type CodeChunk

type CodeChunk struct {
	// contains filtered or unexported fields
}

CodeChunk can either be a slice of smaller CodeChunks or its value can be a string. Think of it as of a union type. Every statement should have a separate CodeChunk. Statements that (directly) contain a block of code should be flagged (it will be used to insert code that "spills" beyond the current block of code).

func (*CodeChunk) AddChprintf

func (cc *CodeChunk) AddChprintf(tc *TypesContext, format string, a ...interface{})

Format using fmt.Sprintf, but with one addition: "%C" can be used to add Generables. Use "%iC" variant for InlineGenerables. Indents are inserted automatically, but for multi-line statements that need extra indents in the middle, use the ForcedIndent generable.

func (*CodeChunk) AddChunks

func (cc *CodeChunk) AddChunks(chunks ...*CodeChunk)

func (*CodeChunk) AddString

func (cc *CodeChunk) AddString(s string)

func (*CodeChunk) NewBlockChunk

func (cc *CodeChunk) NewBlockChunk() *CodeChunk

func (*CodeChunk) NewChunk

func (cc *CodeChunk) NewChunk() *CodeChunk

Created a new empty chunk whose parent is the receiver.

func (*CodeChunk) NewStrChunk

func (cc *CodeChunk) NewStrChunk(s string) *CodeChunk

func (*CodeChunk) ReadAll

func (cc *CodeChunk) ReadAll() string

TODO: implement it in a io.Reader form, not keeping all results in memory

type CompileError

type CompileError struct {
	Message string
	Pos     gotoken.Pos
}

func CompileErrorf

func CompileErrorf(token *Token, message string, args ...interface{}) *CompileError

func ExprErrorf

func ExprErrorf(expr Expr, message string, args ...interface{}) *CompileError

func (*CompileError) Error

func (ce *CompileError) Error() string

func (*CompileError) PrettyString

func (ce *CompileError) PrettyString(fset *gotoken.FileSet) string

type CompoundLit

type CompoundLit struct {
	Left Expr
	// contains filtered or unexported fields
}

implements Expr

func (*CompoundLit) ApplyType

func (ex *CompoundLit) ApplyType(tc *TypesContext, typ Type) error

func (*CompoundLit) Generate

func (lit *CompoundLit) Generate(tc *TypesContext, current *CodeChunk)

func (*CompoundLit) GuessType

func (ex *CompoundLit) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*CompoundLit) Pos

func (e *CompoundLit) Pos() gotoken.Pos

func (*CompoundLit) Type

func (ex *CompoundLit) Type(tc *TypesContext) (Type, error)

type CompoundLitKind

type CompoundLitKind int
const (
	COMPOUND_UNKNOWN CompoundLitKind = iota
	COMPOUND_EMPTY
	COMPOUND_LISTLIKE
	COMPOUND_MAPLIKE
)

type CustomType

type CustomType struct {
	// Base name of the type. Doesn't include package name for external types.
	Name string
	// nil means local
	Package *ImportStmt
	Decl    *TypeDecl
}

func (*CustomType) Kind

func (t *CustomType) Kind() Kind

func (*CustomType) Known

func (t *CustomType) Known() bool

func (*CustomType) MapSubtypes

func (t *CustomType) MapSubtypes(callback func(t Type) bool)

func (*CustomType) NamePtr

func (t *CustomType) NamePtr() *string

func (*CustomType) PackagePtr

func (t *CustomType) PackagePtr() *ImportStmt

func (*CustomType) RootType

func (t *CustomType) RootType() Type

func (*CustomType) String

func (t *CustomType) String() string

func (*CustomType) ZeroValue

func (t *CustomType) ZeroValue() string

type DeclChain

type DeclChain []*VarDecl

Chain of variable declarations. Sample uses:

  • multi-element variable declaration
  • function arguments definition
  • function results definition

func (DeclChain) Generate

func (dc DeclChain) Generate(tc *TypesContext, current *CodeChunk)

type DeclaredType

type DeclaredType interface {
	Type
	NamePtr() *string
	RootType() Type
	PackagePtr() *ImportStmt
}

type DotSelector

type DotSelector struct {
	Left  Expr
	Right *Ident
	// contains filtered or unexported fields
}

implements Expr

func (*DotSelector) ApplyType

func (ex *DotSelector) ApplyType(tc *TypesContext, typ Type) error

func (*DotSelector) Generate

func (ds *DotSelector) Generate(tc *TypesContext, current *CodeChunk)

func (*DotSelector) GuessType

func (ex *DotSelector) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*DotSelector) Pos

func (e *DotSelector) Pos() gotoken.Pos

func (*DotSelector) ReferedObject

func (ex *DotSelector) ReferedObject() Object

func (*DotSelector) Type

func (ex *DotSelector) Type(tc *TypesContext) (Type, error)

type EmptyGenerable

type EmptyGenerable struct{}

func (EmptyGenerable) Generate

func (eg EmptyGenerable) Generate(tc *TypesContext, current *CodeChunk)

func (EmptyGenerable) InlineGenerate

func (vs EmptyGenerable) InlineGenerate(tc *TypesContext, current *CodeChunk, noParenth bool)

type Expr

type Expr interface {
	Pos() gotoken.Pos
}

type ExprStmt

type ExprStmt struct {
	Expression Expr
	// contains filtered or unexported fields
}

implements Stmt Statement wrapper for expressions.

func (*ExprStmt) Generate

func (es *ExprStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*ExprStmt) InlineGenerate

func (es *ExprStmt) InlineGenerate(tc *TypesContext, current *CodeChunk, noParenth bool)

func (*ExprStmt) Label

func (s *ExprStmt) Label() *Object

func (*ExprStmt) NegotiateTypes

func (es *ExprStmt) NegotiateTypes(tc *TypesContext) error

type ExprToProcess

type ExprToProcess interface {
	Expr
	NegotiateTypes(tc *TypesContext) error
}

Provides a type checking context to typed expressions.

type File

type File struct {
	Name, Code, Pkg string
	// contains filtered or unexported fields
}

func NewFile

func NewFile(name, code string) *File

func (*File) Generate

func (f *File) Generate(tc *TypesContext, current *CodeChunk)

func (*File) GenerateCode

func (f *File) GenerateCode() string

func (*File) Parse

func (f *File) Parse() []error

func (*File) ParseAndCheck

func (f *File) ParseAndCheck() []error

func (*File) Typecheck

func (f *File) Typecheck() []error

type ForRangeStmt

type ForRangeStmt struct {

	// Either ScopedVars or OutsideVars is nil
	ScopedVars  *VarDecl
	OutsideVars []Expr
	Series      Expr
	Code        *CodeBlock
	// contains filtered or unexported fields
}

func (*ForRangeStmt) Generate

func (fs *ForRangeStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*ForRangeStmt) Label

func (s *ForRangeStmt) Label() *Object

func (*ForRangeStmt) NegotiateTypes

func (fs *ForRangeStmt) NegotiateTypes(tc *TypesContext) error

type ForStmt

type ForStmt struct {
	ScopedVar  Stmt
	Condition  Expr
	RepeatStmt SimpleStmt
	Code       *CodeBlock
	// contains filtered or unexported fields
}

implements Stmt

func (*ForStmt) Generate

func (fs *ForStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*ForStmt) Label

func (s *ForStmt) Label() *Object

func (*ForStmt) NegotiateTypes

func (fs *ForStmt) NegotiateTypes(tc *TypesContext) error

type FuncCallExpr

type FuncCallExpr struct {
	Left Expr
	Args []Expr
	// Ellipsis is true if the last argument is variadic.
	Ellipsis bool
	// contains filtered or unexported fields
}

implements PrimaryExpr

func (*FuncCallExpr) ApplyType

func (ex *FuncCallExpr) ApplyType(tc *TypesContext, typ Type) error

func (*FuncCallExpr) Generate

func (fc *FuncCallExpr) Generate(tc *TypesContext, current *CodeChunk)

func (*FuncCallExpr) GuessType

func (ex *FuncCallExpr) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*FuncCallExpr) IsNullResult

func (ex *FuncCallExpr) IsNullResult(tc *TypesContext) bool

True if this function call doesn't return any value. Needs to operate on function call that has been already typechecked.

func (*FuncCallExpr) Pos

func (e *FuncCallExpr) Pos() gotoken.Pos

func (*FuncCallExpr) Type

func (ex *FuncCallExpr) Type(tc *TypesContext) (Type, error)

type FuncDecl

type FuncDecl struct {
	Args, Results DeclChain
	// Ellipsis is true if the last argument is variadic.
	Ellipsis bool
	Code     *CodeBlock
	// Is nil for non-method functions
	Receiver *Variable
	// Indicates whether the receiver is a pointer.
	// It is redundant for structs, but is useful for interfaces
	// (where Receiver is nil).
	PtrReceiver bool
	// Names of generic type paramaters. Nil for standard functions.
	GenericParams []string
	// Values of generic parameters. Nil for standard functions.
	GenericParamVals []Type
	// contains filtered or unexported fields
}

implements PrimaryExpr

func (*FuncDecl) ApplyType

func (ex *FuncDecl) ApplyType(tc *TypesContext, typ Type) error

func (*FuncDecl) Generate

func (fd *FuncDecl) Generate(tc *TypesContext, current *CodeChunk)

func (*FuncDecl) GuessType

func (ex *FuncDecl) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*FuncDecl) InlineGenerate

func (fd *FuncDecl) InlineGenerate(tc *TypesContext, current *CodeChunk, noParenth bool)

func (*FuncDecl) Pos

func (e *FuncDecl) Pos() gotoken.Pos

func (*FuncDecl) Type

func (ex *FuncDecl) Type(tc *TypesContext) (Type, error)

type FuncType

type FuncType struct {
	Args, Results []Type
	// Ellipsis is true if the last argument is variadic.
	Ellipsis bool
}

func (*FuncType) Header

func (t *FuncType) Header() string

func (*FuncType) Kind

func (t *FuncType) Kind() Kind

func (*FuncType) Known

func (t *FuncType) Known() bool

func (*FuncType) MapSubtypes

func (t *FuncType) MapSubtypes(callback func(t Type) bool)

func (*FuncType) String

func (t *FuncType) String() string

func (*FuncType) ZeroValue

func (t *FuncType) ZeroValue() string

type Generable

type Generable interface {
	// Generate the full version of the output code.
	Generate(tc *TypesContext, current *CodeChunk)
}

type Generic

type Generic interface {
	Object

	// Name of the generic + names of the params.
	Signature() (name string, params []string)
	Instantiate(tc *TypesContext, params ...Type) (Object, string, []error)
	Code() []rune
	// Imports that should be used when parsing instantiation of the generic.
	// Usually they are inherited from the source file where the generic was declared.
	Imports() Imports
	// Token file containing the definition of the generic and offset where
	// the definition starts in the file.
	Location() (tfile *gotoken.File, offset int)
}

func ExprToGeneric

func ExprToGeneric(e Expr) (t Generic, err error)

Just like ExprToTypeName, but for generics.

type GenericFunc

type GenericFunc struct {
	Func *FuncDecl
	// contains filtered or unexported fields
}

Implements Stmt, Object

func (*GenericFunc) Code

func (gf *GenericFunc) Code() []rune

func (*GenericFunc) Generate

func (gf *GenericFunc) Generate(tc *TypesContext, current *CodeChunk)

func (*GenericFunc) Imports

func (gf *GenericFunc) Imports() Imports

func (*GenericFunc) Instantiate

func (gf *GenericFunc) Instantiate(tc *TypesContext, params ...Type) (Object, string, []error)

func (*GenericFunc) Label

func (s *GenericFunc) Label() *Object

func (*GenericFunc) Location

func (gf *GenericFunc) Location() (*gotoken.File, int)

func (*GenericFunc) Name

func (gf *GenericFunc) Name() string

func (*GenericFunc) NegotiateTypes

func (ls *GenericFunc) NegotiateTypes(tc *TypesContext) error

func (*GenericFunc) ObjectType

func (gf *GenericFunc) ObjectType() ObjectType

func (*GenericFunc) Signature

func (gf *GenericFunc) Signature() (string, []string)

type GenericParamType

type GenericParamType struct {
	Name     string
	Concrete Type
}

Implements Type

func (*GenericParamType) Kind

func (t *GenericParamType) Kind() Kind

func (t *GenericType) Kind() Kind { return t.Concrete.Kind() }

func (*GenericParamType) Known

func (t *GenericParamType) Known() bool

func (*GenericParamType) MapSubtypes

func (t *GenericParamType) MapSubtypes(callback func(t Type) bool)

func (*GenericParamType) String

func (t *GenericParamType) String() string

func (*GenericParamType) ZeroValue

func (t *GenericParamType) ZeroValue() string

type GenericParamTypeDecl

type GenericParamTypeDecl struct {
	// contains filtered or unexported fields
}

Represents an argument to a generic statment (in early stages of compilation they can't be treated as type declarations - they are just placeholders for future types). Implements Object and Stmt

func (*GenericParamTypeDecl) Label

func (s *GenericParamTypeDecl) Label() *Object

func (*GenericParamTypeDecl) Name

func (g *GenericParamTypeDecl) Name() string

func (*GenericParamTypeDecl) ObjectType

func (g *GenericParamTypeDecl) ObjectType() ObjectType

type GenericStruct

type GenericStruct struct {
	// contains filtered or unexported fields
}

Implements Stmt and Type. It is a pseudo-type, can't be directly used in a program.

func (*GenericStruct) Code

func (gs *GenericStruct) Code() []rune

func (*GenericStruct) Generate

func (gs *GenericStruct) Generate(tc *TypesContext, current *CodeChunk)

func (*GenericStruct) Imports

func (gs *GenericStruct) Imports() Imports

func (*GenericStruct) Instantiate

func (gs *GenericStruct) Instantiate(tc *TypesContext, params ...Type) (Object, string, []error)

func (*GenericStruct) Label

func (s *GenericStruct) Label() *Object

func (*GenericStruct) Location

func (gs *GenericStruct) Location() (*gotoken.File, int)

func (*GenericStruct) Name

func (gs *GenericStruct) Name() string

func (*GenericStruct) NegotiateTypes

func (ls *GenericStruct) NegotiateTypes(tc *TypesContext) error

func (*GenericStruct) ObjectType

func (gs *GenericStruct) ObjectType() ObjectType

func (*GenericStruct) Signature

func (gs *GenericStruct) Signature() (string, []string)

type GenericType

type GenericType struct {
	// Base name of the type. Doesn't include package name for external types.
	Name string
	// nil means local
	Package *ImportStmt

	Params []Type
	// This is filled by type checker, it's empty right after parsing.
	Generic *GenericStruct
	// This is filled by type checker, it's empty right after parsing.
	Struct *StructType
}

func (*GenericType) Kind

func (t *GenericType) Kind() Kind

func (*GenericType) Known

func (t *GenericType) Known() bool

func (*GenericType) MapSubtypes

func (t *GenericType) MapSubtypes(callback func(t Type) bool)

func (*GenericType) NamePtr

func (t *GenericType) NamePtr() *string

func (*GenericType) PackagePtr

func (t *GenericType) PackagePtr() *ImportStmt

func (*GenericType) RootType

func (t *GenericType) RootType() Type

func (*GenericType) String

func (t *GenericType) String() string

func (*GenericType) ZeroValue

func (t *GenericType) ZeroValue() string

type Ident

type Ident struct {
	// contains filtered or unexported fields
}

implements PrimaryExpr

func (*Ident) ApplyType

func (ex *Ident) ApplyType(tc *TypesContext, typ Type) error

func (*Ident) Generate

func (id *Ident) Generate(tc *TypesContext, current *CodeChunk)

func (*Ident) GuessType

func (ex *Ident) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*Ident) Pos

func (e *Ident) Pos() gotoken.Pos

func (*Ident) ReferedObject

func (ex *Ident) ReferedObject() Object

func (*Ident) Type

func (ex *Ident) Type(tc *TypesContext) (Type, error)

type IdentStack

type IdentStack []map[string]Object

Stack of scopes available to the piece of code that is currently being parsed. It is a living stack, scopes are pushed to and popped from it as new blocks of code start and end. It is used for initial bonding of names and objects (packages, variables, types), which later helps the type checker.

type IfBranch

type IfBranch struct {
	ScopedVar Stmt
	Condition Expr
	Code      *CodeBlock
	// contains filtered or unexported fields
}

implements Stmt

func (*IfBranch) Label

func (s *IfBranch) Label() *Object

type IfStmt

type IfStmt struct {
	Branches []*IfBranch
	// contains filtered or unexported fields
}

implements Stmt

func (*IfStmt) Generate

func (fs *IfStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*IfStmt) Label

func (s *IfStmt) Label() *Object

func (*IfStmt) NegotiateTypes

func (is *IfStmt) NegotiateTypes(tc *TypesContext) error

type IfaceStmt

type IfaceStmt struct {
	Iface *IfaceType
	// contains filtered or unexported fields
}

implements Stmt

func (*IfaceStmt) Generate

func (is *IfaceStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*IfaceStmt) Label

func (s *IfaceStmt) Label() *Object

func (*IfaceStmt) NegotiateTypes

func (is *IfaceStmt) NegotiateTypes(tc *TypesContext) error

type IfaceType

type IfaceType struct {
	// Keys in the order of declaration
	Keys    []string
	Methods map[string]*FuncDecl
	// contains filtered or unexported fields
}

func (*IfaceType) Kind

func (t *IfaceType) Kind() Kind

func (*IfaceType) Known

func (t *IfaceType) Known() bool

func (*IfaceType) MapSubtypes

func (t *IfaceType) MapSubtypes(callback func(t Type) bool)

func (*IfaceType) String

func (t *IfaceType) String() string

func (*IfaceType) ZeroValue

func (t *IfaceType) ZeroValue() string

type ImportStmt

type ImportStmt struct {
	// contains filtered or unexported fields
}

func (*ImportStmt) Generate

func (i *ImportStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*ImportStmt) Label

func (s *ImportStmt) Label() *Object

func (*ImportStmt) Name

func (i *ImportStmt) Name() string

func (*ImportStmt) NegotiateTypes

func (td *ImportStmt) NegotiateTypes(tc *TypesContext) error

func (*ImportStmt) ObjectType

func (i *ImportStmt) ObjectType() ObjectType

type Imports

type Imports map[string]*ImportStmt

func (*Imports) Local

func (i *Imports) Local() *Package

Return local (relative to the file) package

type InlineGenerable

type InlineGenerable interface {
	Generable
	// Generate a shorter version of the code that e.g. fits into for-loop header.
	InlineGenerate(tc *TypesContext, current *CodeChunk, noParenth bool)
}

type InstKey

type InstKey string

Generic instantiation key.

func NewInstKey

func NewInstKey(g Generic, params []Type) InstKey

type Instantiation

type Instantiation struct {
	FullName string
	Params   []Type
	Generic  Generic
	Object   Object
	Init     Expr // Nil for generics generating types
	// contains filtered or unexported fields
}

func (*Instantiation) ParseAndCheck

func (r *Instantiation) ParseAndCheck() []error

type Kind

type Kind int

type LabelStmt

type LabelStmt struct {
	Branchable Stmt // Either nil or branchable statement (for, switch, etc)
	// contains filtered or unexported fields
}

implements Object and Stmt

func (*LabelStmt) Generate

func (ls *LabelStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*LabelStmt) Label

func (s *LabelStmt) Label() *Object

func (*LabelStmt) Name

func (l *LabelStmt) Name() string

func (*LabelStmt) NegotiateTypes

func (ls *LabelStmt) NegotiateTypes(tc *TypesContext) error

func (*LabelStmt) ObjectType

func (l *LabelStmt) ObjectType() ObjectType

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func NewLexer

func NewLexer(buf []rune, tfile *gotoken.File, offset int) *Lexer

func (*Lexer) EndMark

func (l *Lexer) EndMark(f *fragment)

func (*Lexer) NewMark

func (l *Lexer) NewMark() *fragment

func (*Lexer) Next

func (l *Lexer) Next() *Token

func (*Lexer) Slice

func (l *Lexer) Slice(start, end *Token) []rune

Returns fragment of code [start, end)

type MapType

type MapType struct {
	By, Of Type
}

func (*MapType) Kind

func (t *MapType) Kind() Kind

func (*MapType) Known

func (t *MapType) Known() bool

func (*MapType) MapSubtypes

func (t *MapType) MapSubtypes(callback func(t Type) bool)

func (*MapType) String

func (t *MapType) String() string

func (*MapType) ZeroValue

func (t *MapType) ZeroValue() string

type NilExpr

type NilExpr struct {
	// contains filtered or unexported fields
}

func (*NilExpr) ApplyType

func (ex *NilExpr) ApplyType(tc *TypesContext, typ Type) error

func (*NilExpr) Generate

func (n *NilExpr) Generate(tc *TypesContext, current *CodeChunk)

func (*NilExpr) GuessType

func (ex *NilExpr) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*NilExpr) Pos

func (e *NilExpr) Pos() gotoken.Pos

func (*NilExpr) Type

func (ex *NilExpr) Type(tc *TypesContext) (Type, error)

type Object

type Object interface {
	Name() string
	ObjectType() ObjectType
}

This serves a similar purpose to Go's types.Object

type ObjectExpr

type ObjectExpr interface {
	Expr
	ReferedObject() Object
}

Some expressions refer to an object (e.g. variable, constant, instantiation). If so, they should implement this (not all do at the time of writing). ReferedObject() works only after type checking is done (some expressions can return correct values before that, but that's not guaranteed). Expressions that sometimes refer to an object and sometimes don't (e.g. array expression can refer to a generic instantiation or can just mean the n-th element in a slice (not an object)) - if so, they should implement it but return nils appropriately.

type ObjectType

type ObjectType int

type Package

type Package struct {
	Files []*File

	Fset *gotoken.FileSet
	// contains filtered or unexported fields
}

func NewPackage

func NewPackage(path string, files ...*File) *Package

func (*Package) Get

func (p *Package) Get(name string) Object

func (*Package) GetObject

func (o *Package) GetObject(name string) Object

func (*Package) GetType

func (o *Package) GetType(name string) *TypeDecl

func (*Package) ParseAndCheck

func (o *Package) ParseAndCheck() []error

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(lex *Lexer) *Parser

func NewParserWithoutBuiltins

func NewParserWithoutBuiltins(lex *Lexer) *Parser

func (*Parser) Parse

func (p *Parser) Parse() ([]*TopLevelStmt, error)

func (*Parser) ParseFile

func (p *Parser) ParseFile(f *File) error

type PassStmt

type PassStmt struct {
	// contains filtered or unexported fields
}

implements Stmt

func (*PassStmt) Generate

func (n *PassStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*PassStmt) Label

func (s *PassStmt) Label() *Object

func (*PassStmt) NegotiateTypes

func (p *PassStmt) NegotiateTypes(tc *TypesContext) error

type PkgLocator

type PkgLocator interface {
	Locate(pkgPath string) ([]*File, error)
}

type PkgManager

type PkgManager struct {
	Fset *gotoken.FileSet
	// contains filtered or unexported fields
}

Provides access to packages, makes sure that no package is loaded more than once, etc.

func NewPkgManager

func NewPkgManager(locator PkgLocator) *PkgManager

func (*PkgManager) Load

func (m *PkgManager) Load(path string) (*Package, []error)

type PointerType

type PointerType struct {
	To Type
}

func (*PointerType) Kind

func (t *PointerType) Kind() Kind

func (*PointerType) Known

func (t *PointerType) Known() bool

func (*PointerType) MapSubtypes

func (t *PointerType) MapSubtypes(callback func(t Type) bool)

func (*PointerType) String

func (t *PointerType) String() string

func (*PointerType) ZeroValue

func (t *PointerType) ZeroValue() string

type PrimaryExpr

type PrimaryExpr interface {
	Expr
}

type ReturnStmt

type ReturnStmt struct {
	Func   *FuncDecl
	Values []Expr
	// contains filtered or unexported fields
}

func (*ReturnStmt) Generate

func (rs *ReturnStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*ReturnStmt) Label

func (s *ReturnStmt) Label() *Object

func (*ReturnStmt) NegotiateTypes

func (rs *ReturnStmt) NegotiateTypes(tc *TypesContext) error

type SendStmt

type SendStmt struct {
	Lhs, Rhs Expr
	// contains filtered or unexported fields
}

implements Stmt

func (*SendStmt) Label

func (s *SendStmt) Label() *Object

func (*SendStmt) NegotiateTypes

func (ls *SendStmt) NegotiateTypes(tc *TypesContext) error

type SimpleStmt

type SimpleStmt interface {
	Stmt
}

Simple statements are those that can be used in the 3rd clause of the `for` loop.

type SimpleType

type SimpleType struct {
	ID SimpleTypeID
}

func (*SimpleType) Kind

func (t *SimpleType) Kind() Kind

func (*SimpleType) Known

func (t *SimpleType) Known() bool

func (*SimpleType) MapSubtypes

func (t *SimpleType) MapSubtypes(callback func(t Type) bool)

func (*SimpleType) String

func (t *SimpleType) String() string

func (*SimpleType) ZeroValue

func (t *SimpleType) ZeroValue() string

type SimpleTypeID

type SimpleTypeID int

type SliceExpr

type SliceExpr struct {
	From, To Expr
	// contains filtered or unexported fields
}

Represents subslice extraction - for x[a:b], it represents a:b. Implements Expr.

func (*SliceExpr) Generate

func (se *SliceExpr) Generate(tc *TypesContext, current *CodeChunk)

func (*SliceExpr) Pos

func (e *SliceExpr) Pos() gotoken.Pos

type SliceType

type SliceType struct {
	Of Type
}

func (*SliceType) Kind

func (t *SliceType) Kind() Kind

func (*SliceType) Known

func (t *SliceType) Known() bool

func (*SliceType) MapSubtypes

func (t *SliceType) MapSubtypes(callback func(t Type) bool)

func (*SliceType) String

func (t *SliceType) String() string

func (*SliceType) ZeroValue

func (t *SliceType) ZeroValue() string

type Stmt

type Stmt interface {
	Expr
	Label() *Object
}

type StructStmt

type StructStmt struct {
	Struct *StructType
	Decl   *TypeDecl
	// contains filtered or unexported fields
}

implements Stmt

func (*StructStmt) Generate

func (ss *StructStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*StructStmt) Label

func (s *StructStmt) Label() *Object

func (*StructStmt) NegotiateTypes

func (ss *StructStmt) NegotiateTypes(tc *TypesContext) error

type StructType

type StructType struct {
	Members map[string]Type
	// Keys of the Members map in the order of declaration
	Keys    []string
	Methods map[string]*FuncDecl
	Name    string
	// Names of generic type paramaters. Nil for standard structs.
	GenericParams []string
	// Values of generic parameters. Nil for standard structs.
	GenericParamVals []Type
	// contains filtered or unexported fields
}

func (*StructType) GetTypeN

func (t *StructType) GetTypeN(n int) Type

func (*StructType) Kind

func (t *StructType) Kind() Kind

func (*StructType) Known

func (t *StructType) Known() bool

func (*StructType) MapSubtypes

func (t *StructType) MapSubtypes(callback func(t Type) bool)

func (*StructType) String

func (t *StructType) String() string

func (*StructType) ZeroValue

func (t *StructType) ZeroValue() string

type SwitchBranch

type SwitchBranch struct {

	// This can carry different kinds of expression depending on the switch variant:
	//   - usually it can be any expressions comparable to the switch expression
	//   - for free-form switches this has to be one expression assignable to bool
	//   - for type switches this is a TypeExpr
	//   - `nil` for `default`
	Values []Expr
	Code   *CodeBlock
	// Type switches can declare a variable that has different type in each switch
	// branch. To keep things independent and invariant (and make the generator code less
	// fragile), we actually declare a separate variable internally for each branch
	// (all with the same name).
	// For non-type-switches this is nil.
	TypeSwitchVar *Variable
	// contains filtered or unexported fields
}

implements Stmt

func (*SwitchBranch) Label

func (s *SwitchBranch) Label() *Object

type SwitchStmt

type SwitchStmt struct {

	// Either AssignStmt or VarStmt
	ScopedVar Stmt
	// For free-form switch statements it is nil, for type switches it is either
	// `a.(someType)` or `var b = a.(someType)`, and for the rest it is ExprStmt.
	Value    Stmt
	Branches []*SwitchBranch
	// contains filtered or unexported fields
}

implements Stmt

func (*SwitchStmt) Generate

func (ss *SwitchStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*SwitchStmt) Label

func (s *SwitchStmt) Label() *Object

func (*SwitchStmt) NegotiateTypes

func (ss *SwitchStmt) NegotiateTypes(tc *TypesContext) error

type Token

type Token struct {
	Type   TokenType
	Offset int
	Value  interface{}
	Pos    gotoken.Pos
}

func (*Token) IsCompOp

func (t *Token) IsCompOp() bool

Tells if a token is any of the comparison operators.

func (*Token) IsLogicalOp

func (t *Token) IsLogicalOp() bool

Tells if operator's operands can only be boolean.

func (*Token) IsOrderOp

func (t *Token) IsOrderOp() bool

Tells if a token is any of the order operators.

type TokenType

type TokenType int
const (
	TOKEN_EOF          TokenType = iota + 1
	TOKEN_INDENT                 // indent - []rune of whitespace characters
	TOKEN_FOR                    // the "for" keyword
	TOKEN_WORD                   // alphanumeric word, starts witn a letter
	TOKEN_ASSIGN                 // =
	TOKEN_EQUALS                 // ==
	TOKEN_NEQUALS                // !=
	TOKEN_GT                     // >
	TOKEN_LT                     // <
	TOKEN_EQ_LT                  // <=
	TOKEN_EQ_GT                  // >=
	TOKEN_NEGATE                 // !
	TOKEN_INT                    // Integer number literal
	TOKEN_FLOAT                  // Float number literal
	TOKEN_IMAG                   // Imaginary part literal
	TOKEN_STR                    // string literal
	TOKEN_RUNE                   // rune literal
	TOKEN_DOT                    // .
	TOKEN_ELLIPSIS               // ...
	TOKEN_LPARENTH               // (
	TOKEN_RPARENTH               // )
	TOKEN_LBRACKET               // [
	TOKEN_RBRACKET               // ]
	TOKEN_LBRACE                 // {
	TOKEN_RBRACE                 // }
	TOKEN_PLUS                   // +
	TOKEN_PLUS_ASSIGN            // +=
	TOKEN_INCREMENT              // ++
	TOKEN_MINUS                  // -
	TOKEN_MINUS_ASSIGN           // -=
	TOKEN_DECREMENT              // --
	TOKEN_VAR                    // the "var" keyword
	TOKEN_IF                     // the "if" keyword
	TOKEN_ELSE                   // the "else" keyword
	TOKEN_ELIF                   // the "elif" keyword
	TOKEN_SWITCH                 // the "switch" keyword
	TOKEN_CASE                   // the "case" keyword
	TOKEN_DEFAULT                // the "default" keyword
	TOKEN_RETURN                 // the "return" keyword
	TOKEN_TRUE                   // the "true" keyword
	TOKEN_FALSE                  // the "false" keyword
	TOKEN_STRUCT                 // the "struct" keyword
	TOKEN_MAP                    // the "map" keyword
	TOKEN_FUNC                   // the "func" keyword
	TOKEN_IMPORT                 // the "import" keyword
	TOKEN_AS                     // the "as" keyword
	TOKEN_TYPE                   // the "type" keyword
	TOKEN_IN                     // the "in" keyword
	TOKEN_PASS                   // the "pass" keyword
	TOKEN_PACKAGE                // the "package" keyword
	TOKEN_BREAK                  // the "break" keyword
	TOKEN_CONTINUE               // the "continue" keyword
	TOKEN_FALLTHROUGH            // the "fallthrough" keyword
	TOKEN_GOTO                   // the "goto" keyword
	TOKEN_INTERFACE              // the "interface" keyword
	TOKEN_NIL                    // the "nil" keyword
	TOKEN_CHAN                   // the "chan" keyword
	TOKEN_RANGE                  // the "range" keyword
	TOKEN_WHEN                   // the "when" keyword
	TOKEN_IMPLEMENTS             // the "implements" keyword
	TOKEN_IS                     // the "is" keyword
	TOKEN_MUL                    // *
	TOKEN_DIV                    // /
	TOKEN_MUL_ASSIGN             // *=
	TOKEN_DIV_ASSIGN             // /=
	TOKEN_SHL                    // <<
	TOKEN_SHR                    // >>
	TOKEN_SEND                   // <-
	TOKEN_COMMA                  // ,
	TOKEN_COLON                  // :
	TOKEN_SEMICOLON              // ;
	TOKEN_AMP                    // &
	TOKEN_PIPE                   // |
	TOKEN_PERCENT                // %
	TOKEN_AND                    // &&
	TOKEN_OR                     // ||
	TOKEN_SHARP                  // #
	TOKEN_UNEXP_CHAR             // For error reporting
)

func (TokenType) String

func (i TokenType) String() string

type TopLevelStmt

type TopLevelStmt struct {
	Stmt
	// contains filtered or unexported fields
}

func (*TopLevelStmt) Decls

func (s *TopLevelStmt) Decls() []string

List of top-level symbols declared within this statement.

func (*TopLevelStmt) Deps

func (s *TopLevelStmt) Deps() []string

List of top-level symbols used within this statement.

type TupleType

type TupleType struct {
	Members []Type
}

func (*TupleType) Kind

func (t *TupleType) Kind() Kind

func (*TupleType) Known

func (t *TupleType) Known() bool

func (*TupleType) MapSubtypes

func (t *TupleType) MapSubtypes(callback func(t Type) bool)

func (*TupleType) String

func (t *TupleType) String() string

func (*TupleType) ZeroValue

func (t *TupleType) ZeroValue() string

type Type

type Type interface {
	// True means no underscores beneath, no type inference needed.
	Known() bool
	String() string
	Kind() Kind
	ZeroValue() string
	MapSubtypes(callback func(t Type) bool)
}

func ExprToTypeName

func ExprToTypeName(tc *TypesContext, e Expr) (t Type, err error)

Sometimes it is not immediately obvious if a piece of code is an actual expression or a name of a type. That can happen during during type conversions, for example in the line below we don't know whether 'blah' is a type name or a function during parsing:

blah(123)

This function tells if an expression is really a type name, and returns that type if the answer was yes (nil otherwise). Additionaly, if it encounters an error it returns it, usually they are non-recoverable and can be printed out as compilation errors.

func RootType

func RootType(t Type) Type

func UnderlyingType

func UnderlyingType(t Type) Type

Implements the definition of underlying types from the Go spec.

type TypeAssertion

type TypeAssertion struct {

	// When true, no concrete type was given in the parentheses, just
	// the "type" keyword.
	ForSwitch bool
	Left      Expr
	Right     *TypeExpr
	// contains filtered or unexported fields
}

implements Expr

func (*TypeAssertion) ApplyType

func (ex *TypeAssertion) ApplyType(tc *TypesContext, typ Type) error

func (*TypeAssertion) Generate

func (ta *TypeAssertion) Generate(tc *TypesContext, current *CodeChunk)

func (*TypeAssertion) GuessType

func (ex *TypeAssertion) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*TypeAssertion) Pos

func (e *TypeAssertion) Pos() gotoken.Pos

func (*TypeAssertion) Type

func (ex *TypeAssertion) Type(tc *TypesContext) (Type, error)

type TypeDecl

type TypeDecl struct {
	AliasedType Type
	Methods     map[string]*FuncDecl
	// contains filtered or unexported fields
}

Implements Object and Stmt

func GetBuiltinType

func GetBuiltinType(name string) (*TypeDecl, bool)

func (*TypeDecl) Generate

func (td *TypeDecl) Generate(tc *TypesContext, current *CodeChunk)

func (*TypeDecl) Label

func (s *TypeDecl) Label() *Object

func (*TypeDecl) Name

func (o *TypeDecl) Name() string

func (*TypeDecl) NegotiateTypes

func (td *TypeDecl) NegotiateTypes(tc *TypesContext) error

func (*TypeDecl) ObjectType

func (o *TypeDecl) ObjectType() ObjectType

func (*TypeDecl) Type

func (o *TypeDecl) Type() Type

type TypeExpr

type TypeExpr struct {
	// contains filtered or unexported fields
}

func (*TypeExpr) ApplyType

func (ex *TypeExpr) ApplyType(tc *TypesContext, typ Type) error

func (*TypeExpr) GuessType

func (ex *TypeExpr) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*TypeExpr) Pos

func (e *TypeExpr) Pos() gotoken.Pos

func (*TypeExpr) Type

func (ex *TypeExpr) Type(tc *TypesContext) (Type, error)

type TypedExpr

type TypedExpr interface {
	Expr

	// Infers type of the expression based on facts that are certain - no guessing should
	// happen at this point.
	// Errors returned from Type() are reported as compilation errors.
	// Type() MUSTN'T return GenericType in any case, but the underlying type instead.
	Type(tc *TypesContext) (Type, error)
	// Called by the type checker when it wants this expression to be of a particular type.
	// If all goes well, this should affect the result of further calls to Type().
	// If applying the given type is impossible, appropriate error should be returned (it
	// doesn't always mean the end of negotiation - further calls to Type/ApplyType/GuessType can
	// be expected).
	ApplyType(tc *TypesContext, typ Type) error
	// Tries to guess the most appropriate type for this expression.
	// GuessType(tc *TypesContext) MUSTN'T return GenericType in any case, but the underlying type instead.
	GuessType(tc *TypesContext) (ok bool, typ Type)
}

type TypesContext

type TypesContext struct {
	// contains filtered or unexported fields
}

func NewTypesContext

func NewTypesContext() *TypesContext

func (*TypesContext) GetType

func (tc *TypesContext) GetType(e Expr) Type

func (*TypesContext) IsTypeSet

func (tc *TypesContext) IsTypeSet(e Expr) bool

func (*TypesContext) SetType

func (tc *TypesContext) SetType(e Expr, typ Type)

type UnaryOp

type UnaryOp struct {
	Right Expr
	// contains filtered or unexported fields
}

implements Expr

func (*UnaryOp) ApplyType

func (ex *UnaryOp) ApplyType(tc *TypesContext, typ Type) error

func (*UnaryOp) Generate

func (op *UnaryOp) Generate(tc *TypesContext, current *CodeChunk)

func (*UnaryOp) GuessType

func (ex *UnaryOp) GuessType(tc *TypesContext) (ok bool, typ Type)

func (*UnaryOp) Pos

func (e *UnaryOp) Pos() gotoken.Pos

func (*UnaryOp) Type

func (ex *UnaryOp) Type(tc *TypesContext) (Type, error)

type UnknownType

type UnknownType struct{}

func (*UnknownType) Kind

func (t *UnknownType) Kind() Kind

func (*UnknownType) Known

func (t *UnknownType) Known() bool

func (*UnknownType) MapSubtypes

func (t *UnknownType) MapSubtypes(callback func(t Type) bool)

func (*UnknownType) String

func (t *UnknownType) String() string

func (*UnknownType) ZeroValue

func (t *UnknownType) ZeroValue() string

type VarDecl

type VarDecl struct {
	Vars  []*Variable
	Inits []Expr
}

func (*VarDecl) Generate

func (vd *VarDecl) Generate(tc *TypesContext, current *CodeChunk)

func (*VarDecl) NegotiateTypes

func (vd *VarDecl) NegotiateTypes(tc *TypesContext) error

type VarStmt

type VarStmt struct {
	Vars       DeclChain
	IsFuncStmt bool
	// contains filtered or unexported fields
}

implements Stmt

func (*VarStmt) Generate

func (vs *VarStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*VarStmt) InlineGenerate

func (vs *VarStmt) InlineGenerate(tc *TypesContext, current *CodeChunk, noParenth bool)

func (*VarStmt) Label

func (s *VarStmt) Label() *Object

func (*VarStmt) NegotiateTypes

func (vs *VarStmt) NegotiateTypes(tc *TypesContext) error

type Variable

type Variable struct {
	Type Type
	// contains filtered or unexported fields
}

Implements Object

func (*Variable) Name

func (o *Variable) Name() string

func (*Variable) ObjectType

func (o *Variable) ObjectType() ObjectType

type WhenBranch

type WhenBranch struct {
	Predicates []*WhenPredicate
	Code       *CodeBlock
	True       bool
	// contains filtered or unexported fields
}

func (*WhenBranch) Label

func (s *WhenBranch) Label() *Object

type WhenPredicate

type WhenPredicate struct {
	Kind   WhenPredicateKind
	Target Type
}

type WhenPredicateKind

type WhenPredicateKind int

func TokenToWhenPred

func TokenToWhenPred(t *Token) WhenPredicateKind

type WhenStmt

type WhenStmt struct {
	Args     []Type
	Branches []*WhenBranch
	// contains filtered or unexported fields
}

func (*WhenStmt) Generate

func (ws *WhenStmt) Generate(tc *TypesContext, current *CodeChunk)

func (*WhenStmt) Label

func (s *WhenStmt) Label() *Object

func (*WhenStmt) NegotiateTypes

func (ws *WhenStmt) NegotiateTypes(tc *TypesContext) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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