ast

package
v0.0.0-...-538b3b7 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicPrint

func BasicPrint(v Visitable, out io.Writer) error

Types

type ByteCode

type ByteCode interface {
	Data() []byte
	LoadConstInt(index uint)
	LoadConstString(index uint)
	LoadInt(name string)
	LoadString(name string)
	StoreInt(name string)
	StoreString(name string)
	PopInt()
	PopString()
	DubInt()
	DubString()
	InvokeNative(index rs_api.Index)
	End()
}

type CompilationUnit

type CompilationUnit struct {
	Name       string
	Target     Expression
	Scope      *Scope
	Unresolved []*IdExpr
}

func (*CompilationUnit) Compile

func (unit *CompilationUnit) Compile(env CompilerEnv) bool

func (*CompilationUnit) Generate

func (unit *CompilationUnit) Generate(env CompilerEnv, byteCode ByteCode) bool

func (*CompilationUnit) Resolve

func (unit *CompilationUnit) Resolve(globals *Scope) bool

type CompilerEnv

type CompilerEnv interface {
	Error(message string, where util.Position)
	GetErrors() []string
	GetErrorsCount() int

	Warning(message string, where util.Position)
	GetWarnings() []string
	GetWarningsCount() int

	GetCompilerOptions() CompilerOptions

	ConstPool() ConstPool
}

type CompilerOptions

type CompilerOptions interface {
	WarningIsError() bool
}

type ConstPool

type ConstPool interface {
	PushInt(*rs_api.Int) (uint, error)
	PushString(*rs_api.String) (uint, error)
	Data() []byte
}

type Expression

type Expression interface {
	INode
	fmt.Stringer
	// contains filtered or unexported methods
}

type INode

type INode interface {
	Pos() util.PositionRange
	Compile(env CompilerEnv)
	GetType() rs_api.Type
	Generate(env CompilerEnv, byteCode ByteCode) bool
}

type IVisitor

type IVisitor interface {
	VisitInvalidExpr(e *InvalidExpr) error
	VisitLiteralExpr(e *LiteralExpr) error
	VisitIdExpr(e *IdExpr) error
	VisitParenExpr(e *ParenExpr) error
	VisitPostfixUnaryExpr(e *PostfixUnaryExpr) error
}

type IdExpr

type IdExpr struct {
	Node
	Value  string
	Type   rs_api.Type
	Symbol *Symbol
}

func CreateId

func CreateId(text string, where util.PositionRange) *IdExpr

func (*IdExpr) Apply

func (id *IdExpr) Apply(v IVisitor) error

func (*IdExpr) Compile

func (id *IdExpr) Compile(env CompilerEnv)

func (*IdExpr) Generate

func (id *IdExpr) Generate(env CompilerEnv, byteCode ByteCode) bool

func (*IdExpr) GetType

func (id *IdExpr) GetType() rs_api.Type

func (*IdExpr) String

func (id *IdExpr) String() string

type InvalidExpr

type InvalidExpr struct {
	Node
	Message string
}

func CreateInvalidExpr

func CreateInvalidExpr(message string, where util.PositionRange) *InvalidExpr

func (*InvalidExpr) Apply

func (inv *InvalidExpr) Apply(v IVisitor) error

func (*InvalidExpr) Compile

func (inv *InvalidExpr) Compile(env CompilerEnv)

func (*InvalidExpr) Generate

func (inv *InvalidExpr) Generate(env CompilerEnv, _ ByteCode) bool

func (*InvalidExpr) GetType

func (inv *InvalidExpr) GetType() rs_api.Type

func (*InvalidExpr) String

func (inv *InvalidExpr) String() string

type LiteralExpr

type LiteralExpr struct {
	Node
	IntValue    *rs_api.Int
	StringValue *rs_api.String
	Type        rs_api.Type
}

func CreateLiteral

func CreateLiteral(text string, t token.Type, where util.PositionRange) (*LiteralExpr, error)

func (*LiteralExpr) Apply

func (lit *LiteralExpr) Apply(v IVisitor) error

func (*LiteralExpr) Compile

func (lit *LiteralExpr) Compile(env CompilerEnv)

func (*LiteralExpr) Generate

func (lit *LiteralExpr) Generate(env CompilerEnv, byteCode ByteCode) bool

func (*LiteralExpr) GetType

func (lit *LiteralExpr) GetType() rs_api.Type

func (*LiteralExpr) String

func (lit *LiteralExpr) String() string

type Node

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

func (*Node) Pos

func (node *Node) Pos() util.PositionRange

type ParenExpr

type ParenExpr struct {
	Node
	LParen util.Position
	Target Expression
	RParen util.Position
	Type   rs_api.Type
}

func CreateParenExpr

func CreateParenExpr(lParenPos, rParenPos util.Position, target Expression) *ParenExpr

func (*ParenExpr) Apply

func (p *ParenExpr) Apply(v IVisitor) error

func (*ParenExpr) Compile

func (p *ParenExpr) Compile(env CompilerEnv)

func (*ParenExpr) Generate

func (p *ParenExpr) Generate(env CompilerEnv, byteCode ByteCode) bool

func (*ParenExpr) GetType

func (p *ParenExpr) GetType() rs_api.Type

func (*ParenExpr) String

func (p *ParenExpr) String() string

type PostfixUnaryExpr

type PostfixUnaryExpr struct {
	Node
	Target      Expression
	Operator    token.Type
	OperatorPos util.Position
	Type        rs_api.Type
	// contains filtered or unexported fields
}

func CreatePostfixUnaryExpr

func CreatePostfixUnaryExpr(target Expression,
	operator token.Type, operatorPos util.Position) *PostfixUnaryExpr

func (*PostfixUnaryExpr) Apply

func (un *PostfixUnaryExpr) Apply(v IVisitor) error

func (*PostfixUnaryExpr) Compile

func (un *PostfixUnaryExpr) Compile(env CompilerEnv)

func (*PostfixUnaryExpr) Generate

func (un *PostfixUnaryExpr) Generate(env CompilerEnv, byteCode ByteCode) bool

func (*PostfixUnaryExpr) GetType

func (un *PostfixUnaryExpr) GetType() rs_api.Type

func (*PostfixUnaryExpr) String

func (un *PostfixUnaryExpr) String() string

type Scope

type Scope struct {
	Parent  *Scope
	Symbols map[string]*Symbol
}

func NewScope

func NewScope(parent *Scope) *Scope

func (*Scope) Find

func (s *Scope) Find(symbolName string) *Symbol

func (*Scope) Put

func (s *Scope) Put(symbol *Symbol) (oldSymbol *Symbol)

type Symbol

type Symbol struct {
	Type SymbolType
	Name string
	Pos  util.Position
	Data interface{}
}

func NewSymbol

func NewSymbol(name string, t SymbolType) *Symbol

type SymbolType

type SymbolType byte
const (
	SymbolTypeNone SymbolType = iota
	SymbolTypeVar
	SymbolTypeNativeType
)

type Visitable

type Visitable interface {
	Apply(v IVisitor) error
}

Jump to

Keyboard shortcuts

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