compiler

package
v0.0.0-...-4a27929 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 7 Imported by: 0

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

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

type BooleanNode struct {
	Value    bool
	Location *lex.Location
}

func (*BooleanNode) GetLocation

func (n *BooleanNode) GetLocation() *lex.Location

func (*BooleanNode) String

func (n *BooleanNode) String() string

type BreakStatementNode

type BreakStatementNode struct {
	Location *lex.Location
}

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

func (n *CallNode) GetLocation() *lex.Location

func (*CallNode) String

func (n *CallNode) String() string

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

type ClassFieldNode struct {
	Name      string
	Public    bool
	FieldType TypeNode
}

Helper struct - does not implement Node

type CompileError

type CompileError struct {
	Message  string
	Location *lex.Location
}

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

type ContinueStatementNode struct {
	Location *lex.Location
}

func (*ContinueStatementNode) GetLocation

func (n *ContinueStatementNode) GetLocation() *lex.Location

func (*ContinueStatementNode) String

func (n *ContinueStatementNode) String() string

type EnumCaseNode

type EnumCaseNode struct {
	Label    string
	Types    []TypeNode
	Location *lex.Location
}

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 File

type File struct {
	Statements []StatementNode
	Imports    []string
}

func ParseFile

func ParseFile(filePath string) (*File, error)

func ParseString

func ParseString(input string) (*File, error)

func (*File) String

func (f *File) 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

type FunctionParamNode struct {
	Name      string
	ParamType TypeNode
	Location  *lex.Location
}

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

type ImportStatementNode struct {
	Path     string
	Name     string
	Location *lex.Location
}

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

func (n *IndexNode) GetLocation() *lex.Location

func (*IndexNode) String

func (n *IndexNode) String() string

type InfixNode

type InfixNode struct {
	Operator string
	Left     ExpressionNode
	Right    ExpressionNode
}

func (*InfixNode) GetLocation

func (n *InfixNode) GetLocation() *lex.Location

func (*InfixNode) String

func (n *InfixNode) String() string

type IntegerNode

type IntegerNode struct {
	Value    int
	Location *lex.Location
}

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

func (n *ListNode) GetLocation() *lex.Location

func (*ListNode) String

func (n *ListNode) String() string

type ListTypeNode

type ListTypeNode struct {
	ItemTypeNode TypeNode
	Location     *lex.Location
}

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

func (n *MapNode) GetLocation() *lex.Location

func (*MapNode) String

func (n *MapNode) String() string

type MapPairNode

type MapPairNode struct {
	Key      ExpressionNode
	Value    ExpressionNode
	Location *lex.Location
}

Helper struct - does not implement Node

type MapTypeNode

type MapTypeNode struct {
	KeyTypeNode   TypeNode
	ValueTypeNode TypeNode
	Location      *lex.Location
}

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 Node

type Node interface {
	fmt.Stringer
	GetLocation() *lex.Location
}

type ParameterizedTypeNode

type ParameterizedTypeNode struct {
	Symbol    string
	TypeNodes []TypeNode
	Location  *lex.Location
}

func (*ParameterizedTypeNode) GetLocation

func (n *ParameterizedTypeNode) GetLocation() *lex.Location

func (*ParameterizedTypeNode) String

func (n *ParameterizedTypeNode) String() string

type ParseError

type ParseError struct {
	Message  string
	Location *lex.Location
}

func (*ParseError) Error

func (e *ParseError) Error() string

type PatternNode

type PatternNode interface {
	Node
	// contains filtered or unexported methods
}

type QualifiedSymbolNode

type QualifiedSymbolNode struct {
	Enum     string
	Case     string
	Location *lex.Location
}

func (*QualifiedSymbolNode) GetLocation

func (n *QualifiedSymbolNode) GetLocation() *lex.Location

func (*QualifiedSymbolNode) String

func (n *QualifiedSymbolNode) String() string

type RealNumberNode

type RealNumberNode struct {
	Value    float64
	Location *lex.Location
}

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

type StringNode struct {
	Value    string
	Location *lex.Location
}

func (*StringNode) GetLocation

func (n *StringNode) GetLocation() *lex.Location

func (*StringNode) String

func (n *StringNode) String() string

type SymbolNode

type SymbolNode struct {
	Value    string
	Location *lex.Location
}

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

func (n *TupleNode) GetLocation() *lex.Location

func (*TupleNode) String

func (n *TupleNode) String() string

type TupleTypeNode

type TupleTypeNode struct {
	TypeNodes []TypeNode
	Location  *lex.Location
}

func (*TupleTypeNode) GetLocation

func (n *TupleTypeNode) GetLocation() *lex.Location

func (*TupleTypeNode) String

func (n *TupleTypeNode) String() string

type TypeNode

type TypeNode interface {
	Node
	// contains filtered or unexported methods
}

type UnaryNode

type UnaryNode struct {
	Operator string
	Expr     ExpressionNode
	Location *lex.Location
}

func (*UnaryNode) GetLocation

func (n *UnaryNode) GetLocation() *lex.Location

func (*UnaryNode) String

func (n *UnaryNode) String() string

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

Jump to

Keyboard shortcuts

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