Documentation ¶
Overview ¶
Package ast defines the node types used by the compiler to build syntax trees
Expr Ident Constant, Symbol, Function, Block Unary, Binary, Trinary, Nary, In Mem, RangeTo, RangeLen Call Statement ExprStmt Compound Return, Throw, Break, Continue TryCatch If, Switch For, ForIn, Forever, While, DoWhile
Index ¶
- func Blocks(f *Function)
- func CantBeEmpty(e Expr, cols []string) bool
- func IsColumn(e Expr, cols []string) bool
- func NewChildren(list []Value) children
- type Arg
- type Binary
- func (a *Binary) CanEvalRaw(flds []string) bool
- func (a *Binary) Children(fn func(Node) Node)
- func (a *Binary) Columns() []string
- func (a *Binary) CouldEvalRaw() bool
- func (a *Binary) Echo() string
- func (a *Binary) Eval(c *Context) Value
- func (a *Binary) Get(_ *Thread, m Value) Value
- func (Binary) SetPos(org, end int32)
- func (a *Binary) String() string
- type Block
- type Break
- type Builder
- type Call
- func (a *Call) CanEvalRaw(flds []string) bool
- func (a *Call) Children(fn func(Node) Node)
- func (a *Call) Columns() []string
- func (a *Call) Echo() string
- func (a *Call) Eval(c *Context) Value
- func (a *Call) Get(_ *Thread, m Value) Value
- func (Call) SetPos(org, end int32)
- func (a *Call) String() string
- type Case
- type Compound
- type Constant
- type Context
- type Continue
- type DoWhile
- type Expr
- type ExprPos
- type ExprStmt
- type Factory
- func (Factory) Binary(lhs Expr, tok Token, rhs Expr) Expr
- func (Factory) Call(fn Expr, args []Arg, end int32) Expr
- func (Factory) In(e Expr, exprs []Expr) Expr
- func (Factory) Nary(tok Token, exprs []Expr) Expr
- func (Factory) Symbol(s SuStr) Expr
- func (Factory) Trinary(cond Expr, t Expr, f Expr) Expr
- func (Factory) Unary(tok Token, expr Expr) Expr
- type Folder
- func (f Folder) Binary(lhs Expr, token tok.Token, rhs Expr) Expr
- func (Folder) Call(fn Expr, args []Arg, end int32) Expr
- func (f Folder) In(e Expr, exprs []Expr) Expr
- func (f Folder) Nary(token tok.Token, exprs []Expr) Expr
- func (Folder) Symbol(s SuStr) Expr
- func (f Folder) Trinary(cond Expr, e1 Expr, e2 Expr) Expr
- func (f Folder) Unary(token tok.Token, expr Expr) Expr
- type For
- type ForIn
- type Forever
- type Function
- type Ident
- func (en *Ident) CanEvalRaw([]string) bool
- func (a *Ident) Columns() []string
- func (a *Ident) Echo() string
- func (a *Ident) Eval(c *Context) Value
- func (a *Ident) Get(_ *Thread, m Value) Value
- func (a *Ident) GetEnd() int
- func (a *Ident) GetPos() int
- func (a *Ident) ParamName() string
- func (a *Ident) SetPos(org, end int32)
- func (a *Ident) String() string
- type If
- type In
- func (a *In) CanEvalRaw(flds []string) bool
- func (a *In) Children(fn func(Node) Node)
- func (a *In) Columns() []string
- func (a *In) CouldEvalRaw() bool
- func (a *In) Echo() string
- func (a *In) Eval(c *Context) Value
- func (a *In) Get(_ *Thread, m Value) Value
- func (In) SetPos(org, end int32)
- func (a *In) String() string
- type InRange
- func (a *InRange) CanEvalRaw(flds []string) bool
- func (a *InRange) Children(fn func(Node) Node)
- func (a *InRange) Columns() []string
- func (a *InRange) CouldEvalRaw() bool
- func (a *InRange) Echo() string
- func (a *InRange) Eval(c *Context) Value
- func (InRange) SetPos(org, end int32)
- func (a *InRange) String() string
- type Mem
- type Nary
- func (a *Nary) CanEvalRaw(flds []string) bool
- func (a *Nary) Children(fn func(Node) Node)
- func (a *Nary) Columns() []string
- func (a *Nary) Echo() string
- func (a *Nary) Eval(c *Context) Value
- func (a *Nary) Get(_ *Thread, m Value) Value
- func (Nary) SetPos(org, end int32)
- func (a *Nary) String() string
- type Node
- type Param
- type Params
- type RangeLen
- func (en *RangeLen) CanEvalRaw([]string) bool
- func (a *RangeLen) Children(fn func(Node) Node)
- func (a *RangeLen) Columns() []string
- func (a *RangeLen) Echo() string
- func (a *RangeLen) Eval(c *Context) Value
- func (a *RangeLen) Get(_ *Thread, m Value) Value
- func (RangeLen) SetPos(org, end int32)
- func (a *RangeLen) String() string
- type RangeTo
- func (en *RangeTo) CanEvalRaw([]string) bool
- func (a *RangeTo) Children(fn func(Node) Node)
- func (a *RangeTo) Columns() []string
- func (a *RangeTo) Echo() string
- func (a *RangeTo) Eval(c *Context) Value
- func (a *RangeTo) Get(_ *Thread, m Value) Value
- func (RangeTo) SetPos(org, end int32)
- func (a *RangeTo) String() string
- type Return
- type SetPosAble
- type Statement
- type SuAstNode
- type Switch
- type Symbol
- type Throw
- type Token
- type Trinary
- func (en *Trinary) CanEvalRaw([]string) bool
- func (a *Trinary) Children(fn func(Node) Node)
- func (a *Trinary) Columns() []string
- func (a *Trinary) Echo() string
- func (a *Trinary) Eval(c *Context) Value
- func (a *Trinary) Get(_ *Thread, m Value) Value
- func (Trinary) SetPos(org, end int32)
- func (a *Trinary) String() string
- type TryCatch
- type TwoPos
- type Unary
- type While
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Blocks ¶
func Blocks(f *Function)
Blocks sets compileAsFunction if a block can be compiled as a function i.e. isn't a closure, doesn't share any variables. NOTE: This is trickier than it seems. e.g. Have to handle nested blocks and sharing between peer blocks. Does not process nested functions (they're already codegen and not Ast); they are checked as constructed bottom up.
func CantBeEmpty ¶
func NewChildren ¶
func NewChildren(list []Value) children
Types ¶
type Binary ¶
func (*Binary) CanEvalRaw ¶
CanEvalRaw returns true if Eval doesn't need to unpack the values. It sets evalRaw and Packed which are used later by Eval.
func (*Binary) CouldEvalRaw ¶
CouldEvalRaw is used by replaceExpr to know when to copy
type Block ¶
type Block struct { Name string Function // CompileAsFunction is set and used by codegen CompileAsFunction bool }
func (*Block) CanEvalRaw ¶
type Call ¶
func (*Call) CanEvalRaw ¶
type Constant ¶
type Constant struct { Val Value // Packed is used for queries. It is set by Binary.CanEvalRaw Packed string TwoPos // contains filtered or unexported fields }
func (*Constant) CanEvalRaw ¶
type Expr ¶
type Expr interface { Node Echo() string // Eval, CanEvalRaw, and Columns are used by queries Eval(*Context) Value // CanEvalRaw returns true if Eval doesn't need to unpack the values. // and it sets the Expr so future Eval's will (or will not) be raw. // It must be called before calling Eval. // It is primarily for Where comparisons. CanEvalRaw(flds []string) bool Columns() []string // contains filtered or unexported methods }
Expr is implemented by expression nodes
type Folder ¶
type Folder struct{}
Folder implements constant folding for expressions. Doing the folding as the AST is built is implicitly bottom up without requiring an explicit tree traversal. It also means we only build the folded tree. Some methods are split so they can be used by propfold.
type For ¶
type ForIn ¶
type Function ¶
type Function struct { Final map[string]uint8 Params []Param Body []Statement Base Gnum TwoPos Pos1 int32 Pos2 int32 HasBlocks bool IsNewMethod bool // contains filtered or unexported fields }
func PropFold ¶
PropFold traverses an AST and does constant propagation and folding, modifying the AST
func (*Function) CanEvalRaw ¶
type Ident ¶
type Ident struct { Name string Pos int32 // for check errors Implicit bool // for implicit Record, Object, this // contains filtered or unexported fields }
func (*Ident) CanEvalRaw ¶
type If ¶
type In ¶
type In struct { E Expr Exprs []Expr // Packed is set by CanEvalRaw Packed []string // contains filtered or unexported fields }
func (*In) CanEvalRaw ¶
CanEvalRaw returns true if Eval doesn't need to unpack the values. It sets Packed which is later used by Eval.
func (*In) CouldEvalRaw ¶
CouldEvalRaw is used by replaceExpr to know when to copy
type InRange ¶
type InRange struct { E Expr Org Expr // *Constant End Expr // *Constant OrgTok tok.Token EndTok tok.Token // contains filtered or unexported fields }
InRange is added by Folder to bypass strict compare for same type ranges
func (*InRange) CanEvalRaw ¶
CanEvalRaw returns true if Eval doesn't need to unpack the values. It sets Packed which is later used by Eval.
func (*InRange) CouldEvalRaw ¶
CouldEvalRaw is used by replaceExpr to know when to copy
type Mem ¶
func (*Mem) CanEvalRaw ¶
type Nary ¶
Nary is used for associative binary operators e.g. add, multiply, and, or
func (*Nary) CanEvalRaw ¶
type Node ¶
type Node interface { String() string // Children calls the given function for each child node Children(func(Node) Node) // SetPos is called by the parser SetPos(org, end int32) // Get is for the Value interface for Suneido.Parse Get(*Thread, Value) Value // contains filtered or unexported methods }
Node is embedded by Expr and Statement
type Param ¶
type RangeLen ¶
func (*RangeLen) CanEvalRaw ¶
type RangeTo ¶
func (*RangeTo) CanEvalRaw ¶
type SetPosAble ¶
type SetPosAble interface {
SetPos(org, end int32)
}
type SuAstNode ¶
type SuAstNode struct { ValueBase[SuAstNode] }
func (SuAstNode) SetConcurrent ¶
func (SuAstNode) SetConcurrent()