Documentation ¶
Index ¶
- Variables
- func ReadOperands(numOperands []int, ins []byte) (operands []int, offset int)
- func StripCR(b []byte, comment bool) []byte
- type ArrayLit
- type AssignStmt
- type BadExpr
- type BadStmt
- type BinaryExpr
- type BlockStmt
- type BoolLit
- type BranchStmt
- type CallExpr
- type CharLit
- type CondExpr
- type EmptyStmt
- type Error
- type ErrorExpr
- type ErrorList
- type ExportStmt
- type Expr
- type ExprStmt
- type File
- type FloatLit
- type ForInStmt
- type ForStmt
- type FuncLit
- type FuncType
- type Ident
- type IdentList
- type IfStmt
- type ImmutableExpr
- type ImportExpr
- type IncDecStmt
- type IndexExpr
- type IntLit
- type MapElementLit
- type MapLit
- type Node
- type Opcode
- type ParenExpr
- type Parser
- type Pos
- type ReturnStmt
- type ScanMode
- type Scanner
- type ScannerErrorHandler
- type SelectorExpr
- type SliceExpr
- type SourceFile
- func (f *SourceFile) AddLine(offset int)
- func (f *SourceFile) FileSetPos(offset int) Pos
- func (f *SourceFile) LineCount() int
- func (f *SourceFile) LineStart(line int) Pos
- func (f *SourceFile) Offset(p Pos) int
- func (f *SourceFile) Position(p Pos) (pos SourceFilePos)
- func (f *SourceFile) Set() *SourceFileSet
- type SourceFilePos
- type SourceFileSet
- type Stmt
- type StringLit
- type UnaryExpr
- type UndefinedLit
Constants ¶
This section is empty.
Variables ¶
var OpcodeNames = [...]string{ OpConstant: "CONST", OpPop: "POP", OpTrue: "TRUE", OpFalse: "FALSE", OpBComplement: "NEG", OpEqual: "EQL", OpNotEqual: "NEQ", OpMinus: "NEG", OpLNot: "NOT", OpJumpFalsy: "JMPF", OpAndJump: "ANDJMP", OpOrJump: "ORJMP", OpJump: "JMP", OpNull: "NULL", OpGetGlobal: "GETG", OpSetGlobal: "SETG", OpSetSelGlobal: "SETSG", OpArray: "ARR", OpMap: "MAP", OpError: "ERROR", OpImmutable: "IMMUT", OpIndex: "INDEX", OpSliceIndex: "SLICE", OpCall: "CALL", OpReturn: "RET", OpGetLocal: "GETL", OpSetLocal: "SETL", OpDefineLocal: "DEFL", OpSetSelLocal: "SETSL", OpGetBuiltin: "BUILTIN", OpClosure: "CLOSURE", OpGetFreePtr: "GETFP", OpGetFree: "GETF", OpSetFree: "SETF", OpGetLocalPtr: "GETLP", OpSetSelFree: "SETSF", OpIteratorInit: "ITER", OpIteratorNext: "ITNXT", OpIteratorKey: "ITKEY", OpIteratorValue: "ITVAL", OpBinaryOp: "BINARYOP", OpSuspend: "SUSPEND", }
OpcodeNames are string representation of opcodes.
var OpcodeOperands = [...][]int{ OpConstant: {2}, OpPop: {}, OpTrue: {}, OpFalse: {}, OpBComplement: {}, OpEqual: {}, OpNotEqual: {}, OpMinus: {}, OpLNot: {}, OpJumpFalsy: {2}, OpAndJump: {2}, OpOrJump: {2}, OpJump: {2}, OpNull: {}, OpGetGlobal: {2}, OpSetGlobal: {2}, OpSetSelGlobal: {2, 1}, OpArray: {2}, OpMap: {2}, OpError: {}, OpImmutable: {}, OpIndex: {}, OpSliceIndex: {}, OpCall: {1, 1}, OpReturn: {1}, OpGetLocal: {1}, OpSetLocal: {1}, OpDefineLocal: {1}, OpSetSelLocal: {1, 1}, OpGetBuiltin: {1}, OpClosure: {2, 1}, OpGetFreePtr: {1}, OpGetFree: {1}, OpSetFree: {1}, OpGetLocalPtr: {1}, OpSetSelFree: {1, 1}, OpIteratorInit: {}, OpIteratorNext: {}, OpIteratorKey: {}, OpIteratorValue: {}, OpBinaryOp: {1}, OpSuspend: {}, }
OpcodeOperands is the number of operands.
Functions ¶
func ReadOperands ¶
ReadOperands reads operands from the bytecode.
Types ¶
type ArrayLit ¶
ArrayLit represents an array literal.
type AssignStmt ¶
AssignStmt represents an assignment statement.
func (*AssignStmt) End ¶
func (s *AssignStmt) End() Pos
End returns the position of first character immediately after the node.
func (*AssignStmt) Pos ¶
func (s *AssignStmt) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*AssignStmt) String ¶
func (s *AssignStmt) String() string
type BadExpr ¶
BadExpr represents a bad expression.
type BadStmt ¶
BadStmt represents a bad statement.
type BinaryExpr ¶
BinaryExpr represents a binary operator expression.
func (*BinaryExpr) End ¶
func (e *BinaryExpr) End() Pos
End returns the position of first character immediately after the node.
func (*BinaryExpr) Pos ¶
func (e *BinaryExpr) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*BinaryExpr) String ¶
func (e *BinaryExpr) String() string
type BlockStmt ¶
BlockStmt represents a block statement.
type BoolLit ¶
BoolLit represents a boolean literal.
type BranchStmt ¶
BranchStmt represents a branch statement.
func (*BranchStmt) End ¶
func (s *BranchStmt) End() Pos
End returns the position of first character immediately after the node.
func (*BranchStmt) Pos ¶
func (s *BranchStmt) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*BranchStmt) String ¶
func (s *BranchStmt) String() string
type CallExpr ¶
CallExpr represents a function call expression.
type CharLit ¶
CharLit represents a character literal.
type CondExpr ¶
CondExpr represents a ternary conditional expression.
type EmptyStmt ¶
EmptyStmt represents an empty statement.
type ErrorExpr ¶
ErrorExpr represents an error expression
type ErrorList ¶
type ErrorList []*Error
ErrorList is a collection of parser errors.
func (*ErrorList) Add ¶
func (p *ErrorList) Add(pos SourceFilePos, msg string)
Add adds a new parser error to the collection.
type ExportStmt ¶
ExportStmt represents an export statement.
func (*ExportStmt) End ¶
func (s *ExportStmt) End() Pos
End returns the position of first character immediately after the node.
func (*ExportStmt) Pos ¶
func (s *ExportStmt) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*ExportStmt) String ¶
func (s *ExportStmt) String() string
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
Expr represents an expression node in the AST.
type ExprStmt ¶
type ExprStmt struct {
Expr Expr
}
ExprStmt represents an expression statement.
type File ¶
type File struct { InputFile *SourceFile Stmts []Stmt }
File represents a file unit.
type FloatLit ¶
FloatLit represents a floating point literal.
type ForInStmt ¶
ForInStmt represents a for-in statement.
type ForStmt ¶
ForStmt represents a for statement.
type FuncLit ¶
FuncLit represents a function literal.
type FuncType ¶
FuncType represents a function type definition.
type Ident ¶
Ident represents an identifier.
type IdentList ¶
IdentList represents a list of identifiers.
type IfStmt ¶
type IfStmt struct { IfPos Pos Init Stmt Cond Expr Body *BlockStmt Else Stmt // else branch; or nil }
IfStmt represents an if statement.
type ImmutableExpr ¶
ImmutableExpr represents an immutable expression
func (*ImmutableExpr) End ¶
func (e *ImmutableExpr) End() Pos
End returns the position of first character immediately after the node.
func (*ImmutableExpr) Pos ¶
func (e *ImmutableExpr) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*ImmutableExpr) String ¶
func (e *ImmutableExpr) String() string
type ImportExpr ¶
ImportExpr represents an import expression
func (*ImportExpr) End ¶
func (e *ImportExpr) End() Pos
End returns the position of first character immediately after the node.
func (*ImportExpr) Pos ¶
func (e *ImportExpr) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*ImportExpr) String ¶
func (e *ImportExpr) String() string
type IncDecStmt ¶
IncDecStmt represents increment or decrement statement.
func (*IncDecStmt) End ¶
func (s *IncDecStmt) End() Pos
End returns the position of first character immediately after the node.
func (*IncDecStmt) Pos ¶
func (s *IncDecStmt) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*IncDecStmt) String ¶
func (s *IncDecStmt) String() string
type IndexExpr ¶
IndexExpr represents an index expression.
type IntLit ¶
IntLit represents an integer literal.
type MapElementLit ¶
MapElementLit represents a map element.
func (*MapElementLit) End ¶
func (e *MapElementLit) End() Pos
End returns the position of first character immediately after the node.
func (*MapElementLit) Pos ¶
func (e *MapElementLit) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*MapElementLit) String ¶
func (e *MapElementLit) String() string
type MapLit ¶
type MapLit struct { LBrace Pos Elements []*MapElementLit RBrace Pos }
MapLit represents a map literal.
type Node ¶
type Node interface { // Pos returns the position of first character belonging to the node. Pos() Pos // End returns the position of first character immediately after the node. End() Pos // String returns a string representation of the node. String() string }
Node represents a node in the AST.
type Opcode ¶
type Opcode = byte
Opcode represents a single byte operation code.
const ( OpConstant Opcode = iota // Load constant OpBComplement // bitwise complement OpPop // Pop OpTrue // Push true OpFalse // Push false OpEqual // Equal == OpNotEqual // Not equal != OpMinus // Minus - OpLNot // Logical not ! OpJumpFalsy // Jump if falsy OpAndJump // Logical AND jump OpOrJump // Logical OR jump OpJump // Jump OpNull // Push null OpArray // Array object OpMap // Map object OpError // Error object OpImmutable // Immutable object OpIndex // Index operation OpSliceIndex // Slice operation OpCall // Call function OpReturn // Return OpGetGlobal // Get global variable OpSetGlobal // Set global variable OpSetSelGlobal // Set global variable using selectors OpGetLocal // Get local variable OpSetLocal // Set local variable OpDefineLocal // Define local variable OpSetSelLocal // Set local variable using selectors OpGetFreePtr // Get free variable pointer object OpGetFree // Get free variables OpSetFree // Set free variables OpGetLocalPtr // Get local variable as a pointer OpSetSelFree // Set free variables using selectors OpGetBuiltin // Get builtin function OpClosure // Push closure OpIteratorInit // Iterator init OpIteratorNext // Iterator next OpIteratorKey // Iterator key OpIteratorValue // Iterator value OpBinaryOp // Binary operation OpSuspend // Suspend VM )
List of opcodes
type ParenExpr ¶
ParenExpr represents a parenthesis wrapped expression.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses the Tengo source files. It's based on Go's parser implementation.
type Pos ¶
type Pos int
Pos represents a position in the file set.
const NoPos Pos = 0
NoPos represents an invalid position.
type ReturnStmt ¶
ReturnStmt represents a return statement.
func (*ReturnStmt) End ¶
func (s *ReturnStmt) End() Pos
End returns the position of first character immediately after the node.
func (*ReturnStmt) Pos ¶
func (s *ReturnStmt) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*ReturnStmt) String ¶
func (s *ReturnStmt) String() string
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner reads the Tengo source text. It's based on Go's scanner implementation.
func NewScanner ¶
func NewScanner( file *SourceFile, src []byte, errorHandler ScannerErrorHandler, mode ScanMode, ) *Scanner
NewScanner creates a Scanner.
func (*Scanner) ErrorCount ¶
ErrorCount returns the number of errors.
type ScannerErrorHandler ¶
type ScannerErrorHandler func(pos SourceFilePos, msg string)
ScannerErrorHandler is an error handler for the scanner.
type SelectorExpr ¶
SelectorExpr represents a selector expression.
func (*SelectorExpr) End ¶
func (e *SelectorExpr) End() Pos
End returns the position of first character immediately after the node.
func (*SelectorExpr) Pos ¶
func (e *SelectorExpr) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*SelectorExpr) String ¶
func (e *SelectorExpr) String() string
type SliceExpr ¶
SliceExpr represents a slice expression.
type SourceFile ¶
type SourceFile struct { // SourceFile name as provided to AddFile Name string // SourcePos value range for this file is [base...base+size] Base int // SourceFile size as provided to AddFile Size int // Lines contains the offset of the first character for each line // (the first entry is always 0) Lines []int // contains filtered or unexported fields }
SourceFile represents a source file.
func (*SourceFile) FileSetPos ¶
func (f *SourceFile) FileSetPos(offset int) Pos
FileSetPos returns the position in the file set.
func (*SourceFile) LineCount ¶
func (f *SourceFile) LineCount() int
LineCount returns the current number of lines.
func (*SourceFile) LineStart ¶
func (f *SourceFile) LineStart(line int) Pos
LineStart returns the position of the first character in the line.
func (*SourceFile) Offset ¶
func (f *SourceFile) Offset(p Pos) int
Offset translates the file set position into the file offset.
func (*SourceFile) Position ¶
func (f *SourceFile) Position(p Pos) (pos SourceFilePos)
Position translates the file set position into the file position.
type SourceFilePos ¶
type SourceFilePos struct { Filename string // filename, if any Offset int // offset, starting at 0 Line int // line number, starting at 1 Column int // column number, starting at 1 (byte count) }
SourceFilePos represents a position information in the file.
func (SourceFilePos) IsValid ¶
func (p SourceFilePos) IsValid() bool
IsValid returns true if the position is valid.
func (SourceFilePos) String ¶
func (p SourceFilePos) String() string
String returns a string in one of several forms:
file:line:column valid position with file name file:line valid position with file name but no column (column == 0) line:column valid position without file name line valid position without file name and no column (column == 0) file invalid position with file name - invalid position without file name
type SourceFileSet ¶
type SourceFileSet struct { Base int // base offset for the next file Files []*SourceFile // list of files in the order added to the set LastFile *SourceFile // cache of last file looked up }
SourceFileSet represents a set of source files.
func (*SourceFileSet) AddFile ¶
func (s *SourceFileSet) AddFile(filename string, base, size int) *SourceFile
AddFile adds a new file in the file set.
func (*SourceFileSet) File ¶
func (s *SourceFileSet) File(p Pos) (f *SourceFile)
File returns the file that contains the position p. If no such file is found (for instance for p == NoPos), the result is nil.
func (*SourceFileSet) Position ¶
func (s *SourceFileSet) Position(p Pos) (pos SourceFilePos)
Position converts a SourcePos p in the fileset into a SourceFilePos value.
type Stmt ¶
type Stmt interface { Node // contains filtered or unexported methods }
Stmt represents a statement in the AST.
type StringLit ¶
StringLit represents a string literal.
type UnaryExpr ¶
UnaryExpr represents an unary operator expression.
type UndefinedLit ¶
type UndefinedLit struct {
TokenPos Pos
}
UndefinedLit represents an undefined literal.
func (*UndefinedLit) End ¶
func (e *UndefinedLit) End() Pos
End returns the position of first character immediately after the node.
func (*UndefinedLit) Pos ¶
func (e *UndefinedLit) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*UndefinedLit) String ¶
func (e *UndefinedLit) String() string