Documentation ¶
Overview ¶
Package node is defines the abstract syntax tree (AST) node.
Index ¶
- func ByteCode(bc ByteCoder, cr compResult)
- func ByteCodeNoStck(bc ByteCoder, cr compResult)
- func Graphviz(top graphvizzer)
- func Loop(r lineReader, p Parser, vm *vm.Type, doOut bool)
- type Assign
- type Aton
- type BinOp
- type Block
- type Bool
- type ByteCoder
- type Call
- type Closure
- type Constanter
- type Exit
- type FReader
- type Float
- type For
- type Function
- type HasCaller
- type If
- type IfElse
- type IndexAt
- type IndexFromTo
- type Int
- type Invalid
- type List
- type Local
- type Name
- type Namer
- type Parser
- type ParserError
- type RLReader
- type Read
- type Return
- type STRewriter
- type String
- type SymTbl
- type Toa
- type Type
- type UnOp
- type While
- type Write
- type Yield
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteCode ¶ added in v1.3.0
func ByteCode(bc ByteCoder, cr compResult)
ByteCode compiles bc and appends the results in cr.
The evaluation result is left on the stack.
func ByteCodeNoStck ¶ added in v1.3.0
func ByteCodeNoStck(bc ByteCoder, cr compResult)
ByteCodeNoStck compiles bc and appends the results in cr.
The evaluation result is lost, code is expected to run for side effects.
func Graphviz ¶ added in v1.3.0
func Graphviz(top graphvizzer)
Graphviz writes dot format graphviz output of AST to stdout
print function for debugging calc. It prints an AST transforming it into a graphviz dotfile. One can convert the resulting file into an svg or other image formats.
% ./cmd --ast ../examples/euler_35.calc > x.dot % gvpack -u x.dot > packed.dot % dot -Tsvg packed.dot -o x.svg
Types ¶
type Assign ¶ added in v1.3.0
type BinOp ¶
type BinOp struct { Op string // Op is the operator string Left Type // Left operand Right Type // Right operand }
BinOp is a binary operator of any kind, anything from "=", etc.
type Block ¶
type Block struct {
Body []Type // Body is the block body
}
Block is a code block / sequence that was in '{', '}'.
type ByteCoder ¶ added in v1.3.0
type ByteCoder interface {
// contains filtered or unexported methods
}
type Call ¶
type Call struct { Name Type // Variable referencing function Arguments List // Arguments passed to the function }
Call is function call.
type Closure ¶ added in v1.3.0
type Closure struct { Ix int // Ix is the index in the call frame VarName string // VarName is variable name }
Closure variable reference.
type Constanter ¶ added in v1.5.0
type Constanter interface {
Constant() (value.Type, bool) // ToValue converts a constant node to a value.
}
Constanter converts a constant node to a value.
A constant node is something that can be put in the data segment. Function literal can't be a constant node as they require code.
type Exit ¶ added in v1.3.0
type Exit struct{ Value Type }
Exit exits the interpreter with an os exit code.
type FReader ¶ added in v1.4.0
type FReader struct {
// contains filtered or unexported fields
}
func NewFReader ¶ added in v1.3.0
type For ¶ added in v1.3.0
type For struct { VarRefs List // VarRef is the variable references list Iterators List // Iterator is the iterator list Body Type // Body is the loop body }
For is a loop for iterators ans generators.
type Function ¶
type Function struct { Parameters List // Parameters of the function Body Type // Body of the function LocalCnt int // count of local variables }
Function is a function definition.
type HasCaller ¶ added in v1.5.0
type HasCaller interface {
HasCall() bool
}
HasCaller determines whether a node contains a call or not.
type If ¶
type If struct { Condition Type // Condition is the condition for the if statement TrueCase Type // TrueCase is executed if condition evaluates to true }
If is a conditional construct without an else case.
type IfElse ¶
type IfElse struct { Condition Type // Condition is the condition for the if statement TrueCase Type // TrueCase is executed if condition evaluates to true FalseCase Type // FalseCase is executed if condition evaluates to false }
IfElse is a conditional construct.
type IndexFromTo ¶
type IndexFromTo struct { Ary Type // Ary is the indexed node From Type // From is the start of the range To Type // To is the end of the range }
func (IndexFromTo) HasCall ¶ added in v1.5.0
func (u IndexFromTo) HasCall() bool
func (IndexFromTo) STRewrite ¶ added in v1.3.0
func (i IndexFromTo) STRewrite(symTbl SymTbl) Type
type List ¶
type List struct {
Elems []Type // Elems are the parameters or arguments
}
List is a list of arguments or parameters depending on whether it's a function call or definition.
type Local ¶ added in v1.3.0
type Local struct { Ix int // Ix is the index in the call frame VarName string // VarName is variable name }
Local variable reference.
type Parser ¶ added in v1.3.0
type Parser interface {
Parse(string) ([]Type, ParserError)
}
type ParserError ¶ added in v1.4.0
type ParserError = *combinator.Error
type RLReader ¶ added in v1.4.0
type RLReader struct {
// contains filtered or unexported fields
}
func NewRLReader ¶ added in v1.3.0
func NewRLReader() RLReader
type Return ¶
type Return struct {
Target Type // Target is the returned value
}
Return is a return statement.
type STRewriter ¶ added in v1.3.0
STRewriter is a recursive node transformation that resolves local and closure variable names to indices into the call frame
It is not idempotent. It is supposed to be called after the parser produced the AST and before evaluation. Global variables are untouched. Local variables are changed from Name nodes to either Local or Closure nodes.
type Type ¶
type Type interface { STRewriter ByteCoder Constanter HasCaller // contains filtered or unexported methods }
Type is AST node type.
type While ¶
type While struct { Condition Type // Condition is the condition for the loop Body Type // Body is the loop body }
While is a loop construct.