Documentation ¶
Overview ¶
*
- The Venice compiler. *
- The compiler compiles a Venice program (represented as an abstract syntax tree, the
- output of src/compiler/parser.go) into bytecode instructions. It also checks the static
- types of the programs and reports any errors.
*
- Parse a Venice program into an abstract syntax tree (defined in src/compiler/ast.go). *
- Each `matchXYZ` function expects that `parser.currentToken` is set to the first token
- of the node to be matched, and after it returns `parser.currentToken` is set to one
- past the last token of the node.
Index ¶
- Constants
- Variables
- type AssignStatementNode
- type BooleanNode
- type BreakStatementNode
- type CallNode
- type ClassDeclarationNode
- type ClassFieldNode
- type CompileError
- type Compiler
- type CompoundPatternNode
- type ConstructorFieldNode
- type ConstructorNode
- type ContinueStatementNode
- type EnumCaseNode
- type EnumDeclarationNode
- type ExpressionNode
- type ExpressionStatementNode
- type FieldAccessNode
- type File
- type ForLoopNode
- type FunctionDeclarationNode
- type FunctionInfo
- type FunctionParamNode
- type FunctionTypeNode
- type IfClauseNode
- type IfStatementNode
- type ImportStatementNode
- type IndexNode
- type InfixNode
- type IntegerNode
- type LetStatementNode
- type ListNode
- type ListTypeNode
- type MapNode
- type MapPairNode
- type MapTypeNode
- type MatchClause
- type MatchStatementNode
- type Node
- type ParameterizedTypeNode
- type ParseError
- type PatternNode
- type QualifiedSymbolNode
- type RealNumberNode
- type ReturnStatementNode
- type StatementNode
- type StringNode
- type SymbolNode
- type SymbolTable
- func (symtab *SymbolTable) Get(symbol string) (VeniceType, bool)
- func (symtab *SymbolTable) GetBinding(symbol string) (*SymbolTableBinding, bool)
- func (symtab *SymbolTable) Put(symbol string, value VeniceType)
- func (symtab *SymbolTable) PutVar(symbol string, value VeniceType)
- func (symtab *SymbolTable) SpawnChild() *SymbolTable
- type SymbolTableBinding
- type TemporaryScopeNode
- type TernaryIfNode
- type TupleFieldAccessNode
- type TupleNode
- type TupleTypeNode
- type TypeNode
- type UnaryNode
- type VeniceAnyType
- type VeniceBooleanType
- type VeniceCaseType
- type VeniceClassField
- type VeniceClassType
- type VeniceEnumType
- type VeniceFunctionType
- type VeniceIntegerType
- type VeniceListType
- type VeniceMapType
- type VeniceModuleType
- type VeniceRealNumberType
- type VeniceStringType
- type VeniceSymbolType
- type VeniceTupleType
- type VeniceType
- type VeniceUnionType
- type WhileLoopNode
Constants ¶
View Source
const ( PRECEDENCE_LOWEST int PRECEDENCE_TERNARY_IF PRECEDENCE_OR PRECEDENCE_AND PRECEDENCE_CMP PRECEDENCE_ADD_SUB PRECEDENCE_MUL_DIV PRECEDENCE_PREFIX PRECEDENCE_CALL_INDEX PRECEDENCE_DOT )
TODO(#31): Double-check this order.
Variables ¶
View Source
var ( VENICE_TYPE_ANY = &VeniceAnyType{} VENICE_TYPE_BOOLEAN = &VeniceBooleanType{} VENICE_TYPE_INTEGER = &VeniceIntegerType{} VENICE_TYPE_REAL_NUMBER = &VeniceRealNumberType{} VENICE_TYPE_STRING = &VeniceStringType{} VENICE_TYPE_OPTIONAL = &VeniceEnumType{ Name: "Optional", GenericParameters: []string{"T"}, Cases: []*VeniceCaseType{ &VeniceCaseType{ "Some", []VeniceType{&VeniceSymbolType{"T"}}, }, &VeniceCaseType{"None", nil}, }, } )
Functions ¶
This section is empty.
Types ¶
type AssignStatementNode ¶
type AssignStatementNode struct { Destination ExpressionNode Expr ExpressionNode }
func (*AssignStatementNode) GetLocation ¶
func (n *AssignStatementNode) GetLocation() *lex.Location
func (*AssignStatementNode) String ¶
func (n *AssignStatementNode) String() string
type BooleanNode ¶
func (*BooleanNode) GetLocation ¶
func (n *BooleanNode) GetLocation() *lex.Location
func (*BooleanNode) String ¶
func (n *BooleanNode) String() string
type BreakStatementNode ¶
func (*BreakStatementNode) GetLocation ¶
func (n *BreakStatementNode) GetLocation() *lex.Location
func (*BreakStatementNode) String ¶
func (n *BreakStatementNode) String() string
type CallNode ¶
type CallNode struct { Function ExpressionNode Args []ExpressionNode }
func (*CallNode) GetLocation ¶
type ClassDeclarationNode ¶
type ClassDeclarationNode struct { Name string NoConstructor bool Fields []*ClassFieldNode Location *lex.Location }
func (*ClassDeclarationNode) GetLocation ¶
func (n *ClassDeclarationNode) GetLocation() *lex.Location
func (*ClassDeclarationNode) String ¶
func (n *ClassDeclarationNode) String() string
type ClassFieldNode ¶
Helper struct - does not implement Node
type CompileError ¶
func (*CompileError) Error ¶
func (e *CompileError) Error() string
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
func NewCompiler ¶
func NewCompiler() *Compiler
func (*Compiler) Compile ¶
func (compiler *Compiler) Compile(file *File) (*bytecode.CompiledProgram, error)
func (*Compiler) GetType ¶
func (compiler *Compiler) GetType(expr ExpressionNode) (VeniceType, error)
func (*Compiler) PrintSymbolTable ¶
func (compiler *Compiler) PrintSymbolTable()
func (*Compiler) PrintTypeSymbolTable ¶
func (compiler *Compiler) PrintTypeSymbolTable()
type CompoundPatternNode ¶
type CompoundPatternNode struct { Label string Patterns []PatternNode Elided bool Location *lex.Location }
func (*CompoundPatternNode) GetLocation ¶
func (n *CompoundPatternNode) GetLocation() *lex.Location
func (*CompoundPatternNode) String ¶
func (n *CompoundPatternNode) String() string
type ConstructorFieldNode ¶
type ConstructorFieldNode struct { Name string Value ExpressionNode Location *lex.Location }
func (*ConstructorFieldNode) GetLocation ¶
func (n *ConstructorFieldNode) GetLocation() *lex.Location
func (*ConstructorFieldNode) String ¶
func (n *ConstructorFieldNode) String() string
type ConstructorNode ¶
type ConstructorNode struct { Name string Fields []*ConstructorFieldNode Location *lex.Location }
func (*ConstructorNode) GetLocation ¶
func (n *ConstructorNode) GetLocation() *lex.Location
func (*ConstructorNode) String ¶
func (n *ConstructorNode) String() string
type ContinueStatementNode ¶
func (*ContinueStatementNode) GetLocation ¶
func (n *ContinueStatementNode) GetLocation() *lex.Location
func (*ContinueStatementNode) String ¶
func (n *ContinueStatementNode) String() string
type EnumCaseNode ¶
Helper struct - does not implement Node
type EnumDeclarationNode ¶
type EnumDeclarationNode struct { Name string GenericTypeParameter string Cases []*EnumCaseNode Location *lex.Location }
func (*EnumDeclarationNode) GetLocation ¶
func (n *EnumDeclarationNode) GetLocation() *lex.Location
func (*EnumDeclarationNode) String ¶
func (n *EnumDeclarationNode) String() string
type ExpressionNode ¶
type ExpressionNode interface { Node // contains filtered or unexported methods }
type ExpressionStatementNode ¶
type ExpressionStatementNode struct {
Expr ExpressionNode
}
func (*ExpressionStatementNode) GetLocation ¶
func (n *ExpressionStatementNode) GetLocation() *lex.Location
func (*ExpressionStatementNode) String ¶
func (n *ExpressionStatementNode) String() string
type FieldAccessNode ¶
type FieldAccessNode struct { Expr ExpressionNode Name string }
func (*FieldAccessNode) GetLocation ¶
func (n *FieldAccessNode) GetLocation() *lex.Location
func (*FieldAccessNode) String ¶
func (n *FieldAccessNode) String() string
type ForLoopNode ¶
type ForLoopNode struct { Variables []string Iterable ExpressionNode Body []StatementNode Location *lex.Location }
func (*ForLoopNode) GetLocation ¶
func (n *ForLoopNode) GetLocation() *lex.Location
func (*ForLoopNode) String ¶
func (n *ForLoopNode) String() string
type FunctionDeclarationNode ¶
type FunctionDeclarationNode struct { Name string Params []*FunctionParamNode ReturnType TypeNode Body []StatementNode Location *lex.Location }
func (*FunctionDeclarationNode) GetLocation ¶
func (n *FunctionDeclarationNode) GetLocation() *lex.Location
func (*FunctionDeclarationNode) String ¶
func (n *FunctionDeclarationNode) String() string
type FunctionInfo ¶
type FunctionInfo struct {
// contains filtered or unexported fields
}
type FunctionParamNode ¶
Helper struct - does not implement Node
type FunctionTypeNode ¶
type FunctionTypeNode struct { ParamTypeNodes []TypeNode ReturnTypeNode TypeNode Location *lex.Location }
func (*FunctionTypeNode) GetLocation ¶
func (n *FunctionTypeNode) GetLocation() *lex.Location
func (*FunctionTypeNode) String ¶
func (n *FunctionTypeNode) String() string
type IfClauseNode ¶
type IfClauseNode struct { Condition ExpressionNode Body []StatementNode }
Helper struct - does not implement Node
type IfStatementNode ¶
type IfStatementNode struct { Clauses []*IfClauseNode ElseClause []StatementNode Location *lex.Location }
func (*IfStatementNode) GetLocation ¶
func (n *IfStatementNode) GetLocation() *lex.Location
func (*IfStatementNode) String ¶
func (n *IfStatementNode) String() string
type ImportStatementNode ¶
func (*ImportStatementNode) GetLocation ¶
func (n *ImportStatementNode) GetLocation() *lex.Location
func (*ImportStatementNode) String ¶
func (n *ImportStatementNode) String() string
type IndexNode ¶
type IndexNode struct { Expr ExpressionNode Index ExpressionNode }
func (*IndexNode) GetLocation ¶
type InfixNode ¶
type InfixNode struct { Operator string Left ExpressionNode Right ExpressionNode }
func (*InfixNode) GetLocation ¶
type IntegerNode ¶
func (*IntegerNode) GetLocation ¶
func (n *IntegerNode) GetLocation() *lex.Location
func (*IntegerNode) String ¶
func (n *IntegerNode) String() string
type LetStatementNode ¶
type LetStatementNode struct { Symbol string Type TypeNode IsVar bool Expr ExpressionNode Location *lex.Location }
func (*LetStatementNode) GetLocation ¶
func (n *LetStatementNode) GetLocation() *lex.Location
func (*LetStatementNode) String ¶
func (n *LetStatementNode) String() string
type ListNode ¶
type ListNode struct { Values []ExpressionNode Location *lex.Location }
func (*ListNode) GetLocation ¶
type ListTypeNode ¶
func (*ListTypeNode) GetLocation ¶
func (n *ListTypeNode) GetLocation() *lex.Location
func (*ListTypeNode) String ¶
func (n *ListTypeNode) String() string
type MapNode ¶
type MapNode struct { Pairs []*MapPairNode Location *lex.Location }
func (*MapNode) GetLocation ¶
type MapPairNode ¶
type MapPairNode struct { Key ExpressionNode Value ExpressionNode Location *lex.Location }
Helper struct - does not implement Node
type MapTypeNode ¶
func (*MapTypeNode) GetLocation ¶
func (n *MapTypeNode) GetLocation() *lex.Location
func (*MapTypeNode) String ¶
func (n *MapTypeNode) String() string
type MatchClause ¶
type MatchClause struct { Pattern PatternNode Body []StatementNode }
Helper struct - does not implement Node
func (*MatchClause) String ¶
func (n *MatchClause) String() string
type MatchStatementNode ¶
type MatchStatementNode struct { Expr ExpressionNode Clauses []*MatchClause Default []StatementNode Location *lex.Location }
func (*MatchStatementNode) GetLocation ¶
func (n *MatchStatementNode) GetLocation() *lex.Location
func (*MatchStatementNode) String ¶
func (n *MatchStatementNode) String() string
type ParameterizedTypeNode ¶
func (*ParameterizedTypeNode) GetLocation ¶
func (n *ParameterizedTypeNode) GetLocation() *lex.Location
func (*ParameterizedTypeNode) String ¶
func (n *ParameterizedTypeNode) String() string
type ParseError ¶
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type PatternNode ¶
type PatternNode interface { Node // contains filtered or unexported methods }
type QualifiedSymbolNode ¶
func (*QualifiedSymbolNode) GetLocation ¶
func (n *QualifiedSymbolNode) GetLocation() *lex.Location
func (*QualifiedSymbolNode) String ¶
func (n *QualifiedSymbolNode) String() string
type RealNumberNode ¶
func (*RealNumberNode) GetLocation ¶
func (n *RealNumberNode) GetLocation() *lex.Location
func (*RealNumberNode) String ¶
func (n *RealNumberNode) String() string
type ReturnStatementNode ¶
type ReturnStatementNode struct { Expr ExpressionNode Location *lex.Location }
func (*ReturnStatementNode) GetLocation ¶
func (n *ReturnStatementNode) GetLocation() *lex.Location
func (*ReturnStatementNode) String ¶
func (n *ReturnStatementNode) String() string
type StatementNode ¶
type StatementNode interface { Node // contains filtered or unexported methods }
type StringNode ¶
func (*StringNode) GetLocation ¶
func (n *StringNode) GetLocation() *lex.Location
func (*StringNode) String ¶
func (n *StringNode) String() string
type SymbolNode ¶
func (*SymbolNode) GetLocation ¶
func (n *SymbolNode) GetLocation() *lex.Location
func (*SymbolNode) String ¶
func (n *SymbolNode) String() string
type SymbolTable ¶
type SymbolTable struct { Parent *SymbolTable Symbols map[string]*SymbolTableBinding }
func NewBuiltinSymbolTable ¶
func NewBuiltinSymbolTable() *SymbolTable
func NewBuiltinTypeSymbolTable ¶
func NewBuiltinTypeSymbolTable() *SymbolTable
func (*SymbolTable) Get ¶
func (symtab *SymbolTable) Get(symbol string) (VeniceType, bool)
func (*SymbolTable) GetBinding ¶
func (symtab *SymbolTable) GetBinding(symbol string) (*SymbolTableBinding, bool)
func (*SymbolTable) Put ¶
func (symtab *SymbolTable) Put(symbol string, value VeniceType)
func (*SymbolTable) PutVar ¶
func (symtab *SymbolTable) PutVar(symbol string, value VeniceType)
func (*SymbolTable) SpawnChild ¶
func (symtab *SymbolTable) SpawnChild() *SymbolTable
type SymbolTableBinding ¶
type SymbolTableBinding struct { IsVar bool Type VeniceType }
func NewConstBinding ¶
func NewConstBinding(sType VeniceType) *SymbolTableBinding
func NewVarBinding ¶
func NewVarBinding(sType VeniceType) *SymbolTableBinding
type TemporaryScopeNode ¶
type TemporaryScopeNode struct { Symbol string Value ExpressionNode Scope ExpressionNode }
type TernaryIfNode ¶
type TernaryIfNode struct { Condition ExpressionNode TrueClause ExpressionNode FalseClause ExpressionNode }
func (*TernaryIfNode) GetLocation ¶
func (n *TernaryIfNode) GetLocation() *lex.Location
func (*TernaryIfNode) String ¶
func (n *TernaryIfNode) String() string
type TupleFieldAccessNode ¶
type TupleFieldAccessNode struct { Expr ExpressionNode Index int }
func (*TupleFieldAccessNode) GetLocation ¶
func (n *TupleFieldAccessNode) GetLocation() *lex.Location
func (*TupleFieldAccessNode) String ¶
func (n *TupleFieldAccessNode) String() string
type TupleNode ¶
type TupleNode struct { Values []ExpressionNode Location *lex.Location }
func (*TupleNode) GetLocation ¶
type TupleTypeNode ¶
func (*TupleTypeNode) GetLocation ¶
func (n *TupleTypeNode) GetLocation() *lex.Location
func (*TupleTypeNode) String ¶
func (n *TupleTypeNode) String() string
type UnaryNode ¶
type UnaryNode struct { Operator string Expr ExpressionNode Location *lex.Location }
func (*UnaryNode) GetLocation ¶
type VeniceAnyType ¶
type VeniceAnyType struct{}
func (*VeniceAnyType) GetGenericParameters ¶
func (t *VeniceAnyType) GetGenericParameters() []string
func (*VeniceAnyType) String ¶
func (t *VeniceAnyType) String() string
type VeniceBooleanType ¶
type VeniceBooleanType struct{}
func (*VeniceBooleanType) GetGenericParameters ¶
func (t *VeniceBooleanType) GetGenericParameters() []string
func (*VeniceBooleanType) String ¶
func (t *VeniceBooleanType) String() string
type VeniceCaseType ¶
type VeniceCaseType struct { Label string Types []VeniceType }
Helper struct - does not implement VeniceType
func (*VeniceCaseType) AsFunctionType ¶
func (t *VeniceCaseType) AsFunctionType(enumType *VeniceEnumType) *VeniceFunctionType
type VeniceClassField ¶
type VeniceClassField struct { Name string Public bool FieldType VeniceType }
Helper struct - does not implement VeniceType
type VeniceClassType ¶
type VeniceClassType struct { Name string GenericParameters []string Fields []*VeniceClassField Methods []*VeniceFunctionType }
func (*VeniceClassType) GetGenericParameters ¶
func (t *VeniceClassType) GetGenericParameters() []string
func (*VeniceClassType) String ¶
func (t *VeniceClassType) String() string
type VeniceEnumType ¶
type VeniceEnumType struct { Name string GenericParameters []string Cases []*VeniceCaseType }
func (*VeniceEnumType) GetGenericParameters ¶
func (t *VeniceEnumType) GetGenericParameters() []string
func (*VeniceEnumType) String ¶
func (t *VeniceEnumType) String() string
type VeniceFunctionType ¶
type VeniceFunctionType struct { Name string Public bool GenericParameters []string ParamTypes []VeniceType ReturnType VeniceType IsBuiltin bool }
func (*VeniceFunctionType) GetGenericParameters ¶
func (t *VeniceFunctionType) GetGenericParameters() []string
func (*VeniceFunctionType) String ¶
func (t *VeniceFunctionType) String() string
type VeniceIntegerType ¶
type VeniceIntegerType struct{}
func (*VeniceIntegerType) GetGenericParameters ¶
func (t *VeniceIntegerType) GetGenericParameters() []string
func (*VeniceIntegerType) String ¶
func (t *VeniceIntegerType) String() string
type VeniceListType ¶
type VeniceListType struct {
ItemType VeniceType
}
func (*VeniceListType) GetGenericParameters ¶
func (t *VeniceListType) GetGenericParameters() []string
func (*VeniceListType) String ¶
func (t *VeniceListType) String() string
type VeniceMapType ¶
type VeniceMapType struct { KeyType VeniceType ValueType VeniceType }
func (*VeniceMapType) GetGenericParameters ¶
func (t *VeniceMapType) GetGenericParameters() []string
func (*VeniceMapType) String ¶
func (t *VeniceMapType) String() string
type VeniceModuleType ¶
type VeniceModuleType struct { Name string Types map[string]VeniceType }
func (*VeniceModuleType) GetGenericParameters ¶
func (t *VeniceModuleType) GetGenericParameters() []string
func (*VeniceModuleType) String ¶
func (t *VeniceModuleType) String() string
type VeniceRealNumberType ¶
type VeniceRealNumberType struct{}
func (*VeniceRealNumberType) GetGenericParameters ¶
func (t *VeniceRealNumberType) GetGenericParameters() []string
func (*VeniceRealNumberType) String ¶
func (t *VeniceRealNumberType) String() string
type VeniceStringType ¶
type VeniceStringType struct{}
func (*VeniceStringType) GetGenericParameters ¶
func (t *VeniceStringType) GetGenericParameters() []string
func (*VeniceStringType) String ¶
func (t *VeniceStringType) String() string
type VeniceSymbolType ¶
type VeniceSymbolType struct {
Label string
}
func (*VeniceSymbolType) GetGenericParameters ¶
func (t *VeniceSymbolType) GetGenericParameters() []string
func (*VeniceSymbolType) String ¶
func (t *VeniceSymbolType) String() string
type VeniceTupleType ¶
type VeniceTupleType struct {
ItemTypes []VeniceType
}
func (*VeniceTupleType) GetGenericParameters ¶
func (t *VeniceTupleType) GetGenericParameters() []string
func (*VeniceTupleType) String ¶
func (t *VeniceTupleType) String() string
type VeniceType ¶
type VeniceType interface { fmt.Stringer GetGenericParameters() []string // contains filtered or unexported methods }
func VeniceOptionalTypeOf ¶
func VeniceOptionalTypeOf(concreteType VeniceType) VeniceType
type VeniceUnionType ¶
type VeniceUnionType struct {
Types []VeniceType
}
func (*VeniceUnionType) GetGenericParameters ¶
func (t *VeniceUnionType) GetGenericParameters() []string
func (*VeniceUnionType) String ¶
func (t *VeniceUnionType) String() string
type WhileLoopNode ¶
type WhileLoopNode struct { Condition ExpressionNode Body []StatementNode Location *lex.Location }
func (*WhileLoopNode) GetLocation ¶
func (n *WhileLoopNode) GetLocation() *lex.Location
func (*WhileLoopNode) String ¶
func (n *WhileLoopNode) String() string
Click to show internal directories.
Click to hide internal directories.