Documentation
¶
Index ¶
- Variables
- func AnalyzeFunctionLocals(fn *FunctionLiteral)
- func AnalyzeLambdaLocals(lambda *Lambda)
- func AnalyzeTopLevelLocals(program *Program)
- func DecodeCalleeLocation(v int64) (hops, slotIdx int)
- func EncodeCalleeLocation(hops, slotIdx int) int64
- func EstimateRetainedBytes(program *Program, source string) int
- func FoldConstants(program *Program)
- func IsIntResultOp(op Op) bool
- func IsIntShaped(e Expression) bool
- type AssertStatement
- type AssignStatement
- type AugmentedAssignStatement
- type BlockStatement
- type Boolean
- type BreakStatement
- type BytesLiteral
- type CallExpression
- func (ce *CallExpression) CalleeCache() int64
- func (ce *CallExpression) GetArgsUnpack() []Expression
- func (ce *CallExpression) GetKeywords() map[string]Expression
- func (ce *CallExpression) GetKwargsUnpack() Expression
- func (ce *CallExpression) HasOverflow() bool
- func (ce *CallExpression) Line() int
- func (ce *CallExpression) SetCalleeCache(v int64)
- func (ce *CallExpression) SetOverflow(keywords map[string]Expression, argsUnpack []Expression, ...)
- func (ce *CallExpression) TokenLiteral() string
- type CallOverflow
- type CaseClause
- type ClassStatement
- type CompiledSlot
- type ComprehensionClause
- type ConditionalExpression
- type ContinueStatement
- type DecoratorsOverflow
- type DelStatement
- type DictComprehension
- type DictLiteral
- type DictPairLiteral
- type ElifClause
- type ExceptClause
- type Expression
- type ExpressionStatement
- type FStringLiteral
- func (fsl *FStringLiteral) GetConversions() []string
- func (fsl *FStringLiteral) GetDebugTexts() []string
- func (fsl *FStringLiteral) GetFormatSpecs() []string
- func (fsl *FStringLiteral) Line() int
- func (fsl *FStringLiteral) SetConversions(convs []string)
- func (fsl *FStringLiteral) SetDebugTexts(texts []string)
- func (fsl *FStringLiteral) SetFormatSpecs(specs []string)
- func (fsl *FStringLiteral) TokenLiteral() string
- type FStringOverflow
- type FloatLiteral
- type ForStatement
- type FromImportStatement
- type FuncOverflow
- type FunctionLiteral
- func (fl *FunctionLiteral) GetDefaultValues() map[string]Expression
- func (fl *FunctionLiteral) GetKeywordOnlyStart() int
- func (fl *FunctionLiteral) GetKwargs() *Identifier
- func (fl *FunctionLiteral) GetVariadic() *Identifier
- func (fl *FunctionLiteral) Line() int
- func (fl *FunctionLiteral) SetFuncOverflow(dv map[string]Expression, variadic, kwargs *Identifier, keywordOnlyStart int)
- func (fl *FunctionLiteral) TokenLiteral() string
- type FunctionStatement
- type GlobalStatement
- type Identifier
- type IfStatement
- type ImportOverflow
- type ImportStatement
- func (is *ImportStatement) AppendAdditionalAlias(alias *Identifier)
- func (is *ImportStatement) AppendAdditionalName(name *Identifier)
- func (is *ImportStatement) FullName() string
- func (is *ImportStatement) GetAdditionalAliases() []*Identifier
- func (is *ImportStatement) GetAdditionalNames() []*Identifier
- func (is *ImportStatement) GetAlias() *Identifier
- func (is *ImportStatement) Line() int
- func (is *ImportStatement) SetImportOverflow(alias *Identifier, names, aliases []*Identifier)
- func (is *ImportStatement) TokenLiteral() string
- type IndexExpression
- type IndexTargetSlots
- type InfixExpression
- type IntFastKind
- type IntegerLiteral
- type Lambda
- func (l *Lambda) GetDefaultValues() map[string]Expression
- func (l *Lambda) GetKeywordOnlyStart() int
- func (l *Lambda) GetKwargs() *Identifier
- func (l *Lambda) GetVariadic() *Identifier
- func (l *Lambda) Line() int
- func (l *Lambda) SetFuncOverflow(dv map[string]Expression, variadic, kwargs *Identifier, keywordOnlyStart int)
- func (l *Lambda) TokenLiteral() string
- type LineInfo
- type ListComprehension
- type ListLiteral
- type MatchStatement
- type MethodCallExpression
- func (mce *MethodCallExpression) GetArgsUnpack() []Expression
- func (mce *MethodCallExpression) GetKeywords() map[string]Expression
- func (mce *MethodCallExpression) GetKwargsUnpack() Expression
- func (mce *MethodCallExpression) HasOverflow() bool
- func (mce *MethodCallExpression) Line() int
- func (mce *MethodCallExpression) SetOverflow(keywords map[string]Expression, argsUnpack []Expression, ...)
- func (mce *MethodCallExpression) TokenLiteral() string
- type MultipleAssignStatement
- type Node
- type None
- type NonlocalStatement
- type Op
- type OrPattern
- type PassStatement
- type PrefixExpression
- type Program
- type RaiseStatement
- type ReturnStatement
- type SetComprehension
- type SetLiteral
- type SliceExpression
- type SliceOverflow
- type SliceTargetSlots
- type Statement
- type StringLiteral
- type SymbolTable
- type TryStatement
- type TupleLiteral
- type WalrusExpression
- type WhileStatement
- type WithStatement
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AnalyzeFunctionLocals ¶ added in v0.8.0
func AnalyzeFunctionLocals(fn *FunctionLiteral)
func AnalyzeLambdaLocals ¶ added in v0.8.0
func AnalyzeLambdaLocals(lambda *Lambda)
func AnalyzeTopLevelLocals ¶ added in v0.8.0
func AnalyzeTopLevelLocals(program *Program)
func DecodeCalleeLocation ¶ added in v0.15.0
DecodeCalleeLocation unpacks a packed location into hops and slot index.
func EncodeCalleeLocation ¶ added in v0.15.0
EncodeCalleeLocation packs an environment-chain location into the calleeCache representation (always > 0 since slotIdx >= 0).
func EstimateRetainedBytes ¶ added in v0.8.0
EstimateRetainedBytes approximates the retained heap size of a parsed AST together with the evaluator's compiled form of it, which is built once per program and retained alongside it. The source script is counted separately by callers, so strings that alias the source backing bytes are not charged again here.
func FoldConstants ¶ added in v0.9.2
func FoldConstants(program *Program)
FoldConstants replaces constant sub-expressions with their evaluated literal values. It walks the entire AST including nested function bodies, class bodies, and all blocks.
func IsIntResultOp ¶ added in v0.20.0
IsIntResultOp reports whether op yields an integer when applied to two integers. OpDiv is excluded because it always produces a float, and OpPow because it promotes to float for large or negative exponents.
func IsIntShaped ¶ added in v0.20.0
func IsIntShaped(e Expression) bool
IsIntShaped reports whether e can evaluate to an integer using only side-effect-free operations: an integer literal, an identifier read, or integer arithmetic over two such subtrees.
Types ¶
type AssertStatement ¶
type AssertStatement struct {
Token LineInfo
Condition Expression
Message Expression // Optional
}
func (*AssertStatement) Line ¶
func (as *AssertStatement) Line() int
func (*AssertStatement) TokenLiteral ¶
func (as *AssertStatement) TokenLiteral() string
type AssignStatement ¶
type AssignStatement struct {
Token LineInfo
Left Expression
Value Expression
Chained *AssignStatement // for chained assignment: a = b = 5
}
func (*AssignStatement) Line ¶
func (as *AssignStatement) Line() int
func (*AssignStatement) TokenLiteral ¶
func (as *AssignStatement) TokenLiteral() string
type AugmentedAssignStatement ¶
type AugmentedAssignStatement struct {
Token LineInfo
Name *Identifier
Left Expression
Operator Op
Value Expression
}
func (*AugmentedAssignStatement) Line ¶
func (aas *AugmentedAssignStatement) Line() int
func (*AugmentedAssignStatement) TokenLiteral ¶
func (aas *AugmentedAssignStatement) TokenLiteral() string
type BlockStatement ¶
type BlockStatement struct {
Token LineInfo
Statements []Statement
// Compiled caches the evaluator's compiled form of this block for
// function objects assembled without one (see evaluator.functionBody).
Compiled CompiledSlot
}
func (*BlockStatement) Line ¶
func (bs *BlockStatement) Line() int
func (*BlockStatement) TokenLiteral ¶
func (bs *BlockStatement) TokenLiteral() string
type BreakStatement ¶
type BreakStatement struct {
Token LineInfo
}
func (*BreakStatement) Line ¶
func (bs *BreakStatement) Line() int
func (*BreakStatement) TokenLiteral ¶
func (bs *BreakStatement) TokenLiteral() string
type BytesLiteral ¶ added in v0.27.0
type BytesLiteral struct {
Value []byte
}
func (*BytesLiteral) Line ¶ added in v0.27.0
func (bl *BytesLiteral) Line() int
func (*BytesLiteral) TokenLiteral ¶ added in v0.27.0
func (bl *BytesLiteral) TokenLiteral() string
type CallExpression ¶
type CallExpression struct {
Function Expression
Arguments []Expression
// contains filtered or unexported fields
}
func (*CallExpression) CalleeCache ¶ added in v0.15.0
func (ce *CallExpression) CalleeCache() int64
CalleeCache returns the raw cached callee location (see calleeCache encoding).
func (*CallExpression) GetArgsUnpack ¶ added in v0.8.0
func (ce *CallExpression) GetArgsUnpack() []Expression
func (*CallExpression) GetKeywords ¶ added in v0.8.0
func (ce *CallExpression) GetKeywords() map[string]Expression
func (*CallExpression) GetKwargsUnpack ¶ added in v0.8.0
func (ce *CallExpression) GetKwargsUnpack() Expression
func (*CallExpression) HasOverflow ¶ added in v0.8.0
func (ce *CallExpression) HasOverflow() bool
func (*CallExpression) Line ¶
func (ce *CallExpression) Line() int
func (*CallExpression) SetCalleeCache ¶ added in v0.15.0
func (ce *CallExpression) SetCalleeCache(v int64)
SetCalleeCache stores a resolved callee location.
func (*CallExpression) SetOverflow ¶ added in v0.8.0
func (ce *CallExpression) SetOverflow(keywords map[string]Expression, argsUnpack []Expression, kwargsUnpack Expression)
func (*CallExpression) TokenLiteral ¶
func (ce *CallExpression) TokenLiteral() string
type CallOverflow ¶ added in v0.8.0
type CallOverflow struct {
Keywords map[string]Expression
ArgsUnpack []Expression
KwargsUnpack Expression
}
type CaseClause ¶
type CaseClause struct {
Token LineInfo // The 'case' token
Pattern Expression // The pattern to match (can be literal, identifier for type, dict, or wildcard)
Guard Expression // Optional guard condition (if clause)
Body *BlockStatement
CaptureAs *Identifier // Optional capture variable for the matched value
}
CaseClause represents a single case in a match statement
type ClassStatement ¶
type ClassStatement struct {
Token LineInfo
Name *Identifier
BaseClass Expression
Body *BlockStatement
// contains filtered or unexported fields
}
func (*ClassStatement) GetDecorators ¶ added in v0.8.0
func (cs *ClassStatement) GetDecorators() []Expression
func (*ClassStatement) Line ¶
func (cs *ClassStatement) Line() int
func (*ClassStatement) SetDecorators ¶ added in v0.8.0
func (cs *ClassStatement) SetDecorators(decorators []Expression)
func (*ClassStatement) TokenLiteral ¶
func (cs *ClassStatement) TokenLiteral() string
type CompiledSlot ¶ added in v0.27.2
type CompiledSlot struct {
// contains filtered or unexported fields
}
CompiledSlot caches the evaluator's compiled form of one expression on the node that owns it. It holds an opaque value because ast cannot import the evaluator's types; the evaluator stores and asserts the concrete type. The zero value is ready to use, and a slot is written at most once per process (two racing writers store equivalent closures).
func (*CompiledSlot) Load ¶ added in v0.27.2
func (s *CompiledSlot) Load() any
Load returns the cached compiled form, or nil if none has been stored.
func (*CompiledSlot) Store ¶ added in v0.27.2
func (s *CompiledSlot) Store(v any)
Store caches the compiled form.
type ComprehensionClause ¶ added in v0.3.2
type ComprehensionClause struct {
Variables []Expression
Iterable Expression
Condition Expression // optional
}
ComprehensionClause represents an additional `for var in iterable [if cond]` clause
type ConditionalExpression ¶
type ConditionalExpression struct {
TrueExpr Expression
Condition Expression
FalseExpr Expression
}
func (*ConditionalExpression) Line ¶
func (ce *ConditionalExpression) Line() int
func (*ConditionalExpression) TokenLiteral ¶
func (ce *ConditionalExpression) TokenLiteral() string
type ContinueStatement ¶
type ContinueStatement struct {
Token LineInfo
}
func (*ContinueStatement) Line ¶
func (cs *ContinueStatement) Line() int
func (*ContinueStatement) TokenLiteral ¶
func (cs *ContinueStatement) TokenLiteral() string
type DecoratorsOverflow ¶ added in v0.8.0
type DecoratorsOverflow struct {
Decorators []Expression
}
type DelStatement ¶ added in v0.5.5
type DelStatement struct {
Token LineInfo
Target Expression
// ExtraTargets holds additional targets for "del a, b, c".
ExtraTargets []Expression
}
func (*DelStatement) Line ¶ added in v0.5.5
func (ds *DelStatement) Line() int
func (*DelStatement) TokenLiteral ¶ added in v0.5.5
func (ds *DelStatement) TokenLiteral() string
type DictComprehension ¶ added in v0.2.0
type DictComprehension struct {
Key Expression
Value Expression
Variables []Expression
Iterable Expression
Condition Expression // optional
AdditionalClauses []ComprehensionClause // additional for clauses
}
func (*DictComprehension) Line ¶ added in v0.2.0
func (dc *DictComprehension) Line() int
func (*DictComprehension) TokenLiteral ¶ added in v0.2.0
func (dc *DictComprehension) TokenLiteral() string
type DictLiteral ¶
type DictLiteral struct {
Pairs []DictPairLiteral
}
func (*DictLiteral) Line ¶
func (dl *DictLiteral) Line() int
func (*DictLiteral) TokenLiteral ¶
func (dl *DictLiteral) TokenLiteral() string
type DictPairLiteral ¶ added in v0.5.2
type DictPairLiteral struct {
Key Expression
Value Expression
}
type ElifClause ¶
type ElifClause struct {
Token LineInfo
Condition Expression
Consequence *BlockStatement
}
type ExceptClause ¶
type ExceptClause struct {
Token LineInfo
ExceptType Expression // exception type to catch
ExceptVar *Identifier // variable to bind exception to
Body *BlockStatement
}
type Expression ¶
type Expression interface {
Node
// contains filtered or unexported methods
}
type ExpressionStatement ¶
type ExpressionStatement struct {
Token LineInfo
Expression Expression
}
func (*ExpressionStatement) Line ¶
func (es *ExpressionStatement) Line() int
func (*ExpressionStatement) TokenLiteral ¶
func (es *ExpressionStatement) TokenLiteral() string
type FStringLiteral ¶
type FStringLiteral struct {
Value string
Expressions []Expression
Parts []string
// contains filtered or unexported fields
}
func (*FStringLiteral) GetConversions ¶ added in v0.25.0
func (fsl *FStringLiteral) GetConversions() []string
GetConversions returns the per-expression conversion flags ("r", "s", "a" or ""), aligned with Expressions.
func (*FStringLiteral) GetDebugTexts ¶ added in v0.27.0
func (fsl *FStringLiteral) GetDebugTexts() []string
GetDebugTexts returns the per-expression "=" debug prefixes, aligned with Expressions (empty when the field has no = suffix).
func (*FStringLiteral) GetFormatSpecs ¶ added in v0.8.0
func (fsl *FStringLiteral) GetFormatSpecs() []string
func (*FStringLiteral) Line ¶
func (fsl *FStringLiteral) Line() int
func (*FStringLiteral) SetConversions ¶ added in v0.25.0
func (fsl *FStringLiteral) SetConversions(convs []string)
SetConversions stores per-expression conversion flags, creating the overflow lazily so plain f-strings without specs stay allocation-free.
func (*FStringLiteral) SetDebugTexts ¶ added in v0.27.0
func (fsl *FStringLiteral) SetDebugTexts(texts []string)
SetDebugTexts stores per-expression debug prefixes, creating the overflow lazily like the other f-string extras.
func (*FStringLiteral) SetFormatSpecs ¶ added in v0.8.0
func (fsl *FStringLiteral) SetFormatSpecs(specs []string)
func (*FStringLiteral) TokenLiteral ¶
func (fsl *FStringLiteral) TokenLiteral() string
type FStringOverflow ¶ added in v0.8.0
type FloatLiteral ¶
type FloatLiteral struct {
Value float64
}
func (*FloatLiteral) Line ¶
func (fl *FloatLiteral) Line() int
func (*FloatLiteral) TokenLiteral ¶
func (fl *FloatLiteral) TokenLiteral() string
type ForStatement ¶
type ForStatement struct {
Token LineInfo
Variables []Expression
Iterable Expression
Body *BlockStatement
Else *BlockStatement // optional else clause
}
func (*ForStatement) Line ¶
func (fs *ForStatement) Line() int
func (*ForStatement) TokenLiteral ¶
func (fs *ForStatement) TokenLiteral() string
type FromImportStatement ¶
type FromImportStatement struct {
Token LineInfo // The 'from' token
Module *Identifier // The module name (e.g., "bs4" or "urllib.parse"), nil for "from . import X"
Names []*Identifier // The names to import (e.g., ["BeautifulSoup"])
Aliases []*Identifier // Optional aliases (for "import X as Y"), nil if no alias
RelativeLevel int // Number of leading dots for relative imports (0 = absolute, 1 = ".", 2 = "..", etc.)
}
FromImportStatement represents "from X import Y, Z" statements Also supports relative imports: "from . import X", "from .. import X", "from .module import X"
func (*FromImportStatement) Line ¶
func (fis *FromImportStatement) Line() int
func (*FromImportStatement) TokenLiteral ¶
func (fis *FromImportStatement) TokenLiteral() string
type FuncOverflow ¶ added in v0.8.0
type FuncOverflow struct {
DefaultValues map[string]Expression
Variadic *Identifier
Kwargs *Identifier
KeywordOnlyStart int
}
type FunctionLiteral ¶
type FunctionLiteral struct {
Parameters []*Identifier
Body *BlockStatement
HasNestedFunc bool
LocalSlots map[string]int
LocalSlotNames []string
ParamSlotIndexes []int
// contains filtered or unexported fields
}
func (*FunctionLiteral) GetDefaultValues ¶ added in v0.8.0
func (fl *FunctionLiteral) GetDefaultValues() map[string]Expression
func (*FunctionLiteral) GetKeywordOnlyStart ¶ added in v0.9.1
func (fl *FunctionLiteral) GetKeywordOnlyStart() int
func (*FunctionLiteral) GetKwargs ¶ added in v0.8.0
func (fl *FunctionLiteral) GetKwargs() *Identifier
func (*FunctionLiteral) GetVariadic ¶ added in v0.8.0
func (fl *FunctionLiteral) GetVariadic() *Identifier
func (*FunctionLiteral) Line ¶
func (fl *FunctionLiteral) Line() int
func (*FunctionLiteral) SetFuncOverflow ¶ added in v0.8.0
func (fl *FunctionLiteral) SetFuncOverflow(dv map[string]Expression, variadic, kwargs *Identifier, keywordOnlyStart int)
func (*FunctionLiteral) TokenLiteral ¶
func (fl *FunctionLiteral) TokenLiteral() string
type FunctionStatement ¶
type FunctionStatement struct {
Token LineInfo
Name *Identifier
Function *FunctionLiteral
// contains filtered or unexported fields
}
func (*FunctionStatement) GetDecorators ¶ added in v0.8.0
func (fs *FunctionStatement) GetDecorators() []Expression
func (*FunctionStatement) Line ¶
func (fs *FunctionStatement) Line() int
func (*FunctionStatement) SetDecorators ¶ added in v0.8.0
func (fs *FunctionStatement) SetDecorators(decorators []Expression)
func (*FunctionStatement) TokenLiteral ¶
func (fs *FunctionStatement) TokenLiteral() string
type GlobalStatement ¶
type GlobalStatement struct {
Token LineInfo
Names []*Identifier
}
func (*GlobalStatement) Line ¶
func (gs *GlobalStatement) Line() int
func (*GlobalStatement) TokenLiteral ¶
func (gs *GlobalStatement) TokenLiteral() string
type Identifier ¶
type Identifier struct {
Token LineInfo
Symbols *SymbolTable
Name uint32
// Slot cache for fast local variable access.
// 0 = uncached (zero value), -1 = not a local slot, >0 = slot index + 1.
SlotCache atomic.Int32
}
func NewIdentifier ¶ added in v0.8.0
func NewIdentifier(tok token.Token, symbols *SymbolTable, value string) *Identifier
func NewIdentifierWithLine ¶ added in v0.8.0
func NewIdentifierWithLine(line LineInfo, symbols *SymbolTable, value string) *Identifier
func (*Identifier) Line ¶
func (i *Identifier) Line() int
func (*Identifier) TokenLiteral ¶
func (i *Identifier) TokenLiteral() string
func (*Identifier) Value ¶
func (i *Identifier) Value() string
type IfStatement ¶
type IfStatement struct {
Token LineInfo
Condition Expression
Consequence *BlockStatement
ElifClauses []*ElifClause
Alternative *BlockStatement
}
func (*IfStatement) Line ¶
func (is *IfStatement) Line() int
func (*IfStatement) TokenLiteral ¶
func (is *IfStatement) TokenLiteral() string
type ImportOverflow ¶ added in v0.8.0
type ImportOverflow struct {
Alias *Identifier
AdditionalNames []*Identifier
AdditionalAliases []*Identifier
}
type ImportStatement ¶
type ImportStatement struct {
Token LineInfo
Name *Identifier
// contains filtered or unexported fields
}
func (*ImportStatement) AppendAdditionalAlias ¶ added in v0.8.0
func (is *ImportStatement) AppendAdditionalAlias(alias *Identifier)
func (*ImportStatement) AppendAdditionalName ¶ added in v0.8.0
func (is *ImportStatement) AppendAdditionalName(name *Identifier)
func (*ImportStatement) FullName ¶
func (is *ImportStatement) FullName() string
FullName returns the complete import name (handles dotted imports like urllib.parse)
func (*ImportStatement) GetAdditionalAliases ¶ added in v0.8.0
func (is *ImportStatement) GetAdditionalAliases() []*Identifier
func (*ImportStatement) GetAdditionalNames ¶ added in v0.8.0
func (is *ImportStatement) GetAdditionalNames() []*Identifier
func (*ImportStatement) GetAlias ¶ added in v0.8.0
func (is *ImportStatement) GetAlias() *Identifier
func (*ImportStatement) Line ¶
func (is *ImportStatement) Line() int
func (*ImportStatement) SetImportOverflow ¶ added in v0.8.0
func (is *ImportStatement) SetImportOverflow(alias *Identifier, names, aliases []*Identifier)
func (*ImportStatement) TokenLiteral ¶
func (is *ImportStatement) TokenLiteral() string
type IndexExpression ¶
type IndexExpression struct {
Token LineInfo
Left Expression
Index Expression
IsDotAccess bool // true when desugared from dot notation (obj.attr)
// contains filtered or unexported fields
}
func (*IndexExpression) Line ¶
func (ie *IndexExpression) Line() int
func (*IndexExpression) TargetSlots ¶ added in v0.27.2
func (ie *IndexExpression) TargetSlots() *IndexTargetSlots
TargetSlots returns the node's target slots, allocating them on first use.
func (*IndexExpression) TokenLiteral ¶
func (ie *IndexExpression) TokenLiteral() string
type IndexTargetSlots ¶ added in v0.27.2
type IndexTargetSlots struct {
Left, Index CompiledSlot
}
IndexTargetSlots holds the compiled sub-expressions of an IndexExpression used as an assignment or deletion target.
type InfixExpression ¶
type InfixExpression struct {
Left Expression
Operator Op
// IntFast is set by the parser; see IntFastKind. It occupies padding next to
// Operator, so it costs no extra memory per node.
IntFast IntFastKind
Right Expression
}
func (*InfixExpression) Line ¶
func (ie *InfixExpression) Line() int
func (*InfixExpression) SetIntFast ¶ added in v0.20.0
func (ie *InfixExpression) SetIntFast()
SetIntFast computes and stores ie.IntFast from its operands. Callers that build or rewrite an InfixExpression must call this so the evaluator's fast path stays available; leaving it unset only costs performance, never correctness.
func (*InfixExpression) TokenLiteral ¶
func (ie *InfixExpression) TokenLiteral() string
type IntFastKind ¶ added in v0.20.0
type IntFastKind uint8
IntFastKind classifies an infix node for the evaluator's unboxed-integer fast path (see evaluator/intfast.go). It is a purely structural classification computed once by the parser: it says nothing about runtime types, since a variable may still turn out to hold a float. Its job is to let the evaluator reject the overwhelming majority of nodes with a single byte comparison rather than re-inspecting the tree on every evaluation.
const ( // IntFastNone: not a candidate. Either an operand is not integer-shaped // (a call, an attribute, a float literal, a string) or the operator does not // take integer operands. IntFastNone IntFastKind = iota // IntFastArith: integer-shaped operands, integer result. IntFastArith // IntFastCompare: integer-shaped operands, boolean result. IntFastCompare )
type IntegerLiteral ¶
type IntegerLiteral struct {
Value int64
}
func (*IntegerLiteral) Line ¶
func (il *IntegerLiteral) Line() int
func (*IntegerLiteral) TokenLiteral ¶
func (il *IntegerLiteral) TokenLiteral() string
type Lambda ¶
type Lambda struct {
Parameters []*Identifier
Body Expression
LocalSlots map[string]int
LocalSlotNames []string
ParamSlotIndexes []int
// contains filtered or unexported fields
}
func (*Lambda) GetDefaultValues ¶ added in v0.8.0
func (l *Lambda) GetDefaultValues() map[string]Expression
func (*Lambda) GetKeywordOnlyStart ¶ added in v0.9.1
func (*Lambda) GetKwargs ¶ added in v0.8.0
func (l *Lambda) GetKwargs() *Identifier
func (*Lambda) GetVariadic ¶ added in v0.8.0
func (l *Lambda) GetVariadic() *Identifier
func (*Lambda) SetFuncOverflow ¶ added in v0.8.0
func (l *Lambda) SetFuncOverflow(dv map[string]Expression, variadic, kwargs *Identifier, keywordOnlyStart int)
func (*Lambda) TokenLiteral ¶
type LineInfo ¶ added in v0.8.0
type LineInfo struct {
Line int32
}
func NewLineInfo ¶ added in v0.8.0
type ListComprehension ¶
type ListComprehension struct {
Expression Expression
Variables []Expression // supports tuple unpacking like: for h, t in ...
Iterable Expression
Condition Expression // optional
AdditionalClauses []ComprehensionClause // additional for clauses
}
func (*ListComprehension) Line ¶
func (lc *ListComprehension) Line() int
func (*ListComprehension) TokenLiteral ¶
func (lc *ListComprehension) TokenLiteral() string
type ListLiteral ¶
type ListLiteral struct {
Elements []Expression
}
func (*ListLiteral) Line ¶
func (ll *ListLiteral) Line() int
func (*ListLiteral) TokenLiteral ¶
func (ll *ListLiteral) TokenLiteral() string
type MatchStatement ¶
type MatchStatement struct {
Token LineInfo // The 'match' token
Subject Expression // The expression to match against
Cases []*CaseClause
}
MatchStatement represents a match statement with multiple case clauses
func (*MatchStatement) Line ¶
func (ms *MatchStatement) Line() int
func (*MatchStatement) TokenLiteral ¶
func (ms *MatchStatement) TokenLiteral() string
type MethodCallExpression ¶
type MethodCallExpression struct {
Receiver Expression
Method *Identifier
Arguments []Expression
// contains filtered or unexported fields
}
func (*MethodCallExpression) GetArgsUnpack ¶ added in v0.8.0
func (mce *MethodCallExpression) GetArgsUnpack() []Expression
func (*MethodCallExpression) GetKeywords ¶ added in v0.8.0
func (mce *MethodCallExpression) GetKeywords() map[string]Expression
func (*MethodCallExpression) GetKwargsUnpack ¶ added in v0.8.0
func (mce *MethodCallExpression) GetKwargsUnpack() Expression
func (*MethodCallExpression) HasOverflow ¶ added in v0.8.0
func (mce *MethodCallExpression) HasOverflow() bool
func (*MethodCallExpression) Line ¶
func (mce *MethodCallExpression) Line() int
func (*MethodCallExpression) SetOverflow ¶ added in v0.8.0
func (mce *MethodCallExpression) SetOverflow(keywords map[string]Expression, argsUnpack []Expression, kwargsUnpack Expression)
func (*MethodCallExpression) TokenLiteral ¶
func (mce *MethodCallExpression) TokenLiteral() string
type MultipleAssignStatement ¶
type MultipleAssignStatement struct {
Token LineInfo
Names []*Identifier
Value Expression
StarredIndex int // Index of starred variable (-1 if none)
}
func (*MultipleAssignStatement) Line ¶
func (mas *MultipleAssignStatement) Line() int
func (*MultipleAssignStatement) TokenLiteral ¶
func (mas *MultipleAssignStatement) TokenLiteral() string
type NonlocalStatement ¶
type NonlocalStatement struct {
Token LineInfo
Names []*Identifier
}
func (*NonlocalStatement) Line ¶
func (ns *NonlocalStatement) Line() int
func (*NonlocalStatement) TokenLiteral ¶
func (ns *NonlocalStatement) TokenLiteral() string
type Op ¶ added in v0.8.0
type Op byte
const ( OpNil Op = iota // Arithmetic group (1-12): OpAdd..OpDiv OpAdd OpSub OpMul OpFloorDiv OpMod OpPow OpBitAnd OpBitOr OpBitXor OpLShift OpRShift OpDiv // Comparison group (13-18): OpLt..OpNeq OpLt OpGt OpLte OpGte OpEq OpNeq // Short-circuit logical OpAnd OpOr // Membership/Identity OpIn OpNotIn OpIs OpIsNot // Prefix OpNot OpBitNot OpPos // Augmented assignment: base op + opAugOffset OpAddEq OpSubEq OpMulEq OpFloorDivEq OpModEq OpPowEq OpBitAndEq OpBitOrEq OpBitXorEq OpLShiftEq OpRShiftEq OpDivEq )
func (Op) IsArithmetic ¶ added in v0.8.0
func (Op) IsComparison ¶ added in v0.8.0
type OrPattern ¶ added in v0.2.0
type OrPattern struct {
Patterns []Expression
}
OrPattern represents a pattern like `case 1 | 2 | 3:`
func (*OrPattern) TokenLiteral ¶ added in v0.2.0
type PassStatement ¶
type PassStatement struct {
Token LineInfo
}
func (*PassStatement) Line ¶
func (ps *PassStatement) Line() int
func (*PassStatement) TokenLiteral ¶
func (ps *PassStatement) TokenLiteral() string
type PrefixExpression ¶
type PrefixExpression struct {
Operator Op
Right Expression
}
func (*PrefixExpression) Line ¶
func (pe *PrefixExpression) Line() int
func (*PrefixExpression) TokenLiteral ¶
func (pe *PrefixExpression) TokenLiteral() string
type Program ¶
type Program struct {
Statements []Statement
Symbols *SymbolTable
LocalSlots map[string]int
LocalSlotNames []string
// contains filtered or unexported fields
}
func (*Program) Compiled ¶ added in v0.27.2
Compiled returns the evaluator's compiled form of this program, or nil if it has not been compiled yet.
func (*Program) SetCompiled ¶ added in v0.27.2
SetCompiled stores the evaluator's compiled form of this program.
func (*Program) TokenLiteral ¶
type RaiseStatement ¶
type RaiseStatement struct {
Token LineInfo
Message Expression
}
func (*RaiseStatement) Line ¶
func (rs *RaiseStatement) Line() int
func (*RaiseStatement) TokenLiteral ¶
func (rs *RaiseStatement) TokenLiteral() string
type ReturnStatement ¶
type ReturnStatement struct {
Token LineInfo
ReturnValue Expression
}
func (*ReturnStatement) Line ¶
func (rs *ReturnStatement) Line() int
func (*ReturnStatement) TokenLiteral ¶
func (rs *ReturnStatement) TokenLiteral() string
type SetComprehension ¶ added in v0.2.23
type SetComprehension struct {
Expression Expression
Variables []Expression
Iterable Expression
Condition Expression // optional
AdditionalClauses []ComprehensionClause // additional for clauses
}
func (*SetComprehension) Line ¶ added in v0.2.23
func (sc *SetComprehension) Line() int
func (*SetComprehension) TokenLiteral ¶ added in v0.2.23
func (sc *SetComprehension) TokenLiteral() string
type SetLiteral ¶ added in v0.2.0
type SetLiteral struct {
Elements []Expression
}
func (*SetLiteral) Line ¶ added in v0.2.0
func (sl *SetLiteral) Line() int
func (*SetLiteral) TokenLiteral ¶ added in v0.2.0
func (sl *SetLiteral) TokenLiteral() string
type SliceExpression ¶
type SliceExpression struct {
Left Expression
Start Expression
End Expression
// contains filtered or unexported fields
}
func (*SliceExpression) GetStep ¶ added in v0.8.0
func (se *SliceExpression) GetStep() Expression
func (*SliceExpression) Line ¶
func (se *SliceExpression) Line() int
func (*SliceExpression) SetStep ¶ added in v0.8.0
func (se *SliceExpression) SetStep(step Expression)
func (*SliceExpression) TargetSlots ¶ added in v0.27.2
func (se *SliceExpression) TargetSlots() *SliceTargetSlots
TargetSlots returns the node's target slots, allocating them on first use.
func (*SliceExpression) TokenLiteral ¶
func (se *SliceExpression) TokenLiteral() string
type SliceOverflow ¶ added in v0.8.0
type SliceOverflow struct {
Step Expression
}
type SliceTargetSlots ¶ added in v0.27.2
type SliceTargetSlots struct {
Left, Start, End, Step CompiledSlot
}
SliceTargetSlots holds the compiled parts of a SliceExpression used as an assignment or deletion target.
type StringLiteral ¶
type StringLiteral struct {
Value string
// contains filtered or unexported fields
}
func (*StringLiteral) Boxed ¶ added in v0.20.0
func (sl *StringLiteral) Boxed() any
Boxed returns the cached runtime value for this literal, or nil if unset.
func (*StringLiteral) Line ¶
func (sl *StringLiteral) Line() int
func (*StringLiteral) SetBoxed ¶ added in v0.20.0
func (sl *StringLiteral) SetBoxed(v any)
SetBoxed caches the runtime value for this literal. Callers must always pass the same concrete type, and that value must be immutable — it is shared by every evaluation of this literal.
func (*StringLiteral) TokenLiteral ¶
func (sl *StringLiteral) TokenLiteral() string
type SymbolTable ¶ added in v0.8.0
type SymbolTable struct {
// contains filtered or unexported fields
}
func NewSymbolTable ¶ added in v0.8.0
func NewSymbolTable() *SymbolTable
func (*SymbolTable) Freeze ¶ added in v0.8.0
func (st *SymbolTable) Freeze()
func (*SymbolTable) Intern ¶ added in v0.8.0
func (st *SymbolTable) Intern(name string) uint32
func (*SymbolTable) Resolve ¶ added in v0.8.0
func (st *SymbolTable) Resolve(id uint32) string
type TryStatement ¶
type TryStatement struct {
Token LineInfo
Body *BlockStatement
ExceptClauses []*ExceptClause // multiple except blocks
Else *BlockStatement // runs only when no exception was raised
Finally *BlockStatement
}
func (*TryStatement) Line ¶
func (ts *TryStatement) Line() int
func (*TryStatement) TokenLiteral ¶
func (ts *TryStatement) TokenLiteral() string
type TupleLiteral ¶
type TupleLiteral struct {
Elements []Expression
}
func (*TupleLiteral) Line ¶
func (tl *TupleLiteral) Line() int
func (*TupleLiteral) TokenLiteral ¶
func (tl *TupleLiteral) TokenLiteral() string
type WalrusExpression ¶ added in v0.27.0
type WalrusExpression struct {
Target *Identifier
Value Expression
}
WalrusExpression is an assignment expression (name := value). It binds the value to the target name with the same scoping as an assignment statement and yields the value, so it can be used inline in conditions and calls.
func (*WalrusExpression) Line ¶ added in v0.27.0
func (we *WalrusExpression) Line() int
func (*WalrusExpression) TokenLiteral ¶ added in v0.27.0
func (we *WalrusExpression) TokenLiteral() string
type WhileStatement ¶
type WhileStatement struct {
Token LineInfo
Condition Expression
Body *BlockStatement
Else *BlockStatement // optional else clause
}
func (*WhileStatement) Line ¶
func (ws *WhileStatement) Line() int
func (*WhileStatement) TokenLiteral ¶
func (ws *WhileStatement) TokenLiteral() string
type WithStatement ¶ added in v0.2.0
type WithStatement struct {
Token LineInfo
ContextExpr Expression
Target *Identifier // optional: 'as' binding
Body *BlockStatement
}
func (*WithStatement) Line ¶ added in v0.2.0
func (ws *WithStatement) Line() int
func (*WithStatement) TokenLiteral ¶ added in v0.2.0
func (ws *WithStatement) TokenLiteral() string